mirror of
https://github.com/awalsh128/cache-apt-pkgs-action.git
synced 2026-11-13 21:36:56 +00:00
Codecov flagged lines in #246 as uncovered patch lines; they were untested before the reformat touched them. Add behavior tests for: - Cache: cache miss, missing or empty manifests, unreadable cache dir, metapackage-only restore, install scripts running after their archive with dpkg actions, existing archives, unavailable cache service, and save failures. - ManifestEntry.fromJSON round trip. - buildFileList dropping missing files, updateAptLists skipping update for populated lists and searching only to max depth, and fromInput ignoring a version without a package name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
2 KiB
TypeScript
52 lines
2 KiB
TypeScript
import os from "node:os";
|
|
import path from "node:path";
|
|
import fs from "node:fs";
|
|
import { describe, expect, it } from "vitest";
|
|
import { Manifest, ManifestEntry } from "../src/manifest.js";
|
|
import { CacheKey } from "../src/cache.js";
|
|
import { createPackageName } from "ts-apt";
|
|
import { ActionPackageNames } from "../src/packages.js";
|
|
|
|
describe("manifest", () => {
|
|
it("serializes and deserializes manifest entries", () => {
|
|
const cacheKey = new CacheKey("v1", "4", "amd64", ActionPackageNames.fromInput("curl git"));
|
|
const manifest = new Manifest(
|
|
new Date("2026-01-01T00:00:00.000Z"),
|
|
[new ManifestEntry(createPackageName("curl", "8.1.0", "amd64"), ["/b", "/a"])],
|
|
cacheKey,
|
|
);
|
|
|
|
const parsed = Manifest.fromJSON(JSON.parse(JSON.stringify(manifest)));
|
|
expect(parsed.entries).toHaveLength(1);
|
|
expect(parsed.entries[0]?.packageName.serialize()).toBe("curl:amd64=8.1.0");
|
|
expect(parsed.entries[0]?.filepaths).toEqual(["/a", "/b"]);
|
|
});
|
|
|
|
it("writes and reads manifest files", async () => {
|
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "manifest-test-"));
|
|
const filePath = path.join(tempDir, "manifest.json");
|
|
const cacheKey = new CacheKey("v1", "4", "amd64", ActionPackageNames.fromInput("curl"));
|
|
const manifest = new Manifest(
|
|
new Date("2026-01-01T00:00:00.000Z"),
|
|
[new ManifestEntry(createPackageName("curl", "8.1.0", "amd64"), ["usr/bin/curl"])],
|
|
cacheKey,
|
|
);
|
|
|
|
await manifest.writeToFile(filePath);
|
|
const parsed = await Manifest.readFromFile(filePath);
|
|
expect(parsed.entries).toHaveLength(1);
|
|
expect(parsed.entries[0]?.packageName.serialize()).toBe("curl:amd64=8.1.0");
|
|
});
|
|
|
|
it("ManifestEntry fromJSON parsed entry returns package and sorted files", () => {
|
|
const entry = new ManifestEntry(createPackageName("curl", "8.1.0", "amd64"), [
|
|
"usr/bin/curl",
|
|
"etc/curlrc",
|
|
]);
|
|
|
|
const parsed = ManifestEntry.fromJSON(JSON.parse(JSON.stringify(entry)));
|
|
|
|
expect(parsed).toEqual(entry);
|
|
});
|
|
});
|