Pavel Pogodaev
db05021786
All checks were successful
/ DCO (pull_request) Successful in 1m54s
/ Builds (1.20) (pull_request) Successful in 2m23s
/ Builds (1.21) (pull_request) Successful in 2m0s
/ Vulncheck (pull_request) Successful in 2m7s
/ Lint (pull_request) Successful in 4m16s
/ Tests (1.20) (pull_request) Successful in 2m38s
/ Tests (1.21) (pull_request) Successful in 2m29s
Signed-off-by: Pavel Pogodaev <p.pogodaev@yadro.com>
162 lines
3.3 KiB
Go
162 lines
3.3 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/handler"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDefaultNamespace(t *testing.T) {
|
|
xmlBodyWithNamespace := `
|
|
<CompleteMultipartUpload xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
|
<Part>
|
|
<ETag>string</ETag>
|
|
<PartNumber>1</PartNumber>
|
|
</Part>
|
|
</CompleteMultipartUpload>
|
|
`
|
|
xmlBodyWithInvalidNamespace := `
|
|
<CompleteMultipartUpload xmlns="http://bla.bla.bla/">
|
|
<Part>
|
|
<ETag>string</ETag>
|
|
<PartNumber>1</PartNumber>
|
|
</Part>
|
|
</CompleteMultipartUpload>
|
|
`
|
|
xmlBody := `
|
|
<CompleteMultipartUpload>
|
|
<Part>
|
|
<ETag>string</ETag>
|
|
<PartNumber>1</PartNumber>
|
|
</Part>
|
|
</CompleteMultipartUpload>
|
|
`
|
|
xmlASCII := `<?xml version="1.0" encoding="US-ASCII"?>
|
|
<CompleteMultipartUpload>
|
|
<Part>
|
|
<PartNumber>1</PartNumber>
|
|
<ETag>
|
|
8b73814bee405ec32b5d1fc88cd5d97a
|
|
</ETag>
|
|
</Part>
|
|
</CompleteMultipartUpload>`
|
|
|
|
for _, tc := range []struct {
|
|
settings *appSettings
|
|
input string
|
|
err bool
|
|
}{
|
|
{
|
|
settings: &appSettings{
|
|
defaultXMLNS: false,
|
|
},
|
|
input: xmlBodyWithNamespace,
|
|
err: false,
|
|
},
|
|
{
|
|
settings: &appSettings{
|
|
defaultXMLNS: false,
|
|
},
|
|
input: xmlBody,
|
|
err: true,
|
|
},
|
|
{
|
|
settings: &appSettings{
|
|
defaultXMLNS: false,
|
|
},
|
|
input: xmlBodyWithInvalidNamespace,
|
|
err: true,
|
|
},
|
|
{
|
|
settings: &appSettings{
|
|
defaultXMLNS: true,
|
|
},
|
|
input: xmlBodyWithNamespace,
|
|
err: false,
|
|
},
|
|
{
|
|
settings: &appSettings{
|
|
defaultXMLNS: true,
|
|
},
|
|
input: xmlBody,
|
|
err: false,
|
|
},
|
|
{
|
|
settings: &appSettings{
|
|
defaultXMLNS: true,
|
|
},
|
|
input: xmlBodyWithInvalidNamespace,
|
|
err: true,
|
|
},
|
|
{
|
|
settings: &appSettings{
|
|
defaultXMLNS: true,
|
|
},
|
|
input: xmlASCII,
|
|
err: false,
|
|
},
|
|
} {
|
|
t.Run("", func(t *testing.T) {
|
|
model := new(handler.CompleteMultipartUpload)
|
|
err := tc.settings.NewXMLDecoder(bytes.NewBufferString(tc.input)).Decode(model)
|
|
if tc.err {
|
|
require.Error(t, err)
|
|
} else {
|
|
require.NoError(t, err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNamespacesMarshaling(t *testing.T) {
|
|
dataJSON := `
|
|
{
|
|
"namespaces": {
|
|
"kapusta": {
|
|
"location_constraints": {
|
|
"default": "REP 3",
|
|
"load-1-1": "REP 1 CBF 1 SELECT 1 FROM *"
|
|
},
|
|
"copies_numbers": {
|
|
"default": [
|
|
0
|
|
],
|
|
"load-1-1": [
|
|
1
|
|
]
|
|
}
|
|
},
|
|
"root": {
|
|
"location_constraints": {
|
|
"default": "REP 3",
|
|
"test": "{\"replicas\":[{\"count\":1,\"selector\":\"\"}],\"containerBackupFactor\":1,\"selectors\":[{\"name\":\"\",\"count\":1,\"clause\":\"CLAUSE_UNSPECIFIED\",\"attribute\":\"\",\"filter\":\"Color\"}],\"filters\":[{\"name\":\"Color\",\"key\":\"Color\",\"op\":\"EQ\",\"value\":\"Red\",\"filters\":[]}],\"unique\":false}"
|
|
},
|
|
"copies_numbers": {
|
|
"default": [
|
|
0
|
|
],
|
|
"load-1-1": [
|
|
1
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`
|
|
|
|
var nsConfig NamespacesConfig
|
|
err := json.Unmarshal([]byte(dataJSON), &nsConfig)
|
|
require.NoError(t, err)
|
|
|
|
data, err := json.Marshal(nsConfig)
|
|
require.NoError(t, err)
|
|
|
|
var nsConfig2 NamespacesConfig
|
|
err = json.Unmarshal(data, &nsConfig2)
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, nsConfig, nsConfig2)
|
|
}
|