-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.test.js
54 lines (53 loc) · 2.69 KB
/
helpers.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
let helpers = require('./helpers');
const core = require('@actions/core');
describe('helper functions', () => {
describe('getVMLabel', () => {
afterEach(() => {
core.exportVariable('GITHUB_REPOSITORY', undefined)
core.exportVariable('GITHUB_RUN_NUMBER', undefined);
core.exportVariable('GITHUB_JOB', undefined);
core.exportVariable('GITHUB_ACTION', undefined);
});
test('default (no argument)', async() => {
core.exportVariable('GITHUB_REPOSITORY', 'veertuinc/anka-vm-github-action');
core.exportVariable('GITHUB_RUN_NUMBER', '102');
core.exportVariable('GITHUB_JOB', 'functional-tests');
core.exportVariable('GITHUB_ACTION', 'self2');
expect(await helpers.getVMLabel()).toBe('github-actions-veertuinc/anka-vm-github-action-102-functional-tests-self2')
expect(process.env["self2_vmLabel"]).toBe('github-actions-veertuinc/anka-vm-github-action-102-functional-tests-self2')
}); // TEST
test('custom', async() => {
core.exportVariable('GITHUB_REPOSITORY', 'veertuinc/anka-vm-github-action');
core.exportVariable('GITHUB_RUN_NUMBER', '102');
core.exportVariable('GITHUB_JOB', 'functional-tests');
core.exportVariable('GITHUB_ACTION', 'self3');
expect(await helpers.getVMLabel("build-vms")).toMatch(/build-vms-\d+/)
expect(process.env["self3_vmLabel"]).toMatch(/build-vms-\d+/)
}); // TEST
}); // DESCRIBE
describe('mergeOptions', () => {
test('no args', async() => {
expect(await helpers.mergeOptions()).toEqual({})
}); // TEST
test('hostCommandOptions: populated (string)', async() => {
expect(await helpers.mergeOptions("{ silent: true, cwd: \"/tmp\"}")).toEqual({silent: true, cwd: "/tmp"})
}); // TEST
test('hostCommandOptions: populated (single quotes ERROR)', async() => {
await expect(
helpers.mergeOptions("{ silent: true, cwd: '/tmp'}")
).rejects.toThrowError(/inside of a string/)
}); // TEST
test('hostCommandOptions (string), options (object)', async() => {
expect(await helpers.mergeOptions("{ cwd: \"/tmp\" }",{silent: true})).toEqual({silent: true, cwd: "/tmp"})
}); // TEST
test('hostCommandOptions (undefined), options (object)', async() => {
expect(await helpers.mergeOptions(undefined,{silent: true})).toEqual({silent: true})
}); // TEST
test('hostCommandOptions (object), options (object)', async() => {
expect(await helpers.mergeOptions({silent:false},{silent: true})).toEqual({silent: false})
}); // TEST
test('hostCommandOptions (object), options (undefined)', async() => {
expect(await helpers.mergeOptions({silent:false},undefined)).toEqual({silent: false})
}); // TEST
}); // DESCRIBE
});