|
| 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 | +}); |
0 commit comments