Skip to content

Commit f7eb085

Browse files
authored
test(clients): update payload types in client tests (#7373)
* test: fix lex runtime and mediastore payload tests * test: fix select object content event stream test
1 parent 281c666 commit f7eb085

File tree

3 files changed

+70
-41
lines changed

3 files changed

+70
-41
lines changed

clients/client-lex-runtime-service/test/LexRuntimeService.spec.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,32 @@
1-
import { HttpRequest } from "@smithy/protocol-http";
2-
import { SerializeMiddleware } from "@smithy/types";
3-
import { describe, expect, test as it } from "vitest";
1+
import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src";
2+
import { Readable } from "node:stream";
3+
import { describe, test as it } from "vitest";
44

55
import { LexRuntimeService } from "../src/LexRuntimeService";
66

77
describe("@aws-sdk/client-lex-runtime-service", () => {
88
describe("PostContent", () => {
99
it("should contain correct x-amz-content-sha256 header", async () => {
10-
const validator: SerializeMiddleware<any, any> = (next) => (args) => {
11-
// middleware intercept the request and return it early
12-
const request = args.request as HttpRequest;
13-
expect(request.headers).to.have.property("x-amz-content-sha256", "UNSIGNED-PAYLOAD");
14-
return Promise.resolve({ output: {} as any, response: {} as any });
15-
};
1610
const client = new LexRuntimeService({
1711
region: "us-west-2",
1812
credentials: {
1913
accessKeyId: "CLIENT_TEST",
2014
secretAccessKey: "CLIENT_TEST",
2115
},
2216
});
23-
client.middlewareStack.add(validator, {
24-
step: "serialize",
25-
name: "endpointValidator",
26-
priority: "low",
17+
18+
requireRequestsFrom(client).toMatch({
19+
headers: {
20+
"x-amz-content-sha256": "UNSIGNED-PAYLOAD",
21+
},
2722
});
23+
2824
return await client.postContent({
2925
botAlias: "alias",
3026
botName: "bot",
3127
userId: "user",
3228
contentType: "text/plain; charset=utf-8",
33-
inputStream: "hello world!",
29+
inputStream: Readable.from(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])),
3430
});
3531
});
3632
});

clients/client-mediastore-data/test/MediaStoreData.spec.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,29 @@
1-
import { HttpRequest } from "@smithy/protocol-http";
2-
import { SerializeMiddleware } from "@smithy/types";
3-
import { describe, expect, test as it } from "vitest";
1+
import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src";
2+
import { Readable } from "node:stream";
3+
import { describe, test as it } from "vitest";
44

55
import { MediaStoreData } from "../src/MediaStoreData";
66

77
describe("@aws-sdk/client-mediastore-data", () => {
88
describe("PutObject", () => {
99
it("should contain correct x-amz-content-sha256 header", async () => {
10-
const validator: SerializeMiddleware<any, any> = (next) => (args) => {
11-
// middleware intercept the request and return it early
12-
const request = args.request as HttpRequest;
13-
expect(request.headers).to.have.property("x-amz-content-sha256", "UNSIGNED-PAYLOAD");
14-
return Promise.resolve({ output: {} as any, response: {} as any });
15-
};
1610
const client = new MediaStoreData({
1711
region: "us-west-2",
1812
credentials: {
1913
accessKeyId: "CLIENT_TEST",
2014
secretAccessKey: "CLIENT_TEST",
2115
},
2216
});
23-
client.middlewareStack.add(validator, {
24-
step: "serialize",
25-
name: "endpointValidator",
26-
priority: "low",
17+
18+
requireRequestsFrom(client).toMatch({
19+
headers: {
20+
"x-amz-content-sha256": "UNSIGNED-PAYLOAD",
21+
},
2722
});
23+
2824
return await client.putObject({
2925
Path: "foo.avi",
30-
Body: "binary body",
26+
Body: Readable.from(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])),
3127
});
3228
});
3329
});

clients/client-s3/test/integ/s3-selectObjectContent.integ.spec.ts

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1+
import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src";
12
import { S3 } from "@aws-sdk/client-s3";
23
import { HttpResponse } from "@smithy/protocol-http";
3-
import { Readable } from "stream";
44
import { describe, expect, test as it } from "vitest";
55

6-
import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src";
7-
86
describe("selectObjectContent", () => {
97
const credentials = {
108
accessKeyId: "INTEG",
@@ -34,16 +32,49 @@ describe("selectObjectContent", () => {
3432
.respondWith(
3533
new HttpResponse({
3634
statusCode: 200,
37-
body: Readable.from([
38-
`<?xml version="1.0" encoding="UTF-8"?>`,
39-
`<Payload>`,
40-
`<Records><Payload>blob</Payload></Records>`,
41-
`<Stats><Details><BytesProcessed>100</BytesProcessed><BytesReturned>50</BytesReturned><BytesScanned>100</BytesScanned></Details></Stats>`,
42-
`<Progress><Details><BytesProcessed>100</BytesProcessed><BytesReturned>50</BytesReturned><BytesScanned>100</BytesScanned></Details></Progress>`,
43-
`<Cont></Cont>`,
44-
`<End></End>`,
45-
`</Payload>`,
46-
]),
35+
headers: {
36+
"x-amz-checksum-crc32": "3117266289",
37+
},
38+
body: {
39+
*[Symbol.asyncIterator]() {
40+
// see https://docs.aws.amazon.com/AmazonS3/latest/API/RESTSelectObjectAppendix.html
41+
yield new Uint8Array([
42+
/* message size */ ...[0, 0, 0, 97],
43+
/* header size */ ...[0, 0, 0, 81],
44+
/* prelude crc */ ...[221, 28, 224, 246],
45+
/* headers */
46+
/* :event-type */
47+
11,
48+
...[58, 101, 118, 101, 110, 116, 45, 116, 121, 112, 101],
49+
7,
50+
/* End */
51+
0,
52+
3,
53+
...[69, 110, 100],
54+
/* :content-type */
55+
13,
56+
...[58, 99, 111, 110, 116, 101, 110, 116, 45, 116, 121, 112, 101],
57+
7,
58+
/* application/octet-stream */
59+
0,
60+
24,
61+
...[
62+
97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 47, 111, 99, 116, 101, 116, 45, 115, 116, 114,
63+
101, 97, 109,
64+
],
65+
/* :message-type */
66+
13,
67+
...[58, 109, 101, 115, 115, 97, 103, 101, 45, 116, 121, 112, 101],
68+
7,
69+
/* event */
70+
0,
71+
5,
72+
...[101, 118, 101, 110, 116],
73+
/* message crc */
74+
...[75, 107, 103, 102],
75+
]);
76+
},
77+
},
4778
})
4879
);
4980

@@ -69,5 +100,11 @@ describe("selectObjectContent", () => {
69100
expect(response.$metadata.httpStatusCode).toBe(200);
70101
expect(response).toHaveProperty("Payload");
71102
expect(response.Payload).toBeDefined();
103+
104+
const events = [];
105+
for await (const event of response.Payload!) {
106+
events.push(event);
107+
}
108+
expect(events).toEqual([{ End: {} }]);
72109
});
73110
});

0 commit comments

Comments
 (0)