Skip to content

Commit

Permalink
create the test of verify command
Browse files Browse the repository at this point in the history
  • Loading branch information
To-Ki-O committed Mar 25, 2023
1 parent 8a8f9e5 commit 462ee9f
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/libs/actions.verify.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { assert, assertEquals } from "https://deno.land/std@0.152.0/testing/asserts.ts";
import { assertSpyCall, Stub, stub } from "https://deno.land/std@0.152.0/testing/mock.ts";
import { FakeTime } from "https://deno.land/std@0.152.0/testing/time.ts";
import { afterEach, beforeEach, describe, it } from "https://deno.land/std@0.152.0/testing/bdd.ts";
import { Colors, encoding, zipWrapper } from "../../deps.ts";
import { VerifyAction } from "../../libs/actions.ts";
import { DimJSON, DimLockJSON } from "../../libs/types.ts";
import DenoWrapper from "../../libs/deno_wrapper.ts";
import {
createEmptyDimJson,
createKyGetStub,
fileExists,
removeTemporaryFiles,
temporaryDirectory,
} from "../helper.ts";

describe("VerifyAction", () => {
let consoleLogStub: Stub;
let consoleErrorStub: Stub;
let denoExitStub: Stub;
let denoStdoutStub: Stub;
let fakeTime: FakeTime;
let originalDirectory: string;
let originalOS: "darwin" | "linux" | "windows";

beforeEach(() => {
consoleLogStub = stub(console, "log");
consoleErrorStub = stub(console, "error");
denoExitStub = stub(Deno, "exit");
denoStdoutStub = stub(Deno.stdout, "write");
fakeTime = new FakeTime("2022-01-02T03:04:05.678Z");
originalDirectory = Deno.cwd();
// originalOS = DenoWrapper.build.os;
Deno.chdir(temporaryDirectory);
});

afterEach(() => {
removeTemporaryFiles();
fakeTime.restore();
denoStdoutStub.restore();
denoExitStub.restore();
consoleErrorStub.restore();
consoleLogStub.restore();
DenoWrapper.build.os = originalOS;
Deno.chdir(originalDirectory);
});

it("download from locally existing all data installed dim.json and check that it is recorded in dim.json and dim-lock.json.", async () => {
const kyGetStub = createKyGetStub("dummy");
try {
Deno.copyFileSync(
"../test_data/installed-dim-lock.json",
"dim-lock.json",
);
await new VerifyAction().execute();
assertSpyCall(consoleLogStub, 0, {
args: [
Colors.green(`verification success`),
],
});
} finally {
kyGetStub.restore();
}
});
});

0 comments on commit 462ee9f

Please sign in to comment.