Skip to content

Commit

Permalink
adds integration test for presign url and moves the unit test to serv…
Browse files Browse the repository at this point in the history
…ice/s3 folder
  • Loading branch information
skotambkar committed Nov 18, 2020
1 parent ae09fd0 commit a00f6a4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 53 deletions.
19 changes: 0 additions & 19 deletions service/internal/featuretest/go.mod

This file was deleted.

18 changes: 0 additions & 18 deletions service/internal/featuretest/go.sum

This file was deleted.

40 changes: 25 additions & 15 deletions service/internal/integrationtest/s3/presign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@

package s3

import (
"bytes"
"context"
"io/ioutil"
"net/http"
"strconv"
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/internal/integrationtest"
"github.com/aws/aws-sdk-go-v2/service/s3"
)

func TestInteg_PresignURL_PutObject(t *testing.T) {
key := integrationtest.UniqueID()

ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
defer cancelFn()
Expand All @@ -14,12 +29,9 @@ func TestInteg_PresignURL_PutObject(t *testing.T) {

client := s3.NewFromConfig(cfg)

bucketName := "mockbucket-01"
key := "random"

params := &s3.PutObjectInput{
Bucket: &bucketName,
Key: &key,
Bucket: &setupMetadata.Buckets.Source.Name,
Key: aws.String(key),
Body: bytes.NewReader([]byte(`Hello-world`)),
}

Expand All @@ -32,34 +44,32 @@ func TestInteg_PresignURL_PutObject(t *testing.T) {
t.Errorf("expect no error, got %v", err)
}

// Putobject
t.Logf("url : %v \n", presignRequest.URL)
t.Logf("method : %v \n", presignRequest.Method)
t.Logf("signed headers : %v \n", presignRequest.SignedHeader)

t.Logf("attempting to put request")

// create a http request
req, err := http.NewRequest(presignRequest.Method, presignRequest.URL, nil)
if err != nil {
t.Fatalf("failed to build presigned request, %v", err)
}

// assign the signed headers onto the http request
for k, vs := range presignRequest.SignedHeader {
for _, v := range vs {
req.Header.Add(k, v)
}
}

// Need to ensure that the content length member is set of the HTTP Request
// or the request will not be transmitted correctly with a content length
// or the request will NOT be transmitted correctly with a content length
// value across the wire.
if contLen := req.Header.Get("Content-Length"); len(contLen) > 0 {
req.ContentLength, _ = strconv.ParseInt(contLen, 10, 64)
}

req.Body = ioutil.NopCloser(params.Body)
// assign the request body if not nil
if params.Body != nil {
req.Body = ioutil.NopCloser(params.Body)
}

// Upload the file contents to S3.
// Upload the object to S3.
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Fatalf("failed to do PUT request, %v", err)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unit_test
package customizations_test

import (
"bytes"
Expand Down

0 comments on commit a00f6a4

Please sign in to comment.