diff options
| author | Brad Fitzpatrick <bradfitz@tailscale.com> | 2020-07-27 10:40:34 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@tailscale.com> | 2020-07-27 10:41:06 -0700 |
| commit | e6dbb4425ce4f0a6560b39143645dd1fbe66085b (patch) | |
| tree | ba026418dc6891b13306cacc86b84426b5aeb589 /tailcfg/tailcfg_test.go | |
| parent | 38b0c3eea27564af92416fa2cda9ae52f9aae08a (diff) | |
| download | tailscale-clone.tar.xz tailscale-clone.zip | |
cmd/cloner, tailcfg: fix nil vs len 0 issues, add tests, use for Hostinfoclone
Also use go:generate and https://golang.org/s/generatedcode header style.
Diffstat (limited to 'tailcfg/tailcfg_test.go')
| -rw-r--r-- | tailcfg/tailcfg_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tailcfg/tailcfg_test.go b/tailcfg/tailcfg_test.go index cd35f7647..1ed974f98 100644 --- a/tailcfg/tailcfg_test.go +++ b/tailcfg/tailcfg_test.go @@ -390,3 +390,43 @@ func testKey(t *testing.T, prefix string, in keyIn, out encoding.TextUnmarshaler t.Errorf("mismatch after unmarshal") } } + +func TestCloneUser(t *testing.T) { + tests := []struct { + name string + u *User + }{ + {"nil_logins", &User{}}, + {"zero_logins", &User{Logins: make([]LoginID, 0)}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + u2 := tt.u.Clone() + if !reflect.DeepEqual(tt.u, u2) { + t.Errorf("not equal") + } + }) + } +} + +func TestCloneNode(t *testing.T) { + tests := []struct { + name string + v *Node + }{ + {"nil_fields", &Node{}}, + {"zero_fields", &Node{ + Addresses: make([]wgcfg.CIDR, 0), + AllowedIPs: make([]wgcfg.CIDR, 0), + Endpoints: make([]string, 0), + }}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v2 := tt.v.Clone() + if !reflect.DeepEqual(tt.v, v2) { + t.Errorf("not equal") + } + }) + } +} |
