forked from Firenza/secrets-to-env
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.test.js
83 lines (69 loc) · 2.12 KB
/
main.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const index = require('./main');
const core = require('@actions/core');
jest.mock("@actions/core");
test('lower case regex works', () => {
// Arrange
var secretsObj = new Object();
secretsObj.TEST_VAR = "Hello";
secretsObj.TEST_VAR2 = "Hello2";
core.getInput.mockImplementation((key) => {
if (key === "secrets"){
return JSON.stringify(secretsObj)
}
else if (key === "secret_filter_regex"){
return undefined;
}
else if (key === "env_var_name_lower_case_regex"){
return "(?<=TEST_).*";
}
})
// Act
index();
// Assert
expect(core.exportVariable).toHaveBeenCalledWith("TEST_var", "Hello");
expect(core.exportVariable).toHaveBeenCalledWith("TEST_var2", "Hello2");
});
test('secret filter works', () => {
// Arrange
var secretsObj = new Object();
secretsObj.TEST_VAR = "Hello";
secretsObj.IM_BOB = "BOB";
core.getInput.mockImplementation((key) => {
if (key === "secrets"){
return JSON.stringify(secretsObj)
}
else if (key === "secret_filter_regex"){
return "TEST_.*";
}
else if (key === "env_var_name_lower_case_regex"){
return undefined;
}
})
// Act
index();
// Assert
expect(core.exportVariable).toHaveBeenCalledWith("TEST_VAR", "Hello");
expect(core.exportVariable).not.toHaveBeenCalledWith("IM_BOB", "BOB");
});
test('all secrets processed with no filter', () => {
// Arrange
var secretsObj = new Object();
secretsObj.TEST_VAR = "Hello";
secretsObj.IM_BOB = "BOB";
core.getInput.mockImplementation((key) => {
if (key === "secrets"){
return JSON.stringify(secretsObj)
}
else if (key === "secret_filter_regex"){
return undefined;
}
else if (key === "env_var_name_lower_case_regex"){
return undefined;
}
})
// Act
index();
// Assert
expect(core.exportVariable).toHaveBeenCalledWith("TEST_VAR", "Hello");
expect(core.exportVariable).toHaveBeenCalledWith("IM_BOB", "BOB");
});