Feature 57 (config and provisioning): modules declare config and provisions, their files rendered from templates; synced with main (issues of feature 57, 874)
This commit is contained in:
@@ -7,11 +7,26 @@ import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
|
||||
type Requirement = string | { name: string; optional?: boolean };
|
||||
type Resource = { id: string; type: string; path?: string; content?: string; volumes?: string[]; "only-when-bound"?: string };
|
||||
type Resource = { id: string; type: string; path?: string; content?: string; template?: string; volumes?: string[]; "only-when-bound"?: string };
|
||||
const manifest = JSON.parse(readFileSync(new URL("../module.json", import.meta.url), "utf8")) as {
|
||||
requires: Requirement[];
|
||||
resources: Resource[];
|
||||
build: { artifacts: { name: string; kind: string; from?: string }[] };
|
||||
};
|
||||
// A file's text is its template's, in the module's files/ (novox/hq ADR 0349 §2).
|
||||
const text = (r: Resource): string => {
|
||||
assert.ok(r.template, `${r.id} names no template`);
|
||||
return readFileSync(new URL(`../${r.template}`, import.meta.url), "utf8");
|
||||
};
|
||||
|
||||
test("no file carries its text inline: each names its template, and the build packs files/ into one archive", () => {
|
||||
for (const r of manifest.resources) {
|
||||
assert.equal(r.content, undefined, `${r.id} keeps its text inline`);
|
||||
if (r.type === "file") text(r);
|
||||
}
|
||||
const packs = manifest.build.artifacts.filter((a) => a.kind === "archive" && a.from === "files");
|
||||
assert.deepEqual(packs.map((a) => a.name), ["files"]);
|
||||
});
|
||||
|
||||
const optional = (name: string) =>
|
||||
manifest.requires.some((r) => typeof r !== "string" && r.name === name && r.optional === true);
|
||||
@@ -24,7 +39,7 @@ test("influxdb-api is optional, and route and oidc-client stay hard", () => {
|
||||
|
||||
test("every file naming influxdb-api is delivered only while it is bound", () => {
|
||||
for (const r of manifest.resources) {
|
||||
if (r.type === "file" && /\$\{(bound:influxdb-api:|secret:influxdb-api\})/.test(r.content ?? "")) {
|
||||
if (r.type === "file" && /\$\{(bound:influxdb-api:|secret:influxdb-api\})/.test(text(r))) {
|
||||
assert.equal(r["only-when-bound"], "influxdb-api", `${r.id} names influxdb-api and is delivered while it is absent`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user