diff --git a/Makefile b/Makefile index 996c13e1a8f..9dc36fe4eb1 100644 --- a/Makefile +++ b/Makefile @@ -86,7 +86,10 @@ tidy-modules-. add-module-license-files gen-aws-ptrs format generate-tmpreplace-smithy: smithy-generate update-requires gen-repo-mod-replace update-module-metadata smithy-annotate-stable \ gen-config-asserts gen-internal-codegen copy-attributevalue-feature gen-mod-replace-smithy-. min-go-version-. \ -tidy-modules-. add-module-license-files gen-aws-ptrs format gen-mod-dropreplace-smithy-. +tidy-modules-. add-module-license-files gen-aws-ptrs format gen-mod-dropreplace-smithy-. reset-sum + +reset-sum: + find . -name go.sum -exec git checkout -- {} \; smithy-generate: cd codegen && ./gradlew clean build -Plog-tests && ./gradlew clean diff --git a/internal/protocoltest/awsrestjson/api_op_AllQueryStringTypes_test.go b/internal/protocoltest/awsrestjson/api_op_AllQueryStringTypes_test.go index 931fc1b86f4..b24830c6ddf 100644 --- a/internal/protocoltest/awsrestjson/api_op_AllQueryStringTypes_test.go +++ b/internal/protocoltest/awsrestjson/api_op_AllQueryStringTypes_test.go @@ -3,23 +3,20 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/types" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithytime "github.com/aws/smithy-go/time" "io" - "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" "time" ) @@ -341,25 +338,8 @@ func TestClient_AllQueryStringTypes_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -383,11 +363,15 @@ func TestClient_AllQueryStringTypes_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.AllQueryStringTypes(context.Background(), c.Params) + result, err := client.AllQueryStringTypes(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_ConstantAndVariableQueryString_test.go b/internal/protocoltest/awsrestjson/api_op_ConstantAndVariableQueryString_test.go index a57a0041d11..c196570bb5f 100644 --- a/internal/protocoltest/awsrestjson/api_op_ConstantAndVariableQueryString_test.go +++ b/internal/protocoltest/awsrestjson/api_op_ConstantAndVariableQueryString_test.go @@ -3,20 +3,17 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -73,25 +70,8 @@ func TestClient_ConstantAndVariableQueryString_awsRestjson1Serialize(t *testing. } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -115,11 +95,15 @@ func TestClient_ConstantAndVariableQueryString_awsRestjson1Serialize(t *testing. e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.ConstantAndVariableQueryString(context.Background(), c.Params) + result, err := client.ConstantAndVariableQueryString(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_ConstantQueryString_test.go b/internal/protocoltest/awsrestjson/api_op_ConstantQueryString_test.go index f66c17c0784..c0d175fb68b 100644 --- a/internal/protocoltest/awsrestjson/api_op_ConstantQueryString_test.go +++ b/internal/protocoltest/awsrestjson/api_op_ConstantQueryString_test.go @@ -3,20 +3,17 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -53,25 +50,8 @@ func TestClient_ConstantQueryString_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -95,11 +75,15 @@ func TestClient_ConstantQueryString_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.ConstantQueryString(context.Background(), c.Params) + result, err := client.ConstantQueryString(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_DocumentTypeAsPayload_test.go b/internal/protocoltest/awsrestjson/api_op_DocumentTypeAsPayload_test.go index 0e777d7286a..f0fc51708f7 100644 --- a/internal/protocoltest/awsrestjson/api_op_DocumentTypeAsPayload_test.go +++ b/internal/protocoltest/awsrestjson/api_op_DocumentTypeAsPayload_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/document" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -79,25 +78,8 @@ func TestClient_DocumentTypeAsPayload_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -121,11 +103,15 @@ func TestClient_DocumentTypeAsPayload_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.DocumentTypeAsPayload(context.Background(), c.Params) + result, err := client.DocumentTypeAsPayload(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_DocumentType_test.go b/internal/protocoltest/awsrestjson/api_op_DocumentType_test.go index 3ba1be89b42..902792c0fd0 100644 --- a/internal/protocoltest/awsrestjson/api_op_DocumentType_test.go +++ b/internal/protocoltest/awsrestjson/api_op_DocumentType_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/document" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -178,25 +177,8 @@ func TestClient_DocumentType_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -220,11 +202,15 @@ func TestClient_DocumentType_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.DocumentType(context.Background(), c.Params) + result, err := client.DocumentType(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_EmptyInputAndEmptyOutput_test.go b/internal/protocoltest/awsrestjson/api_op_EmptyInputAndEmptyOutput_test.go index 82ca3338acc..29f4341799f 100644 --- a/internal/protocoltest/awsrestjson/api_op_EmptyInputAndEmptyOutput_test.go +++ b/internal/protocoltest/awsrestjson/api_op_EmptyInputAndEmptyOutput_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -54,25 +53,8 @@ func TestClient_EmptyInputAndEmptyOutput_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -96,11 +78,15 @@ func TestClient_EmptyInputAndEmptyOutput_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.EmptyInputAndEmptyOutput(context.Background(), c.Params) + result, err := client.EmptyInputAndEmptyOutput(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_EndpointOperation_test.go b/internal/protocoltest/awsrestjson/api_op_EndpointOperation_test.go index 8d09bfbb233..4b807c806ad 100644 --- a/internal/protocoltest/awsrestjson/api_op_EndpointOperation_test.go +++ b/internal/protocoltest/awsrestjson/api_op_EndpointOperation_test.go @@ -3,19 +3,16 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -58,29 +55,8 @@ func TestClient_EndpointOperation_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - if name == "RestJsonEndpointTrait" { - t.Skip("disabled test aws.protocoltests.restjson#RestJson aws.protocoltests.restjson#EndpointOperation") - } - - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -104,11 +80,15 @@ func TestClient_EndpointOperation_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.EndpointOperation(context.Background(), c.Params) + result, err := client.EndpointOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_EndpointWithHostLabelOperation_test.go b/internal/protocoltest/awsrestjson/api_op_EndpointWithHostLabelOperation_test.go index 24991de775c..d5b3555c9e4 100644 --- a/internal/protocoltest/awsrestjson/api_op_EndpointWithHostLabelOperation_test.go +++ b/internal/protocoltest/awsrestjson/api_op_EndpointWithHostLabelOperation_test.go @@ -3,20 +3,17 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -64,29 +61,8 @@ func TestClient_EndpointWithHostLabelOperation_awsRestjson1Serialize(t *testing. } for name, c := range cases { t.Run(name, func(t *testing.T) { - if name == "RestJsonEndpointTraitWithHostLabel" { - t.Skip("disabled test aws.protocoltests.restjson#RestJson aws.protocoltests.restjson#EndpointWithHostLabelOperation") - } - - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -110,11 +86,15 @@ func TestClient_EndpointWithHostLabelOperation_awsRestjson1Serialize(t *testing. e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.EndpointWithHostLabelOperation(context.Background(), c.Params) + result, err := client.EndpointWithHostLabelOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_HostWithPathOperation_test.go b/internal/protocoltest/awsrestjson/api_op_HostWithPathOperation_test.go index 9ff065c1b8e..3c5ccf54479 100644 --- a/internal/protocoltest/awsrestjson/api_op_HostWithPathOperation_test.go +++ b/internal/protocoltest/awsrestjson/api_op_HostWithPathOperation_test.go @@ -3,19 +3,16 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -58,25 +55,8 @@ func TestClient_HostWithPathOperation_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -100,11 +80,15 @@ func TestClient_HostWithPathOperation_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HostWithPathOperation(context.Background(), c.Params) + result, err := client.HostWithPathOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_HttpChecksumRequired_test.go b/internal/protocoltest/awsrestjson/api_op_HttpChecksumRequired_test.go index 3f634aa13d2..ec5fec96dd5 100644 --- a/internal/protocoltest/awsrestjson/api_op_HttpChecksumRequired_test.go +++ b/internal/protocoltest/awsrestjson/api_op_HttpChecksumRequired_test.go @@ -3,20 +3,17 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -58,25 +55,8 @@ func TestClient_HttpChecksumRequired_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -100,11 +80,15 @@ func TestClient_HttpChecksumRequired_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpChecksumRequired(context.Background(), c.Params) + result, err := client.HttpChecksumRequired(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_HttpEnumPayload_test.go b/internal/protocoltest/awsrestjson/api_op_HttpEnumPayload_test.go index d774212b8cc..ef2faa578c2 100644 --- a/internal/protocoltest/awsrestjson/api_op_HttpEnumPayload_test.go +++ b/internal/protocoltest/awsrestjson/api_op_HttpEnumPayload_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -54,25 +53,8 @@ func TestClient_HttpEnumPayload_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -96,11 +78,15 @@ func TestClient_HttpEnumPayload_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpEnumPayload(context.Background(), c.Params) + result, err := client.HttpEnumPayload(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_HttpPayloadTraitsWithMediaType_test.go b/internal/protocoltest/awsrestjson/api_op_HttpPayloadTraitsWithMediaType_test.go index 85fd303b43a..db17ff35118 100644 --- a/internal/protocoltest/awsrestjson/api_op_HttpPayloadTraitsWithMediaType_test.go +++ b/internal/protocoltest/awsrestjson/api_op_HttpPayloadTraitsWithMediaType_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -64,25 +63,8 @@ func TestClient_HttpPayloadTraitsWithMediaType_awsRestjson1Serialize(t *testing. } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -106,11 +88,15 @@ func TestClient_HttpPayloadTraitsWithMediaType_awsRestjson1Serialize(t *testing. e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpPayloadTraitsWithMediaType(context.Background(), c.Params) + result, err := client.HttpPayloadTraitsWithMediaType(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_HttpPayloadTraits_test.go b/internal/protocoltest/awsrestjson/api_op_HttpPayloadTraits_test.go index 1c18232a6ef..a9e594c36ff 100644 --- a/internal/protocoltest/awsrestjson/api_op_HttpPayloadTraits_test.go +++ b/internal/protocoltest/awsrestjson/api_op_HttpPayloadTraits_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -80,25 +79,8 @@ func TestClient_HttpPayloadTraits_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -122,11 +104,15 @@ func TestClient_HttpPayloadTraits_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpPayloadTraits(context.Background(), c.Params) + result, err := client.HttpPayloadTraits(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_HttpPayloadWithStructure_test.go b/internal/protocoltest/awsrestjson/api_op_HttpPayloadWithStructure_test.go index 804ef101ddb..ba035f1b1c5 100644 --- a/internal/protocoltest/awsrestjson/api_op_HttpPayloadWithStructure_test.go +++ b/internal/protocoltest/awsrestjson/api_op_HttpPayloadWithStructure_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -69,25 +68,8 @@ func TestClient_HttpPayloadWithStructure_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -111,11 +93,15 @@ func TestClient_HttpPayloadWithStructure_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpPayloadWithStructure(context.Background(), c.Params) + result, err := client.HttpPayloadWithStructure(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_HttpPrefixHeaders_test.go b/internal/protocoltest/awsrestjson/api_op_HttpPrefixHeaders_test.go index ac99add3fda..0eb251e4d45 100644 --- a/internal/protocoltest/awsrestjson/api_op_HttpPrefixHeaders_test.go +++ b/internal/protocoltest/awsrestjson/api_op_HttpPrefixHeaders_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -80,25 +79,8 @@ func TestClient_HttpPrefixHeaders_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -122,11 +104,15 @@ func TestClient_HttpPrefixHeaders_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpPrefixHeaders(context.Background(), c.Params) + result, err := client.HttpPrefixHeaders(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_HttpRequestWithFloatLabels_test.go b/internal/protocoltest/awsrestjson/api_op_HttpRequestWithFloatLabels_test.go index eb962217eb7..12831397dd1 100644 --- a/internal/protocoltest/awsrestjson/api_op_HttpRequestWithFloatLabels_test.go +++ b/internal/protocoltest/awsrestjson/api_op_HttpRequestWithFloatLabels_test.go @@ -3,21 +3,18 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -78,25 +75,8 @@ func TestClient_HttpRequestWithFloatLabels_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -120,11 +100,15 @@ func TestClient_HttpRequestWithFloatLabels_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpRequestWithFloatLabels(context.Background(), c.Params) + result, err := client.HttpRequestWithFloatLabels(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_HttpRequestWithGreedyLabelInPath_test.go b/internal/protocoltest/awsrestjson/api_op_HttpRequestWithGreedyLabelInPath_test.go index 19b177ca6f5..46c6ce94275 100644 --- a/internal/protocoltest/awsrestjson/api_op_HttpRequestWithGreedyLabelInPath_test.go +++ b/internal/protocoltest/awsrestjson/api_op_HttpRequestWithGreedyLabelInPath_test.go @@ -3,20 +3,17 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -51,25 +48,8 @@ func TestClient_HttpRequestWithGreedyLabelInPath_awsRestjson1Serialize(t *testin } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -93,11 +73,15 @@ func TestClient_HttpRequestWithGreedyLabelInPath_awsRestjson1Serialize(t *testin e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpRequestWithGreedyLabelInPath(context.Background(), c.Params) + result, err := client.HttpRequestWithGreedyLabelInPath(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_HttpRequestWithLabelsAndTimestampFormat_test.go b/internal/protocoltest/awsrestjson/api_op_HttpRequestWithLabelsAndTimestampFormat_test.go index fc9a593ffd0..f50fde3ce67 100644 --- a/internal/protocoltest/awsrestjson/api_op_HttpRequestWithLabelsAndTimestampFormat_test.go +++ b/internal/protocoltest/awsrestjson/api_op_HttpRequestWithLabelsAndTimestampFormat_test.go @@ -3,21 +3,18 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithytime "github.com/aws/smithy-go/time" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -57,25 +54,8 @@ func TestClient_HttpRequestWithLabelsAndTimestampFormat_awsRestjson1Serialize(t } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -99,11 +79,15 @@ func TestClient_HttpRequestWithLabelsAndTimestampFormat_awsRestjson1Serialize(t e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpRequestWithLabelsAndTimestampFormat(context.Background(), c.Params) + result, err := client.HttpRequestWithLabelsAndTimestampFormat(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_HttpRequestWithLabels_test.go b/internal/protocoltest/awsrestjson/api_op_HttpRequestWithLabels_test.go index 021b1340e0b..3903ff0ea6e 100644 --- a/internal/protocoltest/awsrestjson/api_op_HttpRequestWithLabels_test.go +++ b/internal/protocoltest/awsrestjson/api_op_HttpRequestWithLabels_test.go @@ -3,21 +3,18 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithytime "github.com/aws/smithy-go/time" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -77,25 +74,8 @@ func TestClient_HttpRequestWithLabels_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -119,11 +99,15 @@ func TestClient_HttpRequestWithLabels_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpRequestWithLabels(context.Background(), c.Params) + result, err := client.HttpRequestWithLabels(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_HttpRequestWithRegexLiteral_test.go b/internal/protocoltest/awsrestjson/api_op_HttpRequestWithRegexLiteral_test.go index 1f366ab8c4c..caaf5c65b80 100644 --- a/internal/protocoltest/awsrestjson/api_op_HttpRequestWithRegexLiteral_test.go +++ b/internal/protocoltest/awsrestjson/api_op_HttpRequestWithRegexLiteral_test.go @@ -3,20 +3,17 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -50,25 +47,8 @@ func TestClient_HttpRequestWithRegexLiteral_awsRestjson1Serialize(t *testing.T) } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -92,11 +72,15 @@ func TestClient_HttpRequestWithRegexLiteral_awsRestjson1Serialize(t *testing.T) e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpRequestWithRegexLiteral(context.Background(), c.Params) + result, err := client.HttpRequestWithRegexLiteral(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_HttpStringPayload_test.go b/internal/protocoltest/awsrestjson/api_op_HttpStringPayload_test.go index b67c6e312c7..5e22268b736 100644 --- a/internal/protocoltest/awsrestjson/api_op_HttpStringPayload_test.go +++ b/internal/protocoltest/awsrestjson/api_op_HttpStringPayload_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -54,25 +53,8 @@ func TestClient_HttpStringPayload_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -96,11 +78,15 @@ func TestClient_HttpStringPayload_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpStringPayload(context.Background(), c.Params) + result, err := client.HttpStringPayload(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_InputAndOutputWithHeaders_test.go b/internal/protocoltest/awsrestjson/api_op_InputAndOutputWithHeaders_test.go index f5e9b153a0b..2488158f80f 100644 --- a/internal/protocoltest/awsrestjson/api_op_InputAndOutputWithHeaders_test.go +++ b/internal/protocoltest/awsrestjson/api_op_InputAndOutputWithHeaders_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -21,9 +22,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" "time" ) @@ -257,25 +256,8 @@ func TestClient_InputAndOutputWithHeaders_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -299,11 +281,15 @@ func TestClient_InputAndOutputWithHeaders_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.InputAndOutputWithHeaders(context.Background(), c.Params) + result, err := client.InputAndOutputWithHeaders(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_JsonBlobs_test.go b/internal/protocoltest/awsrestjson/api_op_JsonBlobs_test.go index 1ae771d1df8..c9c6d5a8b9a 100644 --- a/internal/protocoltest/awsrestjson/api_op_JsonBlobs_test.go +++ b/internal/protocoltest/awsrestjson/api_op_JsonBlobs_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -60,25 +59,8 @@ func TestClient_JsonBlobs_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -102,11 +84,15 @@ func TestClient_JsonBlobs_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.JsonBlobs(context.Background(), c.Params) + result, err := client.JsonBlobs(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_JsonEnums_test.go b/internal/protocoltest/awsrestjson/api_op_JsonEnums_test.go index 3297b7a3cdd..a91ef084f01 100644 --- a/internal/protocoltest/awsrestjson/api_op_JsonEnums_test.go +++ b/internal/protocoltest/awsrestjson/api_op_JsonEnums_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -89,25 +88,8 @@ func TestClient_JsonEnums_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -131,11 +113,15 @@ func TestClient_JsonEnums_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.JsonEnums(context.Background(), c.Params) + result, err := client.JsonEnums(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_JsonIntEnums_test.go b/internal/protocoltest/awsrestjson/api_op_JsonIntEnums_test.go index ee0dd733236..c7334bae95e 100644 --- a/internal/protocoltest/awsrestjson/api_op_JsonIntEnums_test.go +++ b/internal/protocoltest/awsrestjson/api_op_JsonIntEnums_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -91,25 +90,8 @@ func TestClient_JsonIntEnums_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -133,11 +115,15 @@ func TestClient_JsonIntEnums_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.JsonIntEnums(context.Background(), c.Params) + result, err := client.JsonIntEnums(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_JsonLists_test.go b/internal/protocoltest/awsrestjson/api_op_JsonLists_test.go index 8efdcd5590f..977af4007d4 100644 --- a/internal/protocoltest/awsrestjson/api_op_JsonLists_test.go +++ b/internal/protocoltest/awsrestjson/api_op_JsonLists_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -21,9 +22,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" "time" ) @@ -200,25 +199,8 @@ func TestClient_JsonLists_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -242,11 +224,15 @@ func TestClient_JsonLists_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.JsonLists(context.Background(), c.Params) + result, err := client.JsonLists(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_JsonMaps_test.go b/internal/protocoltest/awsrestjson/api_op_JsonMaps_test.go index f1dee2997a7..11d5eb01a97 100644 --- a/internal/protocoltest/awsrestjson/api_op_JsonMaps_test.go +++ b/internal/protocoltest/awsrestjson/api_op_JsonMaps_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -255,25 +254,8 @@ func TestClient_JsonMaps_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -297,11 +279,15 @@ func TestClient_JsonMaps_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.JsonMaps(context.Background(), c.Params) + result, err := client.JsonMaps(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_JsonTimestamps_test.go b/internal/protocoltest/awsrestjson/api_op_JsonTimestamps_test.go index 2992b1a02d9..dc9cdcddf20 100644 --- a/internal/protocoltest/awsrestjson/api_op_JsonTimestamps_test.go +++ b/internal/protocoltest/awsrestjson/api_op_JsonTimestamps_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -171,25 +170,8 @@ func TestClient_JsonTimestamps_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -213,11 +195,15 @@ func TestClient_JsonTimestamps_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.JsonTimestamps(context.Background(), c.Params) + result, err := client.JsonTimestamps(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_JsonUnions_test.go b/internal/protocoltest/awsrestjson/api_op_JsonUnions_test.go index 0749564fb2e..2afa87ef00e 100644 --- a/internal/protocoltest/awsrestjson/api_op_JsonUnions_test.go +++ b/internal/protocoltest/awsrestjson/api_op_JsonUnions_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -21,9 +22,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -262,25 +261,8 @@ func TestClient_JsonUnions_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -304,11 +286,15 @@ func TestClient_JsonUnions_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.JsonUnions(context.Background(), c.Params) + result, err := client.JsonUnions(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_MediaTypeHeader_test.go b/internal/protocoltest/awsrestjson/api_op_MediaTypeHeader_test.go index 92d60bf6365..2a66388c25c 100644 --- a/internal/protocoltest/awsrestjson/api_op_MediaTypeHeader_test.go +++ b/internal/protocoltest/awsrestjson/api_op_MediaTypeHeader_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -58,25 +57,8 @@ func TestClient_MediaTypeHeader_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -100,11 +82,15 @@ func TestClient_MediaTypeHeader_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.MediaTypeHeader(context.Background(), c.Params) + result, err := client.MediaTypeHeader(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_NoInputAndNoOutput_test.go b/internal/protocoltest/awsrestjson/api_op_NoInputAndNoOutput_test.go index d6f5edf130c..269b233516f 100644 --- a/internal/protocoltest/awsrestjson/api_op_NoInputAndNoOutput_test.go +++ b/internal/protocoltest/awsrestjson/api_op_NoInputAndNoOutput_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -53,25 +52,8 @@ func TestClient_NoInputAndNoOutput_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -95,11 +77,15 @@ func TestClient_NoInputAndNoOutput_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.NoInputAndNoOutput(context.Background(), c.Params) + result, err := client.NoInputAndNoOutput(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_NoInputAndOutput_test.go b/internal/protocoltest/awsrestjson/api_op_NoInputAndOutput_test.go index a184f2719d8..c0a2b77b326 100644 --- a/internal/protocoltest/awsrestjson/api_op_NoInputAndOutput_test.go +++ b/internal/protocoltest/awsrestjson/api_op_NoInputAndOutput_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -53,25 +52,8 @@ func TestClient_NoInputAndOutput_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -95,11 +77,15 @@ func TestClient_NoInputAndOutput_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.NoInputAndOutput(context.Background(), c.Params) + result, err := client.NoInputAndOutput(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_NullAndEmptyHeadersClient_test.go b/internal/protocoltest/awsrestjson/api_op_NullAndEmptyHeadersClient_test.go index 7372ad1b586..a1d6389772e 100644 --- a/internal/protocoltest/awsrestjson/api_op_NullAndEmptyHeadersClient_test.go +++ b/internal/protocoltest/awsrestjson/api_op_NullAndEmptyHeadersClient_test.go @@ -3,20 +3,17 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -57,25 +54,8 @@ func TestClient_NullAndEmptyHeadersClient_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -99,11 +79,15 @@ func TestClient_NullAndEmptyHeadersClient_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.NullAndEmptyHeadersClient(context.Background(), c.Params) + result, err := client.NullAndEmptyHeadersClient(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_OmitsNullSerializesEmptyString_test.go b/internal/protocoltest/awsrestjson/api_op_OmitsNullSerializesEmptyString_test.go index 85c6b4453b3..aa19557c435 100644 --- a/internal/protocoltest/awsrestjson/api_op_OmitsNullSerializesEmptyString_test.go +++ b/internal/protocoltest/awsrestjson/api_op_OmitsNullSerializesEmptyString_test.go @@ -3,20 +3,17 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -64,25 +61,8 @@ func TestClient_OmitsNullSerializesEmptyString_awsRestjson1Serialize(t *testing. } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -106,11 +86,15 @@ func TestClient_OmitsNullSerializesEmptyString_awsRestjson1Serialize(t *testing. e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.OmitsNullSerializesEmptyString(context.Background(), c.Params) + result, err := client.OmitsNullSerializesEmptyString(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_PostPlayerAction_test.go b/internal/protocoltest/awsrestjson/api_op_PostPlayerAction_test.go index ac1564df7c7..c9c88c46280 100644 --- a/internal/protocoltest/awsrestjson/api_op_PostPlayerAction_test.go +++ b/internal/protocoltest/awsrestjson/api_op_PostPlayerAction_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -63,25 +62,8 @@ func TestClient_PostPlayerAction_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -105,11 +87,15 @@ func TestClient_PostPlayerAction_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.PostPlayerAction(context.Background(), c.Params) + result, err := client.PostPlayerAction(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_PostUnionWithJsonName_test.go b/internal/protocoltest/awsrestjson/api_op_PostUnionWithJsonName_test.go index cd53ad55af3..65fd46325e1 100644 --- a/internal/protocoltest/awsrestjson/api_op_PostUnionWithJsonName_test.go +++ b/internal/protocoltest/awsrestjson/api_op_PostUnionWithJsonName_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -103,25 +102,8 @@ func TestClient_PostUnionWithJsonName_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -145,11 +127,15 @@ func TestClient_PostUnionWithJsonName_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.PostUnionWithJsonName(context.Background(), c.Params) + result, err := client.PostUnionWithJsonName(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_QueryIdempotencyTokenAutoFill_test.go b/internal/protocoltest/awsrestjson/api_op_QueryIdempotencyTokenAutoFill_test.go index 81543133a44..a9f0398b045 100644 --- a/internal/protocoltest/awsrestjson/api_op_QueryIdempotencyTokenAutoFill_test.go +++ b/internal/protocoltest/awsrestjson/api_op_QueryIdempotencyTokenAutoFill_test.go @@ -3,20 +3,17 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -64,25 +61,8 @@ func TestClient_QueryIdempotencyTokenAutoFill_awsRestjson1Serialize(t *testing.T } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -106,11 +86,15 @@ func TestClient_QueryIdempotencyTokenAutoFill_awsRestjson1Serialize(t *testing.T e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.QueryIdempotencyTokenAutoFill(context.Background(), c.Params) + result, err := client.QueryIdempotencyTokenAutoFill(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_QueryParamsAsStringListMap_test.go b/internal/protocoltest/awsrestjson/api_op_QueryParamsAsStringListMap_test.go index 5f6a18be79e..56e671ce8cf 100644 --- a/internal/protocoltest/awsrestjson/api_op_QueryParamsAsStringListMap_test.go +++ b/internal/protocoltest/awsrestjson/api_op_QueryParamsAsStringListMap_test.go @@ -3,20 +3,17 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -60,25 +57,8 @@ func TestClient_QueryParamsAsStringListMap_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -102,11 +82,15 @@ func TestClient_QueryParamsAsStringListMap_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.QueryParamsAsStringListMap(context.Background(), c.Params) + result, err := client.QueryParamsAsStringListMap(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_QueryPrecedence_test.go b/internal/protocoltest/awsrestjson/api_op_QueryPrecedence_test.go index bc162b26afa..28273d37253 100644 --- a/internal/protocoltest/awsrestjson/api_op_QueryPrecedence_test.go +++ b/internal/protocoltest/awsrestjson/api_op_QueryPrecedence_test.go @@ -3,20 +3,17 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -57,25 +54,8 @@ func TestClient_QueryPrecedence_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -99,11 +79,15 @@ func TestClient_QueryPrecedence_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.QueryPrecedence(context.Background(), c.Params) + result, err := client.QueryPrecedence(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_RecursiveShapes_test.go b/internal/protocoltest/awsrestjson/api_op_RecursiveShapes_test.go index b41fc6184f8..fa2da1ca271 100644 --- a/internal/protocoltest/awsrestjson/api_op_RecursiveShapes_test.go +++ b/internal/protocoltest/awsrestjson/api_op_RecursiveShapes_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -84,25 +83,8 @@ func TestClient_RecursiveShapes_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -126,11 +108,15 @@ func TestClient_RecursiveShapes_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.RecursiveShapes(context.Background(), c.Params) + result, err := client.RecursiveShapes(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_SimpleScalarProperties_test.go b/internal/protocoltest/awsrestjson/api_op_SimpleScalarProperties_test.go index 944068a166d..fe84a4efe4e 100644 --- a/internal/protocoltest/awsrestjson/api_op_SimpleScalarProperties_test.go +++ b/internal/protocoltest/awsrestjson/api_op_SimpleScalarProperties_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -155,25 +154,8 @@ func TestClient_SimpleScalarProperties_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -197,11 +179,15 @@ func TestClient_SimpleScalarProperties_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.SimpleScalarProperties(context.Background(), c.Params) + result, err := client.SimpleScalarProperties(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_StreamingTraitsRequireLength_test.go b/internal/protocoltest/awsrestjson/api_op_StreamingTraitsRequireLength_test.go index 9810f90068a..fe558b857f9 100644 --- a/internal/protocoltest/awsrestjson/api_op_StreamingTraitsRequireLength_test.go +++ b/internal/protocoltest/awsrestjson/api_op_StreamingTraitsRequireLength_test.go @@ -6,18 +6,16 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithyio "github.com/aws/smithy-go/io" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -76,25 +74,8 @@ func TestClient_StreamingTraitsRequireLength_awsRestjson1Serialize(t *testing.T) } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -118,11 +99,15 @@ func TestClient_StreamingTraitsRequireLength_awsRestjson1Serialize(t *testing.T) e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.StreamingTraitsRequireLength(context.Background(), c.Params) + result, err := client.StreamingTraitsRequireLength(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_StreamingTraitsWithMediaType_test.go b/internal/protocoltest/awsrestjson/api_op_StreamingTraitsWithMediaType_test.go index a6c56204312..e708253e03d 100644 --- a/internal/protocoltest/awsrestjson/api_op_StreamingTraitsWithMediaType_test.go +++ b/internal/protocoltest/awsrestjson/api_op_StreamingTraitsWithMediaType_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" smithyio "github.com/aws/smithy-go/io" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -62,25 +61,8 @@ func TestClient_StreamingTraitsWithMediaType_awsRestjson1Serialize(t *testing.T) } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -104,11 +86,15 @@ func TestClient_StreamingTraitsWithMediaType_awsRestjson1Serialize(t *testing.T) e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.StreamingTraitsWithMediaType(context.Background(), c.Params) + result, err := client.StreamingTraitsWithMediaType(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_StreamingTraits_test.go b/internal/protocoltest/awsrestjson/api_op_StreamingTraits_test.go index b7df792b993..c8fe0c5a9d0 100644 --- a/internal/protocoltest/awsrestjson/api_op_StreamingTraits_test.go +++ b/internal/protocoltest/awsrestjson/api_op_StreamingTraits_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" smithyio "github.com/aws/smithy-go/io" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -78,25 +77,8 @@ func TestClient_StreamingTraits_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -120,11 +102,15 @@ func TestClient_StreamingTraits_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.StreamingTraits(context.Background(), c.Params) + result, err := client.StreamingTraits(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_TestBodyStructure_test.go b/internal/protocoltest/awsrestjson/api_op_TestBodyStructure_test.go index af6ddd65ec7..3be53ef7fad 100644 --- a/internal/protocoltest/awsrestjson/api_op_TestBodyStructure_test.go +++ b/internal/protocoltest/awsrestjson/api_op_TestBodyStructure_test.go @@ -3,21 +3,18 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/types" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -79,25 +76,8 @@ func TestClient_TestBodyStructure_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -121,11 +101,15 @@ func TestClient_TestBodyStructure_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.TestBodyStructure(context.Background(), c.Params) + result, err := client.TestBodyStructure(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_TestNoPayload_test.go b/internal/protocoltest/awsrestjson/api_op_TestNoPayload_test.go index 1b126cbbb4b..4b2b6f855f2 100644 --- a/internal/protocoltest/awsrestjson/api_op_TestNoPayload_test.go +++ b/internal/protocoltest/awsrestjson/api_op_TestNoPayload_test.go @@ -3,20 +3,17 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -71,25 +68,8 @@ func TestClient_TestNoPayload_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -113,11 +93,15 @@ func TestClient_TestNoPayload_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.TestNoPayload(context.Background(), c.Params) + result, err := client.TestNoPayload(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_TestPayloadBlob_test.go b/internal/protocoltest/awsrestjson/api_op_TestPayloadBlob_test.go index 647fa611141..9b9bbcef614 100644 --- a/internal/protocoltest/awsrestjson/api_op_TestPayloadBlob_test.go +++ b/internal/protocoltest/awsrestjson/api_op_TestPayloadBlob_test.go @@ -3,20 +3,17 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -72,25 +69,8 @@ func TestClient_TestPayloadBlob_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -114,11 +94,15 @@ func TestClient_TestPayloadBlob_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.TestPayloadBlob(context.Background(), c.Params) + result, err := client.TestPayloadBlob(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_TestPayloadStructure_test.go b/internal/protocoltest/awsrestjson/api_op_TestPayloadStructure_test.go index a36d201a2dd..be9d26ff35e 100644 --- a/internal/protocoltest/awsrestjson/api_op_TestPayloadStructure_test.go +++ b/internal/protocoltest/awsrestjson/api_op_TestPayloadStructure_test.go @@ -3,21 +3,18 @@ package awsrestjson import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/types" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -98,25 +95,8 @@ func TestClient_TestPayloadStructure_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -140,11 +120,15 @@ func TestClient_TestPayloadStructure_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.TestPayloadStructure(context.Background(), c.Params) + result, err := client.TestPayloadStructure(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_TimestampFormatHeaders_test.go b/internal/protocoltest/awsrestjson/api_op_TimestampFormatHeaders_test.go index fb8da71fab6..017202586da 100644 --- a/internal/protocoltest/awsrestjson/api_op_TimestampFormatHeaders_test.go +++ b/internal/protocoltest/awsrestjson/api_op_TimestampFormatHeaders_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -71,25 +70,8 @@ func TestClient_TimestampFormatHeaders_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -113,11 +95,15 @@ func TestClient_TimestampFormatHeaders_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.TimestampFormatHeaders(context.Background(), c.Params) + result, err := client.TimestampFormatHeaders(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/awsrestjson/api_op_UnitInputAndOutput_test.go b/internal/protocoltest/awsrestjson/api_op_UnitInputAndOutput_test.go index cf5d682bc2c..53706276020 100644 --- a/internal/protocoltest/awsrestjson/api_op_UnitInputAndOutput_test.go +++ b/internal/protocoltest/awsrestjson/api_op_UnitInputAndOutput_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -53,25 +52,8 @@ func TestClient_UnitInputAndOutput_awsRestjson1Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -95,11 +77,15 @@ func TestClient_UnitInputAndOutput_awsRestjson1Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.UnitInputAndOutput(context.Background(), c.Params) + result, err := client.UnitInputAndOutput(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/ec2query/api_op_EmptyInputAndEmptyOutput_test.go b/internal/protocoltest/ec2query/api_op_EmptyInputAndEmptyOutput_test.go index 71c9266f859..d6fbc23bdba 100644 --- a/internal/protocoltest/ec2query/api_op_EmptyInputAndEmptyOutput_test.go +++ b/internal/protocoltest/ec2query/api_op_EmptyInputAndEmptyOutput_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -56,25 +55,8 @@ func TestClient_EmptyInputAndEmptyOutput_awsEc2querySerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -98,11 +80,15 @@ func TestClient_EmptyInputAndEmptyOutput_awsEc2querySerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.EmptyInputAndEmptyOutput(context.Background(), c.Params) + result, err := client.EmptyInputAndEmptyOutput(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/ec2query/api_op_EndpointOperation_test.go b/internal/protocoltest/ec2query/api_op_EndpointOperation_test.go index 95da70889bd..0af8e3ba81f 100644 --- a/internal/protocoltest/ec2query/api_op_EndpointOperation_test.go +++ b/internal/protocoltest/ec2query/api_op_EndpointOperation_test.go @@ -3,19 +3,16 @@ package ec2query import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -62,29 +59,8 @@ func TestClient_EndpointOperation_awsEc2querySerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - if name == "Ec2QueryEndpointTrait" { - t.Skip("disabled test aws.protocoltests.ec2#AwsEc2 aws.protocoltests.ec2#EndpointOperation") - } - - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -108,11 +84,15 @@ func TestClient_EndpointOperation_awsEc2querySerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.EndpointOperation(context.Background(), c.Params) + result, err := client.EndpointOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/ec2query/api_op_EndpointWithHostLabelOperation_test.go b/internal/protocoltest/ec2query/api_op_EndpointWithHostLabelOperation_test.go index 684b19dbf61..485df4f194c 100644 --- a/internal/protocoltest/ec2query/api_op_EndpointWithHostLabelOperation_test.go +++ b/internal/protocoltest/ec2query/api_op_EndpointWithHostLabelOperation_test.go @@ -3,20 +3,17 @@ package ec2query import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -67,29 +64,8 @@ func TestClient_EndpointWithHostLabelOperation_awsEc2querySerialize(t *testing.T } for name, c := range cases { t.Run(name, func(t *testing.T) { - if name == "Ec2QueryEndpointTraitWithHostLabel" { - t.Skip("disabled test aws.protocoltests.ec2#AwsEc2 aws.protocoltests.ec2#EndpointWithHostLabelOperation") - } - - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -113,11 +89,15 @@ func TestClient_EndpointWithHostLabelOperation_awsEc2querySerialize(t *testing.T e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.EndpointWithHostLabelOperation(context.Background(), c.Params) + result, err := client.EndpointWithHostLabelOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/ec2query/api_op_HostWithPathOperation_test.go b/internal/protocoltest/ec2query/api_op_HostWithPathOperation_test.go index 5af692ff822..e6abde88ceb 100644 --- a/internal/protocoltest/ec2query/api_op_HostWithPathOperation_test.go +++ b/internal/protocoltest/ec2query/api_op_HostWithPathOperation_test.go @@ -3,19 +3,16 @@ package ec2query import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -58,25 +55,8 @@ func TestClient_HostWithPathOperation_awsEc2querySerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -100,11 +80,15 @@ func TestClient_HostWithPathOperation_awsEc2querySerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HostWithPathOperation(context.Background(), c.Params) + result, err := client.HostWithPathOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/ec2query/api_op_NestedStructures_test.go b/internal/protocoltest/ec2query/api_op_NestedStructures_test.go index 8bfb2442612..672e415ca26 100644 --- a/internal/protocoltest/ec2query/api_op_NestedStructures_test.go +++ b/internal/protocoltest/ec2query/api_op_NestedStructures_test.go @@ -3,21 +3,18 @@ package ec2query import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/ec2query/types" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -64,25 +61,8 @@ func TestClient_NestedStructures_awsEc2querySerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -106,11 +86,15 @@ func TestClient_NestedStructures_awsEc2querySerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.NestedStructures(context.Background(), c.Params) + result, err := client.NestedStructures(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/ec2query/api_op_NoInputAndOutput_test.go b/internal/protocoltest/ec2query/api_op_NoInputAndOutput_test.go index 396179662f1..3be778c8eb5 100644 --- a/internal/protocoltest/ec2query/api_op_NoInputAndOutput_test.go +++ b/internal/protocoltest/ec2query/api_op_NoInputAndOutput_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -56,25 +55,8 @@ func TestClient_NoInputAndOutput_awsEc2querySerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -98,11 +80,15 @@ func TestClient_NoInputAndOutput_awsEc2querySerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.NoInputAndOutput(context.Background(), c.Params) + result, err := client.NoInputAndOutput(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/ec2query/api_op_QueryIdempotencyTokenAutoFill_test.go b/internal/protocoltest/ec2query/api_op_QueryIdempotencyTokenAutoFill_test.go index 925ac6b20f9..6fc30bb53a8 100644 --- a/internal/protocoltest/ec2query/api_op_QueryIdempotencyTokenAutoFill_test.go +++ b/internal/protocoltest/ec2query/api_op_QueryIdempotencyTokenAutoFill_test.go @@ -3,20 +3,17 @@ package ec2query import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -74,25 +71,8 @@ func TestClient_QueryIdempotencyTokenAutoFill_awsEc2querySerialize(t *testing.T) } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -116,11 +96,15 @@ func TestClient_QueryIdempotencyTokenAutoFill_awsEc2querySerialize(t *testing.T) e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.QueryIdempotencyTokenAutoFill(context.Background(), c.Params) + result, err := client.QueryIdempotencyTokenAutoFill(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/ec2query/api_op_QueryLists_test.go b/internal/protocoltest/ec2query/api_op_QueryLists_test.go index dfb16f873be..f2d1083f02b 100644 --- a/internal/protocoltest/ec2query/api_op_QueryLists_test.go +++ b/internal/protocoltest/ec2query/api_op_QueryLists_test.go @@ -3,21 +3,18 @@ package ec2query import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/ec2query/types" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -143,25 +140,8 @@ func TestClient_QueryLists_awsEc2querySerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -185,11 +165,15 @@ func TestClient_QueryLists_awsEc2querySerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.QueryLists(context.Background(), c.Params) + result, err := client.QueryLists(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/ec2query/api_op_QueryTimestamps_test.go b/internal/protocoltest/ec2query/api_op_QueryTimestamps_test.go index 3a028018d3d..721282f51f1 100644 --- a/internal/protocoltest/ec2query/api_op_QueryTimestamps_test.go +++ b/internal/protocoltest/ec2query/api_op_QueryTimestamps_test.go @@ -3,21 +3,18 @@ package ec2query import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithytime "github.com/aws/smithy-go/time" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -60,25 +57,8 @@ func TestClient_QueryTimestamps_awsEc2querySerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -102,11 +82,15 @@ func TestClient_QueryTimestamps_awsEc2querySerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.QueryTimestamps(context.Background(), c.Params) + result, err := client.QueryTimestamps(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/ec2query/api_op_SimpleInputParams_test.go b/internal/protocoltest/ec2query/api_op_SimpleInputParams_test.go index da287eba55e..8fe2707d1f1 100644 --- a/internal/protocoltest/ec2query/api_op_SimpleInputParams_test.go +++ b/internal/protocoltest/ec2query/api_op_SimpleInputParams_test.go @@ -3,22 +3,19 @@ package ec2query import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/ec2query/types" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -292,25 +289,8 @@ func TestClient_SimpleInputParams_awsEc2querySerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -334,11 +314,15 @@ func TestClient_SimpleInputParams_awsEc2querySerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.SimpleInputParams(context.Background(), c.Params) + result, err := client.SimpleInputParams(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/jsonrpc/api_op_EmptyOperation_test.go b/internal/protocoltest/jsonrpc/api_op_EmptyOperation_test.go index b5ce4eddead..022b2cc92f7 100644 --- a/internal/protocoltest/jsonrpc/api_op_EmptyOperation_test.go +++ b/internal/protocoltest/jsonrpc/api_op_EmptyOperation_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" "github.com/google/go-cmp/cmp" @@ -17,9 +18,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -81,25 +80,8 @@ func TestClient_EmptyOperation_awsAwsjson11Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -123,10 +105,14 @@ func TestClient_EmptyOperation_awsAwsjson11Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.EmptyOperation(context.Background(), c.Params) + result, err := client.EmptyOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/jsonrpc/api_op_EndpointOperation_test.go b/internal/protocoltest/jsonrpc/api_op_EndpointOperation_test.go index bd3a08e3dc3..6d7b878578e 100644 --- a/internal/protocoltest/jsonrpc/api_op_EndpointOperation_test.go +++ b/internal/protocoltest/jsonrpc/api_op_EndpointOperation_test.go @@ -3,18 +3,15 @@ package jsonrpc import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -61,29 +58,8 @@ func TestClient_EndpointOperation_awsAwsjson11Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - if name == "AwsJson11EndpointTrait" { - t.Skip("disabled test aws.protocoltests.json#JsonProtocol aws.protocoltests.json#EndpointOperation") - } - - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -107,10 +83,14 @@ func TestClient_EndpointOperation_awsAwsjson11Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.EndpointOperation(context.Background(), c.Params) + result, err := client.EndpointOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/jsonrpc/api_op_EndpointWithHostLabelOperation_test.go b/internal/protocoltest/jsonrpc/api_op_EndpointWithHostLabelOperation_test.go index afa13c934a5..f5a69c2c6ed 100644 --- a/internal/protocoltest/jsonrpc/api_op_EndpointWithHostLabelOperation_test.go +++ b/internal/protocoltest/jsonrpc/api_op_EndpointWithHostLabelOperation_test.go @@ -3,19 +3,16 @@ package jsonrpc import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -67,29 +64,8 @@ func TestClient_EndpointWithHostLabelOperation_awsAwsjson11Serialize(t *testing. } for name, c := range cases { t.Run(name, func(t *testing.T) { - if name == "AwsJson11EndpointTraitWithHostLabel" { - t.Skip("disabled test aws.protocoltests.json#JsonProtocol aws.protocoltests.json#EndpointWithHostLabelOperation") - } - - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -113,10 +89,14 @@ func TestClient_EndpointWithHostLabelOperation_awsAwsjson11Serialize(t *testing. e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.EndpointWithHostLabelOperation(context.Background(), c.Params) + result, err := client.EndpointWithHostLabelOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/jsonrpc/api_op_HostWithPathOperation_test.go b/internal/protocoltest/jsonrpc/api_op_HostWithPathOperation_test.go index f1f6851ca53..c9c3b2cfbfb 100644 --- a/internal/protocoltest/jsonrpc/api_op_HostWithPathOperation_test.go +++ b/internal/protocoltest/jsonrpc/api_op_HostWithPathOperation_test.go @@ -3,18 +3,15 @@ package jsonrpc import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -61,25 +58,8 @@ func TestClient_HostWithPathOperation_awsAwsjson11Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -103,10 +83,14 @@ func TestClient_HostWithPathOperation_awsAwsjson11Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.HostWithPathOperation(context.Background(), c.Params) + result, err := client.HostWithPathOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/jsonrpc/api_op_JsonEnums_test.go b/internal/protocoltest/jsonrpc/api_op_JsonEnums_test.go index 03d3fe8bc64..a9aa1c32259 100644 --- a/internal/protocoltest/jsonrpc/api_op_JsonEnums_test.go +++ b/internal/protocoltest/jsonrpc/api_op_JsonEnums_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/jsonrpc/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" "github.com/google/go-cmp/cmp" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -89,25 +88,8 @@ func TestClient_JsonEnums_awsAwsjson11Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -131,10 +113,14 @@ func TestClient_JsonEnums_awsAwsjson11Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.JsonEnums(context.Background(), c.Params) + result, err := client.JsonEnums(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/jsonrpc/api_op_JsonUnions_test.go b/internal/protocoltest/jsonrpc/api_op_JsonUnions_test.go index b37f730efb2..5dc92d22b27 100644 --- a/internal/protocoltest/jsonrpc/api_op_JsonUnions_test.go +++ b/internal/protocoltest/jsonrpc/api_op_JsonUnions_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/jsonrpc/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithytesting "github.com/aws/smithy-go/testing" smithytime "github.com/aws/smithy-go/time" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -246,25 +245,8 @@ func TestClient_JsonUnions_awsAwsjson11Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -288,10 +270,14 @@ func TestClient_JsonUnions_awsAwsjson11Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.JsonUnions(context.Background(), c.Params) + result, err := client.JsonUnions(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/jsonrpc/api_op_KitchenSinkOperation_test.go b/internal/protocoltest/jsonrpc/api_op_KitchenSinkOperation_test.go index c97468fb3b9..2dad3286209 100644 --- a/internal/protocoltest/jsonrpc/api_op_KitchenSinkOperation_test.go +++ b/internal/protocoltest/jsonrpc/api_op_KitchenSinkOperation_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/jsonrpc/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithytesting "github.com/aws/smithy-go/testing" smithytime "github.com/aws/smithy-go/time" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -693,25 +692,8 @@ func TestClient_KitchenSinkOperation_awsAwsjson11Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -735,10 +717,14 @@ func TestClient_KitchenSinkOperation_awsAwsjson11Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.KitchenSinkOperation(context.Background(), c.Params) + result, err := client.KitchenSinkOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/jsonrpc/api_op_NullOperation_test.go b/internal/protocoltest/jsonrpc/api_op_NullOperation_test.go index 6efb7e01c83..6b28ae2d94a 100644 --- a/internal/protocoltest/jsonrpc/api_op_NullOperation_test.go +++ b/internal/protocoltest/jsonrpc/api_op_NullOperation_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" "github.com/google/go-cmp/cmp" @@ -17,9 +18,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -104,25 +103,8 @@ func TestClient_NullOperation_awsAwsjson11Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -146,10 +128,14 @@ func TestClient_NullOperation_awsAwsjson11Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.NullOperation(context.Background(), c.Params) + result, err := client.NullOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/jsonrpc/api_op_OperationWithOptionalInputOutput_test.go b/internal/protocoltest/jsonrpc/api_op_OperationWithOptionalInputOutput_test.go index a18b85001df..7a1a7d79a03 100644 --- a/internal/protocoltest/jsonrpc/api_op_OperationWithOptionalInputOutput_test.go +++ b/internal/protocoltest/jsonrpc/api_op_OperationWithOptionalInputOutput_test.go @@ -3,19 +3,16 @@ package jsonrpc import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -69,25 +66,8 @@ func TestClient_OperationWithOptionalInputOutput_awsAwsjson11Serialize(t *testin } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -111,10 +91,14 @@ func TestClient_OperationWithOptionalInputOutput_awsAwsjson11Serialize(t *testin e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.OperationWithOptionalInputOutput(context.Background(), c.Params) + result, err := client.OperationWithOptionalInputOutput(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/jsonrpc/api_op_PutAndGetInlineDocuments_test.go b/internal/protocoltest/jsonrpc/api_op_PutAndGetInlineDocuments_test.go index 62e31c757e2..d6893a6ce1e 100644 --- a/internal/protocoltest/jsonrpc/api_op_PutAndGetInlineDocuments_test.go +++ b/internal/protocoltest/jsonrpc/api_op_PutAndGetInlineDocuments_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/jsonrpc/document" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" "github.com/google/go-cmp/cmp" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -66,25 +65,8 @@ func TestClient_PutAndGetInlineDocuments_awsAwsjson11Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -108,10 +90,14 @@ func TestClient_PutAndGetInlineDocuments_awsAwsjson11Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.PutAndGetInlineDocuments(context.Background(), c.Params) + result, err := client.PutAndGetInlineDocuments(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/jsonrpc/api_op_SimpleScalarProperties_test.go b/internal/protocoltest/jsonrpc/api_op_SimpleScalarProperties_test.go index 13ac24ee7a9..5075f574d8f 100644 --- a/internal/protocoltest/jsonrpc/api_op_SimpleScalarProperties_test.go +++ b/internal/protocoltest/jsonrpc/api_op_SimpleScalarProperties_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -105,25 +104,8 @@ func TestClient_SimpleScalarProperties_awsAwsjson11Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -147,10 +129,14 @@ func TestClient_SimpleScalarProperties_awsAwsjson11Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.SimpleScalarProperties(context.Background(), c.Params) + result, err := client.SimpleScalarProperties(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/jsonrpc10/api_op_EmptyInputAndEmptyOutput_test.go b/internal/protocoltest/jsonrpc10/api_op_EmptyInputAndEmptyOutput_test.go index e567970aeb4..764894fabd9 100644 --- a/internal/protocoltest/jsonrpc10/api_op_EmptyInputAndEmptyOutput_test.go +++ b/internal/protocoltest/jsonrpc10/api_op_EmptyInputAndEmptyOutput_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" "github.com/google/go-cmp/cmp" @@ -17,9 +18,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -56,25 +55,8 @@ func TestClient_EmptyInputAndEmptyOutput_awsAwsjson10Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -98,10 +80,14 @@ func TestClient_EmptyInputAndEmptyOutput_awsAwsjson10Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.EmptyInputAndEmptyOutput(context.Background(), c.Params) + result, err := client.EmptyInputAndEmptyOutput(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/jsonrpc10/api_op_EndpointOperation_test.go b/internal/protocoltest/jsonrpc10/api_op_EndpointOperation_test.go index 6567bb75cb2..a55faef03d1 100644 --- a/internal/protocoltest/jsonrpc10/api_op_EndpointOperation_test.go +++ b/internal/protocoltest/jsonrpc10/api_op_EndpointOperation_test.go @@ -3,18 +3,15 @@ package jsonrpc10 import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -57,29 +54,8 @@ func TestClient_EndpointOperation_awsAwsjson10Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - if name == "AwsJson10EndpointTrait" { - t.Skip("disabled test aws.protocoltests.json10#JsonRpc10 aws.protocoltests.json10#EndpointOperation") - } - - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -103,10 +79,14 @@ func TestClient_EndpointOperation_awsAwsjson10Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.EndpointOperation(context.Background(), c.Params) + result, err := client.EndpointOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/jsonrpc10/api_op_EndpointWithHostLabelOperation_test.go b/internal/protocoltest/jsonrpc10/api_op_EndpointWithHostLabelOperation_test.go index 75a838b827b..641fa8d479f 100644 --- a/internal/protocoltest/jsonrpc10/api_op_EndpointWithHostLabelOperation_test.go +++ b/internal/protocoltest/jsonrpc10/api_op_EndpointWithHostLabelOperation_test.go @@ -3,19 +3,16 @@ package jsonrpc10 import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -63,29 +60,8 @@ func TestClient_EndpointWithHostLabelOperation_awsAwsjson10Serialize(t *testing. } for name, c := range cases { t.Run(name, func(t *testing.T) { - if name == "AwsJson10EndpointTraitWithHostLabel" { - t.Skip("disabled test aws.protocoltests.json10#JsonRpc10 aws.protocoltests.json10#EndpointWithHostLabelOperation") - } - - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -109,10 +85,14 @@ func TestClient_EndpointWithHostLabelOperation_awsAwsjson10Serialize(t *testing. e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.EndpointWithHostLabelOperation(context.Background(), c.Params) + result, err := client.EndpointWithHostLabelOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/jsonrpc10/api_op_HostWithPathOperation_test.go b/internal/protocoltest/jsonrpc10/api_op_HostWithPathOperation_test.go index dd13261dc88..59ef65206c3 100644 --- a/internal/protocoltest/jsonrpc10/api_op_HostWithPathOperation_test.go +++ b/internal/protocoltest/jsonrpc10/api_op_HostWithPathOperation_test.go @@ -3,18 +3,15 @@ package jsonrpc10 import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -57,25 +54,8 @@ func TestClient_HostWithPathOperation_awsAwsjson10Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -99,10 +79,14 @@ func TestClient_HostWithPathOperation_awsAwsjson10Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.HostWithPathOperation(context.Background(), c.Params) + result, err := client.HostWithPathOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/jsonrpc10/api_op_JsonUnions_test.go b/internal/protocoltest/jsonrpc10/api_op_JsonUnions_test.go index 9d7d9db62d0..2dad560b404 100644 --- a/internal/protocoltest/jsonrpc10/api_op_JsonUnions_test.go +++ b/internal/protocoltest/jsonrpc10/api_op_JsonUnions_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/jsonrpc10/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithytesting "github.com/aws/smithy-go/testing" smithytime "github.com/aws/smithy-go/time" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -267,25 +266,8 @@ func TestClient_JsonUnions_awsAwsjson10Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -309,10 +291,14 @@ func TestClient_JsonUnions_awsAwsjson10Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.JsonUnions(context.Background(), c.Params) + result, err := client.JsonUnions(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/jsonrpc10/api_op_NoInputAndNoOutput_test.go b/internal/protocoltest/jsonrpc10/api_op_NoInputAndNoOutput_test.go index 27e293d825c..161a3cfdea4 100644 --- a/internal/protocoltest/jsonrpc10/api_op_NoInputAndNoOutput_test.go +++ b/internal/protocoltest/jsonrpc10/api_op_NoInputAndNoOutput_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" "github.com/google/go-cmp/cmp" @@ -17,9 +18,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -59,25 +58,8 @@ func TestClient_NoInputAndNoOutput_awsAwsjson10Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -101,10 +83,14 @@ func TestClient_NoInputAndNoOutput_awsAwsjson10Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.NoInputAndNoOutput(context.Background(), c.Params) + result, err := client.NoInputAndNoOutput(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/jsonrpc10/api_op_NoInputAndOutput_test.go b/internal/protocoltest/jsonrpc10/api_op_NoInputAndOutput_test.go index 0f616a5b32f..2e6f69642b1 100644 --- a/internal/protocoltest/jsonrpc10/api_op_NoInputAndOutput_test.go +++ b/internal/protocoltest/jsonrpc10/api_op_NoInputAndOutput_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" "github.com/google/go-cmp/cmp" @@ -17,9 +18,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -56,25 +55,8 @@ func TestClient_NoInputAndOutput_awsAwsjson10Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -98,10 +80,14 @@ func TestClient_NoInputAndOutput_awsAwsjson10Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.NoInputAndOutput(context.Background(), c.Params) + result, err := client.NoInputAndOutput(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/jsonrpc10/api_op_SimpleScalarProperties_test.go b/internal/protocoltest/jsonrpc10/api_op_SimpleScalarProperties_test.go index ae4f80174f9..53b24c90b92 100644 --- a/internal/protocoltest/jsonrpc10/api_op_SimpleScalarProperties_test.go +++ b/internal/protocoltest/jsonrpc10/api_op_SimpleScalarProperties_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -105,25 +104,8 @@ func TestClient_SimpleScalarProperties_awsAwsjson10Serialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -147,10 +129,14 @@ func TestClient_SimpleScalarProperties_awsAwsjson10Serialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.SimpleScalarProperties(context.Background(), c.Params) + result, err := client.SimpleScalarProperties(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/query/api_op_EmptyInputAndEmptyOutput_test.go b/internal/protocoltest/query/api_op_EmptyInputAndEmptyOutput_test.go index 10c5d3012b2..2ebf71dd559 100644 --- a/internal/protocoltest/query/api_op_EmptyInputAndEmptyOutput_test.go +++ b/internal/protocoltest/query/api_op_EmptyInputAndEmptyOutput_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -56,25 +55,8 @@ func TestClient_EmptyInputAndEmptyOutput_awsAwsquerySerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -98,11 +80,15 @@ func TestClient_EmptyInputAndEmptyOutput_awsAwsquerySerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.EmptyInputAndEmptyOutput(context.Background(), c.Params) + result, err := client.EmptyInputAndEmptyOutput(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/query/api_op_EndpointOperation_test.go b/internal/protocoltest/query/api_op_EndpointOperation_test.go index e0e363144d0..7c00b4c3d8e 100644 --- a/internal/protocoltest/query/api_op_EndpointOperation_test.go +++ b/internal/protocoltest/query/api_op_EndpointOperation_test.go @@ -3,19 +3,16 @@ package query import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -62,29 +59,8 @@ func TestClient_EndpointOperation_awsAwsquerySerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - if name == "AwsQueryEndpointTrait" { - t.Skip("disabled test aws.protocoltests.query#AwsQuery aws.protocoltests.query#EndpointOperation") - } - - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -108,11 +84,15 @@ func TestClient_EndpointOperation_awsAwsquerySerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.EndpointOperation(context.Background(), c.Params) + result, err := client.EndpointOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/query/api_op_EndpointWithHostLabelOperation_test.go b/internal/protocoltest/query/api_op_EndpointWithHostLabelOperation_test.go index 20a5a3acbfe..af5df5c4f6c 100644 --- a/internal/protocoltest/query/api_op_EndpointWithHostLabelOperation_test.go +++ b/internal/protocoltest/query/api_op_EndpointWithHostLabelOperation_test.go @@ -3,20 +3,17 @@ package query import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -67,29 +64,8 @@ func TestClient_EndpointWithHostLabelOperation_awsAwsquerySerialize(t *testing.T } for name, c := range cases { t.Run(name, func(t *testing.T) { - if name == "AwsQueryEndpointTraitWithHostLabel" { - t.Skip("disabled test aws.protocoltests.query#AwsQuery aws.protocoltests.query#EndpointWithHostLabelOperation") - } - - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -113,11 +89,15 @@ func TestClient_EndpointWithHostLabelOperation_awsAwsquerySerialize(t *testing.T e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.EndpointWithHostLabelOperation(context.Background(), c.Params) + result, err := client.EndpointWithHostLabelOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/query/api_op_HostWithPathOperation_test.go b/internal/protocoltest/query/api_op_HostWithPathOperation_test.go index 70a7b61006e..1871ef37afc 100644 --- a/internal/protocoltest/query/api_op_HostWithPathOperation_test.go +++ b/internal/protocoltest/query/api_op_HostWithPathOperation_test.go @@ -3,19 +3,16 @@ package query import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -58,25 +55,8 @@ func TestClient_HostWithPathOperation_awsAwsquerySerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -100,11 +80,15 @@ func TestClient_HostWithPathOperation_awsAwsquerySerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HostWithPathOperation(context.Background(), c.Params) + result, err := client.HostWithPathOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/query/api_op_NestedStructures_test.go b/internal/protocoltest/query/api_op_NestedStructures_test.go index 7ac7d6e4b1e..acbd205cb60 100644 --- a/internal/protocoltest/query/api_op_NestedStructures_test.go +++ b/internal/protocoltest/query/api_op_NestedStructures_test.go @@ -3,21 +3,18 @@ package query import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/query/types" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -64,25 +61,8 @@ func TestClient_NestedStructures_awsAwsquerySerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -106,11 +86,15 @@ func TestClient_NestedStructures_awsAwsquerySerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.NestedStructures(context.Background(), c.Params) + result, err := client.NestedStructures(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/query/api_op_NoInputAndNoOutput_test.go b/internal/protocoltest/query/api_op_NoInputAndNoOutput_test.go index 0ebe7c128cd..fa72d620e7c 100644 --- a/internal/protocoltest/query/api_op_NoInputAndNoOutput_test.go +++ b/internal/protocoltest/query/api_op_NoInputAndNoOutput_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -56,25 +55,8 @@ func TestClient_NoInputAndNoOutput_awsAwsquerySerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -98,11 +80,15 @@ func TestClient_NoInputAndNoOutput_awsAwsquerySerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.NoInputAndNoOutput(context.Background(), c.Params) + result, err := client.NoInputAndNoOutput(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/query/api_op_NoInputAndOutput_test.go b/internal/protocoltest/query/api_op_NoInputAndOutput_test.go index a325e49565f..6934eeae98a 100644 --- a/internal/protocoltest/query/api_op_NoInputAndOutput_test.go +++ b/internal/protocoltest/query/api_op_NoInputAndOutput_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -56,25 +55,8 @@ func TestClient_NoInputAndOutput_awsAwsquerySerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -98,11 +80,15 @@ func TestClient_NoInputAndOutput_awsAwsquerySerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.NoInputAndOutput(context.Background(), c.Params) + result, err := client.NoInputAndOutput(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/query/api_op_QueryIdempotencyTokenAutoFill_test.go b/internal/protocoltest/query/api_op_QueryIdempotencyTokenAutoFill_test.go index debe602dece..5ba9bb01073 100644 --- a/internal/protocoltest/query/api_op_QueryIdempotencyTokenAutoFill_test.go +++ b/internal/protocoltest/query/api_op_QueryIdempotencyTokenAutoFill_test.go @@ -3,20 +3,17 @@ package query import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -74,25 +71,8 @@ func TestClient_QueryIdempotencyTokenAutoFill_awsAwsquerySerialize(t *testing.T) } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -116,11 +96,15 @@ func TestClient_QueryIdempotencyTokenAutoFill_awsAwsquerySerialize(t *testing.T) e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.QueryIdempotencyTokenAutoFill(context.Background(), c.Params) + result, err := client.QueryIdempotencyTokenAutoFill(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/query/api_op_QueryLists_test.go b/internal/protocoltest/query/api_op_QueryLists_test.go index a7523fb2dff..bbab902cfcf 100644 --- a/internal/protocoltest/query/api_op_QueryLists_test.go +++ b/internal/protocoltest/query/api_op_QueryLists_test.go @@ -3,21 +3,18 @@ package query import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/query/types" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -162,25 +159,8 @@ func TestClient_QueryLists_awsAwsquerySerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -204,11 +184,15 @@ func TestClient_QueryLists_awsAwsquerySerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.QueryLists(context.Background(), c.Params) + result, err := client.QueryLists(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/query/api_op_QueryMaps_test.go b/internal/protocoltest/query/api_op_QueryMaps_test.go index e4ab0121eeb..b9b1925cb48 100644 --- a/internal/protocoltest/query/api_op_QueryMaps_test.go +++ b/internal/protocoltest/query/api_op_QueryMaps_test.go @@ -3,21 +3,18 @@ package query import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/query/types" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -218,25 +215,8 @@ func TestClient_QueryMaps_awsAwsquerySerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -260,11 +240,15 @@ func TestClient_QueryMaps_awsAwsquerySerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.QueryMaps(context.Background(), c.Params) + result, err := client.QueryMaps(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/query/api_op_QueryTimestamps_test.go b/internal/protocoltest/query/api_op_QueryTimestamps_test.go index 1271b92f433..34257ae9fac 100644 --- a/internal/protocoltest/query/api_op_QueryTimestamps_test.go +++ b/internal/protocoltest/query/api_op_QueryTimestamps_test.go @@ -3,21 +3,18 @@ package query import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithytime "github.com/aws/smithy-go/time" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -60,25 +57,8 @@ func TestClient_QueryTimestamps_awsAwsquerySerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -102,11 +82,15 @@ func TestClient_QueryTimestamps_awsAwsquerySerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.QueryTimestamps(context.Background(), c.Params) + result, err := client.QueryTimestamps(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/query/api_op_SimpleInputParams_test.go b/internal/protocoltest/query/api_op_SimpleInputParams_test.go index 71d0ab2f75e..3c1d79e7205 100644 --- a/internal/protocoltest/query/api_op_SimpleInputParams_test.go +++ b/internal/protocoltest/query/api_op_SimpleInputParams_test.go @@ -3,22 +3,19 @@ package query import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/query/types" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -254,25 +251,8 @@ func TestClient_SimpleInputParams_awsAwsquerySerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -296,11 +276,15 @@ func TestClient_SimpleInputParams_awsAwsquerySerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.SimpleInputParams(context.Background(), c.Params) + result, err := client.SimpleInputParams(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_AllQueryStringTypes_test.go b/internal/protocoltest/restxml/api_op_AllQueryStringTypes_test.go index 02aa082c197..ebbf010cebf 100644 --- a/internal/protocoltest/restxml/api_op_AllQueryStringTypes_test.go +++ b/internal/protocoltest/restxml/api_op_AllQueryStringTypes_test.go @@ -3,23 +3,20 @@ package restxml import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithytime "github.com/aws/smithy-go/time" "io" - "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" "time" ) @@ -212,25 +209,8 @@ func TestClient_AllQueryStringTypes_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -254,11 +234,15 @@ func TestClient_AllQueryStringTypes_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.AllQueryStringTypes(context.Background(), c.Params) + result, err := client.AllQueryStringTypes(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_BodyWithXmlName_test.go b/internal/protocoltest/restxml/api_op_BodyWithXmlName_test.go index 8793b232767..df2f965a88f 100644 --- a/internal/protocoltest/restxml/api_op_BodyWithXmlName_test.go +++ b/internal/protocoltest/restxml/api_op_BodyWithXmlName_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -65,25 +64,8 @@ func TestClient_BodyWithXmlName_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -107,11 +89,15 @@ func TestClient_BodyWithXmlName_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.BodyWithXmlName(context.Background(), c.Params) + result, err := client.BodyWithXmlName(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_ConstantAndVariableQueryString_test.go b/internal/protocoltest/restxml/api_op_ConstantAndVariableQueryString_test.go index 2ff8ae7518b..5a9887f627f 100644 --- a/internal/protocoltest/restxml/api_op_ConstantAndVariableQueryString_test.go +++ b/internal/protocoltest/restxml/api_op_ConstantAndVariableQueryString_test.go @@ -3,20 +3,17 @@ package restxml import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -73,25 +70,8 @@ func TestClient_ConstantAndVariableQueryString_awsRestxmlSerialize(t *testing.T) } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -115,11 +95,15 @@ func TestClient_ConstantAndVariableQueryString_awsRestxmlSerialize(t *testing.T) e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.ConstantAndVariableQueryString(context.Background(), c.Params) + result, err := client.ConstantAndVariableQueryString(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_ConstantQueryString_test.go b/internal/protocoltest/restxml/api_op_ConstantQueryString_test.go index f83f513a480..48d276117d5 100644 --- a/internal/protocoltest/restxml/api_op_ConstantQueryString_test.go +++ b/internal/protocoltest/restxml/api_op_ConstantQueryString_test.go @@ -3,20 +3,17 @@ package restxml import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -53,25 +50,8 @@ func TestClient_ConstantQueryString_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -95,11 +75,15 @@ func TestClient_ConstantQueryString_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.ConstantQueryString(context.Background(), c.Params) + result, err := client.ConstantQueryString(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_EmptyInputAndEmptyOutput_test.go b/internal/protocoltest/restxml/api_op_EmptyInputAndEmptyOutput_test.go index a9eaa16f4d5..1cedf0b29cb 100644 --- a/internal/protocoltest/restxml/api_op_EmptyInputAndEmptyOutput_test.go +++ b/internal/protocoltest/restxml/api_op_EmptyInputAndEmptyOutput_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -52,25 +51,8 @@ func TestClient_EmptyInputAndEmptyOutput_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -94,11 +76,15 @@ func TestClient_EmptyInputAndEmptyOutput_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.EmptyInputAndEmptyOutput(context.Background(), c.Params) + result, err := client.EmptyInputAndEmptyOutput(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_EndpointOperation_test.go b/internal/protocoltest/restxml/api_op_EndpointOperation_test.go index 525bc930408..e47b7dabb03 100644 --- a/internal/protocoltest/restxml/api_op_EndpointOperation_test.go +++ b/internal/protocoltest/restxml/api_op_EndpointOperation_test.go @@ -3,19 +3,16 @@ package restxml import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -58,29 +55,8 @@ func TestClient_EndpointOperation_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - if name == "RestXmlEndpointTrait" { - t.Skip("disabled test aws.protocoltests.restxml#RestXml aws.protocoltests.restxml#EndpointOperation") - } - - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -104,11 +80,15 @@ func TestClient_EndpointOperation_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.EndpointOperation(context.Background(), c.Params) + result, err := client.EndpointOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_EndpointWithHostLabelHeaderOperation_test.go b/internal/protocoltest/restxml/api_op_EndpointWithHostLabelHeaderOperation_test.go index 36288078b01..1e4821bcedf 100644 --- a/internal/protocoltest/restxml/api_op_EndpointWithHostLabelHeaderOperation_test.go +++ b/internal/protocoltest/restxml/api_op_EndpointWithHostLabelHeaderOperation_test.go @@ -3,20 +3,17 @@ package restxml import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -68,29 +65,8 @@ func TestClient_EndpointWithHostLabelHeaderOperation_awsRestxmlSerialize(t *test } for name, c := range cases { t.Run(name, func(t *testing.T) { - if name == "RestXmlEndpointTraitWithHostLabelAndHttpBinding" { - t.Skip("disabled test aws.protocoltests.restxml#RestXml aws.protocoltests.restxml#EndpointWithHostLabelHeaderOperation") - } - - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -114,11 +90,15 @@ func TestClient_EndpointWithHostLabelHeaderOperation_awsRestxmlSerialize(t *test e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.EndpointWithHostLabelHeaderOperation(context.Background(), c.Params) + result, err := client.EndpointWithHostLabelHeaderOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_EndpointWithHostLabelOperation_test.go b/internal/protocoltest/restxml/api_op_EndpointWithHostLabelOperation_test.go index e913cda2bbb..70cd3c3abb1 100644 --- a/internal/protocoltest/restxml/api_op_EndpointWithHostLabelOperation_test.go +++ b/internal/protocoltest/restxml/api_op_EndpointWithHostLabelOperation_test.go @@ -3,20 +3,17 @@ package restxml import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -67,29 +64,8 @@ func TestClient_EndpointWithHostLabelOperation_awsRestxmlSerialize(t *testing.T) } for name, c := range cases { t.Run(name, func(t *testing.T) { - if name == "RestXmlEndpointTraitWithHostLabel" { - t.Skip("disabled test aws.protocoltests.restxml#RestXml aws.protocoltests.restxml#EndpointWithHostLabelOperation") - } - - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -113,11 +89,15 @@ func TestClient_EndpointWithHostLabelOperation_awsRestxmlSerialize(t *testing.T) e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.EndpointWithHostLabelOperation(context.Background(), c.Params) + result, err := client.EndpointWithHostLabelOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_FlattenedXmlMapWithXmlName_test.go b/internal/protocoltest/restxml/api_op_FlattenedXmlMapWithXmlName_test.go index cf0b2e232cc..40e15c42bbd 100644 --- a/internal/protocoltest/restxml/api_op_FlattenedXmlMapWithXmlName_test.go +++ b/internal/protocoltest/restxml/api_op_FlattenedXmlMapWithXmlName_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -70,25 +69,8 @@ func TestClient_FlattenedXmlMapWithXmlName_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -112,11 +94,15 @@ func TestClient_FlattenedXmlMapWithXmlName_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.FlattenedXmlMapWithXmlName(context.Background(), c.Params) + result, err := client.FlattenedXmlMapWithXmlName(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_FlattenedXmlMap_test.go b/internal/protocoltest/restxml/api_op_FlattenedXmlMap_test.go index d9446e4f7fd..db95385c4f8 100644 --- a/internal/protocoltest/restxml/api_op_FlattenedXmlMap_test.go +++ b/internal/protocoltest/restxml/api_op_FlattenedXmlMap_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -71,25 +70,8 @@ func TestClient_FlattenedXmlMap_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -113,11 +95,15 @@ func TestClient_FlattenedXmlMap_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.FlattenedXmlMap(context.Background(), c.Params) + result, err := client.FlattenedXmlMap(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_HttpPayloadTraitsWithMediaType_test.go b/internal/protocoltest/restxml/api_op_HttpPayloadTraitsWithMediaType_test.go index 84c1038009a..984e7c5df4c 100644 --- a/internal/protocoltest/restxml/api_op_HttpPayloadTraitsWithMediaType_test.go +++ b/internal/protocoltest/restxml/api_op_HttpPayloadTraitsWithMediaType_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -63,25 +62,8 @@ func TestClient_HttpPayloadTraitsWithMediaType_awsRestxmlSerialize(t *testing.T) } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -105,11 +87,15 @@ func TestClient_HttpPayloadTraitsWithMediaType_awsRestxmlSerialize(t *testing.T) e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpPayloadTraitsWithMediaType(context.Background(), c.Params) + result, err := client.HttpPayloadTraitsWithMediaType(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_HttpPayloadTraits_test.go b/internal/protocoltest/restxml/api_op_HttpPayloadTraits_test.go index a1a7c926a0a..533ee4c32f4 100644 --- a/internal/protocoltest/restxml/api_op_HttpPayloadTraits_test.go +++ b/internal/protocoltest/restxml/api_op_HttpPayloadTraits_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -77,25 +76,8 @@ func TestClient_HttpPayloadTraits_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -119,11 +101,15 @@ func TestClient_HttpPayloadTraits_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpPayloadTraits(context.Background(), c.Params) + result, err := client.HttpPayloadTraits(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_HttpPayloadWithMemberXmlName_test.go b/internal/protocoltest/restxml/api_op_HttpPayloadWithMemberXmlName_test.go index 5b979b6759f..0eb2b96efd5 100644 --- a/internal/protocoltest/restxml/api_op_HttpPayloadWithMemberXmlName_test.go +++ b/internal/protocoltest/restxml/api_op_HttpPayloadWithMemberXmlName_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -66,25 +65,8 @@ func TestClient_HttpPayloadWithMemberXmlName_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -108,11 +90,15 @@ func TestClient_HttpPayloadWithMemberXmlName_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpPayloadWithMemberXmlName(context.Background(), c.Params) + result, err := client.HttpPayloadWithMemberXmlName(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_HttpPayloadWithStructure_test.go b/internal/protocoltest/restxml/api_op_HttpPayloadWithStructure_test.go index 26098a43f56..fd50982de79 100644 --- a/internal/protocoltest/restxml/api_op_HttpPayloadWithStructure_test.go +++ b/internal/protocoltest/restxml/api_op_HttpPayloadWithStructure_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -70,25 +69,8 @@ func TestClient_HttpPayloadWithStructure_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -112,11 +94,15 @@ func TestClient_HttpPayloadWithStructure_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpPayloadWithStructure(context.Background(), c.Params) + result, err := client.HttpPayloadWithStructure(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_HttpPayloadWithXmlName_test.go b/internal/protocoltest/restxml/api_op_HttpPayloadWithXmlName_test.go index acc2b262a1c..094da7718cc 100644 --- a/internal/protocoltest/restxml/api_op_HttpPayloadWithXmlName_test.go +++ b/internal/protocoltest/restxml/api_op_HttpPayloadWithXmlName_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -65,25 +64,8 @@ func TestClient_HttpPayloadWithXmlName_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -107,11 +89,15 @@ func TestClient_HttpPayloadWithXmlName_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpPayloadWithXmlName(context.Background(), c.Params) + result, err := client.HttpPayloadWithXmlName(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_HttpPayloadWithXmlNamespaceAndPrefix_test.go b/internal/protocoltest/restxml/api_op_HttpPayloadWithXmlNamespaceAndPrefix_test.go index 4253b3ea8ce..1922ebe1c5e 100644 --- a/internal/protocoltest/restxml/api_op_HttpPayloadWithXmlNamespaceAndPrefix_test.go +++ b/internal/protocoltest/restxml/api_op_HttpPayloadWithXmlNamespaceAndPrefix_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -67,25 +66,8 @@ func TestClient_HttpPayloadWithXmlNamespaceAndPrefix_awsRestxmlSerialize(t *test } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -109,11 +91,15 @@ func TestClient_HttpPayloadWithXmlNamespaceAndPrefix_awsRestxmlSerialize(t *test e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpPayloadWithXmlNamespaceAndPrefix(context.Background(), c.Params) + result, err := client.HttpPayloadWithXmlNamespaceAndPrefix(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_HttpPayloadWithXmlNamespace_test.go b/internal/protocoltest/restxml/api_op_HttpPayloadWithXmlNamespace_test.go index b311c4dbeaf..52d64c4a707 100644 --- a/internal/protocoltest/restxml/api_op_HttpPayloadWithXmlNamespace_test.go +++ b/internal/protocoltest/restxml/api_op_HttpPayloadWithXmlNamespace_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -67,25 +66,8 @@ func TestClient_HttpPayloadWithXmlNamespace_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -109,11 +91,15 @@ func TestClient_HttpPayloadWithXmlNamespace_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpPayloadWithXmlNamespace(context.Background(), c.Params) + result, err := client.HttpPayloadWithXmlNamespace(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_HttpPrefixHeaders_test.go b/internal/protocoltest/restxml/api_op_HttpPrefixHeaders_test.go index 440a12ddeeb..3252ca04102 100644 --- a/internal/protocoltest/restxml/api_op_HttpPrefixHeaders_test.go +++ b/internal/protocoltest/restxml/api_op_HttpPrefixHeaders_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -80,25 +79,8 @@ func TestClient_HttpPrefixHeaders_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -122,11 +104,15 @@ func TestClient_HttpPrefixHeaders_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpPrefixHeaders(context.Background(), c.Params) + result, err := client.HttpPrefixHeaders(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_HttpRequestWithFloatLabels_test.go b/internal/protocoltest/restxml/api_op_HttpRequestWithFloatLabels_test.go index 23b9f6f3e19..a5ff1b86f79 100644 --- a/internal/protocoltest/restxml/api_op_HttpRequestWithFloatLabels_test.go +++ b/internal/protocoltest/restxml/api_op_HttpRequestWithFloatLabels_test.go @@ -3,21 +3,18 @@ package restxml import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -78,25 +75,8 @@ func TestClient_HttpRequestWithFloatLabels_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -120,11 +100,15 @@ func TestClient_HttpRequestWithFloatLabels_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpRequestWithFloatLabels(context.Background(), c.Params) + result, err := client.HttpRequestWithFloatLabels(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_HttpRequestWithGreedyLabelInPath_test.go b/internal/protocoltest/restxml/api_op_HttpRequestWithGreedyLabelInPath_test.go index a7ffdc799ca..bad6a13501b 100644 --- a/internal/protocoltest/restxml/api_op_HttpRequestWithGreedyLabelInPath_test.go +++ b/internal/protocoltest/restxml/api_op_HttpRequestWithGreedyLabelInPath_test.go @@ -3,20 +3,17 @@ package restxml import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -51,25 +48,8 @@ func TestClient_HttpRequestWithGreedyLabelInPath_awsRestxmlSerialize(t *testing. } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -93,11 +73,15 @@ func TestClient_HttpRequestWithGreedyLabelInPath_awsRestxmlSerialize(t *testing. e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpRequestWithGreedyLabelInPath(context.Background(), c.Params) + result, err := client.HttpRequestWithGreedyLabelInPath(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_HttpRequestWithLabelsAndTimestampFormat_test.go b/internal/protocoltest/restxml/api_op_HttpRequestWithLabelsAndTimestampFormat_test.go index 47db83d0569..c81b7ae5cfd 100644 --- a/internal/protocoltest/restxml/api_op_HttpRequestWithLabelsAndTimestampFormat_test.go +++ b/internal/protocoltest/restxml/api_op_HttpRequestWithLabelsAndTimestampFormat_test.go @@ -3,21 +3,18 @@ package restxml import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithytime "github.com/aws/smithy-go/time" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -57,25 +54,8 @@ func TestClient_HttpRequestWithLabelsAndTimestampFormat_awsRestxmlSerialize(t *t } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -99,11 +79,15 @@ func TestClient_HttpRequestWithLabelsAndTimestampFormat_awsRestxmlSerialize(t *t e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpRequestWithLabelsAndTimestampFormat(context.Background(), c.Params) + result, err := client.HttpRequestWithLabelsAndTimestampFormat(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_HttpRequestWithLabels_test.go b/internal/protocoltest/restxml/api_op_HttpRequestWithLabels_test.go index b13fd5b7d1d..4986cb62945 100644 --- a/internal/protocoltest/restxml/api_op_HttpRequestWithLabels_test.go +++ b/internal/protocoltest/restxml/api_op_HttpRequestWithLabels_test.go @@ -3,21 +3,18 @@ package restxml import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithytime "github.com/aws/smithy-go/time" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -58,25 +55,8 @@ func TestClient_HttpRequestWithLabels_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -100,11 +80,15 @@ func TestClient_HttpRequestWithLabels_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.HttpRequestWithLabels(context.Background(), c.Params) + result, err := client.HttpRequestWithLabels(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_InputAndOutputWithHeaders_test.go b/internal/protocoltest/restxml/api_op_InputAndOutputWithHeaders_test.go index ce252418ae6..7903f91ed08 100644 --- a/internal/protocoltest/restxml/api_op_InputAndOutputWithHeaders_test.go +++ b/internal/protocoltest/restxml/api_op_InputAndOutputWithHeaders_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -21,9 +22,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" "time" ) @@ -217,25 +216,8 @@ func TestClient_InputAndOutputWithHeaders_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -259,11 +241,15 @@ func TestClient_InputAndOutputWithHeaders_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.InputAndOutputWithHeaders(context.Background(), c.Params) + result, err := client.InputAndOutputWithHeaders(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_NestedXmlMaps_test.go b/internal/protocoltest/restxml/api_op_NestedXmlMaps_test.go index 40573977911..7f29a89b84c 100644 --- a/internal/protocoltest/restxml/api_op_NestedXmlMaps_test.go +++ b/internal/protocoltest/restxml/api_op_NestedXmlMaps_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -106,25 +105,8 @@ func TestClient_NestedXmlMaps_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -148,11 +130,15 @@ func TestClient_NestedXmlMaps_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.NestedXmlMaps(context.Background(), c.Params) + result, err := client.NestedXmlMaps(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_NoInputAndNoOutput_test.go b/internal/protocoltest/restxml/api_op_NoInputAndNoOutput_test.go index 33d7212bef2..c3c52520490 100644 --- a/internal/protocoltest/restxml/api_op_NoInputAndNoOutput_test.go +++ b/internal/protocoltest/restxml/api_op_NoInputAndNoOutput_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -52,25 +51,8 @@ func TestClient_NoInputAndNoOutput_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -94,11 +76,15 @@ func TestClient_NoInputAndNoOutput_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.NoInputAndNoOutput(context.Background(), c.Params) + result, err := client.NoInputAndNoOutput(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_NoInputAndOutput_test.go b/internal/protocoltest/restxml/api_op_NoInputAndOutput_test.go index d0d15a68482..4a8776bd51c 100644 --- a/internal/protocoltest/restxml/api_op_NoInputAndOutput_test.go +++ b/internal/protocoltest/restxml/api_op_NoInputAndOutput_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -52,25 +51,8 @@ func TestClient_NoInputAndOutput_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -94,11 +76,15 @@ func TestClient_NoInputAndOutput_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.NoInputAndOutput(context.Background(), c.Params) + result, err := client.NoInputAndOutput(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_NullAndEmptyHeadersClient_test.go b/internal/protocoltest/restxml/api_op_NullAndEmptyHeadersClient_test.go index 88113be3fc1..d979e5f526f 100644 --- a/internal/protocoltest/restxml/api_op_NullAndEmptyHeadersClient_test.go +++ b/internal/protocoltest/restxml/api_op_NullAndEmptyHeadersClient_test.go @@ -3,20 +3,17 @@ package restxml import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -57,25 +54,8 @@ func TestClient_NullAndEmptyHeadersClient_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -99,11 +79,15 @@ func TestClient_NullAndEmptyHeadersClient_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.NullAndEmptyHeadersClient(context.Background(), c.Params) + result, err := client.NullAndEmptyHeadersClient(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_OmitsNullSerializesEmptyString_test.go b/internal/protocoltest/restxml/api_op_OmitsNullSerializesEmptyString_test.go index 2cb3332e131..2e056e68beb 100644 --- a/internal/protocoltest/restxml/api_op_OmitsNullSerializesEmptyString_test.go +++ b/internal/protocoltest/restxml/api_op_OmitsNullSerializesEmptyString_test.go @@ -3,20 +3,17 @@ package restxml import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -64,25 +61,8 @@ func TestClient_OmitsNullSerializesEmptyString_awsRestxmlSerialize(t *testing.T) } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -106,11 +86,15 @@ func TestClient_OmitsNullSerializesEmptyString_awsRestxmlSerialize(t *testing.T) e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.OmitsNullSerializesEmptyString(context.Background(), c.Params) + result, err := client.OmitsNullSerializesEmptyString(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_QueryIdempotencyTokenAutoFill_test.go b/internal/protocoltest/restxml/api_op_QueryIdempotencyTokenAutoFill_test.go index fd2243b6ec4..91d68f315bc 100644 --- a/internal/protocoltest/restxml/api_op_QueryIdempotencyTokenAutoFill_test.go +++ b/internal/protocoltest/restxml/api_op_QueryIdempotencyTokenAutoFill_test.go @@ -3,20 +3,17 @@ package restxml import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -64,25 +61,8 @@ func TestClient_QueryIdempotencyTokenAutoFill_awsRestxmlSerialize(t *testing.T) } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -106,11 +86,15 @@ func TestClient_QueryIdempotencyTokenAutoFill_awsRestxmlSerialize(t *testing.T) e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.QueryIdempotencyTokenAutoFill(context.Background(), c.Params) + result, err := client.QueryIdempotencyTokenAutoFill(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_QueryParamsAsStringListMap_test.go b/internal/protocoltest/restxml/api_op_QueryParamsAsStringListMap_test.go index 7a7be7629c0..56a111a4f8a 100644 --- a/internal/protocoltest/restxml/api_op_QueryParamsAsStringListMap_test.go +++ b/internal/protocoltest/restxml/api_op_QueryParamsAsStringListMap_test.go @@ -3,20 +3,17 @@ package restxml import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -60,25 +57,8 @@ func TestClient_QueryParamsAsStringListMap_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -102,11 +82,15 @@ func TestClient_QueryParamsAsStringListMap_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.QueryParamsAsStringListMap(context.Background(), c.Params) + result, err := client.QueryParamsAsStringListMap(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_QueryPrecedence_test.go b/internal/protocoltest/restxml/api_op_QueryPrecedence_test.go index 1a685471846..548fdbea7ec 100644 --- a/internal/protocoltest/restxml/api_op_QueryPrecedence_test.go +++ b/internal/protocoltest/restxml/api_op_QueryPrecedence_test.go @@ -3,20 +3,17 @@ package restxml import ( - "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" "io" - "io/ioutil" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -57,25 +54,8 @@ func TestClient_QueryPrecedence_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -99,11 +79,15 @@ func TestClient_QueryPrecedence_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.QueryPrecedence(context.Background(), c.Params) + result, err := client.QueryPrecedence(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_RecursiveShapes_test.go b/internal/protocoltest/restxml/api_op_RecursiveShapes_test.go index d3df55f837d..011c269c528 100644 --- a/internal/protocoltest/restxml/api_op_RecursiveShapes_test.go +++ b/internal/protocoltest/restxml/api_op_RecursiveShapes_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -85,25 +84,8 @@ func TestClient_RecursiveShapes_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -127,11 +109,15 @@ func TestClient_RecursiveShapes_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.RecursiveShapes(context.Background(), c.Params) + result, err := client.RecursiveShapes(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_SimpleScalarProperties_test.go b/internal/protocoltest/restxml/api_op_SimpleScalarProperties_test.go index b2e59bc9f18..811ca2be5a3 100644 --- a/internal/protocoltest/restxml/api_op_SimpleScalarProperties_test.go +++ b/internal/protocoltest/restxml/api_op_SimpleScalarProperties_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -206,25 +205,8 @@ func TestClient_SimpleScalarProperties_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -248,11 +230,15 @@ func TestClient_SimpleScalarProperties_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.SimpleScalarProperties(context.Background(), c.Params) + result, err := client.SimpleScalarProperties(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_TimestampFormatHeaders_test.go b/internal/protocoltest/restxml/api_op_TimestampFormatHeaders_test.go index 8668faa073b..31a0c96d65f 100644 --- a/internal/protocoltest/restxml/api_op_TimestampFormatHeaders_test.go +++ b/internal/protocoltest/restxml/api_op_TimestampFormatHeaders_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -71,25 +70,8 @@ func TestClient_TimestampFormatHeaders_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -113,11 +95,15 @@ func TestClient_TimestampFormatHeaders_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.TimestampFormatHeaders(context.Background(), c.Params) + result, err := client.TimestampFormatHeaders(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_XmlAttributesOnPayload_test.go b/internal/protocoltest/restxml/api_op_XmlAttributesOnPayload_test.go index 141c3f4daf9..2d69a7b6407 100644 --- a/internal/protocoltest/restxml/api_op_XmlAttributesOnPayload_test.go +++ b/internal/protocoltest/restxml/api_op_XmlAttributesOnPayload_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -66,25 +65,8 @@ func TestClient_XmlAttributesOnPayload_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -108,11 +90,15 @@ func TestClient_XmlAttributesOnPayload_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.XmlAttributesOnPayload(context.Background(), c.Params) + result, err := client.XmlAttributesOnPayload(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_XmlAttributes_test.go b/internal/protocoltest/restxml/api_op_XmlAttributes_test.go index 31b39f7d2f1..fa10ed3d094 100644 --- a/internal/protocoltest/restxml/api_op_XmlAttributes_test.go +++ b/internal/protocoltest/restxml/api_op_XmlAttributes_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -83,25 +82,8 @@ func TestClient_XmlAttributes_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -125,11 +107,15 @@ func TestClient_XmlAttributes_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.XmlAttributes(context.Background(), c.Params) + result, err := client.XmlAttributes(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_XmlBlobs_test.go b/internal/protocoltest/restxml/api_op_XmlBlobs_test.go index 9b1fe138eed..d622aa1ac53 100644 --- a/internal/protocoltest/restxml/api_op_XmlBlobs_test.go +++ b/internal/protocoltest/restxml/api_op_XmlBlobs_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -61,25 +60,8 @@ func TestClient_XmlBlobs_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -103,11 +85,15 @@ func TestClient_XmlBlobs_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.XmlBlobs(context.Background(), c.Params) + result, err := client.XmlBlobs(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_XmlEmptyLists_test.go b/internal/protocoltest/restxml/api_op_XmlEmptyLists_test.go index 533864e4dbc..d2215f1bfa2 100644 --- a/internal/protocoltest/restxml/api_op_XmlEmptyLists_test.go +++ b/internal/protocoltest/restxml/api_op_XmlEmptyLists_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -18,9 +19,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -63,25 +62,8 @@ func TestClient_XmlEmptyLists_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -105,11 +87,15 @@ func TestClient_XmlEmptyLists_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.XmlEmptyLists(context.Background(), c.Params) + result, err := client.XmlEmptyLists(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_XmlEmptyMaps_test.go b/internal/protocoltest/restxml/api_op_XmlEmptyMaps_test.go index 7913345299c..380de2a58dd 100644 --- a/internal/protocoltest/restxml/api_op_XmlEmptyMaps_test.go +++ b/internal/protocoltest/restxml/api_op_XmlEmptyMaps_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -62,25 +61,8 @@ func TestClient_XmlEmptyMaps_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -104,11 +86,15 @@ func TestClient_XmlEmptyMaps_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.XmlEmptyMaps(context.Background(), c.Params) + result, err := client.XmlEmptyMaps(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_XmlEmptyStrings_test.go b/internal/protocoltest/restxml/api_op_XmlEmptyStrings_test.go index 014c088bcfa..54173040305 100644 --- a/internal/protocoltest/restxml/api_op_XmlEmptyStrings_test.go +++ b/internal/protocoltest/restxml/api_op_XmlEmptyStrings_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -62,25 +61,8 @@ func TestClient_XmlEmptyStrings_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -104,11 +86,15 @@ func TestClient_XmlEmptyStrings_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.XmlEmptyStrings(context.Background(), c.Params) + result, err := client.XmlEmptyStrings(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_XmlEnums_test.go b/internal/protocoltest/restxml/api_op_XmlEnums_test.go index f181e23fc48..61a97373ef8 100644 --- a/internal/protocoltest/restxml/api_op_XmlEnums_test.go +++ b/internal/protocoltest/restxml/api_op_XmlEnums_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -96,25 +95,8 @@ func TestClient_XmlEnums_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -138,11 +120,15 @@ func TestClient_XmlEnums_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.XmlEnums(context.Background(), c.Params) + result, err := client.XmlEnums(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_XmlIntEnums_test.go b/internal/protocoltest/restxml/api_op_XmlIntEnums_test.go index e166c3fdc76..c3136507767 100644 --- a/internal/protocoltest/restxml/api_op_XmlIntEnums_test.go +++ b/internal/protocoltest/restxml/api_op_XmlIntEnums_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -96,25 +95,8 @@ func TestClient_XmlIntEnums_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -138,11 +120,15 @@ func TestClient_XmlIntEnums_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.XmlIntEnums(context.Background(), c.Params) + result, err := client.XmlIntEnums(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_XmlLists_test.go b/internal/protocoltest/restxml/api_op_XmlLists_test.go index ff5b8707a44..a31855f3629 100644 --- a/internal/protocoltest/restxml/api_op_XmlLists_test.go +++ b/internal/protocoltest/restxml/api_op_XmlLists_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -21,9 +22,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" "time" ) @@ -197,25 +196,8 @@ func TestClient_XmlLists_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -239,11 +221,15 @@ func TestClient_XmlLists_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.XmlLists(context.Background(), c.Params) + result, err := client.XmlLists(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_XmlMapsXmlName_test.go b/internal/protocoltest/restxml/api_op_XmlMapsXmlName_test.go index d7dfe695d74..65039bcde2b 100644 --- a/internal/protocoltest/restxml/api_op_XmlMapsXmlName_test.go +++ b/internal/protocoltest/restxml/api_op_XmlMapsXmlName_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -83,25 +82,8 @@ func TestClient_XmlMapsXmlName_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -125,11 +107,15 @@ func TestClient_XmlMapsXmlName_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.XmlMapsXmlName(context.Background(), c.Params) + result, err := client.XmlMapsXmlName(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_XmlMaps_test.go b/internal/protocoltest/restxml/api_op_XmlMaps_test.go index e92d69ff00a..af87e82533e 100644 --- a/internal/protocoltest/restxml/api_op_XmlMaps_test.go +++ b/internal/protocoltest/restxml/api_op_XmlMaps_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -83,25 +82,8 @@ func TestClient_XmlMaps_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -125,11 +107,15 @@ func TestClient_XmlMaps_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.XmlMaps(context.Background(), c.Params) + result, err := client.XmlMaps(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_XmlNamespaces_test.go b/internal/protocoltest/restxml/api_op_XmlNamespaces_test.go index e471f5e7c7d..22fa81b81d2 100644 --- a/internal/protocoltest/restxml/api_op_XmlNamespaces_test.go +++ b/internal/protocoltest/restxml/api_op_XmlNamespaces_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -75,25 +74,8 @@ func TestClient_XmlNamespaces_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -117,11 +99,15 @@ func TestClient_XmlNamespaces_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.XmlNamespaces(context.Background(), c.Params) + result, err := client.XmlNamespaces(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_XmlTimestamps_test.go b/internal/protocoltest/restxml/api_op_XmlTimestamps_test.go index 300e12e72af..cde088b551d 100644 --- a/internal/protocoltest/restxml/api_op_XmlTimestamps_test.go +++ b/internal/protocoltest/restxml/api_op_XmlTimestamps_test.go @@ -6,9 +6,10 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -178,25 +177,8 @@ func TestClient_XmlTimestamps_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -220,11 +202,15 @@ func TestClient_XmlTimestamps_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.XmlTimestamps(context.Background(), c.Params) + result, err := client.XmlTimestamps(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxml/api_op_XmlUnions_test.go b/internal/protocoltest/restxml/api_op_XmlUnions_test.go index 8ccfd7463c5..f8c78b794a7 100644 --- a/internal/protocoltest/restxml/api_op_XmlUnions_test.go +++ b/internal/protocoltest/restxml/api_op_XmlUnions_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -20,9 +21,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -148,25 +147,8 @@ func TestClient_XmlUnions_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -190,11 +172,15 @@ func TestClient_XmlUnions_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), Region: "us-west-2", }) - result, err := client.XmlUnions(context.Background(), c.Params) + result, err := client.XmlUnions(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) } diff --git a/internal/protocoltest/restxmlwithnamespace/api_op_SimpleScalarProperties_test.go b/internal/protocoltest/restxmlwithnamespace/api_op_SimpleScalarProperties_test.go index b2a88d664df..2e334af22eb 100644 --- a/internal/protocoltest/restxmlwithnamespace/api_op_SimpleScalarProperties_test.go +++ b/internal/protocoltest/restxmlwithnamespace/api_op_SimpleScalarProperties_test.go @@ -6,10 +6,11 @@ import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" - awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxmlwithnamespace/types" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" "github.com/aws/smithy-go/ptr" smithytesting "github.com/aws/smithy-go/testing" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -19,9 +20,7 @@ import ( "io/ioutil" "math" "net/http" - "net/http/httptest" "net/url" - "strconv" "testing" ) @@ -84,25 +83,8 @@ func TestClient_SimpleScalarProperties_awsRestxmlSerialize(t *testing.T) { } for name, c := range cases { t.Run(name, func(t *testing.T) { - var actualReq *http.Request - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - actualReq = r.Clone(r.Context()) - if len(actualReq.URL.RawPath) == 0 { - actualReq.URL.RawPath = actualReq.URL.Path - } - if v := actualReq.ContentLength; v != 0 { - actualReq.Header.Set("Content-Length", strconv.FormatInt(v, 10)) - } - var buf bytes.Buffer - if _, err := io.Copy(&buf, r.Body); err != nil { - t.Errorf("failed to read request body, %v", err) - } - actualReq.Body = ioutil.NopCloser(&buf) - - w.WriteHeader(200) - })) - defer server.Close() - serverURL := server.URL + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) if err != nil { @@ -126,10 +108,14 @@ func TestClient_SimpleScalarProperties_awsRestxmlSerialize(t *testing.T) { e.SigningRegion = "us-west-2" return e, err }), - HTTPClient: awshttp.NewBuildableClient(), + HTTPClient: protocoltesthttp.NewClient(), Region: "us-west-2", }) - result, err := client.SimpleScalarProperties(context.Background(), c.Params) + result, err := client.SimpleScalarProperties(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) if err != nil { t.Fatalf("expect nil err, got %v", err) }