rclone/backend/frostfs/util_test.go
Aleksey Kravchenko d9fbd56598
Some checks failed
/ DCO (pull_request) Successful in 1m48s
/ Builds (pull_request) Successful in 2m39s
/ Vulncheck (pull_request) Failing after 3m22s
/ Lint (pull_request) Successful in 4m29s
[#1] Add frostfs backend
Signed-off-by: Aleksey Kravchenko <al.kravchenko@yadro.com>
2024-12-21 18:13:23 +03:00

115 lines
2.4 KiB
Go

package frostfs
import (
"strconv"
"testing"
"github.com/stretchr/testify/require"
)
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)
})
}
}