22import "@aws-sdk/crc64-nvme-crt" ;
33
44import { ChecksumAlgorithm , S3 } from "@aws-sdk/client-s3" ;
5+ import { NodeHttpHandler } from "@smithy/node-http-handler" ;
56import { HttpHandler , HttpRequest , HttpResponse } from "@smithy/protocol-http" ;
67import { Readable , Transform } from "stream" ;
78import { describe , expect , test as it } from "vitest" ;
@@ -104,7 +105,19 @@ describe("middleware-flexible-checksums", () => {
104105
105106 it ( "retry doesn't recompute the checksum" , async ( ) => {
106107 const maxAttempts = 3 ;
107- const client = new S3 ( { maxAttempts } ) ;
108+
109+ class CustomHandler extends NodeHttpHandler {
110+ async handle ( ) {
111+ return {
112+ response : new HttpResponse ( {
113+ statusCode : 500 , // Fake Trasient Error
114+ headers : { } ,
115+ } ) ,
116+ } ;
117+ }
118+ }
119+ const requestHandler = new CustomHandler ( ) ;
120+ const client = new S3 ( { maxAttempts, requestHandler } ) ;
108121
109122 let flexChecksCalls = 0 ;
110123 client . middlewareStack . addRelativeTo (
@@ -130,15 +143,6 @@ describe("middleware-flexible-checksums", () => {
130143 }
131144 ) ;
132145
133- requireRequestsFrom ( client )
134- . toMatch ( { method : "PUT" } )
135- . respondWith (
136- new HttpResponse ( {
137- statusCode : 500 , // Fake Trasient Error
138- headers : { } ,
139- } )
140- ) ;
141-
142146 await client
143147 . putObject ( {
144148 Bucket : "b" ,
@@ -147,12 +151,12 @@ describe("middleware-flexible-checksums", () => {
147151 } )
148152 . catch ( ( ) => {
149153 // Expected, since we're faking transient error which is retried.
150- // Validate that flexibleChecksumsMiddleware is called once.
151- expect ( flexChecksCalls ) . toEqual ( 1 ) ;
152- // Validate that retryMiddleware is called maxAttempts times.
153- expect ( retryMiddlewareCalls ) . toEqual ( maxAttempts ) ;
154154 } ) ;
155- expect . hasAssertions ( ) ;
155+
156+ // Validate that flexibleChecksumsMiddleware is called once.
157+ expect ( flexChecksCalls ) . toEqual ( 1 ) ;
158+ // Validate that retryMiddleware is called maxAttempts times.
159+ expect ( retryMiddlewareCalls ) . toEqual ( maxAttempts ) ;
156160 } ) ;
157161 } ) ;
158162
0 commit comments