From b92d0a41ea34fccbd271ce38ada2807ad62c0cff Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Mon, 1 May 2023 13:47:39 -0400 Subject: [PATCH] Improve S3 upload unit test --- aws/s3_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/aws/s3_test.go b/aws/s3_test.go index 32e0c53f..4f2d2628 100644 --- a/aws/s3_test.go +++ b/aws/s3_test.go @@ -1,6 +1,7 @@ package aws import ( + "bytes" "context" "fmt" "strings" @@ -42,6 +43,8 @@ func TestS3ClientUploadOK(t *testing.T) { secretKey := "your-secret-key" bucket := "your-bucket" key := "your/key/path" + expectedData := "test data" + uploadedData := new(bytes.Buffer) mockUploader := &mockUploader{ uploadFn: func(ctx aws.Context, input *s3manager.UploadInput, opts ...func(*s3manager.Uploader)) (*s3manager.UploadOutput, error) { @@ -54,6 +57,10 @@ func TestS3ClientUploadOK(t *testing.T) { if input.Body == nil { t.Errorf("expected body to be non-nil") } + _, err := uploadedData.ReadFrom(input.Body) + if err != nil { + t.Errorf("error reading from input body: %v", err) + } return &s3manager.UploadOutput{}, nil }, } @@ -72,6 +79,9 @@ func TestS3ClientUploadOK(t *testing.T) { if err != nil { t.Fatalf("Unexpected error: %v", err) } + if uploadedData.String() != expectedData { + t.Errorf("expected uploaded data to be %q, got %q", expectedData, uploadedData.String()) + } } func TestS3ClientUploadFail(t *testing.T) {