Skip to content

Commit

Permalink
add unit test for cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jasdel committed Jul 20, 2020
1 parent e7830bf commit 5755532
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions service/s3/s3crypto/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package s3crypto

import (
"bytes"
"io/ioutil"
"net/http"
"os"
"testing"
Expand Down Expand Up @@ -118,6 +119,43 @@ func TestGetWriterStore_TempFile(t *testing.T) {
}
}

func TestGetWriterStore_TempFileWithRetry(t *testing.T) {
responses := []*http.Response{
&http.Response{StatusCode: 500, Header: http.Header{}, Body: ioutil.NopCloser(&bytes.Buffer{})},
&http.Response{StatusCode: 200, Header: http.Header{}, Body: ioutil.NopCloser(&bytes.Buffer{})},
}
s := awstesting.NewClient(aws.NewConfig().WithMaxRetries(10))
s.Handlers.Validate.Clear()
s.Handlers.Send.Clear() // mock sending
s.Handlers.Send.PushBack(func(r *request.Request) {
r.HTTPResponse = responses[0]
responses = responses[1:]
})
type testData struct {
Data string
}
out := &testData{}
r := s.NewRequest(&request.Operation{Name: "Operation"}, nil, out)
f, err := getWriterStore(r, "", true)
if err != nil {
t.Fatalf("expected no error, but received %v", err)
}
tempFile, ok := f.(*os.File)
if !ok {
t.Fatal("io.ReadWriteSeeker expected to be *os.file")
}
err = r.Send()
if err != nil {
t.Errorf("expected no error, but received %v", err)
}
if _, err := os.Stat(tempFile.Name()); !os.IsNotExist(err) {
t.Errorf("expected temp file be deleted, but still exists %v", tempFile.Name())
}
if v := len(responses); v != 0 {
t.Errorf("expect all retries to be used, have %v remaining", v)
}
}

func TestGetWriterStore_Memory(t *testing.T) {
response := http.Response{StatusCode: 200}
s := awstesting.NewClient(aws.NewConfig().WithMaxRetries(10))
Expand Down

0 comments on commit 5755532

Please sign in to comment.