Skip to content

Commit 94ead33

Browse files
committed
test(core): config file and defaults mode integ tests
1 parent 172a3b7 commit 94ead33

8 files changed

+156
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { afterAll, beforeEach, describe, expect, test as it } from "vitest";
2+
import { S3 } from "@aws-sdk/client-s3";
3+
import path from "node:path";
4+
import type { Provider } from "@smithy/types";
5+
6+
describe("defaults mode", () => {
7+
const snapshot = {
8+
...process.env,
9+
};
10+
11+
beforeEach(async () => {
12+
process.env = {};
13+
});
14+
15+
afterAll(async () => {
16+
process.env = snapshot;
17+
});
18+
19+
it("should load various client configuration options from file with default profile", async () => {
20+
process.env.AWS_CONFIG_FILE = path.join(__dirname, "mock-aws-config");
21+
22+
const client = new S3({});
23+
24+
expect(await client.config.region()).toEqual("us-west-2");
25+
});
26+
27+
it("should load various client configuration options from specific profile", async () => {
28+
process.env.AWS_CONFIG_FILE = path.join(__dirname, "mock-aws-config");
29+
30+
const client = new S3({
31+
profile: "abc",
32+
});
33+
34+
expect(await client.config.region()).toEqual("ap-northeast-1");
35+
expect(await (client.config.retryMode as Provider<string>)()).toEqual("adaptive");
36+
expect(await (client.config.disableS3ExpressSessionAuth as Provider<boolean>)()).toEqual(true);
37+
expect(await client.config.maxAttempts()).toEqual(33);
38+
expect(await client.config.requestChecksumCalculation()).toEqual("WHEN_REQUIRED");
39+
expect(await client.config.sigv4aSigningRegionSet()).toEqual(["*", "*", "us-west-2"]);
40+
expect(await client.config.useFipsEndpoint()).toEqual(true);
41+
expect(await (client.config.useArnRegion as Provider<boolean>)()).toEqual(true);
42+
expect(await client.config.useDualstackEndpoint()).toEqual(true);
43+
expect(await client.config.userAgentAppId()).toEqual("blargh");
44+
});
45+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[profile empty]
2+
3+
[default]
4+
region = us-west-2
5+
output = json
6+
7+
[profile abc]
8+
region = ap-northeast-1
9+
retry_mode = adaptive
10+
s3_disable_express_session_auth = true
11+
max_attempts = 33
12+
request_checksum_calculation = when_required
13+
sigv4a_signing_region_set = *,*,us-west-2
14+
use_fips_endpoint = true
15+
s3_use_arn_region = true
16+
use_dualstack_endpoint = true
17+
sdk-ua-app-id = blargh
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { describe, test as it, expect, beforeEach, afterAll } from "vitest";
2+
3+
import { CloudWatch } from "@aws-sdk/client-cloudwatch";
4+
import type { DefaultsMode } from "@smithy/smithy-client";
5+
import type { NodeHttpHandlerOptions, Provider } from "@smithy/types";
6+
import type { Agent as hAgent } from "http";
7+
import type { Agent as hsAgent } from "https";
8+
9+
describe("defaults mode", () => {
10+
const snapshot = {
11+
AWS_EXECUTION_ENV: process.env.AWS_EXECUTION_ENV,
12+
AWS_REGION: process.env.AWS_REGION,
13+
AWS_DEFAULT_REGION: process.env.AWS_DEFAULT_REGION,
14+
AWS_DEFAULTS_MODE: process.env.AWS_DEFAULTS_MODE,
15+
};
16+
17+
beforeEach(async () => {
18+
delete process.env.AWS_EXECUTION_ENV;
19+
delete process.env.AWS_REGION;
20+
delete process.env.AWS_DEFAULT_REGION;
21+
delete process.env.AWS_DEFAULTS_MODE;
22+
});
23+
24+
afterAll(async () => {
25+
Object.assign(process.env, snapshot);
26+
});
27+
28+
const sharedConfig = {
29+
credentials: {
30+
accessKeyId: "INTEG",
31+
secretAccessKey: "INTEG",
32+
},
33+
region: "ap-northeast-1",
34+
};
35+
36+
async function assertCrossRegion(client: CloudWatch) {
37+
expect(await (client.config.defaultsMode as Provider<DefaultsMode>)()).toEqual("cross-region");
38+
const handler = client.config.requestHandler;
39+
40+
type ResolvedNodeHttpHandlerConfig = Omit<NodeHttpHandlerOptions, "httpAgent" | "httpsAgent"> & {
41+
httpAgent: hAgent;
42+
httpsAgent: hsAgent;
43+
};
44+
45+
const config = await (
46+
handler as unknown as {
47+
configProvider: Promise<ResolvedNodeHttpHandlerConfig>;
48+
}
49+
).configProvider;
50+
51+
expect(config).toMatchObject({
52+
connectionTimeout: 3100,
53+
});
54+
}
55+
56+
it("should set a higher timeout due to cross-region defaults mode when auto-detected (ENV)", async () => {
57+
process.env.AWS_DEFAULTS_MODE = "auto";
58+
process.env.AWS_EXECUTION_ENV = "INTEGRATION_TEST";
59+
process.env.AWS_DEFAULT_REGION = "us-east-1";
60+
61+
const client = new CloudWatch(sharedConfig);
62+
63+
await assertCrossRegion(client);
64+
});
65+
66+
it("should set a higher timeout due to cross-region defaults mode when auto-detected (client-config)", async () => {
67+
process.env.AWS_EXECUTION_ENV = "INTEGRATION_TEST";
68+
process.env.AWS_DEFAULT_REGION = "us-east-1";
69+
70+
const client = new CloudWatch({
71+
...sharedConfig,
72+
defaultsMode: "auto",
73+
});
74+
75+
await assertCrossRegion(client);
76+
});
77+
78+
it("should set a higher timeout when cross region defaults-mode is set (ENV)", async () => {
79+
process.env.AWS_DEFAULTS_MODE = "cross-region";
80+
81+
const client = new CloudWatch(sharedConfig);
82+
83+
await assertCrossRegion(client);
84+
});
85+
86+
it("should set a higher timeout when cross region defaults-mode is set (client-config)", async () => {
87+
const client = new CloudWatch({
88+
...sharedConfig,
89+
defaultsMode: "cross-region",
90+
});
91+
92+
await assertCrossRegion(client);
93+
});
94+
});

0 commit comments

Comments
 (0)