-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexecute.test.js
99 lines (96 loc) · 3.61 KB
/
execute.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
let execute = require('./execute');
let fs = require('fs');
describe('execute functions', () => {
let options = "{ silent: false }"
describe('hostCommands', () => {
test('basic', async() => {
await execute.hostCommands("echo 123",options)
await expect(`${execute.STD.trim()}`).toBe("123");
});
test('fail with bad command option', async() => {
await expect(
execute.hostCommands("java --versio",options)
).rejects.toThrowError(/failed with exit code 1/)
});
test('fail with single quotes', async() => {
await expect(
execute.hostCommands("echo 123","{ cwd: './' }")
).rejects.toThrowError(/inside of a string/)
});
test('basic multi', async() => {
await execute.hostCommands("echo 456",options)
await execute.hostCommands("echo 789",options,execute.STD)
await expect(`${execute.STD.trim()}`).toBe("456\n789");
});
test('basic newlines', async() => {
await execute.hostCommands(`
touch /tmp/test
ls -laht ./
ls -laht ../
pwd
echo "HERE" && \
echo "THERE HERE WHERE"
`,options)
await expect(`${execute.STD}`).toMatch(`total `);
await expect(`${execute.STD}`).toMatch(`HERE\nTHERE `);
});
test('only last four lines in error', async() => {
await expect(execute.hostCommands(`
touch /tmp/test
ls -laht ./
ls -laht ../
pwd
echo "HERE" && \
echo "THERE HERE WHERE"
exit 40
`,options)).rejects.toThrowError(/STDOUT: \/Users\/nathanpierce\/anka-vm-github-action\nSTDOUT: HERE\nSTDOUT: THERE HERE WHERE/);
});
test('chained commands and redirection to file', async() => {
await execute.hostCommands("hostname && echo \"test1\" && echo \"Test2\" > /tmp/test && cat /tmp/test",options)
await expect(`${execute.STD}`).toMatch(`\ntest1\nTest2`);
});
test('chained commands and redirection to file', async() => {
await execute.hostCommands("hostname && echo \"test1\" && echo \"Test2\" > /tmp/test && cat /tmp/test",options)
await expect(`${execute.STD}`).toMatch(`\ntest1\nTest2`);
});
test('script execution with args', async() => {
await execute.hostCommands("hostname && ./test.bash 1 2 3 4",options)
await expect(`${execute.STD}`).toMatch(`\n1\n2\n3 4`);
});
describe('options', () => {
test('silent (js object)', async() => {
await execute.hostCommands("echo 123","{silent: false}",options)
await expect(execute.finalHostCommandOptions.silent).toBe(false);
});
test('cwd does not exist (js object)', async() => {
await expect(
execute.hostCommands("echo 123","{silent: true, cwd: \"./doesnotexist\"}",options)
).rejects.toEqual(new Error('exec.exec failed: cannot find ./doesnotexist'))
});
test('cwd (js object)', async() => {
await execute.hostCommands("ls","{cwd: \"./dist\"}")
await expect(`${execute.STD.trim()}`).toBe("index.js");
});
test('json (json)', async() => {
await execute.hostCommands("ls","{\"cwd\": \"./dist\"}")
await expect(`${execute.STD.trim()}`).toBe("index.js");
});
});
});
describe('ankaCp', () => {
describe('in', () => {
describe('errors', () => {
test('file does not exist', async() => {
await expect(
execute.ankaCp(
"in",
"testFile9",
"ankaVmTemplateName",
"./"
)
).rejects.toThrowError(/\"testFile9\" does not exist/);
}); // TEST
}); // DESCRIBE errors
}); // DESCRIBE in
}); // DESCRIBE ankaCp
});