Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
keroxp committed Jun 18, 2024
1 parent 9c1d2e9 commit e23b5c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/setup.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import nock from "nock";
import { downloadCage, getLatestVersion } from "./setup";
import { downloadCage, getLatestVersion, parseChecksum } from "./setup";
import os from "node:os";
import fs from "node:fs/promises";
import path from "node:path";
Expand Down Expand Up @@ -107,3 +107,17 @@ describe("downloadCage", () => {
).rejects.toThrow("Checksum mismatch:");
});
});

describe("parseChecksum", () => {
test("basic", async () => {
const map = await parseChecksum(
path.resolve(__dirname, "testdata/0.1.0/canarycage_0.1.0_checksums.txt"),
);
expect(map.get("canarycage_linux_amd64.zip")).toBe(
"e00aeaebd63dc17194891514411426aa50ec51b1095fe85df927106184c71b47",
);
expect(map.get("canarycage_darwin_arm64.zip")).toBe(
"e00aeaebd63dc17194891514411426aa50ec51b1095fe85df927106184c71b47",
);
});
});
4 changes: 3 additions & 1 deletion src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ function getPlatformArch(): string {
return `${platform}_${arch}`;
}

async function parseChecksum(file: string): Promise<Map<string, string>> {
export async function parseChecksum(
file: string,
): Promise<Map<string, string>> {
const buf = await fs.readFile(file, "utf-8");
const entries: [string, string][] = buf
.split("\n")
Expand Down

0 comments on commit e23b5c8

Please sign in to comment.