This commit is contained in:
@@ -18,9 +18,10 @@ async function createHarness(options = {}) {
|
||||
import { appendFileSync, cpSync } from "node:fs";
|
||||
const args = process.argv.slice(2);
|
||||
const command = args.includes("clone") ? "clone" : args.includes("rev-parse") ? "rev-parse" : "other";
|
||||
appendFileSync(process.env.LOC_TEST_CLONE_LOG, args.join(" ") + "\\n");
|
||||
if (command === "clone") {
|
||||
appendFileSync(process.env.LOC_TEST_CLONE_LOG, "clone\\n");
|
||||
if (process.env.LOC_TEST_HANG === "1") setInterval(() => {}, 1000);
|
||||
if (process.env.LOC_TEST_FAIL === "1") process.exit(2);
|
||||
cpSync(process.env.LOC_TEST_FIXTURE, args.at(-1), { recursive: true });
|
||||
} else if (command === "rev-parse") {
|
||||
process.stdout.write("fixture-commit\\n");
|
||||
@@ -67,6 +68,7 @@ if (command === "clone") {
|
||||
delete process.env.LOC_TEST_FIXTURE;
|
||||
delete process.env.LOC_TEST_CLONE_LOG;
|
||||
delete process.env.LOC_TEST_HANG;
|
||||
delete process.env.LOC_TEST_FAIL;
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
};
|
||||
@@ -86,7 +88,28 @@ test("scans fixture repositories, caches duplicate work, and cleans clone direct
|
||||
assert.equal(first.commit, "fixture-commit");
|
||||
assert.equal(second.lineCount, 2);
|
||||
assert.equal(third.cached, true);
|
||||
assert.equal((await readFile(harness.cloneLog, "utf8")).trim().split("\n").length, 1);
|
||||
const commands = await readFile(harness.cloneLog, "utf8");
|
||||
assert.equal(commands.split("\n").filter((line) => line.includes(" clone ")).length, 1);
|
||||
assert.deepEqual(await readdir(harness.config.tempRoot), []);
|
||||
} finally {
|
||||
await harness.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("checks out requested refs and cleans up failed clones", async () => {
|
||||
const harness = await createHarness();
|
||||
try {
|
||||
await writeFile(path.join(harness.fixture, "main.ts"), "export {};\n");
|
||||
await harness.service.count({ repo: "https://example.test/demo.git", ref: "release-1", sshKey: null });
|
||||
const commands = await readFile(harness.cloneLog, "utf8");
|
||||
assert.match(commands, /fetch --depth 1 origin release-1/);
|
||||
assert.match(commands, /checkout FETCH_HEAD/);
|
||||
|
||||
process.env.LOC_TEST_FAIL = "1";
|
||||
await assert.rejects(
|
||||
harness.service.count({ repo: "https://example.test/failure.git", ref: null, sshKey: null }),
|
||||
{ statusCode: 400 }
|
||||
);
|
||||
assert.deepEqual(await readdir(harness.config.tempRoot), []);
|
||||
} finally {
|
||||
await harness.cleanup();
|
||||
|
||||
Reference in New Issue
Block a user