Refactor edge-broker tests to consolidate file reading logic and streamline assertions
This commit is contained in:
@@ -1,24 +1,41 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
|
||||
const composeSource = readFileSync(new URL("../../../docker-compose.yml", import.meta.url), "utf8");
|
||||
const composeProdSource = readFileSync(new URL("../../../docker-compose.prod.yml", import.meta.url), "utf8");
|
||||
const traefikSource = readFileSync(new URL("../../../services/traefik/traefik.yml", import.meta.url), "utf8");
|
||||
const traefikProdSource = readFileSync(new URL("../../../services/traefik/traefik.prod.yml", import.meta.url), "utf8");
|
||||
function readExistingSource(relativePath) {
|
||||
const sourceUrl = new URL(relativePath, import.meta.url);
|
||||
if (!existsSync(sourceUrl)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return readFileSync(sourceUrl, "utf8");
|
||||
}
|
||||
|
||||
function readExistingSources(relativePaths) {
|
||||
return relativePaths
|
||||
.map((relativePath) => readExistingSource(relativePath))
|
||||
.filter(Boolean)
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
const composeSource = readExistingSources([
|
||||
"../../../docker-compose.yml",
|
||||
"../../../docker-compose.prod.yml",
|
||||
]);
|
||||
const traefikSource = readExistingSources([
|
||||
"../../../services/traefik/traefik.yml",
|
||||
"../../../services/traefik/traefik.prod.yml",
|
||||
]);
|
||||
|
||||
test("traefik does not expose a dedicated public edge broker port", () => {
|
||||
assert.doesNotMatch(traefikSource, /edge-broker:\s*\n\s*address:\s*":4300"/);
|
||||
assert.doesNotMatch(traefikProdSource, /edge-broker:\s*\n\s*address:\s*":4300"/);
|
||||
assert.doesNotMatch(composeSource, /traefik:[\s\S]*ports:[\s\S]*"4300:4300"/);
|
||||
assert.doesNotMatch(composeProdSource, /ports:[\s\S]*"4300:4300"/);
|
||||
assert.doesNotMatch(composeSource, /ports:[\s\S]*"4300:4300"/);
|
||||
});
|
||||
|
||||
test("the docker stack no longer defines an edge broker websocket service", () => {
|
||||
assert.doesNotMatch(composeSource, /\bedge-broker:\b/);
|
||||
assert.doesNotMatch(composeSource, /\/ws\/agent/);
|
||||
assert.doesNotMatch(composeSource, /\/ws\/browser-shell/);
|
||||
assert.doesNotMatch(composeProdSource, /\bedge-broker\b/);
|
||||
});
|
||||
|
||||
test("php services no longer receive broker websocket environment defaults", () => {
|
||||
|
||||
Reference in New Issue
Block a user