mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 07:30:41 +09:00
Merge branch 'master' into feature/datastore
This commit is contained in:
102 files changed
+1252
-366
No files matched your search
@@ -206,6 +206,12 @@ describe("Integration of Clusterio", function() {
|
||||
});
|
||||
});
|
||||
it("should auto start instances with auto_start enabled", async function() {
|
||||
// On windows there's currently no way to automate graceful shutdown of the host
|
||||
// process as CTRL+C is some weird terminal thing and SIGINT isn't a thing.
|
||||
if (process.platform === "win32") {
|
||||
this.skip();
|
||||
}
|
||||
|
||||
slowTest(this);
|
||||
|
||||
let hostProcess;
|
||||
|
||||
@@ -45,7 +45,7 @@ describe("Integration of create tool", function () {
|
||||
assert.equal(hostConfig["host.name"], "local");
|
||||
assert.equal(hostConfig["host.public_address"], "localhost");
|
||||
assert.equal(hostConfig["host.factorio_directory"], "test/factorio");
|
||||
assert.equal(hostConfig["host.controller_url"], "http://localhost:8099");
|
||||
assert.equal(hostConfig["host.controller_url"], "http://localhost:8099/");
|
||||
}).timeout(1200000);
|
||||
it("should create a new controller installation", async function () {
|
||||
this.skip();
|
||||
|
||||
@@ -5,12 +5,14 @@ const path = require("path");
|
||||
const { _exportLocale } = require("@clusterio/host/dist/node/src/export");
|
||||
const { FactorioServer } = require("@clusterio/host/dist/node/src/server");
|
||||
|
||||
const { factorioDir } = require("./index");
|
||||
|
||||
|
||||
describe("Integration of lib/factorio/export", function() {
|
||||
describe("exportLocale()", function() {
|
||||
it("returns a nested Map with base game locale information", async function() {
|
||||
let writePath = path.join("temp", "test", "server");
|
||||
let testServer = new FactorioServer("factorio", writePath, {});
|
||||
let testServer = new FactorioServer(factorioDir, writePath, {});
|
||||
await testServer.init();
|
||||
|
||||
let locale = await _exportLocale(testServer, new Map(), ["base"], "en");
|
||||
|
||||
@@ -126,15 +126,35 @@ async function get(urlPath) {
|
||||
return res;
|
||||
}
|
||||
|
||||
function loadJSON(filePath) {
|
||||
try {
|
||||
// eslint-disable-next-line node/no-sync
|
||||
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
} catch (err) {
|
||||
if (err.code === "ENOENT") {
|
||||
return undefined;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
function getFactorioDir(hostConfig) {
|
||||
const factorioDir = hostConfig?.["host.factorio_directory"] ?? "factorio";
|
||||
return path.join(factorioDir);
|
||||
}
|
||||
|
||||
let controllerProcess;
|
||||
let hostProcess;
|
||||
let control;
|
||||
|
||||
const baseHostConfig = loadJSON("config-host.json");
|
||||
|
||||
let url = "https://localhost:4443/";
|
||||
let controlToken = jwt.sign({ aud: "user", user: "test" }, Buffer.from("TestSecretDoNotUse", "base64"));
|
||||
let instancesDir = path.join("temp", "test", "instances");
|
||||
let modsDir = path.join("temp", "test", "mods");
|
||||
let databaseDir = path.join("temp", "test", "database");
|
||||
let factorioDir = getFactorioDir(baseHostConfig);
|
||||
let pluginListPath = path.join("temp", "test", "plugin-list.json");
|
||||
let controllerConfigPath = path.join("temp", "test", "config-controller.json");
|
||||
let hostConfigPath = path.join("temp", "test", "config-host.json");
|
||||
@@ -161,20 +181,30 @@ function getControl() {
|
||||
}
|
||||
|
||||
function spawn(name, cmd, waitFor) {
|
||||
// eslint-disable-next-line node/no-process-env
|
||||
const silent = process.env.SILENT_TEST;
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log(cmd);
|
||||
let parts = cmd.split(" ");
|
||||
let process = child_process.spawn(parts[0], parts.slice(1), { cwd: path.join("temp", "test") });
|
||||
let stdout = new LineSplitter({ readableObjectMode: true });
|
||||
stdout.on("data", line => {
|
||||
let stderr = new LineSplitter({ readableObjectMode: true });
|
||||
let onDataOut = line => {
|
||||
line = line.toString("utf8");
|
||||
if (waitFor.test(line)) {
|
||||
if (silent) {
|
||||
stdout.off("data", onDataOut);
|
||||
stderr.off("data", onDataErr);
|
||||
}
|
||||
resolve(process);
|
||||
}
|
||||
console.log(name, line);
|
||||
});
|
||||
let stderr = new LineSplitter({ readableObjectMode: true });
|
||||
stderr.on("data", line => { console.log(name, line.toString("utf8")); });
|
||||
};
|
||||
let onDataErr = line => {
|
||||
console.log(name, line.toString("utf8"));
|
||||
};
|
||||
stdout.on("data", onDataOut);
|
||||
stderr.on("data", onDataErr);
|
||||
process.stdout.pipe(stdout);
|
||||
process.stderr.pipe(stderr);
|
||||
});
|
||||
@@ -183,10 +213,17 @@ function spawn(name, cmd, waitFor) {
|
||||
before(async function() {
|
||||
this.timeout(40000);
|
||||
|
||||
// eslint-disable-next-line node/no-process-env
|
||||
const silent = process.env.SILENT_TEST;
|
||||
if (silent) {
|
||||
console.log("SILENT_TEST is present in env, loggers after bootstrap will be muted.");
|
||||
}
|
||||
|
||||
// Some integration tests may cause log events
|
||||
logger.add(new ConsoleTransport({
|
||||
level: "info",
|
||||
format: new lib.TerminalFormat(),
|
||||
filter: () => !silent,
|
||||
}));
|
||||
|
||||
// If fast test is enabled then output that it is
|
||||
@@ -206,6 +243,7 @@ before(async function() {
|
||||
|
||||
await fs.ensureDir(path.join("temp", "test"));
|
||||
|
||||
console.log("Building Mods");
|
||||
await fs.ensureDir(modsDir);
|
||||
await lib.build({
|
||||
build: true,
|
||||
@@ -232,6 +270,7 @@ before(async function() {
|
||||
}
|
||||
await fs.copyFile(`mods/${ssZip}`, `${modsDir}/${ssZip}`);
|
||||
|
||||
console.log("Setting Controller Config");
|
||||
await exec("node ../../packages/controller config set controller.auth_secret TestSecretDoNotUse");
|
||||
await exec("node ../../packages/controller config set controller.http_port 8880");
|
||||
await exec("node ../../packages/controller config set controller.https_port 4443");
|
||||
@@ -240,12 +279,14 @@ before(async function() {
|
||||
await exec("node ../../packages/controller config set controller.tls_certificate ../../test/file/tls/cert.pem");
|
||||
await exec("node ../../packages/controller config set controller.tls_private_key ../../test/file/tls/key.pem");
|
||||
|
||||
console.log("Setting Controller Plugins");
|
||||
await exec("node ../../packages/ctl plugin add ../../plugins/global_chat");
|
||||
await exec("node ../../packages/ctl plugin add ../../plugins/research_sync");
|
||||
await exec("node ../../packages/ctl plugin add ../../plugins/statistics_exporter");
|
||||
await exec("node ../../packages/ctl plugin add ../../plugins/subspace_storage");
|
||||
await exec("node ../../packages/ctl plugin add ../../plugins/player_auth");
|
||||
|
||||
console.log("Bootstrapping");
|
||||
await exec("node ../../packages/controller bootstrap create-admin test");
|
||||
await exec("node ../../packages/controller bootstrap create-ctl-config test");
|
||||
await exec("node ../../packages/ctl control-config set control.tls_ca ../../test/file/tls/cert.pem");
|
||||
@@ -253,7 +294,9 @@ before(async function() {
|
||||
controllerProcess = await spawn("controller:", "node ../../packages/controller run", /Started controller/);
|
||||
|
||||
await execCtl("host create-config --id 4 --name host --generate-token");
|
||||
await exec(`node ../../packages/host config set host.factorio_directory ${path.join("..", "..", "factorio")}`);
|
||||
|
||||
const relativeFactorioDir = path.isAbsolute(factorioDir) ? factorioDir : path.join("..", "..", factorioDir);
|
||||
await exec(`node ../../packages/host config set host.factorio_directory ${relativeFactorioDir}`);
|
||||
await exec("node ../../packages/host config set host.tls_ca ../../test/file/tls/cert.pem");
|
||||
|
||||
hostProcess = await spawn("host:", "node ../../packages/host run", /Started host/);
|
||||
@@ -317,6 +360,7 @@ module.exports = {
|
||||
instancesDir,
|
||||
modsDir,
|
||||
databaseDir,
|
||||
factorioDir,
|
||||
controllerConfigPath,
|
||||
hostConfigPath,
|
||||
controlConfigPath,
|
||||
|
||||
@@ -8,13 +8,13 @@ const lib = require("@clusterio/lib");
|
||||
const { FactorioServer, _getVersion } = require("@clusterio/host/dist/node/src/server");
|
||||
const { logger } = lib;
|
||||
|
||||
const { slowTest } = require("./index");
|
||||
const { slowTest, factorioDir } = require("./index");
|
||||
|
||||
|
||||
describe("Integration of host/src/server", function() {
|
||||
describe("_getVersion()", function() {
|
||||
it("should get a version from factorio's changelog.txt", async function() {
|
||||
let version = await _getVersion(path.join("factorio", "data", "changelog.txt"));
|
||||
let version = await _getVersion(path.join(factorioDir, "data", "changelog.txt"));
|
||||
if (!/^\d+\.\d+\.\d+$/.test(version)) {
|
||||
assert.fail(`Detected version '${version}' does not followed the format x.y.z`);
|
||||
}
|
||||
@@ -23,7 +23,7 @@ describe("Integration of host/src/server", function() {
|
||||
|
||||
describe("class FactorioServer", function() {
|
||||
let writePath = path.join("temp", "test", "integration");
|
||||
let server = new FactorioServer("factorio", writePath, {});
|
||||
let server = new FactorioServer(factorioDir, writePath, {});
|
||||
let logFile;
|
||||
|
||||
before(async function() {
|
||||
|
||||
Reference in new issue
Block a user