use cmp.Diff instead of reflect.DeepEqual
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
665a3cc666
commit
23a3adf8d2
2 changed files with 17 additions and 15 deletions
|
@ -3,7 +3,6 @@ package policy
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
@ -17,6 +16,10 @@ import (
|
||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ipComparer = cmp.Comparer(func(x, y netip.Addr) bool {
|
||||||
|
return x.Compare(y) == 0
|
||||||
|
})
|
||||||
|
|
||||||
func Test(t *testing.T) {
|
func Test(t *testing.T) {
|
||||||
check.TestingT(t)
|
check.TestingT(t)
|
||||||
}
|
}
|
||||||
|
@ -788,8 +791,8 @@ func Test_expandTagOwners(t *testing.T) {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(got, test.want) {
|
if diff := cmp.Diff(test.want, got); diff != "" {
|
||||||
t.Errorf("expandTagOwners() = %v, want %v", got, test.want)
|
t.Errorf("expandTagOwners() = (-want +got):\n%s", diff)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -885,8 +888,8 @@ func Test_expandPorts(t *testing.T) {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(got, test.want) {
|
if diff := cmp.Diff(test.want, got); diff != "" {
|
||||||
t.Errorf("expandPorts() = %v, want %v", got, test.want)
|
t.Errorf("expandPorts() = (-want +got):\n%s", diff)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -946,11 +949,10 @@ func Test_listMachinesInUser(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
if got := filterMachinesByUser(test.args.machines, test.args.user); !reflect.DeepEqual(
|
got := filterMachinesByUser(test.args.machines, test.args.user)
|
||||||
got,
|
|
||||||
test.want,
|
if diff := cmp.Diff(test.want, got); diff != "" {
|
||||||
) {
|
t.Errorf("listMachinesInUser() = (-want +got):\n%s", diff)
|
||||||
t.Errorf("listMachinesInUser() = %v, want %v", got, test.want)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1700,8 +1702,8 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
|
||||||
test.args.nodes,
|
test.args.nodes,
|
||||||
test.args.user,
|
test.args.user,
|
||||||
)
|
)
|
||||||
if !reflect.DeepEqual(got, test.want) {
|
if diff := cmp.Diff(test.want, got, ipComparer); diff != "" {
|
||||||
t.Errorf("excludeCorrectlyTaggedNodes() = %v, want %v", got, test.want)
|
t.Errorf("excludeCorrectlyTaggedNodes() (-want +got):\n%s", diff)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,9 @@ package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
"go4.org/netipx"
|
"go4.org/netipx"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -111,8 +111,8 @@ func Test_parseIPSet(t *testing.T) {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(got, tt.want) {
|
if diff := cmp.Diff(tt.want, got); diff != "" {
|
||||||
t.Errorf("parseIPSet() = %v, want %v", got, tt.want)
|
t.Errorf("parseIPSet() = (-want +got):\n%s", diff)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue