Skip to content

Commit 7cc425d

Browse files
committed
chore(config-resolver): add NodeUseDualstackEndpointConfigOptions
1 parent 5f345dd commit 7cc425d

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { booleanSelector, SelectorType } from "@aws-sdk/node-config-provider";
2+
3+
import {
4+
CONFIG_USE_DUALSTACK_ENDPOINT,
5+
DEFAULT_USE_DUALSTACK_ENDPOINT,
6+
ENV_USE_DUALSTACK_ENDPOINT,
7+
NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS,
8+
} from "./NodeUseDualstackEndpointConfigOptions";
9+
10+
jest.mock("@aws-sdk/node-config-provider");
11+
12+
describe("NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS", () => {
13+
afterEach(() => {
14+
jest.clearAllMocks();
15+
});
16+
17+
const test = (func: Function, obj: { [key: string]: string }, key: string, type: SelectorType) => {
18+
it.each([true, false, undefined])("returns %s", (output) => {
19+
(booleanSelector as jest.Mock).mockReturnValueOnce(output);
20+
expect(func(obj)).toEqual(output);
21+
expect(booleanSelector).toBeCalledWith(obj, key, type);
22+
});
23+
24+
it("throws error", () => {
25+
const mockError = new Error("error");
26+
(booleanSelector as jest.Mock).mockImplementationOnce(() => {
27+
throw mockError;
28+
});
29+
expect(() => {
30+
func(obj);
31+
}).toThrow(mockError);
32+
});
33+
};
34+
35+
describe("calls booleanSelector for environmentVariableSelector", () => {
36+
const env: { [ENV_USE_DUALSTACK_ENDPOINT]: any } = {} as any;
37+
const { environmentVariableSelector } = NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS;
38+
test(environmentVariableSelector, env, ENV_USE_DUALSTACK_ENDPOINT, SelectorType.ENV);
39+
});
40+
41+
describe("calls booleanSelector for configFileSelector", () => {
42+
const profileContent: { [CONFIG_USE_DUALSTACK_ENDPOINT]: any } = {} as any;
43+
const { configFileSelector } = NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS;
44+
test(configFileSelector, profileContent, CONFIG_USE_DUALSTACK_ENDPOINT, SelectorType.CONFIG);
45+
});
46+
47+
it("returns false for default", () => {
48+
const { default: defaultValue } = NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS;
49+
expect(defaultValue).toEqual(DEFAULT_USE_DUALSTACK_ENDPOINT);
50+
});
51+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { LoadedConfigSelectors } from "@aws-sdk/node-config-provider";
2+
import { booleanSelector, SelectorType } from "@aws-sdk/node-config-provider";
3+
4+
export const ENV_USE_DUALSTACK_ENDPOINT = "AWS_USE_DUALSTACK_ENDPOINT";
5+
export const CONFIG_USE_DUALSTACK_ENDPOINT = "use_dualstack_endpoint";
6+
export const DEFAULT_USE_DUALSTACK_ENDPOINT = false;
7+
8+
export const NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS: LoadedConfigSelectors<boolean> = {
9+
environmentVariableSelector: (env: NodeJS.ProcessEnv) =>
10+
booleanSelector(env, ENV_USE_DUALSTACK_ENDPOINT, SelectorType.ENV),
11+
configFileSelector: (profile) => booleanSelector(profile, CONFIG_USE_DUALSTACK_ENDPOINT, SelectorType.CONFIG),
12+
default: false,
13+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from "./NodeUseDualstackEndpointConfigOptions";
12
export * from "./NodeUseFipsEndpointConfigOptions";
23
export * from "./config";
34
export * from "./resolveRegionConfig";

0 commit comments

Comments
 (0)