Skip to content

Commit

Permalink
test(middleware-user-agent): more precise assertions (#6637)
Browse files Browse the repository at this point in the history
* test(middleware-user-agent): more precise assertions

* test(credential-provider-node): suppress console in test

* test: fix parens placement
  • Loading branch information
kuhe authored Nov 7, 2024
1 parent ea3482f commit 9f7c19d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
8 changes: 4 additions & 4 deletions clients/client-s3/test/e2e/S3.browser.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { S3, SelectObjectContentEventStream } from "@aws-sdk/client-s3";
import type { S3, SelectObjectContentEventStream, waitUntilObjectExists } from "@aws-sdk/client-s3";
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
import { FetchHttpHandler } from "@smithy/fetch-http-handler";
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, onTestFailed, test as it } from "vitest";

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

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

//validate the object is uploaded
const waiterState = await waitUntilObjectExists(
// validate the object is uploaded
const waiterState = await (waitUntilObjectExistsImpl as typeof waitUntilObjectExists)(
{
client,
maxWaitTime: 60,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,17 @@ describe("credential-provider-node integration test", () => {
aws_secret_access_key: "INI_STATIC_SECRET_KEY",
});

sts = new STS({
region: "us-west-2",
logger: {
trace() {},
debug() {},
info() {},
warn() {},
error() {},
},
});

await sts.getCallerIdentity({});
const credentials = await sts.config.credentials();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { S3 } from "@aws-sdk/client-s3";
import { AwsCredentialIdentity } from "@aws-sdk/types";
import { describe, expect, expect, test as it } from "vitest";
import { AwsCredentialIdentity, AwsSdkFeatures } from "@aws-sdk/types";
import { describe, expect, test as it } from "vitest";

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

requireRequestsFrom(client).toMatch({
headers: {
"user-agent": /(.*?) m\/(.*?)J(.*?)$/,
["user-agent"](ua) {
const metadata = ua.match(/(.*?) m\/(.*?)$/)[2];
expect(metadata).toContain("J" as AwsSdkFeatures["S3_EXPRESS_BUCKET"]);
},
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { CodeCatalyst } from "@aws-sdk/client-codecatalyst";
import { DynamoDB } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocument } from "@aws-sdk/lib-dynamodb";
import { describe, test as it } from "vitest";
import { AwsSdkFeatures } from "@aws-sdk/types";
import { describe, expect, test as it } from "vitest";

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

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

requireRequestsFrom(doc).toMatch({
headers: {
"user-agent": /(.*?) m\/d,E,O,R$/,
["user-agent"](ua) {
const metadata = ua.match(/(.*?) m\/(.*?)$/)[2];
expect(metadata).toContain("d" as AwsSdkFeatures["DDB_MAPPER"]);
expect(metadata).toContain("E" as AwsSdkFeatures["RETRY_MODE_STANDARD"]);
expect(metadata).toContain("O" as AwsSdkFeatures["ACCOUNT_ID_ENDPOINT"]);
expect(metadata).toContain("R" as AwsSdkFeatures["ACCOUNT_ID_MODE_REQUIRED"]);
},
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test as it, describe, expect } from "vitest";
import { describe, expect, test as it } from "vitest";

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

0 comments on commit 9f7c19d

Please sign in to comment.