Skip to content

Commit fd20076

Browse files
committed
Update test stubs for new SDK and transfermanager behavior
The newer SDK (v1.41.6) and transfermanager (v0.1.18) send additional fields by default that the test stubs weren't expecting: - GetObject now sends ChecksumMode: ENABLED - CreateMultipartUpload now sends ChecksumAlgorithm: CRC32 - UploadPart now sends ChecksumAlgorithm: CRC32 - DownloadObject uses part-based downloads (PartNumber) instead of byte-range downloads Updated stubs and large object test to match the new behavior.
1 parent 352d3da commit fd20076

2 files changed

Lines changed: 33 additions & 33 deletions

File tree

gov2/s3/scenarios/scenario_large_objects_test.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ package scenarios
77

88
import (
99
"context"
10-
"fmt"
1110
"io"
12-
"net/http"
1311
"os"
1412
"strings"
1513
"testing"
1614

17-
"github.com/aws/aws-sdk-go-v2/aws"
1815
"github.com/aws/aws-sdk-go-v2/config"
1916
"github.com/aws/aws-sdk-go-v2/service/s3/types"
2017
"github.com/awsdocs/aws-doc-sdk-examples/gov2/demotools"
@@ -30,17 +27,6 @@ func TestRunLargeObjectScenario(t *testing.T) {
3027
testtools.RunScenarioTests(&scenTest, t)
3128
}
3229

33-
// httpErr is used to mock an HTTP error. This is required by the download manager,
34-
// which calls GetObject until it receives a 415 status code.
35-
type httpErr struct {
36-
statusCode int
37-
}
38-
39-
func (responseErr httpErr) HTTPStatusCode() int { return responseErr.statusCode }
40-
func (responseErr httpErr) Error() string {
41-
return fmt.Sprintf("HTTP error: %v", responseErr.statusCode)
42-
}
43-
4430
// LargeObjectScenarioTest encapsulates data for a scenario test.
4531
type LargeObjectScenarioTest struct {
4632
Answers []string
@@ -58,7 +44,6 @@ func (scenTest *LargeObjectScenarioTest) SetupDataAndStubs() []testtools.Stub {
5844
}
5945
uploadId := "upload-id"
6046
testBody := io.NopCloser(strings.NewReader("Test data!"))
61-
dnRanges := []int{0, 10 * 1024 * 1024, 20 * 1024 * 1024, 30 * 1024 * 1024, 40 * 1024 * 1024}
6247
listKeys := []string{largeKey}
6348
scenTest.Answers = []string{
6449
bucketName, "", "", "y",
@@ -75,15 +60,8 @@ func (scenTest *LargeObjectScenarioTest) SetupDataAndStubs() []testtools.Stub {
7560
stubList = append(stubList, stubs.StubUploadPart(bucketName, largeKey, uploadId, nil))
7661
stubList = append(stubList, stubs.StubCompleteMultipartUpload(bucketName, largeKey, uploadId, []int32{1, 2, 3}, nil))
7762
stubList = append(stubList, stubs.StubHeadObject(bucketName, largeKey, nil))
78-
for i := 0; i < len(dnRanges)-2; i++ {
79-
stubList = append(stubList, stubs.StubGetObject(bucketName, largeKey,
80-
aws.String(fmt.Sprintf("bytes=%v-%v", dnRanges[i], dnRanges[i+1]-1)), testBody, nil))
81-
}
82-
// The S3 downloader calls GetObject until it receives a 416 HTTP status code.
83-
respErr := httpErr{statusCode: http.StatusRequestedRangeNotSatisfiable}
84-
stubList = append(stubList, stubs.StubGetObject(bucketName, largeKey,
85-
aws.String(fmt.Sprintf("bytes=%v-%v", dnRanges[3], dnRanges[4]-1)), testBody,
86-
&testtools.StubError{Err: respErr, ContinueAfter: true}))
63+
// The transfermanager downloads by parts using GetObject with PartNumber.
64+
stubList = append(stubList, stubs.StubGetObjectByPart(bucketName, largeKey, 1, 1, 10, testBody, nil))
8765
stubList = append(stubList, stubs.StubDeleteObjects(bucketName, listKeys, nil))
8866
for _, key := range listKeys {
8967
stubList = append(stubList, stubs.StubHeadObject(bucketName, key,

gov2/s3/stubs/bucket_basics_stubs.go

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ func StubCreateMultipartUpload(bucketName string, objectKey string, uploadId str
8383
return testtools.Stub{
8484
OperationName: "CreateMultipartUpload",
8585
Input: &s3.CreateMultipartUploadInput{
86-
Bucket: aws.String(bucketName),
87-
Key: aws.String(objectKey),
86+
Bucket: aws.String(bucketName),
87+
Key: aws.String(objectKey),
88+
ChecksumAlgorithm: types.ChecksumAlgorithmCrc32,
8889
},
8990
Output: &s3.CreateMultipartUploadOutput{
9091
Bucket: aws.String(bucketName),
@@ -100,9 +101,10 @@ func StubUploadPart(bucketName string, objectKey string, uploadId string,
100101
return testtools.Stub{
101102
OperationName: "UploadPart",
102103
Input: &s3.UploadPartInput{
103-
Bucket: aws.String(bucketName),
104-
Key: aws.String(objectKey),
105-
UploadId: aws.String(uploadId),
104+
Bucket: aws.String(bucketName),
105+
Key: aws.String(objectKey),
106+
UploadId: aws.String(uploadId),
107+
ChecksumAlgorithm: types.ChecksumAlgorithmCrc32,
106108
},
107109
Output: &s3.UploadPartOutput{},
108110
SkipErrorTest: true,
@@ -137,13 +139,33 @@ func StubGetObject(bucketName string, objectKey string, byteRange *string, body
137139
return testtools.Stub{
138140
OperationName: "GetObject",
139141
Input: &s3.GetObjectInput{
140-
Bucket: aws.String(bucketName),
141-
Key: aws.String(objectKey),
142-
Range: byteRange,
142+
Bucket: aws.String(bucketName),
143+
Key: aws.String(objectKey),
144+
Range: byteRange,
145+
ChecksumMode: types.ChecksumModeEnabled,
143146
},
144147
Output: &s3.GetObjectOutput{
145148
Body: body,
146149
},
150+
Error: raiseErr,
151+
IgnoreFields: []string{"PartNumber"},
152+
}
153+
}
154+
155+
func StubGetObjectByPart(bucketName string, objectKey string, partNumber int32, partsCount int32, contentLength int64, body io.ReadCloser, raiseErr *testtools.StubError) testtools.Stub {
156+
return testtools.Stub{
157+
OperationName: "GetObject",
158+
Input: &s3.GetObjectInput{
159+
Bucket: aws.String(bucketName),
160+
Key: aws.String(objectKey),
161+
PartNumber: aws.Int32(partNumber),
162+
ChecksumMode: types.ChecksumModeEnabled,
163+
},
164+
Output: &s3.GetObjectOutput{
165+
Body: body,
166+
PartsCount: aws.Int32(partsCount),
167+
ContentLength: aws.Int64(contentLength),
168+
},
147169
Error: raiseErr,
148170
}
149171
}
@@ -217,7 +239,7 @@ func StubPresignedRequest(method string, bucketName string, objectKey string, ra
217239
input = &s3.PutObjectInput{Bucket: aws.String(bucketName), Key: aws.String(objectKey)}
218240
case "GET":
219241
opName = "GetObject"
220-
input = &s3.GetObjectInput{Bucket: aws.String(bucketName), Key: aws.String(objectKey)}
242+
input = &s3.GetObjectInput{Bucket: aws.String(bucketName), Key: aws.String(objectKey), ChecksumMode: types.ChecksumModeEnabled}
221243
case "DELETE":
222244
opName = "DeleteObject"
223245
input = &s3.DeleteObjectInput{Bucket: aws.String(bucketName), Key: aws.String(objectKey)}

0 commit comments

Comments
 (0)