-
Notifications
You must be signed in to change notification settings - Fork 35
/
setup.ts
49 lines (46 loc) · 1.05 KB
/
setup.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
import { readableStreamToText, spawn } from "bun";
import { afterAll, beforeAll } from "bun:test";
const removeStatefiles = async () => {
const proc = spawn([
"find",
".",
"-type",
"f",
"-o",
"-name",
"*.tfstate",
"-o",
"-name",
"*.tfstate.lock.info",
"-delete",
]);
await proc.exited;
};
const removeOldContainers = async () => {
let proc = spawn([
"docker",
"ps",
"-a",
"-q",
"--filter",
`label=modules-test`,
]);
let containerIDsRaw = await readableStreamToText(proc.stdout);
let exitCode = await proc.exited;
if (exitCode !== 0) {
throw new Error(containerIDsRaw);
}
containerIDsRaw = containerIDsRaw.trim();
if (containerIDsRaw === "") {
return;
}
proc = spawn(["docker", "rm", "-f", ...containerIDsRaw.split("\n")]);
const stdout = await readableStreamToText(proc.stdout);
exitCode = await proc.exited;
if (exitCode !== 0) {
throw new Error(stdout);
}
};
afterAll(async () => {
await Promise.all([removeStatefiles(), removeOldContainers()]);
});