@@ -7,7 +7,7 @@ import { describe, expect, test as it } from "vitest";
77import { ChecksumAlgorithm as Algo , S3 } from "../../src/index" ;
88
99describe ( "Flexible Checksums" , ( ) => {
10- const testCases = [
10+ const testCases : [ string , string , string ] [ ] = [
1111 [ "" , ChecksumAlgorithm . CRC32 , "AAAAAA==" ] ,
1212 [ "abc" , ChecksumAlgorithm . CRC32 , "NSRBwg==" ] ,
1313 [ "Hello world" , ChecksumAlgorithm . CRC32 , "i9aeUg==" ] ,
@@ -26,10 +26,10 @@ describe("Flexible Checksums", () => {
2626 ] ;
2727
2828 describe ( "putObject" , ( ) => {
29- testCases . forEach ( ( [ body , checksumAlgorithm , checksumValue ] ) => {
30- const checksumHeader = `x-amz- checksum- ${ checksumAlgorithm . toLowerCase ( ) } ` ;
31-
32- describe ( `sets ${ checksumHeader } =" ${ checksumValue } "" for checksum=" ${ checksumAlgorithm } "` , ( ) => {
29+ describe . each ( testCases ) (
30+ `for body="%s" and checksumAlgorithm="%s", sets checksum="%s"` ,
31+ ( body , checksumAlgorithm , checksumValue ) => {
32+ const checksumHeader = `x-amz- checksum- ${ checksumAlgorithm . toLowerCase ( ) } ` ;
3333 const getBodyAsReadableStream = ( content : string ) => {
3434 const readableStream = new Readable ( ) ;
3535 const separator = " " ;
@@ -44,13 +44,15 @@ describe("Flexible Checksums", () => {
4444 return readableStream ;
4545 } ;
4646
47- it ( `when body is sent as a request ` , async ( ) => {
47+ it ( `when body is sent as a string ` , async ( ) => {
4848 const requestChecksumValidator : BuildMiddleware < any , any > = ( next ) => async ( args ) => {
4949 // middleware intercept the request and return it early
5050 const request = args . request as HttpRequest ;
5151 const { headers } = request ;
52- expect ( headers [ "x-amz-sdk-checksum-algorithm" ] ) . to . equal ( checksumAlgorithm ) ;
53- expect ( headers [ checksumHeader ] ) . to . equal ( checksumValue ) ;
52+
53+ expect ( headers [ "x-amz-sdk-checksum-algorithm" ] ) . toEqual ( checksumAlgorithm ) ;
54+ expect ( headers [ checksumHeader ] ) . toEqual ( checksumValue ) ;
55+
5456 return { output : { } as any , response : { } as any } ;
5557 } ;
5658
@@ -79,16 +81,16 @@ describe("Flexible Checksums", () => {
7981 // middleware intercept the request and return it early
8082 const request = args . request as HttpRequest ;
8183 const { headers, body } = request ;
82- expect ( headers [ "content-length" ] ) . to . be . undefined ;
83- expect ( headers [ "content-encoding" ] ) . to . equal ( "aws-chunked" ) ;
84- expect ( headers [ "transfer-encoding" ] ) . to . equal ( "chunked" ) ;
85- expect ( headers [ "x-amz-content-sha256" ] ) . to . equal ( "STREAMING-UNSIGNED-PAYLOAD-TRAILER" ) ;
86- expect ( headers [ "x-amz-trailer" ] ) . to . equal ( checksumHeader ) ;
84+ expect ( headers [ "content-length" ] ) . toBeUndefined ( ) ;
85+ expect ( headers [ "content-encoding" ] ) . toEqual ( "aws-chunked" ) ;
86+ expect ( headers [ "transfer-encoding" ] ) . toEqual ( "chunked" ) ;
87+ expect ( headers [ "x-amz-content-sha256" ] ) . toEqual ( "STREAMING-UNSIGNED-PAYLOAD-TRAILER" ) ;
88+ expect ( headers [ "x-amz-trailer" ] ) . toEqual ( checksumHeader ) ;
8789 body . on ( "data" , ( data : any ) => {
8890 const stringValue = data . toString ( ) ;
8991 if ( stringValue . startsWith ( checksumHeader ) ) {
9092 const receivedChecksum = stringValue . replace ( "\r\n" , "" ) . split ( ":" ) [ 1 ] ;
91- expect ( receivedChecksum ) . to . equal ( checksumValue ) ;
93+ expect ( receivedChecksum ) . toEqual ( checksumValue ) ;
9294 }
9395 } ) ;
9496 return { output : { } as any , response : { } as any } ;
@@ -114,15 +116,16 @@ describe("Flexible Checksums", () => {
114116 ChecksumAlgorithm : checksumAlgorithm as Algo ,
115117 } ) ;
116118 } ) ;
117- } ) ;
118- } ) ;
119+ }
120+ ) ;
119121 } ) ;
120122
121123 describe ( "getObject" , async ( ) => {
122- testCases . forEach ( ( [ body , checksumAlgorithm , checksumValue ] ) => {
123- const checksumHeader = `x-amz-checksum-${ checksumAlgorithm . toLowerCase ( ) } ` ;
124+ it . each ( testCases ) (
125+ `for body="%s" and checksumAlgorithm="%s", validates ChecksumMode` ,
126+ async ( body , checksumAlgorithm , checksumValue ) => {
127+ const checksumHeader = `x-amz-checksum-${ checksumAlgorithm . toLowerCase ( ) } ` ;
124128
125- it ( `validates ${ checksumHeader } ="${ checksumValue } "" set for checksum="${ checksumAlgorithm } "` , async ( ) => {
126129 const responseBody = new Readable ( ) ;
127130 responseBody . push ( body ) ;
128131 responseBody . push ( null ) ;
@@ -162,9 +165,9 @@ describe("Flexible Checksums", () => {
162165 ChecksumMode : "ENABLED" ,
163166 } ) ;
164167 ( Body as Readable ) . on ( "data" , ( chunk ) => {
165- expect ( chunk . toString ( ) ) . to . equal ( body ) ;
168+ expect ( chunk . toString ( ) ) . toEqual ( body ) ;
166169 } ) ;
167- } ) ;
168- } ) ;
170+ }
171+ ) ;
169172 } ) ;
170173} ) ;
0 commit comments