58 lines
1.9 KiB
JavaScript
58 lines
1.9 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import {
|
|
DEFAULT_STAGING_BASE_URL,
|
|
INSTALLER_SCRIPT_REQUIRED_SNIPPETS,
|
|
buildChecks,
|
|
normalizeBaseUrl,
|
|
parseArgs,
|
|
validateInstallerScriptBody,
|
|
} from "./staging-edge-gateway-smoke.mjs";
|
|
|
|
test("normalizeBaseUrl strips trailing slashes", () => {
|
|
assert.equal(normalizeBaseUrl("https://api.truckwash.io:4433///"), DEFAULT_STAGING_BASE_URL);
|
|
});
|
|
|
|
test("parseArgs accepts base URL and install token", () => {
|
|
const options = parseArgs([
|
|
"--base-url",
|
|
"https://staging.example.test/",
|
|
"--install-token",
|
|
"token-123",
|
|
]);
|
|
|
|
assert.equal(options.baseUrl, "https://staging.example.test/");
|
|
assert.equal(options.installToken, "token-123");
|
|
assert.equal(options.help, false);
|
|
});
|
|
|
|
test("buildChecks targets the public staging endpoints", () => {
|
|
const checks = buildChecks(DEFAULT_STAGING_BASE_URL, "abc 123");
|
|
|
|
assert.deepEqual(checks.map((check) => check.url), [
|
|
"https://api.truckwash.io:4433/ping",
|
|
"https://api.truckwash.io:4433/edge-agent/artifacts/agent.php",
|
|
"https://api.truckwash.io:4433/edge-agent/artifacts/truckwash-edge-agent.service",
|
|
"https://api.truckwash.io:4433/edge-agent/install.sh?token=abc%20123",
|
|
]);
|
|
});
|
|
|
|
test("validateInstallerScriptBody requires install-session reporting wiring", () => {
|
|
const script = `
|
|
INSTALL_STATUS_URL="https://api.truckwash.io:4433/edge-agent/install-token/status"
|
|
report_install_status "FAILED"
|
|
begin_install_phase "VERIFY_TOKEN" "Verifying install token"
|
|
begin_install_phase "WAIT_FOR_CLAIM" "Waiting for gateway heartbeat and claim"
|
|
`;
|
|
|
|
assert.deepEqual(validateInstallerScriptBody(script), INSTALLER_SCRIPT_REQUIRED_SNIPPETS);
|
|
});
|
|
|
|
test("validateInstallerScriptBody rejects missing installer status hooks", () => {
|
|
assert.throws(
|
|
() => validateInstallerScriptBody("echo hello"),
|
|
/Installer script is missing required status wiring/
|
|
);
|
|
});
|