Add lock file for configs

This commit is contained in:
Cooldude2606 committed 2026-01-07 01:20:40 +00:00
1 parent 00cf0f59ec
commit bccb6527a7
9 files changed
+361 -18

No files matched your search

+38 -3
View File
@@ -13,7 +13,7 @@ const { wait } = lib;
const testStrings = require("../lib/factorio/test_strings");
const {
TestControl, TestControlConnector, url, controlToken, slowTest,
exec, execCtl, execCtlProcess, execHost, sendRcon, getControl,
execCtl, execCtlProcess, execController, execHost, sendRcon, getControl,
spawnNode, instancesDir, factorioDir,
} = require("./index");
@@ -109,12 +109,31 @@ describe("Integration of Clusterio", function() {
describe("clusteriocontroller", function() {
describe("bootstrap generate-user-token", function() {
it("work for existing user", async function() {
await exec("node ../../packages/controller bootstrap generate-user-token test");
await execController("bootstrap generate-user-token test");
});
it("fails if user does not exist", async function() {
await assert.rejects(
exec("node ../../packages/controller bootstrap generate-user-token invalid")
execController("bootstrap generate-user-token invalid")
);
});
});
describe("bootstrap create-admin", function() {
it("refuses to modify the database files", async function() {
await assert.rejects(
execController("bootstrap create-admin BootstrapAdminTest")
);
});
});
describe("config", function() {
it("can read the config file", async function() {
await execController("config list");
});
it("refuses to modify the config files", async function() {
await assert.rejects(
execController("confit set controller.name ConfigEditTest")
);
});
});
@@ -143,6 +162,9 @@ describe("Integration of Clusterio", function() {
await events.once(connectorB, "resume");
await connectorB.close(1000, "");
});
it("refuses to start a second process", async function() {
await assert.rejects(execController("run"));
});
});
describe("queryLogRequestHandler", function() {
@@ -245,6 +267,19 @@ describe("Integration of Clusterio", function() {
await stopAltHost(hostProcess);
}
});
describe("config", function() {
it("can read the config file", async function() {
await execHost("config list");
});
it("refuses to modify the config files", async function() {
await assert.rejects(
execHost("confit set host.name ConfigEditTest")
);
});
});
it("refuses to start a second process", async function() {
await assert.rejects(execHost("run"));
});
});
describe("clusterioctl", function() {
+9 -8
View File
@@ -173,26 +173,26 @@ let controllerConfigPath = path.join("temp", "test", "config-controller.json");
let hostConfigPath = path.join("temp", "test", "config-host.json");
let controlConfigPath = path.join("temp", "test", "config-control.json");
async function exec(command, options = {}) {
function exec(command, options = {}) {
// Uncomment to show commands run in tests
// console.log(command);
options = { cwd: path.join("temp", "test"), ...options };
return await util.promisify(child_process.exec)(command, options);
return util.promisify(child_process.exec)(command, options);
}
async function execController(...args) {
function execController(...args) {
args[0] = `node --enable-source-maps ../../packages/controller ${args[0]}`;
return await exec(...args);
return exec(...args);
}
async function execHost(...args) {
function execHost(...args) {
args[0] = `node --enable-source-maps ../../packages/host ${args[0]}`;
return await exec(...args);
return exec(...args);
}
async function execCtlProcess(...args) {
function execCtlProcess(...args) {
args[0] = `node --enable-source-maps ../../packages/ctl ${args[0]}`;
return await exec(...args);
return exec(...args);
}
let inExecCtl = false;
@@ -394,6 +394,7 @@ module.exports = {
TestControl,
TestControlConnector,
TestHostConnector,
execController,
execCtlProcess,
slowTest,
get,