@@ -24,134 +24,141 @@ describe("@aws-sdk/lib-storage", () => {
2424 Key = `` ;
2525 data = randomBytes ( 20_240_000 ) ;
2626 dataString = data . toString ( ) ;
27-
28- client = new S3 ( {
29- region,
30- } ) ;
3127 } ) ;
3228
33- describe ( "Upload" , ( ) => {
34- beforeAll ( ( ) => {
35- Key = `multi-part-file-${ Date . now ( ) } ` ;
36- } ) ;
37- afterAll ( async ( ) => {
38- await client . deleteObject ( { Bucket, Key } ) ;
39- } ) ;
40-
41- it ( "should upload in parts for input type bytes" , async ( ) => {
42- const s3Upload = new Upload ( {
43- client,
44- params : {
45- Bucket,
46- Key,
47- Body : data ,
48- } ,
29+ describe . each ( [ undefined , "WHEN_REQUIRED" , "WHEN_SUPPORTED" ] ) (
30+ "requestChecksumCalculation: %s" ,
31+ ( requestChecksumCalculation ) => {
32+ beforeAll ( ( ) => {
33+ // @ts -expect-error: Types of property 'requestChecksumCalculation' are incompatible
34+ client = new S3 ( {
35+ region,
36+ requestChecksumCalculation,
37+ } ) ;
38+ Key = `multi-part-file-${ Date . now ( ) } ` ;
4939 } ) ;
50- await s3Upload . done ( ) ;
5140
52- const object = await client . getObject ( {
53- Bucket,
54- Key,
41+ afterAll ( async ( ) => {
42+ await client . deleteObject ( { Bucket, Key } ) ;
5543 } ) ;
5644
57- expect ( await object . Body ?. transformToString ( ) ) . toEqual ( dataString ) ;
58- } ) ;
59-
60- it ( "should upload in parts for input type string" , async ( ) => {
61- const s3Upload = new Upload ( {
62- client,
63- params : {
45+ it ( "should upload in parts for input type bytes" , async ( ) => {
46+ const s3Upload = new Upload ( {
47+ client,
48+ params : {
49+ Bucket,
50+ Key,
51+ Body : data ,
52+ } ,
53+ } ) ;
54+ await s3Upload . done ( ) ;
55+
56+ const object = await client . getObject ( {
6457 Bucket,
6558 Key,
66- Body : dataString ,
67- } ,
68- } ) ;
69- await s3Upload . done ( ) ;
59+ } ) ;
7060
71- const object = await client . getObject ( {
72- Bucket,
73- Key,
61+ expect ( await object . Body ?. transformToString ( ) ) . toEqual ( dataString ) ;
7462 } ) ;
7563
76- expect ( await object . Body ?. transformToString ( ) ) . toEqual ( dataString ) ;
77- } ) ;
78-
79- it ( "should upload in parts for input type Readable" , async ( ) => {
80- const s3Upload = new Upload ( {
81- client,
82- params : {
64+ it ( "should upload in parts for input type string" , async ( ) => {
65+ const s3Upload = new Upload ( {
66+ client,
67+ params : {
68+ Bucket,
69+ Key,
70+ Body : dataString ,
71+ } ,
72+ } ) ;
73+ await s3Upload . done ( ) ;
74+
75+ const object = await client . getObject ( {
8376 Bucket,
8477 Key,
85- Body : Readable . from ( data ) ,
86- } ,
87- } ) ;
88- await s3Upload . done ( ) ;
78+ } ) ;
8979
90- const object = await client . getObject ( {
91- Bucket,
92- Key,
80+ expect ( await object . Body ?. transformToString ( ) ) . toEqual ( dataString ) ;
9381 } ) ;
9482
95- expect ( await object . Body ?. transformToString ( ) ) . toEqual ( dataString ) ;
96- } ) ;
97-
98- it ( "should call AbortMultipartUpload if unable to complete a multipart upload." , async ( ) => {
99- class MockFailureS3 extends S3 {
100- public counter = 0 ;
101- async send ( command : any , ...rest : any [ ] ) {
102- if ( command ?. constructor ?. name === "UploadPartCommand" && this . counter ++ % 3 === 0 ) {
103- throw new Error ( "simulated upload part error" ) ;
104- }
105- return super . send ( command , ...rest ) ;
106- }
107- }
83+ it ( "should upload in parts for input type Readable" , async ( ) => {
84+ const s3Upload = new Upload ( {
85+ client,
86+ params : {
87+ Bucket,
88+ Key,
89+ Body : Readable . from ( data ) ,
90+ } ,
91+ } ) ;
92+ await s3Upload . done ( ) ;
93+
94+ const object = await client . getObject ( {
95+ Bucket,
96+ Key,
97+ } ) ;
10898
109- const client = new MockFailureS3 ( {
110- region,
99+ expect ( await object . Body ?. transformToString ( ) ) . toEqual ( dataString ) ;
111100 } ) ;
112101
113- const requestLog = [ ] as string [ ] ;
114-
115- client . middlewareStack . add (
116- ( next , context ) => async ( args ) => {
117- const result = await next ( args ) ;
118- requestLog . push ( [ context . clientName , context . commandName , result . output . $metadata . httpStatusCode ] . join ( " " ) ) ;
119- return result ;
120- } ,
121- {
122- name : "E2eRequestLog" ,
123- step : "build" ,
124- override : true ,
102+ it ( "should call AbortMultipartUpload if unable to complete a multipart upload." , async ( ) => {
103+ class MockFailureS3 extends S3 {
104+ public counter = 0 ;
105+ async send ( command : any , ...rest : any [ ] ) {
106+ if ( command ?. constructor ?. name === "UploadPartCommand" && this . counter ++ % 3 === 0 ) {
107+ throw new Error ( "simulated upload part error" ) ;
108+ }
109+ return super . send ( command , ...rest ) ;
110+ }
125111 }
126- ) ;
127112
128- const s3Upload = new Upload ( {
129- client,
130- params : {
131- Bucket,
132- Key,
133- Body : data ,
134- } ,
113+ const client = new MockFailureS3 ( {
114+ region,
115+ } ) ;
116+
117+ const requestLog = [ ] as string [ ] ;
118+
119+ client . middlewareStack . add (
120+ ( next , context ) => async ( args ) => {
121+ const result = await next ( args ) ;
122+ requestLog . push (
123+ [ context . clientName , context . commandName , result . output . $metadata . httpStatusCode ] . join ( " " )
124+ ) ;
125+ return result ;
126+ } ,
127+ {
128+ name : "E2eRequestLog" ,
129+ step : "build" ,
130+ override : true ,
131+ }
132+ ) ;
133+
134+ const s3Upload = new Upload ( {
135+ client,
136+ params : {
137+ Bucket,
138+ Key,
139+ Body : data ,
140+ } ,
141+ } ) ;
142+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
143+ await s3Upload . done ( ) . catch ( ( ignored ) => { } ) ;
144+
145+ const uploadStatus = await client
146+ . listParts ( {
147+ Bucket,
148+ Key,
149+ UploadId : s3Upload . uploadId ,
150+ } )
151+ . then ( ( listParts ) => listParts . $metadata . httpStatusCode )
152+ . catch ( ( err ) => err . toString ( ) ) ;
153+
154+ expect ( uploadStatus ) . toMatch ( / N o S u c h U p l o a d : ( .* ?) a b o r t e d o r c o m p l e t e d \. / ) ;
155+ expect ( requestLog ) . toEqual ( [
156+ "S3Client CreateMultipartUploadCommand 200" ,
157+ "S3Client UploadPartCommand 200" ,
158+ "S3Client UploadPartCommand 200" ,
159+ "S3Client AbortMultipartUploadCommand 204" ,
160+ ] ) ;
135161 } ) ;
136- // eslint-disable-next-line @typescript-eslint/no-unused-vars
137- await s3Upload . done ( ) . catch ( ( ignored ) => { } ) ;
138-
139- const uploadStatus = await client
140- . listParts ( {
141- Bucket,
142- Key,
143- UploadId : s3Upload . uploadId ,
144- } )
145- . then ( ( listParts ) => listParts . $metadata . httpStatusCode )
146- . catch ( ( err ) => err . toString ( ) ) ;
147-
148- expect ( uploadStatus ) . toMatch ( / N o S u c h U p l o a d : ( .* ?) a b o r t e d o r c o m p l e t e d \. / ) ;
149- expect ( requestLog ) . toEqual ( [
150- "S3Client CreateMultipartUploadCommand 200" ,
151- "S3Client UploadPartCommand 200" ,
152- "S3Client UploadPartCommand 200" ,
153- "S3Client AbortMultipartUploadCommand 204" ,
154- ] ) ;
155- } ) ;
156- } ) ;
162+ }
163+ ) ;
157164} , 45_000 ) ;
0 commit comments