| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { formatBytes, installCommands, shortDigest } from "./packages.ts"; |
| 5 | |
| 6 | test("sizes read as registries show them", () => { |
| 7 | assert.equal(formatBytes(0), "0 B"); |
| 8 | assert.equal(formatBytes(812), "812 B"); |
| 9 | assert.equal(formatBytes(12_340_000), "12.3 MB"); |
| 10 | assert.equal(formatBytes(1_400_000_000), "1.4 GB"); |
| 11 | assert.equal(formatBytes(250_000_000), "250 MB"); |
| 12 | }); |
| 13 | |
| 14 | test("digests shorten for lists", () => { |
| 15 | assert.equal(shortDigest("sha256:3f2a9c1b7d0e55aa"), "3f2a9c1b7d0e"); |
| 16 | }); |
| 17 | |
| 18 | test("a container image is pulled by its address and tag", () => { |
| 19 | const pkg = { ecosystem: "container" as const, address: "g1t.sh/acme/web", name: "web", workspace: "acme" }; |
| 20 | assert.deepEqual(installCommands(pkg, "latest", "ada"), { |
| 21 | login: "docker login g1t.sh -u ada", |
| 22 | install: "docker pull g1t.sh/acme/web:latest", |
| 23 | }); |
| 24 | assert.equal(installCommands(pkg, null, "ada").install, "docker pull g1t.sh/acme/web"); |
| 25 | }); |