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 := ` string 1 ` xmlBodyWithInvalidNamespace := ` string 1 ` xmlBody := ` string 1 ` xmlASCII := ` 1 8b73814bee405ec32b5d1fc88cd5d97a ` 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) }