Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions packages/util-endpoints/src/env-endpoint.integ.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { DynamoDB } from "@aws-sdk/client-dynamodb";
import { S3 } from "@aws-sdk/client-s3";
import { afterAll, beforeEach, describe, test as it } from "vitest";

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

/**
* This is an AWS-specific integration test for a piece of functionality that is contained
* within `@smithy/middleware-endpoint` (another repository).
*
* It augments unit tests in that package.
*/
describe("environment variable custom endpoint", () => {
beforeEach(async () => {
delete process.env.AWS_ENDPOINT_URL;
delete process.env.AWS_ENDPOINT_URL_DYNAMODB;
});

afterAll(async () => {
delete process.env.AWS_ENDPOINT_URL;
delete process.env.AWS_ENDPOINT_URL_DYNAMODB;
});

it("should override a client endpoint if none is set on the client", async () => {
process.env.AWS_ENDPOINT_URL = "https://localhost/1";
const s3 = new S3({
region: "us-west-2",
});
const ddb = new DynamoDB({
region: "us-west-2",
});

requireRequestsFrom(s3).toMatch({
hostname: /localhost/,
path: /\/1/,
});
requireRequestsFrom(ddb).toMatch({
hostname: /localhost/,
path: /\/1/,
});

await s3.listBuckets();
await ddb.listTables();
});

it("should defer to the client's manually set endpoint", async () => {
process.env.AWS_ENDPOINT_URL = "https://localhost/1";
const s3 = new S3({
region: "us-west-2",
endpoint: "https://localhost/2",
});
const ddb = new DynamoDB({
region: "us-west-2",
endpoint: "https://localhost/2",
});

requireRequestsFrom(s3).toMatch({
hostname: /localhost/,
path: /\/2/,
});
requireRequestsFrom(ddb).toMatch({
hostname: /localhost/,
path: /\/2/,
});

await s3.listBuckets();
await ddb.listTables();
});

it("should allow a specific service id to be chosen in the env variable name", async () => {
process.env.AWS_ENDPOINT_URL_DYNAMODB = "https://localhost/1";
const s3 = new S3({
region: "us-west-2",
});
const ddb = new DynamoDB({
region: "us-west-2",
});

requireRequestsFrom(s3).toMatch({
hostname: /s3\.us-west-2\.amazonaws\.com/,
});
requireRequestsFrom(ddb).toMatch({
hostname: /localhost/,
path: /\/1/,
});

await s3.listBuckets();
await ddb.listTables();
});
});
Loading