2023-04-24 23:49:12 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCopiesNumberPicker(t *testing.T) {
|
2023-05-18 13:20:00 +00:00
|
|
|
var locationConstraints = map[string][]uint32{}
|
2023-04-24 23:49:12 +00:00
|
|
|
locationConstraint1 := "one"
|
|
|
|
locationConstraint2 := "two"
|
2023-05-18 13:20:00 +00:00
|
|
|
locationConstraints[locationConstraint1] = []uint32{2, 3, 4}
|
2023-04-24 23:49:12 +00:00
|
|
|
|
2023-09-08 11:17:14 +00:00
|
|
|
config := &configMock{
|
|
|
|
copiesNumbers: locationConstraints,
|
|
|
|
defaultCopiesNumbers: []uint32{1},
|
2023-04-24 23:49:12 +00:00
|
|
|
}
|
|
|
|
h := handler{
|
|
|
|
cfg: config,
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata := map[string]string{}
|
|
|
|
|
|
|
|
t.Run("pick default copies number", func(t *testing.T) {
|
|
|
|
metadata["somekey1"] = "5, 6, 7"
|
|
|
|
expectedCopiesNumbers := []uint32{1}
|
|
|
|
|
2023-11-21 08:51:07 +00:00
|
|
|
actualCopiesNumbers, err := h.pickCopiesNumbers(metadata, "", locationConstraint2)
|
2023-04-24 23:49:12 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, expectedCopiesNumbers, actualCopiesNumbers)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("pick copies number vector according to location constraint", func(t *testing.T) {
|
|
|
|
metadata["somekey2"] = "6, 7, 8"
|
|
|
|
expectedCopiesNumbers := []uint32{2, 3, 4}
|
|
|
|
|
2023-11-21 08:51:07 +00:00
|
|
|
actualCopiesNumbers, err := h.pickCopiesNumbers(metadata, "", locationConstraint1)
|
2023-04-24 23:49:12 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, expectedCopiesNumbers, actualCopiesNumbers)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("pick copies number from metadata", func(t *testing.T) {
|
|
|
|
metadata["frostfs-copies-number"] = "7, 8, 9"
|
|
|
|
expectedCopiesNumbers := []uint32{7, 8, 9}
|
|
|
|
|
2023-11-21 08:51:07 +00:00
|
|
|
actualCopiesNumbers, err := h.pickCopiesNumbers(metadata, "", locationConstraint2)
|
2023-04-24 23:49:12 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, expectedCopiesNumbers, actualCopiesNumbers)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("pick copies number from metadata with no space", func(t *testing.T) {
|
|
|
|
metadata["frostfs-copies-number"] = "7,8,9"
|
|
|
|
expectedCopiesNumbers := []uint32{7, 8, 9}
|
|
|
|
|
2023-11-21 08:51:07 +00:00
|
|
|
actualCopiesNumbers, err := h.pickCopiesNumbers(metadata, "", locationConstraint2)
|
2023-04-24 23:49:12 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, expectedCopiesNumbers, actualCopiesNumbers)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("pick copies number from metadata with trailing comma", func(t *testing.T) {
|
|
|
|
metadata["frostfs-copies-number"] = "11, 12, 13, "
|
|
|
|
expectedCopiesNumbers := []uint32{11, 12, 13}
|
|
|
|
|
2023-11-21 08:51:07 +00:00
|
|
|
actualCopiesNumbers, err := h.pickCopiesNumbers(metadata, "", locationConstraint2)
|
2023-04-24 23:49:12 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, expectedCopiesNumbers, actualCopiesNumbers)
|
|
|
|
})
|
|
|
|
}
|