[#473] Add tests for rem values of traverser
All checks were successful
Build / Build Components (1.20) (pull_request) Successful in 3m52s
Build / Build Components (1.19) (pull_request) Successful in 4m8s
ci/woodpecker/pr/pre-commit Pipeline was successful
Tests and linters / Lint (pull_request) Successful in 9m3s
Tests and linters / Tests with -race (pull_request) Successful in 5m27s
Tests and linters / Tests (1.20) (pull_request) Successful in 6m18s
Tests and linters / Tests (1.19) (pull_request) Successful in 13m54s
ci/woodpecker/push/pre-commit Pipeline was successful

Signed-off-by: Alex Vanin <a.vanin@yadro.com>
This commit is contained in:
Alexey Vanin 2023-07-05 20:12:55 +03:00
parent c6df6c84ae
commit f354b8a270

View file

@ -208,3 +208,55 @@ func TestTraverserObjectScenarios(t *testing.T) {
require.True(t, tr.Success()) 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)
})
}
}