Skip to content

Commit 9f7c19d

Browse files
authored
test(middleware-user-agent): more precise assertions (#6637)
* test(middleware-user-agent): more precise assertions * test(credential-provider-node): suppress console in test * test: fix parens placement
1 parent ea3482f commit 9f7c19d

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

clients/client-s3/test/e2e/S3.browser.e2e.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import type { S3, SelectObjectContentEventStream } from "@aws-sdk/client-s3";
1+
import type { S3, SelectObjectContentEventStream, waitUntilObjectExists } from "@aws-sdk/client-s3";
22
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
33
import { FetchHttpHandler } from "@smithy/fetch-http-handler";
44
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, onTestFailed, test as it } from "vitest";
55

66
import { getIntegTestResources } from "../../../../tests/e2e/get-integ-test-resources";
77
import { getRuntimeConfig } from "../../src/runtimeConfig.browser";
8-
import { S3 as S3Impl, waitUntilObjectExists } from "../browser-build/browser-s3-bundle";
8+
import { S3 as S3Impl, waitUntilObjectExists as waitUntilObjectExistsImpl } from "../browser-build/browser-s3-bundle";
99
import { createBuffer } from "./helpers";
1010

1111
describe("@aws-sdk/client-s3", () => {
@@ -242,8 +242,8 @@ describe("@aws-sdk/client-s3", () => {
242242
});
243243
expect(completeResult.$metadata.httpStatusCode).toEqual(200);
244244

245-
//validate the object is uploaded
246-
const waiterState = await waitUntilObjectExists(
245+
// validate the object is uploaded
246+
const waiterState = await (waitUntilObjectExistsImpl as typeof waitUntilObjectExists)(
247247
{
248248
client,
249249
maxWaitTime: 60,

packages/credential-provider-node/src/credential-provider-node.integ.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,17 @@ describe("credential-provider-node integration test", () => {
293293
aws_secret_access_key: "INI_STATIC_SECRET_KEY",
294294
});
295295

296+
sts = new STS({
297+
region: "us-west-2",
298+
logger: {
299+
trace() {},
300+
debug() {},
301+
info() {},
302+
warn() {},
303+
error() {},
304+
},
305+
});
306+
296307
await sts.getCallerIdentity({});
297308
const credentials = await sts.config.credentials();
298309

packages/middleware-sdk-s3/src/s3-express/middleware-s3-express.integ.spec.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { S3 } from "@aws-sdk/client-s3";
2-
import { AwsCredentialIdentity } from "@aws-sdk/types";
3-
import { describe, expect, expect, test as it } from "vitest";
2+
import { AwsCredentialIdentity, AwsSdkFeatures } from "@aws-sdk/types";
3+
import { describe, expect, test as it } from "vitest";
44

55
import { requireRequestsFrom } from "../../../../private/aws-util-test/src";
66
import { S3ExpressIdentity, S3ExpressIdentityProvider } from "./index";
@@ -94,7 +94,10 @@ describe("middleware-s3-express", () => {
9494

9595
requireRequestsFrom(client).toMatch({
9696
headers: {
97-
"user-agent": /(.*?) m\/(.*?)J(.*?)$/,
97+
["user-agent"](ua) {
98+
const metadata = ua.match(/(.*?) m\/(.*?)$/)[2];
99+
expect(metadata).toContain("J" as AwsSdkFeatures["S3_EXPRESS_BUCKET"]);
100+
},
98101
},
99102
});
100103

packages/middleware-user-agent/src/middleware-user-agent.integ.spec.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { CodeCatalyst } from "@aws-sdk/client-codecatalyst";
22
import { DynamoDB } from "@aws-sdk/client-dynamodb";
33
import { DynamoDBDocument } from "@aws-sdk/lib-dynamodb";
4-
import { describe, test as it } from "vitest";
4+
import { AwsSdkFeatures } from "@aws-sdk/types";
5+
import { describe, expect, test as it } from "vitest";
56

67
import { requireRequestsFrom } from "../../../private/aws-util-test/src";
78

@@ -38,7 +39,13 @@ describe("middleware-user-agent", () => {
3839

3940
requireRequestsFrom(doc).toMatch({
4041
headers: {
41-
"user-agent": /(.*?) m\/d,E,O,R$/,
42+
["user-agent"](ua) {
43+
const metadata = ua.match(/(.*?) m\/(.*?)$/)[2];
44+
expect(metadata).toContain("d" as AwsSdkFeatures["DDB_MAPPER"]);
45+
expect(metadata).toContain("E" as AwsSdkFeatures["RETRY_MODE_STANDARD"]);
46+
expect(metadata).toContain("O" as AwsSdkFeatures["ACCOUNT_ID_ENDPOINT"]);
47+
expect(metadata).toContain("R" as AwsSdkFeatures["ACCOUNT_ID_MODE_REQUIRED"]);
48+
},
4249
},
4350
});
4451

private/aws-util-test/src/requests/test-http-handler.integ.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { test as it, describe, expect } from "vitest";
1+
import { describe, expect, test as it } from "vitest";
22

33
// import { JsonProtocol } from "@aws-sdk/aws-protocoltests-json";
44
// CI has difficult importing a named private client from the workspace.

0 commit comments

Comments
 (0)