replace template_spec test with config_variables test (#4034)

After introducing new config loading this PR replaces the obsolete
template test with a config test.
This commit is contained in:
Karsten Hassel
2026-02-09 20:35:54 +01:00
committed by GitHub
parent 1dc3032171
commit 6cb3e24c2a
8 changed files with 56 additions and 33 deletions

View File

@@ -248,6 +248,7 @@
"Reis",
"rejas",
"relativehumidity",
"resultstring",
"Resig",
"roboto",
"rohitdharavath",
@@ -288,6 +289,7 @@
"TESTMODE",
"testpass",
"testuser",
"teststring",
"thomasrockhu",
"thumbslider",
"timeformat",

View File

@@ -9,7 +9,7 @@ import stylistic from "@stylistic/eslint-plugin";
import vitest from "@vitest/eslint-plugin";
export default defineConfig([
globalIgnores(["config/**", "modules/**/*", "js/positions.js", "tests/configs/port_variable.js"]),
globalIgnores(["config/**", "modules/**/*", "js/positions.js", "tests/configs/config_variables.js"]),
{
files: ["**/*.js"],
languageOptions: {

View File

@@ -0,0 +1,7 @@
MM_LANGUAGE=de
MM_TIME_FORMAT=12
MM_LOG_INFO=INFO
MM_LOG_ERROR=ERROR
SECRET_IP1="127.0.0.1"
SECRET_IP2="::ffff:127.0.0.1"
SECRET_IP3=1

View File

@@ -0,0 +1,12 @@
let config = require(`${process.cwd()}/tests/configs/default.js`).configFactory({
language: "${MM_LANGUAGE}",
logLevel: ["${MM_LOG_ERROR}", "LOG", "WARN", "${MM_LOG_INFO}"],
timeFormat: ${MM_TIME_FORMAT},
hideConfigSecrets: true,
ipWhitelist: ["${SECRET_IP2}", "::${SECRET_IP3}", "${SECRET_IP1}"]
});
/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {
module.exports = config;
}

View File

@@ -1 +0,0 @@
MM_PORT=8090

View File

@@ -1,8 +0,0 @@
let config = require(`${process.cwd()}/tests/configs/default.js`).configFactory({
port: ${MM_PORT}
});
/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {
module.exports = config;
}

View File

@@ -0,0 +1,34 @@
const helpers = require("./helpers/global-setup");
describe("config with variables and secrets", () => {
beforeAll(async () => {
await helpers.startApplication("tests/configs/config_variables.js");
});
afterAll(async () => {
await helpers.stopApplication();
});
it("config.language should be \"de\"", async () => {
expect(config.language).toBe("de");
});
it("config.loglevel should be [\"ERROR\", \"LOG\", \"WARN\", \"INFO\"]", async () => {
expect(config.logLevel).toStrictEqual(["ERROR", "LOG", "WARN", "INFO"]);
});
it("config.ipWhitelist should be [\"::ffff:127.0.0.1\", \"::1\", \"127.0.0.1\"]", async () => {
expect(config.ipWhitelist).toStrictEqual(["::ffff:127.0.0.1", "::1", "127.0.0.1"]);
});
it("config.timeFormat should be 12", async () => {
expect(config.timeFormat).toBe(12); // default is 24
});
it("/config endpoint should show redacted secrets", async () => {
const res = await fetch(`http://localhost:${config.port}/config`);
expect(res.status).toBe(200);
const cfg = await res.json();
expect(cfg.ipWhitelist).toStrictEqual(["**SECRET_IP2**", "::**SECRET_IP3**", "**SECRET_IP1**"]);
});
});

View File

@@ -1,23 +0,0 @@
const fs = require("node:fs");
const helpers = require("./helpers/global-setup");
describe("templated config with port variable", () => {
beforeAll(async () => {
await helpers.startApplication("tests/configs/port_variable.js");
});
afterAll(async () => {
await helpers.stopApplication();
try {
fs.unlinkSync("tests/configs/port_variable.js");
} catch (err) {
// do nothing
}
});
it("should return 200", async () => {
const port = global.testPort || 8080;
const res = await fetch(`http://localhost:${port}`);
expect(res.status).toBe(200);
});
});