-
Notifications
You must be signed in to change notification settings - Fork 1
/
diskspace.test.js
113 lines (99 loc) · 4.26 KB
/
diskspace.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const test = require("ava");
const execSync = require("child_process").execSync;
const path = require("path");
const action = "node " + path.join(__dirname, "index.js");
const realHost = process.env.INTEGRATION_HOST;
if (realHost) {
test("test enough space via internet", (t) => {
try {
const threshold = 100;
process.env["INPUT_THRESHOLD"] = threshold;
process.env["INPUT_HOST"] = realHost;
process.env["INPUT_USER"] = "ec2-user";
process.env["INPUT_SSH"] = process.env.INTEGRATION_SSH || "ssh";
const result = execSync(action, { env: process.env }).toString();
const re = `::notice::threshold\\(${threshold}\\) <= avail\\(\\d+\\)`;
const match = result.match(new RegExp(re));
t.truthy(match, JSON.stringify({ result, re, match }, null, 2));
} catch (error) {
t.fail(error instanceof Error ? error.stdout.toString() : error);
}
});
test("test not enough space via internet", (t) => {
const threshold = 1024 * 1024;
process.env["INPUT_THRESHOLD"] = threshold;
process.env["INPUT_HOST"] = realHost;
process.env["INPUT_USER"] = "ec2-user";
process.env["INPUT_SSH"] = process.env.INTEGRATION_SSH || "ssh";
const error = t.throws(() => execSync(action, { env: process.env }), {
instanceOf: Error,
});
const result = error.stdout.toString();
const re = `::warning::threshold\\(${threshold}\\) > avail\\(\\d+\\)`;
const match = result.match(new RegExp(re));
t.truthy(match, JSON.stringify({ result, re, match }, null, 2));
});
}
test("test enough space", (t) => {
process.env["INPUT_THRESHOLD"] = 100;
process.env["INPUT_HOST"] = "-host-";
process.env["INPUT_USER"] = "-user-";
process.env["INPUT_SSH"] = "node " + path.join(__dirname, "echo.js");
process.env["INPUT_CMD"] = "Avail 300";
process.env["INPUT_PATTERN"] = "[0-9]+";
try {
const result = execSync(action, { env: process.env }).toString();
const needle = "::notice::threshold(100) <= avail(300)";
const found = result.includes(needle);
t.truthy(found, JSON.stringify({ result, needle }, null, 2));
} catch (error) {
t.fail(error instanceof Error ? error.stdout.toString() : error);
}
});
test("test not enough space", (t) => {
process.env["INPUT_THRESHOLD"] = 100;
process.env["INPUT_HOST"] = "-host-";
process.env["INPUT_USER"] = "-user-";
process.env["INPUT_SSH"] = "node " + path.join(__dirname, "echo.js");
process.env["INPUT_CMD"] = "Avail 30";
process.env["INPUT_PATTERN"] = "[0-9]+";
const error = t.throws(() => execSync(action, { env: process.env }), {
instanceOf: Error,
});
const result = error.stdout.toString();
const needle = "::warning::threshold(100) > avail(30)";
const found = result.includes(needle);
t.truthy(found, JSON.stringify({ result, needle }, null, 2));
});
test("test custom settings", (t) => {
process.env["INPUT_THRESHOLD"] = 123;
process.env["INPUT_HOST"] = "-host-";
process.env["INPUT_USER"] = "-user-";
process.env["INPUT_SSH"] = "node " + path.join(__dirname, "echo.js");
process.env["INPUT_CMD"] = "=cmd= _321_";
process.env["INPUT_PATTERN"] = "-l,-user-,-host-,=cmd=,_([0-9]+)_";
try {
const result = execSync(action, { env: process.env }).toString();
const re = /::notice::threshold\(123\) <= avail\(321\)/;
const match = result.match(re);
t.truthy(match, JSON.stringify({ result, re, match }, null, 2));
} catch (error) {
t.fail(error instanceof Error ? error.stdout.toString() : error);
}
});
test("test custom pattern only", (t) => {
process.env["INPUT_THRESHOLD"] = 123;
process.env["INPUT_HOST"] = "-host-";
process.env["INPUT_USER"] = "-user-";
process.env["INPUT_PATTERN"] = "321";
try {
const result = execSync(action, { env: process.env }).toString();
const needle = "::notice::threshold(123) <= avail(321)";
t.truthy(
result.includes(needle),
JSON.stringify({ result, needle }, null, 2)
);
} catch (error) {
t.fail(error instanceof Error ? error.stdout.toString() : error);
}
});