Skip to content

Commit

Permalink
use cmp.Diff instead of reflect.DeepEqual
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Jul 1, 2023
1 parent 665a3cc commit 23a3adf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
26 changes: 14 additions & 12 deletions hscontrol/policy/acls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package policy
import (
"errors"
"net/netip"
"reflect"
"testing"

"github.com/google/go-cmp/cmp"
Expand All @@ -17,6 +16,10 @@ import (
"tailscale.com/tailcfg"
)

var ipComparer = cmp.Comparer(func(x, y netip.Addr) bool {
return x.Compare(y) == 0
})

func Test(t *testing.T) {
check.TestingT(t)
}
Expand Down Expand Up @@ -788,8 +791,8 @@ func Test_expandTagOwners(t *testing.T) {

return
}
if !reflect.DeepEqual(got, test.want) {
t.Errorf("expandTagOwners() = %v, want %v", got, test.want)
if diff := cmp.Diff(test.want, got); diff != "" {
t.Errorf("expandTagOwners() = (-want +got):\n%s", diff)
}
})
}
Expand Down Expand Up @@ -885,8 +888,8 @@ func Test_expandPorts(t *testing.T) {

return
}
if !reflect.DeepEqual(got, test.want) {
t.Errorf("expandPorts() = %v, want %v", got, test.want)
if diff := cmp.Diff(test.want, got); diff != "" {
t.Errorf("expandPorts() = (-want +got):\n%s", diff)
}
})
}
Expand Down Expand Up @@ -946,11 +949,10 @@ func Test_listMachinesInUser(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if got := filterMachinesByUser(test.args.machines, test.args.user); !reflect.DeepEqual(
got,
test.want,
) {
t.Errorf("listMachinesInUser() = %v, want %v", got, test.want)
got := filterMachinesByUser(test.args.machines, test.args.user)

if diff := cmp.Diff(test.want, got); diff != "" {
t.Errorf("listMachinesInUser() = (-want +got):\n%s", diff)
}
})
}
Expand Down Expand Up @@ -1700,8 +1702,8 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
test.args.nodes,
test.args.user,
)
if !reflect.DeepEqual(got, test.want) {
t.Errorf("excludeCorrectlyTaggedNodes() = %v, want %v", got, test.want)
if diff := cmp.Diff(test.want, got, ipComparer); diff != "" {
t.Errorf("excludeCorrectlyTaggedNodes() (-want +got):\n%s", diff)
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions hscontrol/util/addr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package util

import (
"net/netip"
"reflect"
"testing"

"github.com/google/go-cmp/cmp"
"go4.org/netipx"
)

Expand Down Expand Up @@ -111,8 +111,8 @@ func Test_parseIPSet(t *testing.T) {

return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("parseIPSet() = %v, want %v", got, tt.want)
if diff := cmp.Diff(tt.want, got); diff != "" {
t.Errorf("parseIPSet() = (-want +got):\n%s", diff)
}
})
}
Expand Down

0 comments on commit 23a3adf

Please sign in to comment.