Initial Dockge image update checker
All checks were successful
Build / test (push) Successful in 14s
All checks were successful
Build / test (push) Successful in 14s
This commit is contained in:
35
test/compose-parser.test.js
Normal file
35
test/compose-parser.test.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import { parseComposeImages } from "../src/compose-parser.js";
|
||||
|
||||
test("extracts service images from compose content", () => {
|
||||
const compose = `
|
||||
services:
|
||||
web:
|
||||
image: nginx:1.27
|
||||
api:
|
||||
build: .
|
||||
image: "ghcr.io/example/api:main" # comment
|
||||
networks:
|
||||
default:
|
||||
`;
|
||||
|
||||
assert.deepEqual(parseComposeImages(compose), [
|
||||
{ service: "web", image: "nginx:1.27", line: 4 },
|
||||
{ service: "api", image: "ghcr.io/example/api:main", line: 7 },
|
||||
]);
|
||||
});
|
||||
|
||||
test("ignores top-level image keys outside services", () => {
|
||||
const compose = `
|
||||
x-template:
|
||||
image: ignored
|
||||
services:
|
||||
worker:
|
||||
image: alpine
|
||||
`;
|
||||
|
||||
assert.deepEqual(parseComposeImages(compose), [
|
||||
{ service: "worker", image: "alpine", line: 6 },
|
||||
]);
|
||||
});
|
||||
28
test/image-ref.test.js
Normal file
28
test/image-ref.test.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import { digestMatchesRepoDigests, parseImageRef } from "../src/image-ref.js";
|
||||
|
||||
test("parses Docker Hub shorthand image references", () => {
|
||||
assert.deepEqual(parseImageRef("nginx:1.27"), {
|
||||
original: "nginx:1.27",
|
||||
registry: "registry-1.docker.io",
|
||||
repository: "library/nginx",
|
||||
tag: "1.27",
|
||||
registryRef: "registry-1.docker.io/library/nginx:1.27",
|
||||
repositoryRef: "registry-1.docker.io/library/nginx",
|
||||
});
|
||||
});
|
||||
|
||||
test("parses custom registry image references", () => {
|
||||
assert.deepEqual(parseImageRef("ghcr.io/example/app:main").registryRef, "ghcr.io/example/app:main");
|
||||
});
|
||||
|
||||
test("defaults missing tags to latest", () => {
|
||||
assert.equal(parseImageRef("redis").tag, "latest");
|
||||
});
|
||||
|
||||
test("matches remote digests against repo digests", () => {
|
||||
const imageRef = parseImageRef("nginx:latest");
|
||||
assert.equal(digestMatchesRepoDigests("sha256:abc", ["registry-1.docker.io/library/nginx@sha256:abc"], imageRef), true);
|
||||
assert.equal(digestMatchesRepoDigests("sha256:def", ["registry-1.docker.io/library/nginx@sha256:abc"], imageRef), false);
|
||||
});
|
||||
Reference in New Issue
Block a user