diff --git a/internal/fixtures/protocol/generate.go b/internal/fixtures/protocol/generate.go index 8f5e2a109d2..2065474670a 100644 --- a/internal/fixtures/protocol/generate.go +++ b/internal/fixtures/protocol/generate.go @@ -49,6 +49,7 @@ var _ json.Marshaler var _ time.Time var _ xmlutil.XMLNode var _ xml.Attr +var _ utilassert.Imported var _ = ioutil.Discard var _ = util.Trim("") var _ = url.Values{} @@ -76,6 +77,7 @@ var extraImports = []string{ "", "github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil", "github.com/aws/aws-sdk-go/internal/util", + "github.com/aws/aws-sdk-go/internal/util/utilassert", "github.com/stretchr/testify/assert", } @@ -138,16 +140,45 @@ type tplInputTestCaseData struct { } func (t tplInputTestCaseData) BodyAssertions() string { - protocol, code := t.TestCase.TestSuite.API.Metadata.Protocol, "" + code := &bytes.Buffer{} + protocol := t.TestCase.TestSuite.API.Metadata.Protocol + + // Extract the body bytes + switch protocol { + case "rest-xml": + fmt.Fprintln(code, "body := util.SortXML(r.Body)") + default: + fmt.Fprintln(code, "body, _ := ioutil.ReadAll(r.Body)") + } + + // Generate the body verification code + expectedBody := util.Trim(t.TestCase.InputTest.Body) switch protocol { + case "ec2", "query": + fmt.Fprintf(code, "utilassert.AssertQuery(t, `%s`, util.Trim(string(body)))", + expectedBody) case "rest-xml": - code += "body := util.SortXML(r.Body)\n" + if strings.HasPrefix(expectedBody, "<") { + fmt.Fprintf(code, "utilassert.AssertXML(t, `%s`, util.Trim(string(body)), %s{})", + expectedBody, t.TestCase.Given.InputRef.ShapeName) + } else { + fmt.Fprintf(code, "assert.Equal(t, `%s`, util.Trim(string(body)))", + expectedBody) + } + case "json", "jsonrpc", "rest-json": + if strings.HasPrefix(expectedBody, "{") { + fmt.Fprintf(code, "utilassert.AssertJSON(t, `%s`, util.Trim(string(body)))", + expectedBody) + } else { + fmt.Fprintf(code, "assert.Equal(t, `%s`, util.Trim(string(body)))", + expectedBody) + } default: - code += "body, _ := ioutil.ReadAll(r.Body)\n" + fmt.Fprintf(code, "assert.Equal(t, `%s`, util.Trim(string(body)))", + expectedBody) } - code += "assert.Equal(t, util.Trim(`" + t.TestCase.InputTest.Body + "`), util.Trim(string(body)))" - return code + return code.String() } var tplOutputTestCase = template.Must(template.New("outputcase").Parse(` diff --git a/internal/fixtures/protocol/input/json.json b/internal/fixtures/protocol/input/json.json index 7fa6e1f1b82..0dc59b5f59f 100644 --- a/internal/fixtures/protocol/input/json.json +++ b/internal/fixtures/protocol/input/json.json @@ -417,7 +417,7 @@ "X-Amz-Target": "com.amazonaws.foo.OperationName", "Content-Type": "application/x-amz-json-1.1" }, - "body": "{\"RecursiveStruct\": {\"RecursiveMap\": {\"bar\": {\"NoRecurse\": \"bar\"}, \"foo\": {\"NoRecurse\": \"foo\"}}}}" + "body": "{\"RecursiveStruct\": {\"RecursiveMap\": {\"foo\": {\"NoRecurse\": \"foo\"}, \"bar\": {\"NoRecurse\": \"bar\"}}}}" } } ] diff --git a/internal/fixtures/protocol/input/query.json b/internal/fixtures/protocol/input/query.json index 9ae2195dc5a..c188b0548b2 100644 --- a/internal/fixtures/protocol/input/query.json +++ b/internal/fixtures/protocol/input/query.json @@ -288,6 +288,57 @@ } ] }, + { + "description": "Serialize map type with locationName", + "metadata": { + "protocol": "query", + "apiVersion": "2014-01-01" + }, + "shapes": { + "InputShape": { + "type": "structure", + "members": { + "MapArg": { + "shape": "StringMap" + } + } + }, + "StringMap": { + "type": "map", + "key": { + "shape": "StringType", + "locationName": "TheKey" + }, + "value": { + "shape": "StringType", + "locationName": "TheValue" + } + }, + "StringType": { + "type": "string" + } + }, + "cases": [ + { + "given": { + "input": { + "shape": "InputShape" + }, + "name": "OperationName" + }, + "params": { + "MapArg": { + "key1": "val1", + "key2": "val2" + } + }, + "serialized": { + "uri": "/", + "body": "Action=OperationName&Version=2014-01-01&MapArg.entry.1.TheKey=key1&MapArg.entry.1.TheValue=val1&MapArg.entry.2.TheKey=key2&MapArg.entry.2.TheValue=val2" + } + } + ] + }, { "description": "Base64 encoded Blobs", "metadata": { @@ -544,7 +595,7 @@ }, "serialized": { "uri": "/", - "body": "Action=OperationName&Version=2014-01-01&RecursiveStruct.RecursiveMap.entry.1.key=bar&RecursiveStruct.RecursiveMap.entry.1.value.NoRecurse=bar&RecursiveStruct.RecursiveMap.entry.2.key=foo&RecursiveStruct.RecursiveMap.entry.2.value.NoRecurse=foo" + "body": "Action=OperationName&Version=2014-01-01&RecursiveStruct.RecursiveMap.entry.1.key=foo&RecursiveStruct.RecursiveMap.entry.1.value.NoRecurse=foo&RecursiveStruct.RecursiveMap.entry.2.key=bar&RecursiveStruct.RecursiveMap.entry.2.value.NoRecurse=bar" } } ] diff --git a/internal/fixtures/protocol/input/rest-json.json b/internal/fixtures/protocol/input/rest-json.json index 1d0544d93d9..49eb83ea7af 100644 --- a/internal/fixtures/protocol/input/rest-json.json +++ b/internal/fixtures/protocol/input/rest-json.json @@ -809,7 +809,7 @@ "serialized": { "uri": "/path", "headers": {}, - "body": "{\"RecursiveStruct\": {\"RecursiveMap\": {\"bar\": {\"NoRecurse\": \"bar\"}, \"foo\": {\"NoRecurse\": \"foo\"}}}}" + "body": "{\"RecursiveStruct\": {\"RecursiveMap\": {\"foo\": {\"NoRecurse\": \"foo\"}, \"bar\": {\"NoRecurse\": \"bar\"}}}}" } } ] diff --git a/internal/fixtures/protocol/input/rest-xml.json b/internal/fixtures/protocol/input/rest-xml.json index 40994378340..2a9e7e7e989 100644 --- a/internal/fixtures/protocol/input/rest-xml.json +++ b/internal/fixtures/protocol/input/rest-xml.json @@ -1260,7 +1260,7 @@ }, "serialized": { "uri": "/path", - "body": "barbarfoofoo" + "body": "foofoobarbar" } } ] diff --git a/internal/protocol/ec2query/build_test.go b/internal/protocol/ec2query/build_test.go index 8b2e59a8ae0..fd2f039ba56 100644 --- a/internal/protocol/ec2query/build_test.go +++ b/internal/protocol/ec2query/build_test.go @@ -20,6 +20,7 @@ import ( "github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil" "github.com/aws/aws-sdk-go/internal/signer/v4" "github.com/aws/aws-sdk-go/internal/util" + "github.com/aws/aws-sdk-go/internal/util/utilassert" "github.com/stretchr/testify/assert" ) @@ -29,6 +30,7 @@ var _ json.Marshaler var _ time.Time var _ xmlutil.XMLNode var _ xml.Attr +var _ utilassert.Imported var _ = ioutil.Discard var _ = util.Trim("") var _ = url.Values{} @@ -672,7 +674,7 @@ func TestInputService1ProtocolTestScalarMembersCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&Bar=val2&Foo=val1&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&Bar=val2&Foo=val1&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -700,7 +702,7 @@ func TestInputService2ProtocolTestStructureWithLocationNameAndQueryNameAppliedTo // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&BarLocationName=val2&Foo=val1&Version=2014-01-01&yuckQueryName=val3`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&BarLocationName=val2&Foo=val1&Version=2014-01-01&yuckQueryName=val3`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -728,7 +730,7 @@ func TestInputService3ProtocolTestNestedStructureMembersCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&Struct.Scalar=foo&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&Struct.Scalar=foo&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -758,7 +760,7 @@ func TestInputService4ProtocolTestListTypesCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&ListArg.1=foo&ListArg.2=bar&ListArg.3=baz&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&ListArg.1=foo&ListArg.2=bar&ListArg.3=baz&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -788,7 +790,7 @@ func TestInputService5ProtocolTestListWithLocationNameAppliedToMemberCase1(t *te // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&ListMemberName.1=a&ListMemberName.2=b&ListMemberName.3=c&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&ListMemberName.1=a&ListMemberName.2=b&ListMemberName.3=c&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -818,7 +820,7 @@ func TestInputService6ProtocolTestListWithLocationNameAndQueryNameCase1(t *testi // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&ListQueryName.1=a&ListQueryName.2=b&ListQueryName.3=c&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&ListQueryName.1=a&ListQueryName.2=b&ListQueryName.3=c&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -844,7 +846,7 @@ func TestInputService7ProtocolTestBase64EncodedBlobsCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&BlobArg=Zm9v&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&BlobArg=Zm9v&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -870,7 +872,7 @@ func TestInputService8ProtocolTestTimestampValuesCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&TimeArg=2015-01-25T08%3A00%3A00Z&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&TimeArg=2015-01-25T08%3A00%3A00Z&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) diff --git a/internal/protocol/ec2query/unmarshal_test.go b/internal/protocol/ec2query/unmarshal_test.go index 3d7b0430bdc..9c8ec6f9d7a 100644 --- a/internal/protocol/ec2query/unmarshal_test.go +++ b/internal/protocol/ec2query/unmarshal_test.go @@ -20,6 +20,7 @@ import ( "github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil" "github.com/aws/aws-sdk-go/internal/signer/v4" "github.com/aws/aws-sdk-go/internal/util" + "github.com/aws/aws-sdk-go/internal/util/utilassert" "github.com/stretchr/testify/assert" ) @@ -29,6 +30,7 @@ var _ json.Marshaler var _ time.Time var _ xmlutil.XMLNode var _ xml.Attr +var _ utilassert.Imported var _ = ioutil.Discard var _ = util.Trim("") var _ = url.Values{} diff --git a/internal/protocol/jsonrpc/build_test.go b/internal/protocol/jsonrpc/build_test.go index 39f0babc684..89d51b4b6f4 100644 --- a/internal/protocol/jsonrpc/build_test.go +++ b/internal/protocol/jsonrpc/build_test.go @@ -20,6 +20,7 @@ import ( "github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil" "github.com/aws/aws-sdk-go/internal/signer/v4" "github.com/aws/aws-sdk-go/internal/util" + "github.com/aws/aws-sdk-go/internal/util/utilassert" "github.com/stretchr/testify/assert" ) @@ -29,6 +30,7 @@ var _ json.Marshaler var _ time.Time var _ xmlutil.XMLNode var _ xml.Attr +var _ utilassert.Imported var _ = ioutil.Discard var _ = util.Trim("") var _ = url.Values{} @@ -730,7 +732,7 @@ func TestInputService1ProtocolTestScalarMembersCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"Name":"myname"}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"Name":"myname"}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -758,7 +760,7 @@ func TestInputService2ProtocolTestTimestampValuesCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"TimeArg":1422172800}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"TimeArg":1422172800}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -786,7 +788,7 @@ func TestInputService3ProtocolTestBase64EncodedBlobsCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"BlobArg":"Zm9v"}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"BlobArg":"Zm9v"}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -817,7 +819,7 @@ func TestInputService3ProtocolTestBase64EncodedBlobsCase2(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"BlobMap":{"key1":"Zm9v","key2":"YmFy"}}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"BlobMap":{"key1":"Zm9v","key2":"YmFy"}}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -848,7 +850,7 @@ func TestInputService4ProtocolTestNestedBlobsCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"ListParam":["Zm9v","YmFy"]}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"ListParam":["Zm9v","YmFy"]}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -878,7 +880,7 @@ func TestInputService5ProtocolTestRecursiveShapesCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"RecursiveStruct":{"NoRecurse":"foo"}}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"RecursiveStruct":{"NoRecurse":"foo"}}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -910,7 +912,7 @@ func TestInputService5ProtocolTestRecursiveShapesCase2(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"RecursiveStruct":{"RecursiveStruct":{"NoRecurse":"foo"}}}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"RecursiveStruct":{"RecursiveStruct":{"NoRecurse":"foo"}}}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -946,7 +948,7 @@ func TestInputService5ProtocolTestRecursiveShapesCase3(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"RecursiveStruct":{"RecursiveStruct":{"RecursiveStruct":{"RecursiveStruct":{"NoRecurse":"foo"}}}}}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"RecursiveStruct":{"RecursiveStruct":{"RecursiveStruct":{"RecursiveStruct":{"NoRecurse":"foo"}}}}}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -983,7 +985,7 @@ func TestInputService5ProtocolTestRecursiveShapesCase4(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"RecursiveStruct":{"RecursiveList":[{"NoRecurse":"foo"},{"NoRecurse":"bar"}]}}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"RecursiveStruct":{"RecursiveList":[{"NoRecurse":"foo"},{"NoRecurse":"bar"}]}}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -1022,7 +1024,7 @@ func TestInputService5ProtocolTestRecursiveShapesCase5(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"RecursiveStruct":{"RecursiveList":[{"NoRecurse":"foo"},{"RecursiveStruct":{"NoRecurse":"bar"}}]}}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"RecursiveStruct":{"RecursiveList":[{"NoRecurse":"foo"},{"RecursiveStruct":{"NoRecurse":"bar"}}]}}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -1059,7 +1061,7 @@ func TestInputService5ProtocolTestRecursiveShapesCase6(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"RecursiveStruct":{"RecursiveMap":{"bar":{"NoRecurse":"bar"},"foo":{"NoRecurse":"foo"}}}}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"RecursiveStruct":{"RecursiveMap":{"foo":{"NoRecurse":"foo"},"bar":{"NoRecurse":"bar"}}}}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -1087,7 +1089,7 @@ func TestInputService6ProtocolTestEmptyMapsCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"Map":{}}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"Map":{}}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) diff --git a/internal/protocol/jsonrpc/unmarshal_test.go b/internal/protocol/jsonrpc/unmarshal_test.go index 1d2ae9fa21f..15170e8eb35 100644 --- a/internal/protocol/jsonrpc/unmarshal_test.go +++ b/internal/protocol/jsonrpc/unmarshal_test.go @@ -20,6 +20,7 @@ import ( "github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil" "github.com/aws/aws-sdk-go/internal/signer/v4" "github.com/aws/aws-sdk-go/internal/util" + "github.com/aws/aws-sdk-go/internal/util/utilassert" "github.com/stretchr/testify/assert" ) @@ -29,6 +30,7 @@ var _ json.Marshaler var _ time.Time var _ xmlutil.XMLNode var _ xml.Attr +var _ utilassert.Imported var _ = ioutil.Discard var _ = util.Trim("") var _ = url.Values{} diff --git a/internal/protocol/query/build_test.go b/internal/protocol/query/build_test.go index 7b29fd79d74..ce9e825b332 100644 --- a/internal/protocol/query/build_test.go +++ b/internal/protocol/query/build_test.go @@ -20,6 +20,7 @@ import ( "github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil" "github.com/aws/aws-sdk-go/internal/signer/v4" "github.com/aws/aws-sdk-go/internal/util" + "github.com/aws/aws-sdk-go/internal/util/utilassert" "github.com/stretchr/testify/assert" ) @@ -29,6 +30,7 @@ var _ json.Marshaler var _ time.Time var _ xmlutil.XMLNode var _ xml.Attr +var _ utilassert.Imported var _ = ioutil.Discard var _ = util.Trim("") var _ = url.Values{} @@ -558,7 +560,7 @@ func (c *InputService7ProtocolTest) InputService7TestCaseOperation1(input *Input } type InputService7TestShapeInputService7TestCaseOperation1Input struct { - BlobArg []byte `type:"blob"` + MapArg map[string]*string `locationNameKey:"TheKey" locationNameValue:"TheValue" type:"map"` metadataInputService7TestShapeInputService7TestCaseOperation1Input `json:"-" xml:"-"` } @@ -633,7 +635,7 @@ func (c *InputService8ProtocolTest) InputService8TestCaseOperation1(input *Input } type InputService8TestShapeInputService8TestCaseOperation1Input struct { - TimeArg *time.Time `type:"timestamp" timestampFormat:"iso8601"` + BlobArg []byte `type:"blob"` metadataInputService8TestShapeInputService8TestCaseOperation1Input `json:"-" xml:"-"` } @@ -686,13 +688,13 @@ func (c *InputService9ProtocolTest) newRequest(op *request.Operation, params, da const opInputService9TestCaseOperation1 = "OperationName" // InputService9TestCaseOperation1Request generates a request for the InputService9TestCaseOperation1 operation. -func (c *InputService9ProtocolTest) InputService9TestCaseOperation1Request(input *InputService9TestShapeInputShape) (req *request.Request, output *InputService9TestShapeInputService9TestCaseOperation1Output) { +func (c *InputService9ProtocolTest) InputService9TestCaseOperation1Request(input *InputService9TestShapeInputService9TestCaseOperation1Input) (req *request.Request, output *InputService9TestShapeInputService9TestCaseOperation1Output) { op := &request.Operation{ Name: opInputService9TestCaseOperation1, } if input == nil { - input = &InputService9TestShapeInputShape{} + input = &InputService9TestShapeInputService9TestCaseOperation1Input{} } req = c.newRequest(op, input, output) @@ -701,203 +703,278 @@ func (c *InputService9ProtocolTest) InputService9TestCaseOperation1Request(input return } -func (c *InputService9ProtocolTest) InputService9TestCaseOperation1(input *InputService9TestShapeInputShape) (*InputService9TestShapeInputService9TestCaseOperation1Output, error) { +func (c *InputService9ProtocolTest) InputService9TestCaseOperation1(input *InputService9TestShapeInputService9TestCaseOperation1Input) (*InputService9TestShapeInputService9TestCaseOperation1Output, error) { req, out := c.InputService9TestCaseOperation1Request(input) err := req.Send() return out, err } -const opInputService9TestCaseOperation2 = "OperationName" +type InputService9TestShapeInputService9TestCaseOperation1Input struct { + TimeArg *time.Time `type:"timestamp" timestampFormat:"iso8601"` + + metadataInputService9TestShapeInputService9TestCaseOperation1Input `json:"-" xml:"-"` +} + +type metadataInputService9TestShapeInputService9TestCaseOperation1Input struct { + SDKShapeTraits bool `type:"structure"` +} + +type InputService9TestShapeInputService9TestCaseOperation1Output struct { + metadataInputService9TestShapeInputService9TestCaseOperation1Output `json:"-" xml:"-"` +} -// InputService9TestCaseOperation2Request generates a request for the InputService9TestCaseOperation2 operation. -func (c *InputService9ProtocolTest) InputService9TestCaseOperation2Request(input *InputService9TestShapeInputShape) (req *request.Request, output *InputService9TestShapeInputService9TestCaseOperation2Output) { +type metadataInputService9TestShapeInputService9TestCaseOperation1Output struct { + SDKShapeTraits bool `type:"structure"` +} + +type InputService10ProtocolTest struct { + *service.Service +} + +// New returns a new InputService10ProtocolTest client. +func NewInputService10ProtocolTest(config *aws.Config) *InputService10ProtocolTest { + service := &service.Service{ + ServiceInfo: serviceinfo.ServiceInfo{ + Config: defaults.DefaultConfig.Merge(config), + ServiceName: "inputservice10protocoltest", + APIVersion: "2014-01-01", + }, + } + service.Initialize() + + // Handlers + service.Handlers.Sign.PushBack(v4.Sign) + service.Handlers.Build.PushBack(query.Build) + service.Handlers.Unmarshal.PushBack(query.Unmarshal) + service.Handlers.UnmarshalMeta.PushBack(query.UnmarshalMeta) + service.Handlers.UnmarshalError.PushBack(query.UnmarshalError) + + return &InputService10ProtocolTest{service} +} + +// newRequest creates a new request for a InputService10ProtocolTest operation and runs any +// custom request initialization. +func (c *InputService10ProtocolTest) newRequest(op *request.Operation, params, data interface{}) *request.Request { + req := c.NewRequest(op, params, data) + + return req +} + +const opInputService10TestCaseOperation1 = "OperationName" + +// InputService10TestCaseOperation1Request generates a request for the InputService10TestCaseOperation1 operation. +func (c *InputService10ProtocolTest) InputService10TestCaseOperation1Request(input *InputService10TestShapeInputShape) (req *request.Request, output *InputService10TestShapeInputService10TestCaseOperation1Output) { op := &request.Operation{ - Name: opInputService9TestCaseOperation2, + Name: opInputService10TestCaseOperation1, } if input == nil { - input = &InputService9TestShapeInputShape{} + input = &InputService10TestShapeInputShape{} } req = c.newRequest(op, input, output) - output = &InputService9TestShapeInputService9TestCaseOperation2Output{} + output = &InputService10TestShapeInputService10TestCaseOperation1Output{} req.Data = output return } -func (c *InputService9ProtocolTest) InputService9TestCaseOperation2(input *InputService9TestShapeInputShape) (*InputService9TestShapeInputService9TestCaseOperation2Output, error) { - req, out := c.InputService9TestCaseOperation2Request(input) +func (c *InputService10ProtocolTest) InputService10TestCaseOperation1(input *InputService10TestShapeInputShape) (*InputService10TestShapeInputService10TestCaseOperation1Output, error) { + req, out := c.InputService10TestCaseOperation1Request(input) err := req.Send() return out, err } -const opInputService9TestCaseOperation3 = "OperationName" +const opInputService10TestCaseOperation2 = "OperationName" -// InputService9TestCaseOperation3Request generates a request for the InputService9TestCaseOperation3 operation. -func (c *InputService9ProtocolTest) InputService9TestCaseOperation3Request(input *InputService9TestShapeInputShape) (req *request.Request, output *InputService9TestShapeInputService9TestCaseOperation3Output) { +// InputService10TestCaseOperation2Request generates a request for the InputService10TestCaseOperation2 operation. +func (c *InputService10ProtocolTest) InputService10TestCaseOperation2Request(input *InputService10TestShapeInputShape) (req *request.Request, output *InputService10TestShapeInputService10TestCaseOperation2Output) { op := &request.Operation{ - Name: opInputService9TestCaseOperation3, + Name: opInputService10TestCaseOperation2, } if input == nil { - input = &InputService9TestShapeInputShape{} + input = &InputService10TestShapeInputShape{} } req = c.newRequest(op, input, output) - output = &InputService9TestShapeInputService9TestCaseOperation3Output{} + output = &InputService10TestShapeInputService10TestCaseOperation2Output{} req.Data = output return } -func (c *InputService9ProtocolTest) InputService9TestCaseOperation3(input *InputService9TestShapeInputShape) (*InputService9TestShapeInputService9TestCaseOperation3Output, error) { - req, out := c.InputService9TestCaseOperation3Request(input) +func (c *InputService10ProtocolTest) InputService10TestCaseOperation2(input *InputService10TestShapeInputShape) (*InputService10TestShapeInputService10TestCaseOperation2Output, error) { + req, out := c.InputService10TestCaseOperation2Request(input) err := req.Send() return out, err } -const opInputService9TestCaseOperation4 = "OperationName" +const opInputService10TestCaseOperation3 = "OperationName" -// InputService9TestCaseOperation4Request generates a request for the InputService9TestCaseOperation4 operation. -func (c *InputService9ProtocolTest) InputService9TestCaseOperation4Request(input *InputService9TestShapeInputShape) (req *request.Request, output *InputService9TestShapeInputService9TestCaseOperation4Output) { +// InputService10TestCaseOperation3Request generates a request for the InputService10TestCaseOperation3 operation. +func (c *InputService10ProtocolTest) InputService10TestCaseOperation3Request(input *InputService10TestShapeInputShape) (req *request.Request, output *InputService10TestShapeInputService10TestCaseOperation3Output) { op := &request.Operation{ - Name: opInputService9TestCaseOperation4, + Name: opInputService10TestCaseOperation3, } if input == nil { - input = &InputService9TestShapeInputShape{} + input = &InputService10TestShapeInputShape{} } req = c.newRequest(op, input, output) - output = &InputService9TestShapeInputService9TestCaseOperation4Output{} + output = &InputService10TestShapeInputService10TestCaseOperation3Output{} req.Data = output return } -func (c *InputService9ProtocolTest) InputService9TestCaseOperation4(input *InputService9TestShapeInputShape) (*InputService9TestShapeInputService9TestCaseOperation4Output, error) { - req, out := c.InputService9TestCaseOperation4Request(input) +func (c *InputService10ProtocolTest) InputService10TestCaseOperation3(input *InputService10TestShapeInputShape) (*InputService10TestShapeInputService10TestCaseOperation3Output, error) { + req, out := c.InputService10TestCaseOperation3Request(input) err := req.Send() return out, err } -const opInputService9TestCaseOperation5 = "OperationName" +const opInputService10TestCaseOperation4 = "OperationName" -// InputService9TestCaseOperation5Request generates a request for the InputService9TestCaseOperation5 operation. -func (c *InputService9ProtocolTest) InputService9TestCaseOperation5Request(input *InputService9TestShapeInputShape) (req *request.Request, output *InputService9TestShapeInputService9TestCaseOperation5Output) { +// InputService10TestCaseOperation4Request generates a request for the InputService10TestCaseOperation4 operation. +func (c *InputService10ProtocolTest) InputService10TestCaseOperation4Request(input *InputService10TestShapeInputShape) (req *request.Request, output *InputService10TestShapeInputService10TestCaseOperation4Output) { op := &request.Operation{ - Name: opInputService9TestCaseOperation5, + Name: opInputService10TestCaseOperation4, } if input == nil { - input = &InputService9TestShapeInputShape{} + input = &InputService10TestShapeInputShape{} } req = c.newRequest(op, input, output) - output = &InputService9TestShapeInputService9TestCaseOperation5Output{} + output = &InputService10TestShapeInputService10TestCaseOperation4Output{} req.Data = output return } -func (c *InputService9ProtocolTest) InputService9TestCaseOperation5(input *InputService9TestShapeInputShape) (*InputService9TestShapeInputService9TestCaseOperation5Output, error) { - req, out := c.InputService9TestCaseOperation5Request(input) +func (c *InputService10ProtocolTest) InputService10TestCaseOperation4(input *InputService10TestShapeInputShape) (*InputService10TestShapeInputService10TestCaseOperation4Output, error) { + req, out := c.InputService10TestCaseOperation4Request(input) err := req.Send() return out, err } -const opInputService9TestCaseOperation6 = "OperationName" +const opInputService10TestCaseOperation5 = "OperationName" -// InputService9TestCaseOperation6Request generates a request for the InputService9TestCaseOperation6 operation. -func (c *InputService9ProtocolTest) InputService9TestCaseOperation6Request(input *InputService9TestShapeInputShape) (req *request.Request, output *InputService9TestShapeInputService9TestCaseOperation6Output) { +// InputService10TestCaseOperation5Request generates a request for the InputService10TestCaseOperation5 operation. +func (c *InputService10ProtocolTest) InputService10TestCaseOperation5Request(input *InputService10TestShapeInputShape) (req *request.Request, output *InputService10TestShapeInputService10TestCaseOperation5Output) { op := &request.Operation{ - Name: opInputService9TestCaseOperation6, + Name: opInputService10TestCaseOperation5, } if input == nil { - input = &InputService9TestShapeInputShape{} + input = &InputService10TestShapeInputShape{} } req = c.newRequest(op, input, output) - output = &InputService9TestShapeInputService9TestCaseOperation6Output{} + output = &InputService10TestShapeInputService10TestCaseOperation5Output{} req.Data = output return } -func (c *InputService9ProtocolTest) InputService9TestCaseOperation6(input *InputService9TestShapeInputShape) (*InputService9TestShapeInputService9TestCaseOperation6Output, error) { - req, out := c.InputService9TestCaseOperation6Request(input) +func (c *InputService10ProtocolTest) InputService10TestCaseOperation5(input *InputService10TestShapeInputShape) (*InputService10TestShapeInputService10TestCaseOperation5Output, error) { + req, out := c.InputService10TestCaseOperation5Request(input) err := req.Send() return out, err } -type InputService9TestShapeInputService9TestCaseOperation1Output struct { - metadataInputService9TestShapeInputService9TestCaseOperation1Output `json:"-" xml:"-"` +const opInputService10TestCaseOperation6 = "OperationName" + +// InputService10TestCaseOperation6Request generates a request for the InputService10TestCaseOperation6 operation. +func (c *InputService10ProtocolTest) InputService10TestCaseOperation6Request(input *InputService10TestShapeInputShape) (req *request.Request, output *InputService10TestShapeInputService10TestCaseOperation6Output) { + op := &request.Operation{ + Name: opInputService10TestCaseOperation6, + } + + if input == nil { + input = &InputService10TestShapeInputShape{} + } + + req = c.newRequest(op, input, output) + output = &InputService10TestShapeInputService10TestCaseOperation6Output{} + req.Data = output + return } -type metadataInputService9TestShapeInputService9TestCaseOperation1Output struct { +func (c *InputService10ProtocolTest) InputService10TestCaseOperation6(input *InputService10TestShapeInputShape) (*InputService10TestShapeInputService10TestCaseOperation6Output, error) { + req, out := c.InputService10TestCaseOperation6Request(input) + err := req.Send() + return out, err +} + +type InputService10TestShapeInputService10TestCaseOperation1Output struct { + metadataInputService10TestShapeInputService10TestCaseOperation1Output `json:"-" xml:"-"` +} + +type metadataInputService10TestShapeInputService10TestCaseOperation1Output struct { SDKShapeTraits bool `type:"structure"` } -type InputService9TestShapeInputService9TestCaseOperation2Output struct { - metadataInputService9TestShapeInputService9TestCaseOperation2Output `json:"-" xml:"-"` +type InputService10TestShapeInputService10TestCaseOperation2Output struct { + metadataInputService10TestShapeInputService10TestCaseOperation2Output `json:"-" xml:"-"` } -type metadataInputService9TestShapeInputService9TestCaseOperation2Output struct { +type metadataInputService10TestShapeInputService10TestCaseOperation2Output struct { SDKShapeTraits bool `type:"structure"` } -type InputService9TestShapeInputService9TestCaseOperation3Output struct { - metadataInputService9TestShapeInputService9TestCaseOperation3Output `json:"-" xml:"-"` +type InputService10TestShapeInputService10TestCaseOperation3Output struct { + metadataInputService10TestShapeInputService10TestCaseOperation3Output `json:"-" xml:"-"` } -type metadataInputService9TestShapeInputService9TestCaseOperation3Output struct { +type metadataInputService10TestShapeInputService10TestCaseOperation3Output struct { SDKShapeTraits bool `type:"structure"` } -type InputService9TestShapeInputService9TestCaseOperation4Output struct { - metadataInputService9TestShapeInputService9TestCaseOperation4Output `json:"-" xml:"-"` +type InputService10TestShapeInputService10TestCaseOperation4Output struct { + metadataInputService10TestShapeInputService10TestCaseOperation4Output `json:"-" xml:"-"` } -type metadataInputService9TestShapeInputService9TestCaseOperation4Output struct { +type metadataInputService10TestShapeInputService10TestCaseOperation4Output struct { SDKShapeTraits bool `type:"structure"` } -type InputService9TestShapeInputService9TestCaseOperation5Output struct { - metadataInputService9TestShapeInputService9TestCaseOperation5Output `json:"-" xml:"-"` +type InputService10TestShapeInputService10TestCaseOperation5Output struct { + metadataInputService10TestShapeInputService10TestCaseOperation5Output `json:"-" xml:"-"` } -type metadataInputService9TestShapeInputService9TestCaseOperation5Output struct { +type metadataInputService10TestShapeInputService10TestCaseOperation5Output struct { SDKShapeTraits bool `type:"structure"` } -type InputService9TestShapeInputService9TestCaseOperation6Output struct { - metadataInputService9TestShapeInputService9TestCaseOperation6Output `json:"-" xml:"-"` +type InputService10TestShapeInputService10TestCaseOperation6Output struct { + metadataInputService10TestShapeInputService10TestCaseOperation6Output `json:"-" xml:"-"` } -type metadataInputService9TestShapeInputService9TestCaseOperation6Output struct { +type metadataInputService10TestShapeInputService10TestCaseOperation6Output struct { SDKShapeTraits bool `type:"structure"` } -type InputService9TestShapeInputShape struct { - RecursiveStruct *InputService9TestShapeRecursiveStructType `type:"structure"` +type InputService10TestShapeInputShape struct { + RecursiveStruct *InputService10TestShapeRecursiveStructType `type:"structure"` - metadataInputService9TestShapeInputShape `json:"-" xml:"-"` + metadataInputService10TestShapeInputShape `json:"-" xml:"-"` } -type metadataInputService9TestShapeInputShape struct { +type metadataInputService10TestShapeInputShape struct { SDKShapeTraits bool `type:"structure"` } -type InputService9TestShapeRecursiveStructType struct { +type InputService10TestShapeRecursiveStructType struct { NoRecurse *string `type:"string"` - RecursiveList []*InputService9TestShapeRecursiveStructType `type:"list"` + RecursiveList []*InputService10TestShapeRecursiveStructType `type:"list"` - RecursiveMap map[string]*InputService9TestShapeRecursiveStructType `type:"map"` + RecursiveMap map[string]*InputService10TestShapeRecursiveStructType `type:"map"` - RecursiveStruct *InputService9TestShapeRecursiveStructType `type:"structure"` + RecursiveStruct *InputService10TestShapeRecursiveStructType `type:"structure"` - metadataInputService9TestShapeRecursiveStructType `json:"-" xml:"-"` + metadataInputService10TestShapeRecursiveStructType `json:"-" xml:"-"` } -type metadataInputService9TestShapeRecursiveStructType struct { +type metadataInputService10TestShapeRecursiveStructType struct { SDKShapeTraits bool `type:"structure"` } @@ -923,7 +1000,7 @@ func TestInputService1ProtocolTestScalarMembersCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&Bar=val2&Foo=val1&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&Bar=val2&Foo=val1&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -951,7 +1028,7 @@ func TestInputService2ProtocolTestNestedStructureMembersCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&StructArg.ScalarArg=foo&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&StructArg.ScalarArg=foo&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -981,7 +1058,7 @@ func TestInputService3ProtocolTestListTypesCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&ListArg.member.1=foo&ListArg.member.2=bar&ListArg.member.3=baz&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&ListArg.member.1=foo&ListArg.member.2=bar&ListArg.member.3=baz&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -1012,7 +1089,7 @@ func TestInputService4ProtocolTestFlattenedListCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&ListArg.1=a&ListArg.2=b&ListArg.3=c&ScalarArg=foo&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&ListArg.1=a&ListArg.2=b&ListArg.3=c&ScalarArg=foo&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -1043,7 +1120,7 @@ func TestInputService5ProtocolTestFlattenedListWithLocationNameCase1(t *testing. // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&ListArgLocation.1=a&ListArgLocation.2=b&ListArgLocation.3=c&ScalarArg=foo&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&ListArgLocation.1=a&ListArgLocation.2=b&ListArgLocation.3=c&ScalarArg=foo&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -1072,7 +1149,7 @@ func TestInputService6ProtocolTestSerializeMapTypeCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&MapArg.entry.1.key=key1&MapArg.entry.1.value=val1&MapArg.entry.2.key=key2&MapArg.entry.2.value=val2&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&MapArg.entry.1.key=key1&MapArg.entry.1.value=val1&MapArg.entry.2.key=key2&MapArg.entry.2.value=val2&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -1081,12 +1158,15 @@ func TestInputService6ProtocolTestSerializeMapTypeCase1(t *testing.T) { } -func TestInputService7ProtocolTestBase64EncodedBlobsCase1(t *testing.T) { +func TestInputService7ProtocolTestSerializeMapTypeWithLocationNameCase1(t *testing.T) { svc := NewInputService7ProtocolTest(nil) svc.Endpoint = "https://test" input := &InputService7TestShapeInputService7TestCaseOperation1Input{ - BlobArg: []byte("foo"), + MapArg: map[string]*string{ + "key1": aws.String("val1"), + "key2": aws.String("val2"), + }, } req, _ := svc.InputService7TestCaseOperation1Request(input) r := req.HTTPRequest @@ -1098,7 +1178,7 @@ func TestInputService7ProtocolTestBase64EncodedBlobsCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&BlobArg=Zm9v&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&MapArg.entry.1.TheKey=key1&MapArg.entry.1.TheValue=val1&MapArg.entry.2.TheKey=key2&MapArg.entry.2.TheValue=val2&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -1107,12 +1187,12 @@ func TestInputService7ProtocolTestBase64EncodedBlobsCase1(t *testing.T) { } -func TestInputService8ProtocolTestTimestampValuesCase1(t *testing.T) { +func TestInputService8ProtocolTestBase64EncodedBlobsCase1(t *testing.T) { svc := NewInputService8ProtocolTest(nil) svc.Endpoint = "https://test" input := &InputService8TestShapeInputService8TestCaseOperation1Input{ - TimeArg: aws.Time(time.Unix(1422172800, 0)), + BlobArg: []byte("foo"), } req, _ := svc.InputService8TestCaseOperation1Request(input) r := req.HTTPRequest @@ -1124,7 +1204,7 @@ func TestInputService8ProtocolTestTimestampValuesCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&TimeArg=2015-01-25T08%3A00%3A00Z&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&BlobArg=Zm9v&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -1133,16 +1213,42 @@ func TestInputService8ProtocolTestTimestampValuesCase1(t *testing.T) { } -func TestInputService9ProtocolTestRecursiveShapesCase1(t *testing.T) { +func TestInputService9ProtocolTestTimestampValuesCase1(t *testing.T) { svc := NewInputService9ProtocolTest(nil) svc.Endpoint = "https://test" - input := &InputService9TestShapeInputShape{ - RecursiveStruct: &InputService9TestShapeRecursiveStructType{ + input := &InputService9TestShapeInputService9TestCaseOperation1Input{ + TimeArg: aws.Time(time.Unix(1422172800, 0)), + } + req, _ := svc.InputService9TestCaseOperation1Request(input) + r := req.HTTPRequest + + // build request + query.Build(req) + assert.NoError(t, req.Error) + + // assert body + assert.NotNil(t, r.Body) + body, _ := ioutil.ReadAll(r.Body) + utilassert.AssertQuery(t, `Action=OperationName&TimeArg=2015-01-25T08%3A00%3A00Z&Version=2014-01-01`, util.Trim(string(body))) + + // assert URL + assert.Equal(t, "https://test/", r.URL.String()) + + // assert headers + +} + +func TestInputService10ProtocolTestRecursiveShapesCase1(t *testing.T) { + svc := NewInputService10ProtocolTest(nil) + svc.Endpoint = "https://test" + + input := &InputService10TestShapeInputShape{ + RecursiveStruct: &InputService10TestShapeRecursiveStructType{ NoRecurse: aws.String("foo"), }, } - req, _ := svc.InputService9TestCaseOperation1Request(input) + req, _ := svc.InputService10TestCaseOperation1Request(input) r := req.HTTPRequest // build request @@ -1152,7 +1258,7 @@ func TestInputService9ProtocolTestRecursiveShapesCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&RecursiveStruct.NoRecurse=foo&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&RecursiveStruct.NoRecurse=foo&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -1161,18 +1267,18 @@ func TestInputService9ProtocolTestRecursiveShapesCase1(t *testing.T) { } -func TestInputService9ProtocolTestRecursiveShapesCase2(t *testing.T) { - svc := NewInputService9ProtocolTest(nil) +func TestInputService10ProtocolTestRecursiveShapesCase2(t *testing.T) { + svc := NewInputService10ProtocolTest(nil) svc.Endpoint = "https://test" - input := &InputService9TestShapeInputShape{ - RecursiveStruct: &InputService9TestShapeRecursiveStructType{ - RecursiveStruct: &InputService9TestShapeRecursiveStructType{ + input := &InputService10TestShapeInputShape{ + RecursiveStruct: &InputService10TestShapeRecursiveStructType{ + RecursiveStruct: &InputService10TestShapeRecursiveStructType{ NoRecurse: aws.String("foo"), }, }, } - req, _ := svc.InputService9TestCaseOperation2Request(input) + req, _ := svc.InputService10TestCaseOperation2Request(input) r := req.HTTPRequest // build request @@ -1182,7 +1288,7 @@ func TestInputService9ProtocolTestRecursiveShapesCase2(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&RecursiveStruct.RecursiveStruct.NoRecurse=foo&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&RecursiveStruct.RecursiveStruct.NoRecurse=foo&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -1191,22 +1297,22 @@ func TestInputService9ProtocolTestRecursiveShapesCase2(t *testing.T) { } -func TestInputService9ProtocolTestRecursiveShapesCase3(t *testing.T) { - svc := NewInputService9ProtocolTest(nil) +func TestInputService10ProtocolTestRecursiveShapesCase3(t *testing.T) { + svc := NewInputService10ProtocolTest(nil) svc.Endpoint = "https://test" - input := &InputService9TestShapeInputShape{ - RecursiveStruct: &InputService9TestShapeRecursiveStructType{ - RecursiveStruct: &InputService9TestShapeRecursiveStructType{ - RecursiveStruct: &InputService9TestShapeRecursiveStructType{ - RecursiveStruct: &InputService9TestShapeRecursiveStructType{ + input := &InputService10TestShapeInputShape{ + RecursiveStruct: &InputService10TestShapeRecursiveStructType{ + RecursiveStruct: &InputService10TestShapeRecursiveStructType{ + RecursiveStruct: &InputService10TestShapeRecursiveStructType{ + RecursiveStruct: &InputService10TestShapeRecursiveStructType{ NoRecurse: aws.String("foo"), }, }, }, }, } - req, _ := svc.InputService9TestCaseOperation3Request(input) + req, _ := svc.InputService10TestCaseOperation3Request(input) r := req.HTTPRequest // build request @@ -1216,7 +1322,7 @@ func TestInputService9ProtocolTestRecursiveShapesCase3(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&RecursiveStruct.RecursiveStruct.RecursiveStruct.RecursiveStruct.NoRecurse=foo&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&RecursiveStruct.RecursiveStruct.RecursiveStruct.RecursiveStruct.NoRecurse=foo&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -1225,13 +1331,13 @@ func TestInputService9ProtocolTestRecursiveShapesCase3(t *testing.T) { } -func TestInputService9ProtocolTestRecursiveShapesCase4(t *testing.T) { - svc := NewInputService9ProtocolTest(nil) +func TestInputService10ProtocolTestRecursiveShapesCase4(t *testing.T) { + svc := NewInputService10ProtocolTest(nil) svc.Endpoint = "https://test" - input := &InputService9TestShapeInputShape{ - RecursiveStruct: &InputService9TestShapeRecursiveStructType{ - RecursiveList: []*InputService9TestShapeRecursiveStructType{ + input := &InputService10TestShapeInputShape{ + RecursiveStruct: &InputService10TestShapeRecursiveStructType{ + RecursiveList: []*InputService10TestShapeRecursiveStructType{ { NoRecurse: aws.String("foo"), }, @@ -1241,7 +1347,7 @@ func TestInputService9ProtocolTestRecursiveShapesCase4(t *testing.T) { }, }, } - req, _ := svc.InputService9TestCaseOperation4Request(input) + req, _ := svc.InputService10TestCaseOperation4Request(input) r := req.HTTPRequest // build request @@ -1251,7 +1357,7 @@ func TestInputService9ProtocolTestRecursiveShapesCase4(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&RecursiveStruct.RecursiveList.member.1.NoRecurse=foo&RecursiveStruct.RecursiveList.member.2.NoRecurse=bar&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&RecursiveStruct.RecursiveList.member.1.NoRecurse=foo&RecursiveStruct.RecursiveList.member.2.NoRecurse=bar&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -1260,25 +1366,25 @@ func TestInputService9ProtocolTestRecursiveShapesCase4(t *testing.T) { } -func TestInputService9ProtocolTestRecursiveShapesCase5(t *testing.T) { - svc := NewInputService9ProtocolTest(nil) +func TestInputService10ProtocolTestRecursiveShapesCase5(t *testing.T) { + svc := NewInputService10ProtocolTest(nil) svc.Endpoint = "https://test" - input := &InputService9TestShapeInputShape{ - RecursiveStruct: &InputService9TestShapeRecursiveStructType{ - RecursiveList: []*InputService9TestShapeRecursiveStructType{ + input := &InputService10TestShapeInputShape{ + RecursiveStruct: &InputService10TestShapeRecursiveStructType{ + RecursiveList: []*InputService10TestShapeRecursiveStructType{ { NoRecurse: aws.String("foo"), }, { - RecursiveStruct: &InputService9TestShapeRecursiveStructType{ + RecursiveStruct: &InputService10TestShapeRecursiveStructType{ NoRecurse: aws.String("bar"), }, }, }, }, } - req, _ := svc.InputService9TestCaseOperation5Request(input) + req, _ := svc.InputService10TestCaseOperation5Request(input) r := req.HTTPRequest // build request @@ -1288,7 +1394,7 @@ func TestInputService9ProtocolTestRecursiveShapesCase5(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&RecursiveStruct.RecursiveList.member.1.NoRecurse=foo&RecursiveStruct.RecursiveList.member.2.RecursiveStruct.NoRecurse=bar&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&RecursiveStruct.RecursiveList.member.1.NoRecurse=foo&RecursiveStruct.RecursiveList.member.2.RecursiveStruct.NoRecurse=bar&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -1297,13 +1403,13 @@ func TestInputService9ProtocolTestRecursiveShapesCase5(t *testing.T) { } -func TestInputService9ProtocolTestRecursiveShapesCase6(t *testing.T) { - svc := NewInputService9ProtocolTest(nil) +func TestInputService10ProtocolTestRecursiveShapesCase6(t *testing.T) { + svc := NewInputService10ProtocolTest(nil) svc.Endpoint = "https://test" - input := &InputService9TestShapeInputShape{ - RecursiveStruct: &InputService9TestShapeRecursiveStructType{ - RecursiveMap: map[string]*InputService9TestShapeRecursiveStructType{ + input := &InputService10TestShapeInputShape{ + RecursiveStruct: &InputService10TestShapeRecursiveStructType{ + RecursiveMap: map[string]*InputService10TestShapeRecursiveStructType{ "bar": { NoRecurse: aws.String("bar"), }, @@ -1313,7 +1419,7 @@ func TestInputService9ProtocolTestRecursiveShapesCase6(t *testing.T) { }, }, } - req, _ := svc.InputService9TestCaseOperation6Request(input) + req, _ := svc.InputService10TestCaseOperation6Request(input) r := req.HTTPRequest // build request @@ -1323,7 +1429,7 @@ func TestInputService9ProtocolTestRecursiveShapesCase6(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`Action=OperationName&RecursiveStruct.RecursiveMap.entry.1.key=bar&RecursiveStruct.RecursiveMap.entry.1.value.NoRecurse=bar&RecursiveStruct.RecursiveMap.entry.2.key=foo&RecursiveStruct.RecursiveMap.entry.2.value.NoRecurse=foo&Version=2014-01-01`), util.Trim(string(body))) + utilassert.AssertQuery(t, `Action=OperationName&RecursiveStruct.RecursiveMap.entry.1.key=foo&RecursiveStruct.RecursiveMap.entry.1.value.NoRecurse=foo&RecursiveStruct.RecursiveMap.entry.2.key=bar&RecursiveStruct.RecursiveMap.entry.2.value.NoRecurse=bar&Version=2014-01-01`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) diff --git a/internal/protocol/query/unmarshal_test.go b/internal/protocol/query/unmarshal_test.go index a0dcfc43adb..65b7130f319 100644 --- a/internal/protocol/query/unmarshal_test.go +++ b/internal/protocol/query/unmarshal_test.go @@ -20,6 +20,7 @@ import ( "github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil" "github.com/aws/aws-sdk-go/internal/signer/v4" "github.com/aws/aws-sdk-go/internal/util" + "github.com/aws/aws-sdk-go/internal/util/utilassert" "github.com/stretchr/testify/assert" ) @@ -29,6 +30,7 @@ var _ json.Marshaler var _ time.Time var _ xmlutil.XMLNode var _ xml.Attr +var _ utilassert.Imported var _ = ioutil.Discard var _ = util.Trim("") var _ = url.Values{} diff --git a/internal/protocol/restjson/build_test.go b/internal/protocol/restjson/build_test.go index 34cbae46ec8..110741e68e0 100644 --- a/internal/protocol/restjson/build_test.go +++ b/internal/protocol/restjson/build_test.go @@ -20,6 +20,7 @@ import ( "github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil" "github.com/aws/aws-sdk-go/internal/signer/v4" "github.com/aws/aws-sdk-go/internal/util" + "github.com/aws/aws-sdk-go/internal/util/utilassert" "github.com/stretchr/testify/assert" ) @@ -29,6 +30,7 @@ var _ json.Marshaler var _ time.Time var _ xmlutil.XMLNode var _ xml.Attr +var _ utilassert.Imported var _ = ioutil.Discard var _ = util.Trim("") var _ = url.Values{} @@ -1430,7 +1432,7 @@ func TestInputService4ProtocolTestURIParameterQuerystringParamsAndJSONBodyCase1( // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"Config":{"A":"one","B":"two"}}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"Config":{"A":"one","B":"two"}}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/2014-01-01/jobsByPipeline/foo?Ascending=true&PageToken=bar", r.URL.String()) @@ -1463,7 +1465,7 @@ func TestInputService5ProtocolTestURIParameterQuerystringParamsHeadersAndJSONBod // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"Config":{"A":"one","B":"two"}}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"Config":{"A":"one","B":"two"}}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/2014-01-01/jobsByPipeline/foo?Ascending=true&PageToken=bar", r.URL.String()) @@ -1492,7 +1494,7 @@ func TestInputService6ProtocolTestStreamingPayloadCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`contents`), util.Trim(string(body))) + assert.Equal(t, `contents`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/2014-01-01/vaults/name/archives", r.URL.String()) @@ -1519,7 +1521,7 @@ func TestInputService7ProtocolTestStringPayloadCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`bar`), util.Trim(string(body))) + assert.Equal(t, `bar`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -1545,7 +1547,7 @@ func TestInputService8ProtocolTestBlobPayloadCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`bar`), util.Trim(string(body))) + assert.Equal(t, `bar`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -1592,7 +1594,7 @@ func TestInputService9ProtocolTestStructurePayloadCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"baz":"bar"}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"baz":"bar"}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -1679,7 +1681,7 @@ func TestInputService11ProtocolTestRecursiveShapesCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"RecursiveStruct":{"NoRecurse":"foo"}}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"RecursiveStruct":{"NoRecurse":"foo"}}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/path", r.URL.String()) @@ -1709,7 +1711,7 @@ func TestInputService11ProtocolTestRecursiveShapesCase2(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"RecursiveStruct":{"RecursiveStruct":{"NoRecurse":"foo"}}}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"RecursiveStruct":{"RecursiveStruct":{"NoRecurse":"foo"}}}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/path", r.URL.String()) @@ -1743,7 +1745,7 @@ func TestInputService11ProtocolTestRecursiveShapesCase3(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"RecursiveStruct":{"RecursiveStruct":{"RecursiveStruct":{"RecursiveStruct":{"NoRecurse":"foo"}}}}}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"RecursiveStruct":{"RecursiveStruct":{"RecursiveStruct":{"RecursiveStruct":{"NoRecurse":"foo"}}}}}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/path", r.URL.String()) @@ -1778,7 +1780,7 @@ func TestInputService11ProtocolTestRecursiveShapesCase4(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"RecursiveStruct":{"RecursiveList":[{"NoRecurse":"foo"},{"NoRecurse":"bar"}]}}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"RecursiveStruct":{"RecursiveList":[{"NoRecurse":"foo"},{"NoRecurse":"bar"}]}}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/path", r.URL.String()) @@ -1815,7 +1817,7 @@ func TestInputService11ProtocolTestRecursiveShapesCase5(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"RecursiveStruct":{"RecursiveList":[{"NoRecurse":"foo"},{"RecursiveStruct":{"NoRecurse":"bar"}}]}}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"RecursiveStruct":{"RecursiveList":[{"NoRecurse":"foo"},{"RecursiveStruct":{"NoRecurse":"bar"}}]}}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/path", r.URL.String()) @@ -1850,7 +1852,7 @@ func TestInputService11ProtocolTestRecursiveShapesCase6(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"RecursiveStruct":{"RecursiveMap":{"bar":{"NoRecurse":"bar"},"foo":{"NoRecurse":"foo"}}}}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"RecursiveStruct":{"RecursiveMap":{"foo":{"NoRecurse":"foo"},"bar":{"NoRecurse":"bar"}}}}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/path", r.URL.String()) @@ -1876,7 +1878,7 @@ func TestInputService12ProtocolTestTimestampValuesCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) - assert.Equal(t, util.Trim(`{"TimeArg":1422172800}`), util.Trim(string(body))) + utilassert.AssertJSON(t, `{"TimeArg":1422172800}`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/path", r.URL.String()) diff --git a/internal/protocol/restjson/unmarshal_test.go b/internal/protocol/restjson/unmarshal_test.go index 58d7f47fb56..22ba837275a 100644 --- a/internal/protocol/restjson/unmarshal_test.go +++ b/internal/protocol/restjson/unmarshal_test.go @@ -20,6 +20,7 @@ import ( "github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil" "github.com/aws/aws-sdk-go/internal/signer/v4" "github.com/aws/aws-sdk-go/internal/util" + "github.com/aws/aws-sdk-go/internal/util/utilassert" "github.com/stretchr/testify/assert" ) @@ -29,6 +30,7 @@ var _ json.Marshaler var _ time.Time var _ xmlutil.XMLNode var _ xml.Attr +var _ utilassert.Imported var _ = ioutil.Discard var _ = util.Trim("") var _ = url.Values{} diff --git a/internal/protocol/restxml/build_test.go b/internal/protocol/restxml/build_test.go index 253bc2989c1..e92cf5469dd 100644 --- a/internal/protocol/restxml/build_test.go +++ b/internal/protocol/restxml/build_test.go @@ -20,6 +20,7 @@ import ( "github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil" "github.com/aws/aws-sdk-go/internal/signer/v4" "github.com/aws/aws-sdk-go/internal/util" + "github.com/aws/aws-sdk-go/internal/util/utilassert" "github.com/stretchr/testify/assert" ) @@ -29,6 +30,7 @@ var _ json.Marshaler var _ time.Time var _ xmlutil.XMLNode var _ xml.Attr +var _ utilassert.Imported var _ = ioutil.Discard var _ = util.Trim("") var _ = url.Values{} @@ -1933,7 +1935,7 @@ func TestInputService1ProtocolTestBasicXMLSerializationCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`barfoo`), util.Trim(string(body))) + utilassert.AssertXML(t, `barfoo`, util.Trim(string(body)), InputService1TestShapeInputShape{}) // assert URL assert.Equal(t, "https://test/2014-01-01/hostedzone", r.URL.String()) @@ -1960,7 +1962,7 @@ func TestInputService1ProtocolTestBasicXMLSerializationCase2(t *testing.T) { // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`barfoo`), util.Trim(string(body))) + utilassert.AssertXML(t, `barfoo`, util.Trim(string(body)), InputService1TestShapeInputShape{}) // assert URL assert.Equal(t, "https://test/2014-01-01/hostedzone", r.URL.String()) @@ -1989,7 +1991,7 @@ func TestInputService2ProtocolTestSerializeOtherScalarTypesCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`true3false1.2`), util.Trim(string(body))) + utilassert.AssertXML(t, `true3false1.2`, util.Trim(string(body)), InputService2TestShapeInputService2TestCaseOperation1Input{}) // assert URL assert.Equal(t, "https://test/2014-01-01/hostedzone", r.URL.String()) @@ -2019,7 +2021,7 @@ func TestInputService3ProtocolTestNestedStructuresCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`bazba`), util.Trim(string(body))) + utilassert.AssertXML(t, `bazba`, util.Trim(string(body)), InputService3TestShapeInputService3TestCaseOperation1Input{}) // assert URL assert.Equal(t, "https://test/2014-01-01/hostedzone", r.URL.String()) @@ -2046,7 +2048,7 @@ func TestInputService4ProtocolTestNestedStructuresCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`baz`), util.Trim(string(body))) + utilassert.AssertXML(t, `baz`, util.Trim(string(body)), InputService4TestShapeInputService4TestCaseOperation1Input{}) // assert URL assert.Equal(t, "https://test/2014-01-01/hostedzone", r.URL.String()) @@ -2076,7 +2078,7 @@ func TestInputService5ProtocolTestNonFlattenedListsCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`onetwothree`), util.Trim(string(body))) + utilassert.AssertXML(t, `onetwothree`, util.Trim(string(body)), InputService5TestShapeInputService5TestCaseOperation1Input{}) // assert URL assert.Equal(t, "https://test/2014-01-01/hostedzone", r.URL.String()) @@ -2106,7 +2108,7 @@ func TestInputService6ProtocolTestNonFlattenedListsWithLocationNameCase1(t *test // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`onetwothree`), util.Trim(string(body))) + utilassert.AssertXML(t, `onetwothree`, util.Trim(string(body)), InputService6TestShapeInputService6TestCaseOperation1Input{}) // assert URL assert.Equal(t, "https://test/2014-01-01/hostedzone", r.URL.String()) @@ -2136,7 +2138,7 @@ func TestInputService7ProtocolTestFlattenedListsCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`onetwothree`), util.Trim(string(body))) + utilassert.AssertXML(t, `onetwothree`, util.Trim(string(body)), InputService7TestShapeInputService7TestCaseOperation1Input{}) // assert URL assert.Equal(t, "https://test/2014-01-01/hostedzone", r.URL.String()) @@ -2166,7 +2168,7 @@ func TestInputService8ProtocolTestFlattenedListsWithLocationNameCase1(t *testing // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`onetwothree`), util.Trim(string(body))) + utilassert.AssertXML(t, `onetwothree`, util.Trim(string(body)), InputService8TestShapeInputService8TestCaseOperation1Input{}) // assert URL assert.Equal(t, "https://test/2014-01-01/hostedzone", r.URL.String()) @@ -2202,7 +2204,7 @@ func TestInputService9ProtocolTestListOfStructuresCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`onetwothree`), util.Trim(string(body))) + utilassert.AssertXML(t, `onetwothree`, util.Trim(string(body)), InputService9TestShapeInputService9TestCaseOperation1Input{}) // assert URL assert.Equal(t, "https://test/2014-01-01/hostedzone", r.URL.String()) @@ -2231,7 +2233,7 @@ func TestInputService10ProtocolTestBlobAndTimestampShapesCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`Zm9v2015-01-25T08:00:00Z`), util.Trim(string(body))) + utilassert.AssertXML(t, `Zm9v2015-01-25T08:00:00Z`, util.Trim(string(body)), InputService10TestShapeInputService10TestCaseOperation1Input{}) // assert URL assert.Equal(t, "https://test/2014-01-01/hostedzone", r.URL.String()) @@ -2283,7 +2285,7 @@ func TestInputService12ProtocolTestStringPayloadCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`bar`), util.Trim(string(body))) + assert.Equal(t, `bar`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -2309,7 +2311,7 @@ func TestInputService13ProtocolTestBlobPayloadCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`bar`), util.Trim(string(body))) + assert.Equal(t, `bar`, util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -2356,7 +2358,7 @@ func TestInputService14ProtocolTestStructurePayloadCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`bar`), util.Trim(string(body))) + utilassert.AssertXML(t, `bar`, util.Trim(string(body)), InputService14TestShapeInputShape{}) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -2406,7 +2408,7 @@ func TestInputService15ProtocolTestXMLAttributeCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`foo@example.com`), util.Trim(string(body))) + utilassert.AssertXML(t, `foo@example.com`, util.Trim(string(body)), InputService15TestShapeInputService15TestCaseOperation1Input{}) // assert URL assert.Equal(t, "https://test/", r.URL.String()) @@ -2496,7 +2498,7 @@ func TestInputService18ProtocolTestRecursiveShapesCase1(t *testing.T) { // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`foo`), util.Trim(string(body))) + utilassert.AssertXML(t, `foo`, util.Trim(string(body)), InputService18TestShapeInputShape{}) // assert URL assert.Equal(t, "https://test/path", r.URL.String()) @@ -2526,7 +2528,7 @@ func TestInputService18ProtocolTestRecursiveShapesCase2(t *testing.T) { // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`foo`), util.Trim(string(body))) + utilassert.AssertXML(t, `foo`, util.Trim(string(body)), InputService18TestShapeInputShape{}) // assert URL assert.Equal(t, "https://test/path", r.URL.String()) @@ -2560,7 +2562,7 @@ func TestInputService18ProtocolTestRecursiveShapesCase3(t *testing.T) { // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`foo`), util.Trim(string(body))) + utilassert.AssertXML(t, `foo`, util.Trim(string(body)), InputService18TestShapeInputShape{}) // assert URL assert.Equal(t, "https://test/path", r.URL.String()) @@ -2595,7 +2597,7 @@ func TestInputService18ProtocolTestRecursiveShapesCase4(t *testing.T) { // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`foobar`), util.Trim(string(body))) + utilassert.AssertXML(t, `foobar`, util.Trim(string(body)), InputService18TestShapeInputShape{}) // assert URL assert.Equal(t, "https://test/path", r.URL.String()) @@ -2632,7 +2634,7 @@ func TestInputService18ProtocolTestRecursiveShapesCase5(t *testing.T) { // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`foobar`), util.Trim(string(body))) + utilassert.AssertXML(t, `foobar`, util.Trim(string(body)), InputService18TestShapeInputShape{}) // assert URL assert.Equal(t, "https://test/path", r.URL.String()) @@ -2667,7 +2669,7 @@ func TestInputService18ProtocolTestRecursiveShapesCase6(t *testing.T) { // assert body assert.NotNil(t, r.Body) body := util.SortXML(r.Body) - assert.Equal(t, util.Trim(`barbarfoofoo`), util.Trim(string(body))) + utilassert.AssertXML(t, `foofoobarbar`, util.Trim(string(body)), InputService18TestShapeInputShape{}) // assert URL assert.Equal(t, "https://test/path", r.URL.String()) diff --git a/internal/protocol/restxml/unmarshal_test.go b/internal/protocol/restxml/unmarshal_test.go index bf73cb8e3ad..3f712eb8047 100644 --- a/internal/protocol/restxml/unmarshal_test.go +++ b/internal/protocol/restxml/unmarshal_test.go @@ -20,6 +20,7 @@ import ( "github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil" "github.com/aws/aws-sdk-go/internal/signer/v4" "github.com/aws/aws-sdk-go/internal/util" + "github.com/aws/aws-sdk-go/internal/util/utilassert" "github.com/stretchr/testify/assert" ) @@ -29,6 +30,7 @@ var _ json.Marshaler var _ time.Time var _ xmlutil.XMLNode var _ xml.Attr +var _ utilassert.Imported var _ = ioutil.Discard var _ = util.Trim("") var _ = url.Values{} diff --git a/internal/util/utilassert/assert.go b/internal/util/utilassert/assert.go new file mode 100644 index 00000000000..7f92485cd99 --- /dev/null +++ b/internal/util/utilassert/assert.go @@ -0,0 +1,178 @@ +// Package utilassert provides testing assertion generation functions. +package utilassert + +import ( + "fmt" + "reflect" + "regexp" + "strconv" + "strings" + "testing" + "encoding/json" + + "github.com/aws/aws-sdk-go/internal/model/api" + "github.com/aws/aws-sdk-go/internal/util/utilsort" + "github.com/stretchr/testify/assert" + "net/url" + "sort" + "encoding/xml" +) + +// Imported allows importing the utilassert package without using its contents. +// var _ utilassert.Imported +type Imported struct{} + +// findMember searches the shape for the member with the matching key name. +func findMember(shape *api.Shape, key string) string { + for actualKey := range shape.MemberRefs { + if strings.ToLower(key) == strings.ToLower(actualKey) { + return actualKey + } + } + return "" +} + +// GenerateAssertions builds assertions for a shape based on its type. +// +// The shape's recursive values also will have assertions generated for them. +func GenerateAssertions(out interface{}, shape *api.Shape, prefix string) string { + switch t := out.(type) { + case map[string]interface{}: + keys := utilsort.SortedKeys(t) + + code := "" + if shape.Type == "map" { + for _, k := range keys { + v := t[k] + s := shape.ValueRef.Shape + code += GenerateAssertions(v, s, prefix+"[\""+k+"\"]") + } + } else { + for _, k := range keys { + v := t[k] + m := findMember(shape, k) + s := shape.MemberRefs[m].Shape + code += GenerateAssertions(v, s, prefix+"."+m+"") + } + } + return code + case []interface{}: + code := "" + for i, v := range t { + s := shape.MemberRef.Shape + code += GenerateAssertions(v, s, prefix+"["+strconv.Itoa(i)+"]") + } + return code + default: + switch shape.Type { + case "timestamp": + return fmt.Sprintf("assert.Equal(t, time.Unix(%#v, 0).UTC().String(), %s.String())\n", out, prefix) + case "blob": + return fmt.Sprintf("assert.Equal(t, %#v, string(%s))\n", out, prefix) + case "integer", "long": + return fmt.Sprintf("assert.Equal(t, int64(%#v), *%s)\n", out, prefix) + default: + if !reflect.ValueOf(out).IsValid() { + return fmt.Sprintf("assert.Nil(t, *%s)\n", prefix) + } + return fmt.Sprintf("assert.Equal(t, %#v, *%s)\n", out, prefix) + } + } +} + +// Match is a testing helper to test for testing error by comparing expected +// with a regular expression. +func Match(t *testing.T, regex, expected string) { + if !regexp.MustCompile(regex).Match([]byte(expected)) { + t.Errorf("%q\n\tdoes not match /%s/", expected, regex) + } +} + +// AssertQuery verifies the expect HTTP query string matches the actual. +func AssertQuery(t *testing.T, expect, actual string, msgAndArgs ...interface{}) bool { + expectQ, err := url.ParseQuery(expect) + if err != nil { + t.Errorf(errMsg("unable to parse expected Query", err, msgAndArgs)) + return false + } + actualQ, err := url.ParseQuery(expect) + if err != nil { + t.Errorf(errMsg("unable to parse actual Query", err, msgAndArgs)) + return false + } + + // Make sure the keys are the same + if !assert.Equal(t, queryValueKeys(expectQ), queryValueKeys(actualQ), msgAndArgs...) { + return false + } + + for k, expectQVals := range expectQ { + sort.Strings(expectQVals) + actualQVals := actualQ[k] + sort.Strings(actualQVals) + assert.Equal(t, expectQVals, actualQVals, msgAndArgs...) + } + + return true +} + +// AssertJSON verifies that the expect json string matches the actual. +func AssertJSON(t *testing.T, expect, actual string, msgAndArgs ...interface{}) bool { + expectVal := map[string]interface{}{} + if err := json.Unmarshal([]byte(expect), &expectVal); err != nil { + t.Errorf(errMsg("unable to parse expected JSON", err, msgAndArgs...)) + return false; + } + + actualVal := map[string]interface{}{} + if err := json.Unmarshal([]byte(actual), &actualVal); err != nil { + t.Errorf(errMsg("unable to parse actual JSON", err, msgAndArgs...)) + return false; + } + + return assert.Equal(t, expectVal, actualVal, msgAndArgs...) +} + +// AssertXML verifies that the expect xml string matches the actual. +func AssertXML(t *testing.T, expect, actual string, container interface{}, msgAndArgs ...interface{}) bool { + expectVal := container + if err := xml.Unmarshal([]byte(expect), &expectVal); err != nil { + t.Errorf(errMsg("unable to parse expected XML", err, msgAndArgs...)) + } + + actualVal := container + if err := xml.Unmarshal([]byte(actual), &actualVal); err != nil { + t.Errorf(errMsg("unable to parse actual XML", err, msgAndArgs...)) + } + return assert.Equal(t, expectVal, actualVal, msgAndArgs...) +} + +func errMsg(baseMsg string, err error, msgAndArgs ...interface{}) string { + message := messageFromMsgAndArgs(msgAndArgs) + if message != "" { + message += ", " + } + return fmt.Sprintf("%s%s, %v", message, baseMsg, err) +} + +func messageFromMsgAndArgs(msgAndArgs []interface{}) string { + if len(msgAndArgs) == 0 || msgAndArgs == nil { + return "" + } + if len(msgAndArgs) == 1 { + return msgAndArgs[0].(string) + } + if len(msgAndArgs) > 1 { + return fmt.Sprintf(msgAndArgs[0].(string), msgAndArgs[1:]...) + } + return "" +} + +func queryValueKeys(v url.Values) []string { + keys := make([]string, 0, len(v)) + for k := range v { + keys = append(keys, k) + } + sort.Strings(keys) + return keys +} \ No newline at end of file diff --git a/internal/util/utilassert/assert_test.go b/internal/util/utilassert/assert_test.go new file mode 100644 index 00000000000..3bb9ee53549 --- /dev/null +++ b/internal/util/utilassert/assert_test.go @@ -0,0 +1,63 @@ +package utilassert_test + +import ( + "encoding/xml" + "github.com/aws/aws-sdk-go/internal/util/utilassert" + "testing" +) + +func TestAssertJSON(t *testing.T) { + cases := []struct { + e, a string + asserts bool + }{ + { + e: `{"RecursiveStruct":{"RecursiveMap":{"foo":{"NoRecurse":"foo"},"bar":{"NoRecurse":"bar"}}}}`, + a: `{"RecursiveStruct":{"RecursiveMap":{"bar":{"NoRecurse":"bar"},"foo":{"NoRecurse":"foo"}}}}`, + asserts: true, + }, + } + + for i, c := range cases { + mockT := &testing.T{} + if utilassert.AssertJSON(mockT, c.e, c.a) != c.asserts { + t.Error("Assert JSON result was not expected.", i) + } + } +} + +func TestAssertXML(t *testing.T) { + cases := []struct { + e, a string + asserts bool + container struct { + XMLName xml.Name `xml:"OperationRequest"` + NS string `xml:"xmlns,attr"` + RecursiveStruct struct { + RecursiveMap struct { + Entries []struct { + XMLName xml.Name `xml:"entries"` + Key string `xml:"key"` + Value struct { + XMLName xml.Name `xml:"value"` + NoRecurse string + } + } + } + } + } + }{ + { + e: `foofoobarbar`, + a: `barbarfoofoo`, + asserts: true, + }, + } + + for i, c := range cases { +// mockT := &testing.T{} + if utilassert.AssertXML(t, c.e, c.a, c.container) != c.asserts { + t.Error("Assert XML result was not expected.", i) + } + } +} diff --git a/internal/util/utilassert/utilassert.go b/internal/util/utilassert/utilassert.go deleted file mode 100644 index bb57d0a330a..00000000000 --- a/internal/util/utilassert/utilassert.go +++ /dev/null @@ -1,76 +0,0 @@ -// Package utilassert provides testing assertion generation functions. -package utilassert - -import ( - "fmt" - "regexp" - "strconv" - "strings" - "testing" - - "github.com/aws/aws-sdk-go/internal/model/api" - "github.com/aws/aws-sdk-go/internal/util/utilsort" -) - -// findMember searches the shape for the member with the matching key name. -func findMember(shape *api.Shape, key string) string { - for actualKey := range shape.MemberRefs { - if strings.ToLower(key) == strings.ToLower(actualKey) { - return actualKey - } - } - return "" -} - -// GenerateAssertions builds assertions for a shape based on its type. -// -// The shape's recursive values also will have assertions generated for them. -func GenerateAssertions(out interface{}, shape *api.Shape, prefix string) string { - switch t := out.(type) { - case map[string]interface{}: - keys := utilsort.SortedKeys(t) - - code := "" - if shape.Type == "map" { - for _, k := range keys { - v := t[k] - s := shape.ValueRef.Shape - code += GenerateAssertions(v, s, prefix+"[\""+k+"\"]") - } - } else { - for _, k := range keys { - v := t[k] - m := findMember(shape, k) - s := shape.MemberRefs[m].Shape - code += GenerateAssertions(v, s, prefix+"."+m+"") - } - } - return code - case []interface{}: - code := "" - for i, v := range t { - s := shape.MemberRef.Shape - code += GenerateAssertions(v, s, prefix+"["+strconv.Itoa(i)+"]") - } - return code - default: - switch shape.Type { - case "timestamp": - return fmt.Sprintf("assert.Equal(t, time.Unix(%#v, 0).UTC().String(), %s.String())\n", out, prefix) - case "blob": - return fmt.Sprintf("assert.Equal(t, %#v, string(%s))\n", out, prefix) - case "integer", "long": - return fmt.Sprintf("assert.Equal(t, int64(%#v), *%s)\n", out, prefix) - default: - return fmt.Sprintf("assert.Equal(t, %#v, *%s)\n", out, prefix) - } - } -} - -// Match is a testing helper to test for testing error by comparing expected -// with a regular expression. -func Match(t *testing.T, regex, expected string) { - if !regexp.MustCompile(regex).Match([]byte(expected)) { - t.Errorf("%q\n\tdoes not match /%s/", expected, regex) - } -}