util/slicesx: add EqualSameNil, like slices.Equal but same nilness
Then use it in tailcfg which had it duplicated a couple times. I think we have it a few other places too. And use slices.Equal in wgengine/router too. (found while looking for callers) Updates #cleanup Change-Id: If5350eee9b3ef071882a3db29a305081e4cd9d23 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
72e53749c1
commit
5f5c9142cc
@ -7,6 +7,8 @@ import (
|
||||
"reflect"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
)
|
||||
|
||||
func TestInterleave(t *testing.T) {
|
||||
@ -84,3 +86,14 @@ func TestPartition(t *testing.T) {
|
||||
t.Errorf("odds: got %v, want %v", odds, wantOdds)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEqualSameNil(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
c.Check(EqualSameNil([]string{"a"}, []string{"a"}), qt.Equals, true)
|
||||
c.Check(EqualSameNil([]string{"a"}, []string{"b"}), qt.Equals, false)
|
||||
c.Check(EqualSameNil([]string{"a"}, []string{}), qt.Equals, false)
|
||||
c.Check(EqualSameNil([]string{}, []string{}), qt.Equals, true)
|
||||
c.Check(EqualSameNil(nil, []string{}), qt.Equals, false)
|
||||
c.Check(EqualSameNil([]string{}, nil), qt.Equals, false)
|
||||
c.Check(EqualSameNil[[]string](nil, nil), qt.Equals, true)
|
||||
}
|
||||
|
Reference in New Issue
Block a user