From 320678f284e0db3fefa28d5cd3fd30b8603319df Mon Sep 17 00:00:00 2001 From: George Fu Date: Mon, 22 Sep 2025 18:13:03 +0000 Subject: [PATCH 1/2] test: fix lex runtime and mediastore payload tests --- .../test/LexRuntimeService.spec.ts | 24 ++++++++----------- .../test/MediaStoreData.spec.ts | 24 ++++++++----------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/clients/client-lex-runtime-service/test/LexRuntimeService.spec.ts b/clients/client-lex-runtime-service/test/LexRuntimeService.spec.ts index d6a00e65b167..a8752671e63c 100644 --- a/clients/client-lex-runtime-service/test/LexRuntimeService.spec.ts +++ b/clients/client-lex-runtime-service/test/LexRuntimeService.spec.ts @@ -1,18 +1,12 @@ -import { HttpRequest } from "@smithy/protocol-http"; -import { SerializeMiddleware } from "@smithy/types"; -import { describe, expect, test as it } from "vitest"; +import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src"; +import { Readable } from "node:stream"; +import { describe, test as it } from "vitest"; import { LexRuntimeService } from "../src/LexRuntimeService"; describe("@aws-sdk/client-lex-runtime-service", () => { describe("PostContent", () => { it("should contain correct x-amz-content-sha256 header", async () => { - const validator: SerializeMiddleware = (next) => (args) => { - // middleware intercept the request and return it early - const request = args.request as HttpRequest; - expect(request.headers).to.have.property("x-amz-content-sha256", "UNSIGNED-PAYLOAD"); - return Promise.resolve({ output: {} as any, response: {} as any }); - }; const client = new LexRuntimeService({ region: "us-west-2", credentials: { @@ -20,17 +14,19 @@ describe("@aws-sdk/client-lex-runtime-service", () => { secretAccessKey: "CLIENT_TEST", }, }); - client.middlewareStack.add(validator, { - step: "serialize", - name: "endpointValidator", - priority: "low", + + requireRequestsFrom(client).toMatch({ + headers: { + "x-amz-content-sha256": "UNSIGNED-PAYLOAD", + }, }); + return await client.postContent({ botAlias: "alias", botName: "bot", userId: "user", contentType: "text/plain; charset=utf-8", - inputStream: "hello world!", + inputStream: Readable.from(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])), }); }); }); diff --git a/clients/client-mediastore-data/test/MediaStoreData.spec.ts b/clients/client-mediastore-data/test/MediaStoreData.spec.ts index 4e0bdd39bd45..0994185d8611 100644 --- a/clients/client-mediastore-data/test/MediaStoreData.spec.ts +++ b/clients/client-mediastore-data/test/MediaStoreData.spec.ts @@ -1,18 +1,12 @@ -import { HttpRequest } from "@smithy/protocol-http"; -import { SerializeMiddleware } from "@smithy/types"; -import { describe, expect, test as it } from "vitest"; +import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src"; +import { Readable } from "node:stream"; +import { describe, test as it } from "vitest"; import { MediaStoreData } from "../src/MediaStoreData"; describe("@aws-sdk/client-mediastore-data", () => { describe("PutObject", () => { it("should contain correct x-amz-content-sha256 header", async () => { - const validator: SerializeMiddleware = (next) => (args) => { - // middleware intercept the request and return it early - const request = args.request as HttpRequest; - expect(request.headers).to.have.property("x-amz-content-sha256", "UNSIGNED-PAYLOAD"); - return Promise.resolve({ output: {} as any, response: {} as any }); - }; const client = new MediaStoreData({ region: "us-west-2", credentials: { @@ -20,14 +14,16 @@ describe("@aws-sdk/client-mediastore-data", () => { secretAccessKey: "CLIENT_TEST", }, }); - client.middlewareStack.add(validator, { - step: "serialize", - name: "endpointValidator", - priority: "low", + + requireRequestsFrom(client).toMatch({ + headers: { + "x-amz-content-sha256": "UNSIGNED-PAYLOAD", + }, }); + return await client.putObject({ Path: "foo.avi", - Body: "binary body", + Body: Readable.from(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])), }); }); }); From 67f755f865d0a097547d93a84a5ffec41d47559a Mon Sep 17 00:00:00 2001 From: George Fu Date: Mon, 22 Sep 2025 18:57:28 +0000 Subject: [PATCH 2/2] test: fix select object content event stream test --- .../s3-selectObjectContent.integ.spec.ts | 63 +++++++++++++++---- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/clients/client-s3/test/integ/s3-selectObjectContent.integ.spec.ts b/clients/client-s3/test/integ/s3-selectObjectContent.integ.spec.ts index fd31f7bfa1c1..6d260ef00cb5 100644 --- a/clients/client-s3/test/integ/s3-selectObjectContent.integ.spec.ts +++ b/clients/client-s3/test/integ/s3-selectObjectContent.integ.spec.ts @@ -1,10 +1,8 @@ +import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src"; import { S3 } from "@aws-sdk/client-s3"; import { HttpResponse } from "@smithy/protocol-http"; -import { Readable } from "stream"; import { describe, expect, test as it } from "vitest"; -import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src"; - describe("selectObjectContent", () => { const credentials = { accessKeyId: "INTEG", @@ -34,16 +32,49 @@ describe("selectObjectContent", () => { .respondWith( new HttpResponse({ statusCode: 200, - body: Readable.from([ - ``, - ``, - `blob`, - `
10050100
`, - `
10050100
`, - ``, - ``, - `
`, - ]), + headers: { + "x-amz-checksum-crc32": "3117266289", + }, + body: { + *[Symbol.asyncIterator]() { + // see https://docs.aws.amazon.com/AmazonS3/latest/API/RESTSelectObjectAppendix.html + yield new Uint8Array([ + /* message size */ ...[0, 0, 0, 97], + /* header size */ ...[0, 0, 0, 81], + /* prelude crc */ ...[221, 28, 224, 246], + /* headers */ + /* :event-type */ + 11, + ...[58, 101, 118, 101, 110, 116, 45, 116, 121, 112, 101], + 7, + /* End */ + 0, + 3, + ...[69, 110, 100], + /* :content-type */ + 13, + ...[58, 99, 111, 110, 116, 101, 110, 116, 45, 116, 121, 112, 101], + 7, + /* application/octet-stream */ + 0, + 24, + ...[ + 97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 47, 111, 99, 116, 101, 116, 45, 115, 116, 114, + 101, 97, 109, + ], + /* :message-type */ + 13, + ...[58, 109, 101, 115, 115, 97, 103, 101, 45, 116, 121, 112, 101], + 7, + /* event */ + 0, + 5, + ...[101, 118, 101, 110, 116], + /* message crc */ + ...[75, 107, 103, 102], + ]); + }, + }, }) ); @@ -69,5 +100,11 @@ describe("selectObjectContent", () => { expect(response.$metadata.httpStatusCode).toBe(200); expect(response).toHaveProperty("Payload"); expect(response.Payload).toBeDefined(); + + const events = []; + for await (const event of response.Payload!) { + events.push(event); + } + expect(events).toEqual([{ End: {} }]); }); });