From 0f376a5d836c42d3e7be74e69a7bdbd748204158 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 16 May 2022 16:30:53 +0300 Subject: [PATCH] [#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 --- pkg/services/control/service_test.go | 15 +++++++++++++-- pkg/services/control/types_test.go | 12 +++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/pkg/services/control/service_test.go b/pkg/services/control/service_test.go index 3c89fc7d58..c80d8ee8fc 100644 --- a/pkg/services/control/service_test.go +++ b/pkg/services/control/service_test.go @@ -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 } func generateListShardsResponseBody() *control.ListShardsResponse_Body { body := new(control.ListShardsResponse_Body) body.SetShards([]*control.ShardInfo{ - generateShardInfo(), - generateShardInfo(), + generateShardInfo(0), + generateShardInfo(1), }) return body diff --git a/pkg/services/control/types_test.go b/pkg/services/control/types_test.go index 619e4b61f8..31c3885dc1 100644 --- a/pkg/services/control/types_test.go +++ b/pkg/services/control/types_test.go @@ -2,6 +2,8 @@ package control_test import ( "bytes" + "path/filepath" + "strconv" "testing" "github.com/google/uuid" @@ -125,19 +127,19 @@ func equalNodeInfos(n1, n2 *control.NodeInfo) bool { return true } -func generateShardInfo() *control.ShardInfo { +func generateShardInfo(id int) *control.ShardInfo { si := new(control.ShardInfo) - path := "/nice/dir/awesome/files" + path := "/nice/dir/awesome/files/" + strconv.Itoa(id) uid, _ := uuid.NewRandom() bin, _ := uid.MarshalBinary() si.SetID(bin) si.SetMode(control.ShardMode_READ_WRITE) - si.SetMetabasePath(path) - si.SetBlobstorPath(path) - si.SetWriteCachePath(path) + si.SetMetabasePath(filepath.Join(path, "meta")) + si.SetBlobstorPath(filepath.Join(path, "blobstor")) + si.SetWriteCachePath(filepath.Join(path, "writecache")) return si }