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,18 @@ 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+ class CustomHandler extends NodeHttpHandler {
109+ async handle ( ) {
110+ return {
111+ response : new HttpResponse ( {
112+ statusCode : 500 , // Fake Trasient Error
113+ headers : { } ,
114+ } ) ,
115+ } ;
116+ }
117+ }
118+ const requestHandler = new CustomHandler ( ) ;
119+ const client = new S3 ( { maxAttempts, requestHandler } ) ;
108120
109121 let flexChecksCalls = 0 ;
110122 client . middlewareStack . addRelativeTo (
@@ -130,15 +142,6 @@ describe("middleware-flexible-checksums", () => {
130142 }
131143 ) ;
132144
133- requireRequestsFrom ( client )
134- . toMatch ( { method : "PUT" } )
135- . respondWith (
136- new HttpResponse ( {
137- statusCode : 500 , // Fake Trasient Error
138- headers : { } ,
139- } )
140- ) ;
141-
142145 await client
143146 . putObject ( {
144147 Bucket : "b" ,
@@ -147,12 +150,12 @@ describe("middleware-flexible-checksums", () => {
147150 } )
148151 . catch ( ( ) => {
149152 // 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 ) ;
154153 } ) ;
155- expect . hasAssertions ( ) ;
154+
155+ // Validate that flexibleChecksumsMiddleware is called once.
156+ expect ( flexChecksCalls ) . toEqual ( 1 ) ;
157+ // Validate that retryMiddleware is called maxAttempts times.
158+ expect ( retryMiddlewareCalls ) . toEqual ( maxAttempts ) ;
156159 } ) ;
157160 } ) ;
158161
0 commit comments