From 43c1631f26676a092d05d5e286eb11d461282846 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Tue, 1 Feb 2022 16:39:56 +0100 Subject: [PATCH] tests: Use cmp.Equal to avoid mutating arguments --- bill-of-materials.json | 9 +++++++++ go.mod | 2 ++ tests/framework/integration/cluster.go | 13 +++---------- tests/go.mod | 2 ++ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/bill-of-materials.json b/bill-of-materials.json index 0a66e6c54..82254a5aa 100644 --- a/bill-of-materials.json +++ b/bill-of-materials.json @@ -179,6 +179,15 @@ } ] }, + { + "project": "github.com/google/go-cmp/cmp", + "licenses": [ + { + "type": "BSD 3-clause \"New\" or \"Revised\" License", + "confidence": 0.9663865546218487 + } + ] + }, { "project": "github.com/gorilla/websocket", "licenses": [ diff --git a/go.mod b/go.mod index 4e2211060..85b246469 100644 --- a/go.mod +++ b/go.mod @@ -48,6 +48,7 @@ require ( github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/google/btree v1.0.1 // indirect + github.com/google/go-cmp v0.5.6 // indirect github.com/gorilla/websocket v1.4.2 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect @@ -81,6 +82,7 @@ require ( golang.org/x/net v0.0.0-20220105145211-5b0dc2dfae98 // indirect golang.org/x/sys v0.0.0-20211123173158-ef496fb156ab // indirect golang.org/x/text v0.3.7 // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1 // indirect google.golang.org/protobuf v1.27.1 // indirect gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect diff --git a/tests/framework/integration/cluster.go b/tests/framework/integration/cluster.go index a32e63471..4600e092d 100644 --- a/tests/framework/integration/cluster.go +++ b/tests/framework/integration/cluster.go @@ -58,6 +58,8 @@ import ( "go.uber.org/zap/zapcore" "go.uber.org/zap/zaptest" + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "github.com/soheilhy/cmux" "go.uber.org/zap" "golang.org/x/crypto/bcrypt" @@ -483,16 +485,7 @@ func (c *Cluster) waitVersion() { func isMembersEqual(membs []*pb.Member, wmembs []*pb.Member) bool { sort.Sort(SortableMemberSliceByPeerURLs(membs)) sort.Sort(SortableMemberSliceByPeerURLs(wmembs)) - for i := range membs { - membs[i].ID = 0 - if membs[i].PeerURLs == nil { - membs[i].PeerURLs = []string{} - } - if membs[i].ClientURLs == nil { - membs[i].ClientURLs = []string{} - } - } - return reflect.DeepEqual(membs, wmembs) + return cmp.Equal(membs, wmembs, cmpopts.IgnoreFields(pb.Member{}, "ID", "PeerURLs", "ClientURLs")) } func newLocalListener(t testutil.TB) net.Listener { diff --git a/tests/go.mod b/tests/go.mod index 9e3cbdb77..2850b0f02 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -19,6 +19,7 @@ require ( github.com/dustin/go-humanize v1.0.0 github.com/gogo/protobuf v1.3.2 github.com/golang/protobuf v1.5.2 + github.com/google/go-cmp v0.5.6 github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 @@ -77,6 +78,7 @@ require ( golang.org/x/net v0.0.0-20220105145211-5b0dc2dfae98 // indirect golang.org/x/sys v0.0.0-20211123173158-ef496fb156ab // indirect golang.org/x/text v0.3.7 // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1 // indirect google.golang.org/protobuf v1.27.1 // indirect gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect