From e3f771a36c8e45cfc1169db04850b1d4caa2f881 Mon Sep 17 00:00:00 2001 From: Jeppe Bundgaard Date: Tue, 14 Apr 2026 16:41:18 +0200 Subject: [PATCH] Refactor edge-broker tests to consolidate file reading logic and streamline assertions --- services/edge-broker/test/config.test.mjs | 35 +++++++++++++++++------ 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/services/edge-broker/test/config.test.mjs b/services/edge-broker/test/config.test.mjs index aea1139a..f8966eb7 100644 --- a/services/edge-broker/test/config.test.mjs +++ b/services/edge-broker/test/config.test.mjs @@ -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", () => {