Files
factorio-clusterio/test/integration/clusterio.js
T
Hornwitser 8b9bb59357 Fix fast-test
Fix incorrect locations for slowTest in clusterio integration tests and
add slowTest to the patch integration tests.  Fixes fast-test being
broken.
2019-12-14 17:53:34 +01:00

130 lines
4.0 KiB
JavaScript

const assert = require("assert").strict;
const fs = require("fs-extra");
const path = require("path");
const link = require("lib/link");
const plugin = require("lib/plugin");
const master = require("../../master");
const client = require("../../client");
const clusterctl = require("../../clusterctl");
const { version } = require("../../package");
describe("Integration of Clusterio", function() {
let testControl;
let testControlConnection;
let testSlave;
let testSlaveConnection;
let instancesDir = path.join("test", "temp", "instances");
// Mark that this test takes a lot of time, or depeneds on a test
// that takes a lot of time.
function slowTest(test) {
if (process.env.FAST_TEST) {
test.skip();
}
test.timeout(20000);
}
before(async function() {
master._db.slaves = new Map();
master._db.instances = new Map([
[11, { id: 11, name: "foo", slaveId: 4 }],
[21, { id: 21, name: "bar", slaveId: 5 }],
]);
Object.assign(master._config, {
description: "test",
visibility: { public: false, lan: false },
username: "test",
token: "",
game_password: "",
verify_user_identity: false,
allow_commands: "admins-only",
auto_pause: false,
});
let [controlClient, controlServer] = link.VirtualConnector.makePair();
testControl = new clusterctl._Control(controlClient);
testControlConnection = new master._ControlConnection({ agent: "test", version }, controlServer);
master._controlConnections.push(testControlConnection);
await fs.remove(instancesDir);
await fs.ensureDir(instancesDir)
let [slaveClient, slaveServer] = link.VirtualConnector.makePair();
testSlave = new client._Slave(slaveClient, {
id: 4,
name: "slave",
instanceDirectory: instancesDir,
factorioDirectory: "factorio",
masterURL: "http://invalid",
masterAuthToken: "invalid",
publicIP: "invalid",
}, await plugin.getPluginInfos("plugins"));
testSlaveConnection = new master._SlaveConnection({ agent: "test", version, name: "slave", id: 4}, slaveServer);
master._slaveConnections.set(4, testSlaveConnection);
});
describe("clusterctl", function() {
describe("list-slaves", function() {
it("does not throw", async function() {
await clusterctl._commands.get("list-slaves").run({}, testControl);
});
});
describe("list-instances", function() {
it("does not throw", async function() {
await clusterctl._commands.get("list-instances").run({}, testControl);
});
});
describe("create-instances", function() {
it("creates the instance", async function() {
await clusterctl._commands.get("create-instance").run({name: "test", slave: "slave"}, testControl);
assert(await fs.exists(path.join(instancesDir, "test")), "Instance was not created");
});
});
describe("create-save", function() {
it("creates a save", async function() {
slowTest(this);
await clusterctl._commands.get("create-save").run({instance: "test"}, testControl);
});
});
describe("start-instance", function() {
it("starts the instance", async function() {
slowTest(this);
await clusterctl._commands.get("start-instance").run({instance: "test"}, testControl);
// TODO check that the instance actually stopped
});
});
describe("send-rcon", function() {
it("sends the command", async function() {
slowTest(this);
await clusterctl._commands.get("send-rcon").run({instance: "test", command: "test"}, testControl);
// TODO check that the command was received
});
});
describe("stop-instance", function() {
it("stops the instance", async function() {
slowTest(this);
await clusterctl._commands.get("stop-instance").run({instance: "test"}, testControl);
// TODO check that the instance actually stopped
});
});
describe("delete-instance", function() {
it("deletes the instance", async function() {
slowTest(this);
await clusterctl._commands.get("delete-instance").run({instance: "test"}, testControl);
assert(!await fs.exists(path.join(instancesDir, "test")), "Instance was not deleted");
});
});
});
});