|
| 1 | +import { DynamoDB } from "@aws-sdk/client-dynamodb"; |
| 2 | +import { S3 } from "@aws-sdk/client-s3"; |
| 3 | +import { afterAll, beforeEach, describe, test as it } from "vitest"; |
| 4 | + |
| 5 | +import { requireRequestsFrom } from "../../../private/aws-util-test/src"; |
| 6 | + |
| 7 | +/** |
| 8 | + * This is an AWS-specific integration test for a piece of functionality that is contained |
| 9 | + * within `@smithy/middleware-endpoint` (another repository). |
| 10 | + * |
| 11 | + * It augments unit tests in that package. |
| 12 | + */ |
| 13 | +describe("environment variable custom endpoint", () => { |
| 14 | + beforeEach(async () => { |
| 15 | + delete process.env.AWS_ENDPOINT_URL; |
| 16 | + delete process.env.AWS_ENDPOINT_URL_DYNAMODB; |
| 17 | + }); |
| 18 | + |
| 19 | + afterAll(async () => { |
| 20 | + delete process.env.AWS_ENDPOINT_URL; |
| 21 | + delete process.env.AWS_ENDPOINT_URL_DYNAMODB; |
| 22 | + }); |
| 23 | + |
| 24 | + it("should override a client endpoint if none is set on the client", async () => { |
| 25 | + process.env.AWS_ENDPOINT_URL = "https://localhost/1"; |
| 26 | + const s3 = new S3({ |
| 27 | + region: "us-west-2", |
| 28 | + }); |
| 29 | + const ddb = new DynamoDB({ |
| 30 | + region: "us-west-2", |
| 31 | + }); |
| 32 | + |
| 33 | + requireRequestsFrom(s3).toMatch({ |
| 34 | + hostname: /localhost/, |
| 35 | + path: /\/1/, |
| 36 | + }); |
| 37 | + requireRequestsFrom(ddb).toMatch({ |
| 38 | + hostname: /localhost/, |
| 39 | + path: /\/1/, |
| 40 | + }); |
| 41 | + |
| 42 | + await s3.listBuckets(); |
| 43 | + await ddb.listTables(); |
| 44 | + }); |
| 45 | + |
| 46 | + it("should defer to the client's manually set endpoint", async () => { |
| 47 | + process.env.AWS_ENDPOINT_URL = "https://localhost/1"; |
| 48 | + const s3 = new S3({ |
| 49 | + region: "us-west-2", |
| 50 | + endpoint: "https://localhost/2", |
| 51 | + }); |
| 52 | + const ddb = new DynamoDB({ |
| 53 | + region: "us-west-2", |
| 54 | + endpoint: "https://localhost/2", |
| 55 | + }); |
| 56 | + |
| 57 | + requireRequestsFrom(s3).toMatch({ |
| 58 | + hostname: /localhost/, |
| 59 | + path: /\/2/, |
| 60 | + }); |
| 61 | + requireRequestsFrom(ddb).toMatch({ |
| 62 | + hostname: /localhost/, |
| 63 | + path: /\/2/, |
| 64 | + }); |
| 65 | + |
| 66 | + await s3.listBuckets(); |
| 67 | + await ddb.listTables(); |
| 68 | + }); |
| 69 | + |
| 70 | + it("should allow a specific service id to be chosen in the env variable name", async () => { |
| 71 | + process.env.AWS_ENDPOINT_URL_DYNAMODB = "https://localhost/1"; |
| 72 | + const s3 = new S3({ |
| 73 | + region: "us-west-2", |
| 74 | + }); |
| 75 | + const ddb = new DynamoDB({ |
| 76 | + region: "us-west-2", |
| 77 | + }); |
| 78 | + |
| 79 | + requireRequestsFrom(s3).toMatch({ |
| 80 | + hostname: /s3\.us-west-2\.amazonaws\.com/, |
| 81 | + }); |
| 82 | + requireRequestsFrom(ddb).toMatch({ |
| 83 | + hostname: /localhost/, |
| 84 | + path: /\/1/, |
| 85 | + }); |
| 86 | + |
| 87 | + await s3.listBuckets(); |
| 88 | + await ddb.listTables(); |
| 89 | + }); |
| 90 | +}); |
0 commit comments