|
| 1 | +import { |
| 2 | + CONFIG_USE_FIPS_ENDPOINT, |
| 3 | + DEFAULT_USE_FIPS_ENDPOINT, |
| 4 | + ENV_USE_FIPS_ENDPOINT, |
| 5 | + NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS, |
| 6 | +} from "./NodeUseFipsEndpointConfigOptions"; |
| 7 | + |
| 8 | +describe("NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS", () => { |
| 9 | + const test = (selector, obj, key) => { |
| 10 | + beforeEach(() => { |
| 11 | + delete obj[key]; |
| 12 | + }); |
| 13 | + |
| 14 | + it(`should return undefined if ${key} is not defined`, () => { |
| 15 | + expect(selector(obj)).toBeUndefined(); |
| 16 | + }); |
| 17 | + |
| 18 | + it.each([ |
| 19 | + [true, "true"], |
| 20 | + [false, "false"], |
| 21 | + ])(`should return boolean %s if ${key}="%s"`, (output, input) => { |
| 22 | + obj[key] = input; |
| 23 | + expect(selector(obj)).toBe(output); |
| 24 | + }); |
| 25 | + |
| 26 | + it.each(["0", "1", "yes", "no", undefined, null, void 0, ""])(`should throw if ${key}=%s`, (input) => { |
| 27 | + obj[key] = input; |
| 28 | + expect(() => selector(obj)).toThrow(); |
| 29 | + }); |
| 30 | + }; |
| 31 | + |
| 32 | + describe("environment variable selector", () => { |
| 33 | + const env: { [ENV_USE_FIPS_ENDPOINT]: any } = {} as any; |
| 34 | + const { environmentVariableSelector } = NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS; |
| 35 | + test(environmentVariableSelector, env, ENV_USE_FIPS_ENDPOINT); |
| 36 | + }); |
| 37 | + |
| 38 | + describe("config file selector", () => { |
| 39 | + const profileContent: { [CONFIG_USE_FIPS_ENDPOINT]: any } = {} as any; |
| 40 | + const { configFileSelector } = NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS; |
| 41 | + test(configFileSelector, profileContent, CONFIG_USE_FIPS_ENDPOINT); |
| 42 | + }); |
| 43 | + |
| 44 | + it(`returns ${DEFAULT_USE_FIPS_ENDPOINT} by default`, () => { |
| 45 | + const { default: defaultValue } = NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS; |
| 46 | + expect(defaultValue).toEqual(DEFAULT_USE_FIPS_ENDPOINT); |
| 47 | + }); |
| 48 | +}); |
0 commit comments