205 lines
4.2 KiB
Go
205 lines
4.2 KiB
Go
package frostfs
|
|
|
|
import (
|
|
"strconv"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGetZoneAndContainerNames(t *testing.T) {
|
|
for i, tc := range []struct {
|
|
cnrStr string
|
|
defZone string
|
|
expectedName string
|
|
expectedZone string
|
|
}{
|
|
{
|
|
cnrStr: "",
|
|
defZone: "def_zone",
|
|
expectedName: "",
|
|
expectedZone: "def_zone",
|
|
},
|
|
{
|
|
cnrStr: "",
|
|
defZone: "def_zone",
|
|
expectedName: "",
|
|
expectedZone: "def_zone",
|
|
},
|
|
{
|
|
cnrStr: "cnr_name",
|
|
defZone: "def_zone",
|
|
expectedName: "cnr_name",
|
|
expectedZone: "def_zone",
|
|
},
|
|
{
|
|
cnrStr: "cnr_name.",
|
|
defZone: "def_zone",
|
|
expectedName: "cnr_name",
|
|
expectedZone: "def_zone",
|
|
},
|
|
{
|
|
cnrStr: ".cnr_zone",
|
|
defZone: "def_zone",
|
|
expectedName: "",
|
|
expectedZone: "cnr_zone",
|
|
}, {
|
|
cnrStr: ".cnr_zone",
|
|
defZone: "def_zone",
|
|
expectedName: "",
|
|
expectedZone: "cnr_zone",
|
|
},
|
|
} {
|
|
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
|
actualName, actualZone := getContainerNameAndZone(tc.cnrStr, tc.defZone)
|
|
require.Equal(t, tc.expectedZone, actualZone)
|
|
require.Equal(t, tc.expectedName, actualName)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseContainerCreationPolicy(t *testing.T) {
|
|
for i, tc := range []struct {
|
|
ACLString string
|
|
ExpectedError bool
|
|
}{
|
|
{
|
|
ACLString: "",
|
|
ExpectedError: true,
|
|
},
|
|
{
|
|
ACLString: "public-ready",
|
|
ExpectedError: true,
|
|
},
|
|
{
|
|
ACLString: "public-read",
|
|
ExpectedError: false,
|
|
},
|
|
{
|
|
ACLString: "public-read-write",
|
|
ExpectedError: false,
|
|
},
|
|
{
|
|
ACLString: "private",
|
|
ExpectedError: false,
|
|
},
|
|
} {
|
|
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
|
rules, err := parseContainerCreationPolicyString(tc.ACLString)
|
|
if tc.ExpectedError {
|
|
require.Error(t, err)
|
|
require.Nil(t, rules)
|
|
} else {
|
|
require.NoError(t, err)
|
|
require.NotNil(t, rules)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseEndpoints(t *testing.T) {
|
|
for i, tc := range []struct {
|
|
EndpointsParam string
|
|
ExpectedError bool
|
|
ExpectedResult []endpointInfo
|
|
}{
|
|
{
|
|
EndpointsParam: "s01.frostfs.devenv:8080",
|
|
ExpectedResult: []endpointInfo{{
|
|
Address: "s01.frostfs.devenv:8080",
|
|
Priority: 1,
|
|
Weight: 1,
|
|
}},
|
|
},
|
|
{
|
|
EndpointsParam: "s01.frostfs.devenv:8080,2",
|
|
ExpectedResult: []endpointInfo{{
|
|
Address: "s01.frostfs.devenv:8080",
|
|
Priority: 2,
|
|
Weight: 1,
|
|
}},
|
|
},
|
|
{
|
|
EndpointsParam: "s01.frostfs.devenv:8080,2,3",
|
|
ExpectedResult: []endpointInfo{{
|
|
Address: "s01.frostfs.devenv:8080",
|
|
Priority: 2,
|
|
Weight: 3,
|
|
}},
|
|
},
|
|
{
|
|
EndpointsParam: " s01.frostfs.devenv:8080 s02.frostfs.devenv:8080 ",
|
|
ExpectedResult: []endpointInfo{
|
|
{
|
|
Address: "s01.frostfs.devenv:8080",
|
|
Priority: 1,
|
|
Weight: 1,
|
|
},
|
|
{
|
|
Address: "s02.frostfs.devenv:8080",
|
|
Priority: 1,
|
|
Weight: 1,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
EndpointsParam: "s01.frostfs.devenv:8080,1,1 s02.frostfs.devenv:8080,2,1 s03.frostfs.devenv:8080,2,9",
|
|
ExpectedResult: []endpointInfo{
|
|
{
|
|
Address: "s01.frostfs.devenv:8080",
|
|
Priority: 1,
|
|
Weight: 1,
|
|
},
|
|
{
|
|
Address: "s02.frostfs.devenv:8080",
|
|
Priority: 2,
|
|
Weight: 1,
|
|
},
|
|
{
|
|
Address: "s03.frostfs.devenv:8080",
|
|
Priority: 2,
|
|
Weight: 9,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
EndpointsParam: "s01.frostfs.devenv:8080,-1,1",
|
|
ExpectedError: true,
|
|
},
|
|
{
|
|
EndpointsParam: "s01.frostfs.devenv:8080,,",
|
|
ExpectedError: true,
|
|
},
|
|
{
|
|
EndpointsParam: "s01.frostfs.devenv:8080,sd,sd",
|
|
ExpectedError: true,
|
|
},
|
|
{
|
|
EndpointsParam: "s01.frostfs.devenv:8080,1,0",
|
|
ExpectedError: true,
|
|
},
|
|
{
|
|
EndpointsParam: "s01.frostfs.devenv:8080,1 s02.frostfs.devenv:8080",
|
|
ExpectedError: true,
|
|
},
|
|
{
|
|
EndpointsParam: "s01.frostfs.devenv:8080,1,2 s02.frostfs.devenv:8080",
|
|
ExpectedError: true,
|
|
},
|
|
{
|
|
EndpointsParam: "s01.frostfs.devenv:8080,1,2 s02.frostfs.devenv:8080,1",
|
|
ExpectedError: true,
|
|
},
|
|
} {
|
|
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
|
res, err := parseEndpoints(tc.EndpointsParam)
|
|
if tc.ExpectedError {
|
|
require.Error(t, err)
|
|
return
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
require.Equal(t, tc.ExpectedResult, res)
|
|
})
|
|
}
|
|
}
|