package handler import ( "testing" "github.com/stretchr/testify/require" ) func TestCopiesNumberPicker(t *testing.T) { var locationConstraints = map[string][]uint32{} locationConstraint1 := "one" locationConstraint2 := "two" locationConstraints[locationConstraint1] = []uint32{2, 3, 4} config := &configMock{ copiesNumbers: locationConstraints, defaultCopiesNumbers: []uint32{1}, } 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} actualCopiesNumbers, err := h.pickCopiesNumbers(metadata, locationConstraint2) 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} actualCopiesNumbers, err := h.pickCopiesNumbers(metadata, locationConstraint1) 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} actualCopiesNumbers, err := h.pickCopiesNumbers(metadata, locationConstraint2) 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} actualCopiesNumbers, err := h.pickCopiesNumbers(metadata, locationConstraint2) 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} actualCopiesNumbers, err := h.pickCopiesNumbers(metadata, locationConstraint2) require.NoError(t, err) require.Equal(t, expectedCopiesNumbers, actualCopiesNumbers) }) }