From 8db7d37cd0624321d615a9ad626f3564d7787ffd Mon Sep 17 00:00:00 2001 From: skotambkar Date: Thu, 19 Nov 2020 22:37:05 -0800 Subject: [PATCH] enable empty body test for presign --- service/internal/integrationtest/go.mod | 1 + .../integrationtest/s3/presign_test.go | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/service/internal/integrationtest/go.mod b/service/internal/integrationtest/go.mod index eac1fcefbfb..3b835ba95d0 100644 --- a/service/internal/integrationtest/go.mod +++ b/service/internal/integrationtest/go.mod @@ -87,6 +87,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/wafv2 v0.29.0 github.com/aws/aws-sdk-go-v2/service/workspaces v0.29.0 github.com/awslabs/smithy-go v0.3.1-0.20201120010914-c02b9493fe20 + github.com/google/go-cmp v0.5.2 ) go 1.15 diff --git a/service/internal/integrationtest/s3/presign_test.go b/service/internal/integrationtest/s3/presign_test.go index 9aa8e4483d2..027329cd383 100644 --- a/service/internal/integrationtest/s3/presign_test.go +++ b/service/internal/integrationtest/s3/presign_test.go @@ -36,13 +36,12 @@ func TestInteg_PresignURL(t *testing.T) { "nil-body": { expectedSignedHeader: http.Header{}, }, - // TODO: fix PutObject with an empty body returning 501 - // "empty-body": { - // body: bytes.NewReader([]byte("")), - // expectedSignedHeader: http.Header{ - // "content-type": {"application/octet-stream"}, - // }, - // }, + "empty-body": { + body: bytes.NewReader([]byte("")), + expectedSignedHeader: http.Header{ + "content-type": {"application/octet-stream"}, + }, + }, } for name, c := range cases { @@ -72,7 +71,7 @@ func TestInteg_PresignURL(t *testing.T) { presignRequest, err := presignerClient.PresignPutObject(ctx, putObjectInput) if err != nil { - t.Errorf("expect no error, got %v", err) + t.Fatalf("expect no error, got %v", err) } for k, v := range c.expectedSignedHeader { @@ -146,6 +145,9 @@ func sendHTTPRequest(presignRequest *v4.PresignedHTTPRequest, body io.Reader) (* // assign the request body if not nil if body != nil { req.Body = ioutil.NopCloser(body) + if req.ContentLength == 0 { + req.Body = nil + } } // Upload the object to S3.