Skip to content

Commit

Permalink
Split unzip test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ta-Hirose committed Sep 28, 2022
1 parent e2b96b9 commit dd18a05
Showing 1 changed file with 55 additions and 23 deletions.
78 changes: 55 additions & 23 deletions tests/libs/actions.install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { afterEach, beforeEach, describe, it } from "https://deno.land/std@0.152
import { Colors, encoding } from "../../deps.ts";
import { InstallAction } from "../../libs/actions.ts";
import { DimJSON, DimLockJSON } from "../../libs/types.ts";
import { getBuild } from "../../libs/postprocess/unzipper.ts";
import {
createEmptyDimJson,
createKyGetStub,
Expand Down Expand Up @@ -396,38 +397,69 @@ describe("InstallAction", () => {
}
});

it("check that the command to extract the downloaded file is entered and recorded in dim.json and dim-lock.json.", async () => {
it("check that the command for darwin to extract the downloaded file is entered and recorded in dim.json and dim-lock.json.", async () => {
createEmptyDimJson();
const kyGetStub = createKyGetStub("dummy");
const denoRunStub = stub(Deno, "run");
const denoRunStub = stub(Deno, "run", () => ({
output: () => {},
status: () => Promise.resolve({ success: true }),
rid: 1,
} as Deno.Process));
const osStub = stub(getBuild, "getOs", () => {
return "darwin";
});
try {
await new InstallAction().execute(
{ name: "unzip", postProcesses: ["unzip"] },
"https://example.com/dummy.zip",
);
assert(fileExists("data_files/unzip/dummy.zip"));
if (Deno.build.os === "darwin") {
assertSpyCall(denoRunStub, 0, {
args: [{
cmd: [
"ditto",
"-xk",
"--sequesterRsrc",
"./data_files/unzip/dummy.zip",
"./data_files/unzip",
],
stdout: "piped",
stderr: "piped",
}],
});
} else {
assertSpyCall(denoRunStub, 0, {
args: [{
cmd: ["unzip", "./data_files/unzip/dummy.zip", "-d", "./data_files/unzip"],
}],
});
}
assertSpyCall(denoRunStub, 0, {
args: [{
cmd: [
"ditto",
"-xk",
"--sequesterRsrc",
"./data_files/unzip/dummy.zip",
"./data_files/unzip",
],
stdout: "piped",
stderr: "piped",
}],
});
} finally {
osStub.restore();
denoRunStub.restore();
kyGetStub.restore();
}
});

it("check that the command for linux to extract the downloaded file is entered and recorded in dim.json and dim-lock.json.", async () => {
createEmptyDimJson();
const kyGetStub = createKyGetStub("dummy");
const denoRunStub = stub(Deno, "run", () => ({
output: () => {},
status: () => Promise.resolve({ success: true }),
rid: 1,
} as Deno.Process));
const denoCloseStub = stub(Deno, "close");
const osStub = stub(getBuild, "getOs", () => {
return "linux";
});
try {
await new InstallAction().execute(
{ name: "unzip", postProcesses: ["unzip"] },
"https://example.com/dummy.zip",
);
assert(fileExists("data_files/unzip/dummy.zip"));
assertSpyCall(denoRunStub, 0, {
args: [{
cmd: ["unzip", "./data_files/unzip/dummy.zip", "-d", "./data_files/unzip"],
}],
});
} finally {
osStub.restore();
denoCloseStub.restore();
denoRunStub.restore();
kyGetStub.restore();
}
Expand Down

0 comments on commit dd18a05

Please sign in to comment.