github.com/ledgerwatch/erigon-lib@v1.0.0/gointerfaces/remote/sort_test.go (about) 1 package remote_test 2 3 import ( 4 "testing" 5 6 "github.com/ledgerwatch/erigon-lib/gointerfaces/remote" 7 "github.com/ledgerwatch/erigon-lib/gointerfaces/types" 8 "github.com/stretchr/testify/assert" 9 "golang.org/x/exp/slices" 10 ) 11 12 func TestSort(t *testing.T) { 13 tests := []struct { 14 name string 15 got *remote.NodesInfoReply 16 want *remote.NodesInfoReply 17 }{ 18 { 19 name: "sort by name", 20 got: &remote.NodesInfoReply{ 21 NodesInfo: []*types.NodeInfoReply{ 22 {Name: "b", Enode: "c"}, 23 {Name: "a", Enode: "d"}, 24 }, 25 }, 26 want: &remote.NodesInfoReply{ 27 NodesInfo: []*types.NodeInfoReply{ 28 {Name: "a", Enode: "d"}, 29 {Name: "b", Enode: "c"}, 30 }, 31 }, 32 }, 33 { 34 name: "sort by enode", 35 got: &remote.NodesInfoReply{ 36 NodesInfo: []*types.NodeInfoReply{ 37 {Name: "a", Enode: "d"}, 38 {Name: "a", Enode: "c"}, 39 }, 40 }, 41 want: &remote.NodesInfoReply{ 42 NodesInfo: []*types.NodeInfoReply{ 43 {Name: "a", Enode: "c"}, 44 {Name: "a", Enode: "d"}, 45 }, 46 }, 47 }, 48 } 49 for _, tt := range tests { 50 t.Run(tt.name, func(t *testing.T) { 51 52 slices.SortFunc(tt.got.NodesInfo, remote.NodeInfoReplyLess) 53 assert.Equal(t, tt.want, tt.got) 54 }) 55 } 56 }