-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloader.test.ts
69 lines (62 loc) · 1.68 KB
/
loader.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { load } from './loader';
import { ConfigBlock } from "./contracts";
import { ProvidedConfigValue } from "./providers/providedConfigValue";
import { safeExpect } from '@paradoxical-io/common-test';
function schemaShape(): ConfigBlock<ProvidedConfig> {
return {
host: {
auth: {
allowAssume: {
doc: "Whether to use assumed auth. The assumed auth username will come in as the value using scheme 'assume'",
format: Boolean,
default: true,
env: 'HOST_AUTH_ALLOW_ASSUME',
},
},
},
dynamic: {
providerType: {
doc: 'How to load the value',
default: 'ParameterStore',
format: ['ParameterStore', 'Static'],
},
value: {
doc: 'The ssm path',
format: String,
default: '/path/to/ssm'
}
}
};
}
interface ProvidedConfig {
host: {
auth: {
allowAssume: boolean;
};
};
dynamic: ProvidedConfigValue
}
/**
* The actual resolved config
*/
// @ts-ignore
interface Config {
host: {
auth: {
allowAssume: boolean;
};
};
dynamic: string
}
test('loads from an object', async () => {
const config = load<ProvidedConfig>({}, 'local', schemaShape);
safeExpect(config).not.toBeNull();
safeExpect(config.host.auth.allowAssume).toEqual(true);
safeExpect(config.dynamic.providerType).toEqual('ParameterStore');
safeExpect(config.dynamic.value).toEqual('/path/to/ssm');
});
test('loads from an with defaults', async () => {
const config = load<ProvidedConfig>({ host: { auth: { allowAssume: false } } }, 'local', schemaShape);
safeExpect(config).not.toBeNull();
safeExpect(config.host.auth.allowAssume).toEqual(false);
});