From f354b8a270b3cb5486df4927f4c461715a999b56 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 5 Jul 2023 20:12:55 +0300 Subject: [PATCH] [#473] Add tests for rem values of traverser Signed-off-by: Alex Vanin --- .../placement/traverser_test.go | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/pkg/services/object_manager/placement/traverser_test.go b/pkg/services/object_manager/placement/traverser_test.go index 66fd8afe07..1b307da6fc 100644 --- a/pkg/services/object_manager/placement/traverser_test.go +++ b/pkg/services/object_manager/placement/traverser_test.go @@ -208,3 +208,55 @@ func TestTraverserObjectScenarios(t *testing.T) { require.True(t, tr.Success()) }) } + +func TestTraverserRemValues(t *testing.T) { + selectors := []int{3, 4, 5} + replicas := []int{2, 3, 4} + + nodes, cnr := testPlacement(t, selectors, replicas) + nodesCopy := copyVectors(nodes) + + testCases := [...]struct { + name string + copyNumbers []uint32 + expectedRem []int + }{ + { + name: "zero copy numbers", + copyNumbers: []uint32{}, + expectedRem: replicas, + }, + { + name: "compatible zero copy numbers", + copyNumbers: []uint32{0}, + expectedRem: replicas, + }, + { + name: "copy numbers for all replicas", + copyNumbers: []uint32{1, 1, 1}, + expectedRem: []int{1, 1, 1}, + }, + { + name: "single copy numbers for multiple replicas", + copyNumbers: []uint32{1}, + expectedRem: []int{1}, // may be a bit unexpected + }, + { + name: "multiple copy numbers for multiple replicas", + copyNumbers: []uint32{1, 1}, + expectedRem: []int{1, 1, 4}, + }, + } + + for _, testCase := range testCases { + t.Run(testCase.name, func(t *testing.T) { + tr, err := NewTraverser( + ForContainer(cnr), + UseBuilder(&testBuilder{vectors: nodesCopy}), + WithCopyNumbers(testCase.copyNumbers), + ) + require.NoError(t, err) + require.Equal(t, testCase.expectedRem, tr.rem) + }) + } +}