You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.0 KiB
TypeScript
50 lines
1.0 KiB
TypeScript
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()]);
|
|
});
|