From ffeed56a647598e0da245f26a86a101c07204e16 Mon Sep 17 00:00:00 2001 From: Tianyi Wang Date: Mon, 4 Dec 2023 23:46:53 -0500 Subject: [PATCH] Add request compression assertion to protocol unit tests --- .../api_op_PutWithContentEncoding_test.go | 12 ++++++++++++ .../ec2query/api_op_PutWithContentEncoding_test.go | 12 ++++++++++++ .../jsonrpc/api_op_PutWithContentEncoding_test.go | 12 ++++++++++++ .../jsonrpc10/api_op_PutWithContentEncoding_test.go | 12 ++++++++++++ .../query/api_op_PutWithContentEncoding_test.go | 12 ++++++++++++ .../restxml/api_op_PutWithContentEncoding_test.go | 12 ++++++++++++ 6 files changed, 72 insertions(+) diff --git a/internal/protocoltest/awsrestjson/api_op_PutWithContentEncoding_test.go b/internal/protocoltest/awsrestjson/api_op_PutWithContentEncoding_test.go index 016e9350589..d0b44c924cf 100644 --- a/internal/protocoltest/awsrestjson/api_op_PutWithContentEncoding_test.go +++ b/internal/protocoltest/awsrestjson/api_op_PutWithContentEncoding_test.go @@ -3,11 +3,13 @@ package awsrestjson import ( + "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" + smithyrequestcompression "github.com/aws/smithy-go/private/requestcompression" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -63,6 +65,7 @@ func TestClient_PutWithContentEncoding_awsRestjson1Serialize(t *testing.T) { for name, c := range cases { t.Run(name, func(t *testing.T) { actualReq := &http.Request{} + rawBodyBuf := &bytes.Buffer{} serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) @@ -95,7 +98,12 @@ func TestClient_PutWithContentEncoding_awsRestjson1Serialize(t *testing.T) { options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) }) + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyrequestcompression.AddCaptureUncompressedRequestMiddleware(stack, rawBodyBuf) + }) }) + disable := client.Options().DisableRequestCompression + min := client.Options().RequestMinCompressSizeBytes if err != nil { t.Fatalf("expect nil err, got %v", err) } @@ -120,6 +128,10 @@ func TestClient_PutWithContentEncoding_awsRestjson1Serialize(t *testing.T) { t.Errorf("expect body equal, got %v", err) } } + if err := smithytesting.CompareCompressedBytes(rawBodyBuf, actualReq.Body, + disable, min, "gzip"); err != nil { + t.Errorf("unzipped request body not match: %q", err) + } }) } } diff --git a/internal/protocoltest/ec2query/api_op_PutWithContentEncoding_test.go b/internal/protocoltest/ec2query/api_op_PutWithContentEncoding_test.go index c4aa7a2eee4..aaa4876093e 100644 --- a/internal/protocoltest/ec2query/api_op_PutWithContentEncoding_test.go +++ b/internal/protocoltest/ec2query/api_op_PutWithContentEncoding_test.go @@ -3,11 +3,13 @@ package ec2query import ( + "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" + smithyrequestcompression "github.com/aws/smithy-go/private/requestcompression" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -63,6 +65,7 @@ func TestClient_PutWithContentEncoding_awsEc2querySerialize(t *testing.T) { for name, c := range cases { t.Run(name, func(t *testing.T) { actualReq := &http.Request{} + rawBodyBuf := &bytes.Buffer{} serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) @@ -95,7 +98,12 @@ func TestClient_PutWithContentEncoding_awsEc2querySerialize(t *testing.T) { options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) }) + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyrequestcompression.AddCaptureUncompressedRequestMiddleware(stack, rawBodyBuf) + }) }) + disable := client.Options().DisableRequestCompression + min := client.Options().RequestMinCompressSizeBytes if err != nil { t.Fatalf("expect nil err, got %v", err) } @@ -120,6 +128,10 @@ func TestClient_PutWithContentEncoding_awsEc2querySerialize(t *testing.T) { t.Errorf("expect body equal, got %v", err) } } + if err := smithytesting.CompareCompressedBytes(rawBodyBuf, actualReq.Body, + disable, min, "gzip"); err != nil { + t.Errorf("unzipped request body not match: %q", err) + } }) } } diff --git a/internal/protocoltest/jsonrpc/api_op_PutWithContentEncoding_test.go b/internal/protocoltest/jsonrpc/api_op_PutWithContentEncoding_test.go index 5f8e353057f..c7ba37eaae2 100644 --- a/internal/protocoltest/jsonrpc/api_op_PutWithContentEncoding_test.go +++ b/internal/protocoltest/jsonrpc/api_op_PutWithContentEncoding_test.go @@ -3,11 +3,13 @@ package jsonrpc import ( + "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" + smithyrequestcompression "github.com/aws/smithy-go/private/requestcompression" "github.com/aws/smithy-go/ptr" smithytesting "github.com/aws/smithy-go/testing" "io" @@ -62,6 +64,7 @@ func TestClient_PutWithContentEncoding_awsAwsjson11Serialize(t *testing.T) { for name, c := range cases { t.Run(name, func(t *testing.T) { actualReq := &http.Request{} + rawBodyBuf := &bytes.Buffer{} serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) @@ -93,7 +96,12 @@ func TestClient_PutWithContentEncoding_awsAwsjson11Serialize(t *testing.T) { options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) }) + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyrequestcompression.AddCaptureUncompressedRequestMiddleware(stack, rawBodyBuf) + }) }) + disable := client.Options().DisableRequestCompression + min := client.Options().RequestMinCompressSizeBytes if err != nil { t.Fatalf("expect nil err, got %v", err) } @@ -118,6 +126,10 @@ func TestClient_PutWithContentEncoding_awsAwsjson11Serialize(t *testing.T) { t.Errorf("expect body equal, got %v", err) } } + if err := smithytesting.CompareCompressedBytes(rawBodyBuf, actualReq.Body, + disable, min, "gzip"); err != nil { + t.Errorf("unzipped request body not match: %q", err) + } }) } } diff --git a/internal/protocoltest/jsonrpc10/api_op_PutWithContentEncoding_test.go b/internal/protocoltest/jsonrpc10/api_op_PutWithContentEncoding_test.go index bb5aff04953..f10dec03f98 100644 --- a/internal/protocoltest/jsonrpc10/api_op_PutWithContentEncoding_test.go +++ b/internal/protocoltest/jsonrpc10/api_op_PutWithContentEncoding_test.go @@ -3,11 +3,13 @@ package jsonrpc10 import ( + "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" + smithyrequestcompression "github.com/aws/smithy-go/private/requestcompression" "github.com/aws/smithy-go/ptr" smithytesting "github.com/aws/smithy-go/testing" "io" @@ -62,6 +64,7 @@ func TestClient_PutWithContentEncoding_awsAwsjson10Serialize(t *testing.T) { for name, c := range cases { t.Run(name, func(t *testing.T) { actualReq := &http.Request{} + rawBodyBuf := &bytes.Buffer{} serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) @@ -93,7 +96,12 @@ func TestClient_PutWithContentEncoding_awsAwsjson10Serialize(t *testing.T) { options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) }) + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyrequestcompression.AddCaptureUncompressedRequestMiddleware(stack, rawBodyBuf) + }) }) + disable := client.Options().DisableRequestCompression + min := client.Options().RequestMinCompressSizeBytes if err != nil { t.Fatalf("expect nil err, got %v", err) } @@ -118,6 +126,10 @@ func TestClient_PutWithContentEncoding_awsAwsjson10Serialize(t *testing.T) { t.Errorf("expect body equal, got %v", err) } } + if err := smithytesting.CompareCompressedBytes(rawBodyBuf, actualReq.Body, + disable, min, "gzip"); err != nil { + t.Errorf("unzipped request body not match: %q", err) + } }) } } diff --git a/internal/protocoltest/query/api_op_PutWithContentEncoding_test.go b/internal/protocoltest/query/api_op_PutWithContentEncoding_test.go index 040d583408b..30156132795 100644 --- a/internal/protocoltest/query/api_op_PutWithContentEncoding_test.go +++ b/internal/protocoltest/query/api_op_PutWithContentEncoding_test.go @@ -3,11 +3,13 @@ package query import ( + "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" + smithyrequestcompression "github.com/aws/smithy-go/private/requestcompression" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -63,6 +65,7 @@ func TestClient_PutWithContentEncoding_awsAwsquerySerialize(t *testing.T) { for name, c := range cases { t.Run(name, func(t *testing.T) { actualReq := &http.Request{} + rawBodyBuf := &bytes.Buffer{} serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) @@ -95,7 +98,12 @@ func TestClient_PutWithContentEncoding_awsAwsquerySerialize(t *testing.T) { options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) }) + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyrequestcompression.AddCaptureUncompressedRequestMiddleware(stack, rawBodyBuf) + }) }) + disable := client.Options().DisableRequestCompression + min := client.Options().RequestMinCompressSizeBytes if err != nil { t.Fatalf("expect nil err, got %v", err) } @@ -120,6 +128,10 @@ func TestClient_PutWithContentEncoding_awsAwsquerySerialize(t *testing.T) { t.Errorf("expect body equal, got %v", err) } } + if err := smithytesting.CompareCompressedBytes(rawBodyBuf, actualReq.Body, + disable, min, "gzip"); err != nil { + t.Errorf("unzipped request body not match: %q", err) + } }) } } diff --git a/internal/protocoltest/restxml/api_op_PutWithContentEncoding_test.go b/internal/protocoltest/restxml/api_op_PutWithContentEncoding_test.go index 9dd09be9fc1..cef29870146 100644 --- a/internal/protocoltest/restxml/api_op_PutWithContentEncoding_test.go +++ b/internal/protocoltest/restxml/api_op_PutWithContentEncoding_test.go @@ -3,11 +3,13 @@ package restxml import ( + "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" "github.com/aws/smithy-go/middleware" smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" + smithyrequestcompression "github.com/aws/smithy-go/private/requestcompression" "github.com/aws/smithy-go/ptr" smithyrand "github.com/aws/smithy-go/rand" smithytesting "github.com/aws/smithy-go/testing" @@ -63,6 +65,7 @@ func TestClient_PutWithContentEncoding_awsRestxmlSerialize(t *testing.T) { for name, c := range cases { t.Run(name, func(t *testing.T) { actualReq := &http.Request{} + rawBodyBuf := &bytes.Buffer{} serverURL := "http://localhost:8888/" if c.Host != nil { u, err := url.Parse(serverURL) @@ -95,7 +98,12 @@ func TestClient_PutWithContentEncoding_awsRestxmlSerialize(t *testing.T) { options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) }) + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyrequestcompression.AddCaptureUncompressedRequestMiddleware(stack, rawBodyBuf) + }) }) + disable := client.Options().DisableRequestCompression + min := client.Options().RequestMinCompressSizeBytes if err != nil { t.Fatalf("expect nil err, got %v", err) } @@ -120,6 +128,10 @@ func TestClient_PutWithContentEncoding_awsRestxmlSerialize(t *testing.T) { t.Errorf("expect body equal, got %v", err) } } + if err := smithytesting.CompareCompressedBytes(rawBodyBuf, actualReq.Body, + disable, min, "gzip"); err != nil { + t.Errorf("unzipped request body not match: %q", err) + } }) } }