-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinput.test.js
62 lines (58 loc) · 2.46 KB
/
input.test.js
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
jest.mock('@actions/core');
core = require('@actions/core');
input = require('./input')
test('Input is all good', () => {
core.getInput = jest.fn()
core.getInput.mockReturnValueOnce('p-asdf')
core.getInput.mockReturnValueOnce('JWT')
core.getInput.mockReturnValueOnce('https://api.akeyless.io')
core.getInput.mockReturnValueOnce('/path/to/aws/producer')
core.getInput.mockReturnValueOnce('{"/some/static/secret":"secret_key"}')
core.getInput.mockReturnValueOnce('{"/some/dynamic/secret":"other_key"}')
core.getBooleanInput = jest.fn()
core.getBooleanInput.mockReturnValueOnce(true)
core.getBooleanInput.mockReturnValueOnce(true)
params = input.fetchAndValidateInput()
expect(params).toEqual({
'accessId': 'p-asdf',
'accessType': 'jwt',
'apiUrl': 'https://api.akeyless.io',
'producerForAwsAccess': '/path/to/aws/producer',
'staticSecrets': {'/some/static/secret': 'secret_key'},
'dynamicSecrets': {'/some/dynamic/secret': 'other_key'},
'exportSecretsToOutputs': true,
'exportSecretsToEnvironment': true,
})
expect(core.getInput.mock.calls).toEqual([
['access-id', {"required": true}],
['access-type'],
['api-url'],
['producer-for-aws-access'],
['static-secrets'],
['dynamic-secrets'],
]);
expect(core.getBooleanInput.mock.calls).toEqual([
['export-secrets-to-outputs'],
['export-secrets-to-environment'],
]);
});
test('check string', () => {
core.getInput = jest.fn();
core.getInput.mockReturnValueOnce('p-asdf');
core.getInput.mockReturnValueOnce(343);
core.getInput.mockReturnValue('sup');
expect(() => {input.fetchAndValidateInput()}).toThrow("Input 'access-type' should be a string");
})
test('invalid access type', () => {
core.getInput = jest.fn();
core.getInput.mockReturnValueOnce('p-asdf');
core.getInput.mockReturnValueOnce('asdf');
core.getInput.mockReturnValueOnce('https://api.akeyless.io');
core.getInput.mockReturnValueOnce('/path/to/aws/producer');
core.getInput.mockReturnValueOnce('{"/some/static/secret":"secret_key"}');
core.getInput.mockReturnValueOnce('{"/some/dynamic/secret":"other_key"}');
core.getBooleanInput = jest.fn();
core.getBooleanInput.mockReturnValueOnce(true);
core.getBooleanInput.mockReturnValueOnce(true);
expect(() => {input.fetchAndValidateInput()}).toThrow("access-type must be one of: ['jwt', 'aws_iam']");
})