[#1388] services/control: Extend tests for ShardInfo marshaling

It is nice to have different paths for different components and also
check that the information returned is different for different shards.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-05-16 16:30:53 +03:00 committed by LeL
parent f15e6e888f
commit 0f376a5d83
2 changed files with 20 additions and 7 deletions

View file

@ -108,14 +108,25 @@ func equalListShardResponseBodies(b1, b2 *control.ListShardsResponse_Body) bool
} }
} }
for i := range b1.Shards {
for j := i + 1; j < len(b1.Shards); j++ {
if b1.Shards[i].GetMetabasePath() == b2.Shards[j].GetMetabasePath() ||
b1.Shards[i].GetBlobstorPath() == b2.Shards[j].GetBlobstorPath() ||
b1.Shards[i].GetWritecachePath() == b2.Shards[j].GetWritecachePath() ||
bytes.Equal(b1.Shards[i].GetShard_ID(), b2.Shards[j].GetShard_ID()) {
return false
}
}
}
return true return true
} }
func generateListShardsResponseBody() *control.ListShardsResponse_Body { func generateListShardsResponseBody() *control.ListShardsResponse_Body {
body := new(control.ListShardsResponse_Body) body := new(control.ListShardsResponse_Body)
body.SetShards([]*control.ShardInfo{ body.SetShards([]*control.ShardInfo{
generateShardInfo(), generateShardInfo(0),
generateShardInfo(), generateShardInfo(1),
}) })
return body return body

View file

@ -2,6 +2,8 @@ package control_test
import ( import (
"bytes" "bytes"
"path/filepath"
"strconv"
"testing" "testing"
"github.com/google/uuid" "github.com/google/uuid"
@ -125,19 +127,19 @@ func equalNodeInfos(n1, n2 *control.NodeInfo) bool {
return true return true
} }
func generateShardInfo() *control.ShardInfo { func generateShardInfo(id int) *control.ShardInfo {
si := new(control.ShardInfo) si := new(control.ShardInfo)
path := "/nice/dir/awesome/files" path := "/nice/dir/awesome/files/" + strconv.Itoa(id)
uid, _ := uuid.NewRandom() uid, _ := uuid.NewRandom()
bin, _ := uid.MarshalBinary() bin, _ := uid.MarshalBinary()
si.SetID(bin) si.SetID(bin)
si.SetMode(control.ShardMode_READ_WRITE) si.SetMode(control.ShardMode_READ_WRITE)
si.SetMetabasePath(path) si.SetMetabasePath(filepath.Join(path, "meta"))
si.SetBlobstorPath(path) si.SetBlobstorPath(filepath.Join(path, "blobstor"))
si.SetWriteCachePath(path) si.SetWriteCachePath(filepath.Join(path, "writecache"))
return si return si
} }