erigon-pulse/gointerfaces/remote/sort_test.go
Dmitry Savelev da3c239ed6
Add nodeInfo GRPC methods (#196)
* Add nodeInfo

* Remove interfaces for replacement

Signed-off-by: Dmitry Savelev <darksawa@gmail.com>

* Squashed 'interfaces/' content from commit 67abfdd

git-subtree-dir: interfaces
git-subtree-split: 67abfdd23b3bbef0d2f0c038275b6f47820d7f5e
2021-11-30 14:41:31 +00:00

58 lines
1.1 KiB
Go

package remote_test
import (
"sort"
"testing"
"github.com/ledgerwatch/erigon-lib/gointerfaces/remote"
"github.com/ledgerwatch/erigon-lib/gointerfaces/types"
"github.com/stretchr/testify/assert"
)
func TestSort(t *testing.T) {
tests := []struct {
name string
got *remote.NodesInfoReply
want *remote.NodesInfoReply
}{
{
name: "sort by name",
got: &remote.NodesInfoReply{
NodesInfo: []*types.NodeInfoReply{
{Name: "b", Enode: "c"},
{Name: "a", Enode: "d"},
},
},
want: &remote.NodesInfoReply{
NodesInfo: []*types.NodeInfoReply{
{Name: "a", Enode: "d"},
{Name: "b", Enode: "c"},
},
},
},
{
name: "sort by enode",
got: &remote.NodesInfoReply{
NodesInfo: []*types.NodeInfoReply{
{Name: "a", Enode: "d"},
{Name: "a", Enode: "c"},
},
},
want: &remote.NodesInfoReply{
NodesInfo: []*types.NodeInfoReply{
{Name: "a", Enode: "c"},
{Name: "a", Enode: "d"},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
sort.Sort(tt.got)
assert.Equal(t, tt.want, tt.got)
})
}
}