Skip to content

Commit 9fbd398

Browse files
committed
test: extend NodeHttpHandler to return transient error
1 parent b01b06d commit 9fbd398

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

packages/middleware-flexible-checksums/src/middleware-flexible-checksums.integ.spec.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import "@aws-sdk/crc64-nvme-crt";
33

44
import { ChecksumAlgorithm, S3 } from "@aws-sdk/client-s3";
5+
import { NodeHttpHandler } from "@smithy/node-http-handler";
56
import { HttpHandler, HttpRequest, HttpResponse } from "@smithy/protocol-http";
67
import { Readable, Transform } from "stream";
78
import { 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

Comments
 (0)