Skip to content

Commit 4e33329

Browse files
committed
test: extend NodeHttpHandler to return transient error
1 parent b01b06d commit 4e33329

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

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

Lines changed: 19 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,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

Comments
 (0)