-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbin-get_test.ts
101 lines (94 loc) · 2.15 KB
/
bin-get_test.ts
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
import { exists } from "https://deno.land/[email protected]/fs/exists.ts";
import { assert } from "https://deno.land/[email protected]/testing/asserts.ts";
const defaultAllows = new Map<string, string | null>([
["--allow-write", "/usr/bin/,/tmp"],
["--allow-env", null],
["--allow-read", null],
["--allow-net", "api.github.com"],
]);
function getAllowList(options: Map<string, string>): string[] {
const allowsList = defaultAllows;
return Array.from(
Array.from(allowsList).map(([k, v]) => {
if (options.has(k)) {
if (v) {
v += options.get(k);
} else {
v = options.get(k) + "";
}
}
if (v) {
return `${k}=${v}`;
}
return k;
}).values(),
);
}
const testPackages: string[] = [
"helm/helm",
"sachaos/viddy",
"r-darwish/topgrade",
"hadolint/hadolint",
"whalebrew/whalebrew",
"mutagen-io/mutagen",
"mutagen-io/mutagen-compose"
];
for (const testPackage of testPackages) {
Deno.test(`Test install ${testPackage}`, async () => {
const p = Deno.run({
cmd: [
"deno",
"run",
"--allow-all",
"./bin-get.ts",
"install",
testPackage,
"--force",
],
});
await p.status();
Deno.close(p.rid);
});
assert(
await exists(`/usr/bin/` + testPackage.split("/")[1]),
`${testPackage} should be installed in /usr/bin/`,
);
}
Deno.test(`Test install helm with predefined allow list`, async () => {
const p = Deno.run({
cmd: [
"deno",
"run",
...getAllowList(
new Map<string, string>([["--allow-net", ",get.helm.sh"]]),
),
"./bin-get.ts",
"install",
"helm/helm",
"--force",
],
});
await p.status();
Deno.close(p.rid);
});
Deno.test("Test install helm with custom location", async () => {
const p = Deno.run({
cmd: [
"deno",
"run",
"--allow-all",
"./bin-get.ts",
"install",
"helm/helm",
"--force",
"--directory",
"/root/.bin/",
],
});
await p.status();
Deno.close(p.rid);
assert(
await exists("/root/.bin/helm"),
`helm should be installed in /root/.bin/helm`,
);
});