[#1048] control: Add unit test for ListShards
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
f88a12eaa7
commit
4e989e7133
2 changed files with 59 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
package control_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
||||
|
@ -79,3 +80,43 @@ func generateSetNetmapStatusRequestBody() *control.SetNetmapStatusRequest_Body {
|
|||
func equalSetnetmapStatusRequestBodies(b1, b2 *control.SetNetmapStatusRequest_Body) bool {
|
||||
return b1.GetStatus() == b2.GetStatus()
|
||||
}
|
||||
|
||||
func TestListShardsResponse_Body_StableMarshal(t *testing.T) {
|
||||
testStableMarshal(t,
|
||||
generateListShardsResponseBody(),
|
||||
new(control.ListShardsResponse_Body),
|
||||
func(m1, m2 protoMessage) bool {
|
||||
return equalListShardResponseBodies(
|
||||
m1.(*control.ListShardsResponse_Body),
|
||||
m2.(*control.ListShardsResponse_Body),
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func equalListShardResponseBodies(b1, b2 *control.ListShardsResponse_Body) bool {
|
||||
if len(b1.Shards) != len(b2.Shards) {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := range b1.Shards {
|
||||
if b1.Shards[i].GetMetabasePath() != b2.Shards[i].GetMetabasePath() ||
|
||||
b1.Shards[i].GetBlobstorePath() != b2.Shards[i].GetBlobstorePath() ||
|
||||
b1.Shards[i].GetWritecachePath() != b2.Shards[i].GetWritecachePath() ||
|
||||
!bytes.Equal(b1.Shards[i].GetShard_ID(), b2.Shards[i].GetShard_ID()) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func generateListShardsResponseBody() *control.ListShardsResponse_Body {
|
||||
body := new(control.ListShardsResponse_Body)
|
||||
body.SetShards([]*control.ShardInfo{
|
||||
generateShardInfo(),
|
||||
generateShardInfo(),
|
||||
})
|
||||
|
||||
return body
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
||||
)
|
||||
|
||||
|
@ -123,3 +124,20 @@ func equalNodeInfos(n1, n2 *control.NodeInfo) bool {
|
|||
|
||||
return true
|
||||
}
|
||||
|
||||
func generateShardInfo() *control.ShardInfo {
|
||||
si := new(control.ShardInfo)
|
||||
|
||||
path := "/nice/dir/awesome/files"
|
||||
|
||||
uid, _ := uuid.NewRandom()
|
||||
bin, _ := uid.MarshalBinary()
|
||||
|
||||
si.SetID(bin)
|
||||
si.SetMode(control.ShardMode_READ_WRITE)
|
||||
si.SetMetabasePath(path)
|
||||
si.SetBlobstorePath(path)
|
||||
si.SetWriteCachePath(path)
|
||||
|
||||
return si
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue