mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 07:30:41 +09:00
Prefix clusterio/lib imports with lib
Use lib* prefix for the modules impored from the lib package to help distinguish them more from ordinary variables. Fix up the naming convention for files to be consistently lowercase_underscore for JavaScript files.
This commit is contained in:
1 parent
fbbaf3dd3a
commit
24397b75cc
55 files changed
+692
-668
No files matched your search
@@ -3,13 +3,13 @@ const assert = require("assert").strict;
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const link = require("@clusterio/lib/link");
|
||||
const libLink = require("@clusterio/lib/link");
|
||||
|
||||
const { slowTest, get, execCtl, sendRcon, getControl, instancesDir } = require("./index");
|
||||
|
||||
|
||||
async function getInstances() {
|
||||
let result = await link.messages.listInstances.send(getControl());
|
||||
let result = await libLink.messages.listInstances.send(getControl());
|
||||
return new Map(result.list.map(instance => [instance.id, instance]));
|
||||
}
|
||||
|
||||
@@ -170,14 +170,14 @@ describe("Integration of Clusterio", function() {
|
||||
|
||||
describe("user set-admin/whitelisted/banned", function() {
|
||||
async function getUsers() {
|
||||
let result = await link.messages.listUsers.send(getControl());
|
||||
let result = await libLink.messages.listUsers.send(getControl());
|
||||
return new Map(result.list.map(user => [user.name, user]));
|
||||
}
|
||||
|
||||
let lists = ["admin", "whitelisted", "banned"];
|
||||
it("should add and remove the given user to the list", async function() {
|
||||
slowTest(this);
|
||||
await link.messages.createUser.send(getControl(), { name: "list_test" });
|
||||
await libLink.messages.createUser.send(getControl(), { name: "list_test" });
|
||||
let user = (await getUsers()).get("list_test");
|
||||
for (let list of lists) {
|
||||
assert.equal(user[`is_${list}`], false, `unexpected ${list} status`);
|
||||
@@ -248,7 +248,7 @@ describe("Integration of Clusterio", function() {
|
||||
it("should create the given role", async function() {
|
||||
let args = "--description \"A temp role\" --permissions core.control.connect";
|
||||
await execCtl(`role create temp ${args}`);
|
||||
let result = await link.messages.listRoles.send(getControl());
|
||||
let result = await libLink.messages.listRoles.send(getControl());
|
||||
let role = result.list.find(role => role.name === "temp");
|
||||
assert.deepEqual(role, { id: 5, name: "temp", description: "A temp role", permissions: ["core.control.connect"] });
|
||||
});
|
||||
@@ -258,7 +258,7 @@ describe("Integration of Clusterio", function() {
|
||||
it("should modify the given role", async function() {
|
||||
let args = "--name new --description \"A new role\" --permissions";
|
||||
await execCtl(`role edit temp ${args}`);
|
||||
let result = await link.messages.listRoles.send(getControl());
|
||||
let result = await libLink.messages.listRoles.send(getControl());
|
||||
let role = result.list.find(role => role.name === "new");
|
||||
assert.deepEqual(role, { id: 5, name: "new", description: "A new role", permissions: [] });
|
||||
});
|
||||
@@ -267,7 +267,7 @@ describe("Integration of Clusterio", function() {
|
||||
describe("role delete", function() {
|
||||
it("should modify the given role", async function() {
|
||||
await execCtl("role delete new");
|
||||
let result = await link.messages.listRoles.send(getControl());
|
||||
let result = await libLink.messages.listRoles.send(getControl());
|
||||
let role = result.list.find(role => role.name === "new");
|
||||
assert(!role, "Role was not deleted");
|
||||
});
|
||||
@@ -282,7 +282,7 @@ describe("Integration of Clusterio", function() {
|
||||
describe("user create", function() {
|
||||
it("should create the given user", async function() {
|
||||
await execCtl("user create temp");
|
||||
let result = await link.messages.listUsers.send(getControl());
|
||||
let result = await libLink.messages.listUsers.send(getControl());
|
||||
let user = result.list.find(user => user.name === "temp");
|
||||
assert(user, "user was not created");
|
||||
});
|
||||
@@ -291,7 +291,7 @@ describe("Integration of Clusterio", function() {
|
||||
describe("user set-roles", function() {
|
||||
it("should set the roles on the user", async function() {
|
||||
await execCtl("user set-roles temp Admin");
|
||||
let result = await link.messages.listUsers.send(getControl());
|
||||
let result = await libLink.messages.listUsers.send(getControl());
|
||||
let user = result.list.find(user => user.name === "temp");
|
||||
assert.deepEqual(user.roles, [0]);
|
||||
});
|
||||
@@ -300,7 +300,7 @@ describe("Integration of Clusterio", function() {
|
||||
describe("user delete", function() {
|
||||
it("should delete the user", async function() {
|
||||
await execCtl("user delete temp");
|
||||
let result = await link.messages.listUsers.send(getControl());
|
||||
let result = await libLink.messages.listUsers.send(getControl());
|
||||
let user = result.list.find(user => user.name === "temp");
|
||||
assert(!user, "user was note deleted");
|
||||
});
|
||||
|
||||
@@ -2,17 +2,17 @@
|
||||
const assert = require("assert").strict;
|
||||
const path = require("path");
|
||||
|
||||
const factorio = require("@clusterio/lib/factorio");
|
||||
const libFactorio = require("@clusterio/lib/factorio");
|
||||
|
||||
|
||||
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 factorio.FactorioServer("factorio", writePath, {});
|
||||
let testServer = new libFactorio.FactorioServer("factorio", writePath, {});
|
||||
await testServer.init();
|
||||
|
||||
let locale = await factorio._exportLocale(testServer, new Map(), ["base"], "en");
|
||||
let locale = await libFactorio._exportLocale(testServer, new Map(), ["base"], "en");
|
||||
|
||||
assert(locale instanceof Map, "locale is not a map");
|
||||
assert.equal(locale.get("entity-name.fish"), "Fish");
|
||||
|
||||
@@ -7,14 +7,14 @@ const phin = require("phin");
|
||||
const util = require("util");
|
||||
const events = require("events");
|
||||
|
||||
const link = require("@clusterio/lib/link");
|
||||
const libLink = require("@clusterio/lib/link");
|
||||
const server = require("@clusterio/lib/factorio/server");
|
||||
|
||||
|
||||
class TestControl extends link.Link {
|
||||
class TestControl extends libLink.Link {
|
||||
constructor(connector) {
|
||||
super("control", "master", connector);
|
||||
link.attachAllMessages(this);
|
||||
libLink.attachAllMessages(this);
|
||||
}
|
||||
|
||||
async prepareDisconnectRequestHandler(message, request) {
|
||||
@@ -27,7 +27,7 @@ class TestControl extends link.Link {
|
||||
async instanceOutputEventHandler() { }
|
||||
}
|
||||
|
||||
class TestControlConnector extends link.WebSocketClientConnector {
|
||||
class TestControlConnector extends libLink.WebSocketClientConnector {
|
||||
register() {
|
||||
this.sendHandshake("register_control", { token: this.token, agent: "clusterioctl", version: "test" });
|
||||
}
|
||||
@@ -81,7 +81,7 @@ async function execCtl(...args) {
|
||||
}
|
||||
|
||||
async function sendRcon(instanceId, command) {
|
||||
let response = await link.messages.sendRcon.send(control, { instance_id: instanceId, command });
|
||||
let response = await libLink.messages.sendRcon.send(control, { instance_id: instanceId, command });
|
||||
return response.result;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ const fs = require("fs-extra");
|
||||
const jszip = require("jszip");
|
||||
const path = require("path");
|
||||
|
||||
const factorio = require("@clusterio/lib/factorio");
|
||||
const libFactorio = require("@clusterio/lib/factorio");
|
||||
|
||||
const { slowTest } = require("./index");
|
||||
|
||||
@@ -17,7 +17,7 @@ describe("Integration of lib/factorio/patch", function() {
|
||||
let savePath = path.join("temp", "test", "integration", "saves", "test.zip");
|
||||
it("should patch a freeplay game", async function() {
|
||||
slowTest(this);
|
||||
await factorio.patch(savePath, [{
|
||||
await libFactorio.patch(savePath, [{
|
||||
name: "test",
|
||||
version: "1.0.0",
|
||||
dependencies: {},
|
||||
@@ -39,7 +39,7 @@ describe("Integration of lib/factorio/patch", function() {
|
||||
});
|
||||
it("should remove old modules in a save", async function() {
|
||||
slowTest(this);
|
||||
await factorio.patch(savePath, []);
|
||||
await libFactorio.patch(savePath, []);
|
||||
let zip = await jszip.loadAsync(await fs.readFile(savePath));
|
||||
assert.equal(zip.file("test/modules/test/test.lua"), null);
|
||||
});
|
||||
|
||||
@@ -4,8 +4,8 @@ const events = require("events");
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const factorio = require("@clusterio/lib/factorio");
|
||||
const errors = require("@clusterio/lib/errors");
|
||||
const libFactorio = require("@clusterio/lib/factorio");
|
||||
const libErrors = require("@clusterio/lib/errors");
|
||||
|
||||
const { slowTest } = require("./index");
|
||||
|
||||
@@ -13,7 +13,7 @@ const { slowTest } = require("./index");
|
||||
describe("Integration of lib/factorio/server", function() {
|
||||
describe("_getVersion()", function() {
|
||||
it("should get a version from factorio's changelog.txt", async function() {
|
||||
let version = await factorio._getVersion(path.join("factorio", "data", "changelog.txt"));
|
||||
let version = await libFactorio._getVersion(path.join("factorio", "data", "changelog.txt"));
|
||||
if (!/^\d+\.\d+\.\d+$/.test(version)) {
|
||||
assert.fail(`Detected version '${version}' does not followed the format x.y.z`);
|
||||
}
|
||||
@@ -22,7 +22,7 @@ describe("Integration of lib/factorio/server", function() {
|
||||
|
||||
describe("class FactorioServer", function() {
|
||||
let writePath = path.join("temp", "test", "integration");
|
||||
let server = new factorio.FactorioServer("factorio", writePath, {});
|
||||
let server = new libFactorio.FactorioServer("factorio", writePath, {});
|
||||
let logFile;
|
||||
|
||||
before(async function() {
|
||||
@@ -215,7 +215,9 @@ describe("Integration of lib/factorio/server", function() {
|
||||
|
||||
await assert.rejects(
|
||||
startPromise,
|
||||
new errors.EnvironmentError("Factorio server was unexpectedly killed, is the system low on memory?")
|
||||
new libErrors.EnvironmentError(
|
||||
"Factorio server was unexpectedly killed, is the system low on memory?"
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
@@ -225,7 +227,7 @@ describe("Integration of lib/factorio/server", function() {
|
||||
|
||||
await assert.rejects(
|
||||
server.start("does-not-exist.zip"),
|
||||
new errors.EnvironmentError("Factorio server unexpectedly shut down with code 1")
|
||||
new libErrors.EnvironmentError("Factorio server unexpectedly shut down with code 1")
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
+18
-18
@@ -1,9 +1,9 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
|
||||
const command = require("@clusterio/lib/command");
|
||||
const errors = require("@clusterio/lib/errors");
|
||||
const link = require("@clusterio/lib/link");
|
||||
const libCommand = require("@clusterio/lib/command");
|
||||
const libErrors = require("@clusterio/lib/errors");
|
||||
const libLink = require("@clusterio/lib/link");
|
||||
const mock = require("../mock");
|
||||
|
||||
|
||||
@@ -39,49 +39,49 @@ describe("lib/command", function() {
|
||||
});
|
||||
|
||||
let testControl = new mock.MockControl(mockConnector);
|
||||
link.messages.listSlaves.attach(testControl);
|
||||
link.messages.listInstances.attach(testControl);
|
||||
link.messages.listRoles.attach(testControl);
|
||||
libLink.messages.listSlaves.attach(testControl);
|
||||
libLink.messages.listInstances.attach(testControl);
|
||||
libLink.messages.listRoles.attach(testControl);
|
||||
|
||||
describe("resolveSlave", function() {
|
||||
it("should pass an integer like string back", async function() {
|
||||
assert.equal(await command.resolveSlave(null, "123"), 123);
|
||||
assert.equal(await libCommand.resolveSlave(null, "123"), 123);
|
||||
});
|
||||
it("should resolve a slave name with the master server", async function() {
|
||||
assert.equal(await command.resolveSlave(testControl, "Test Slave"), 11);
|
||||
assert.equal(await libCommand.resolveSlave(testControl, "Test Slave"), 11);
|
||||
});
|
||||
it("should throw if slave is not found", async function() {
|
||||
await assert.rejects(
|
||||
command.resolveSlave(testControl, "invalid"),
|
||||
new errors.CommandError("No slave named invalid")
|
||||
libCommand.resolveSlave(testControl, "invalid"),
|
||||
new libErrors.CommandError("No slave named invalid")
|
||||
);
|
||||
});
|
||||
});
|
||||
describe("resolveInstance", function() {
|
||||
it("should pass an integer like string back", async function() {
|
||||
assert.equal(await command.resolveInstance(null, "123"), 123);
|
||||
assert.equal(await libCommand.resolveInstance(null, "123"), 123);
|
||||
});
|
||||
it("should resolve an instance name with the master server", async function() {
|
||||
assert.equal(await command.resolveInstance(testControl, "Test Instance"), 57);
|
||||
assert.equal(await libCommand.resolveInstance(testControl, "Test Instance"), 57);
|
||||
});
|
||||
it("should throw if instance is not found", async function() {
|
||||
await assert.rejects(
|
||||
command.resolveInstance(testControl, "invalid"),
|
||||
new errors.CommandError("No instance named invalid")
|
||||
libCommand.resolveInstance(testControl, "invalid"),
|
||||
new libErrors.CommandError("No instance named invalid")
|
||||
);
|
||||
});
|
||||
});
|
||||
describe("retrieveRole", function() {
|
||||
it("should retrieve a role by id from an integer like string", async function() {
|
||||
assert.deepEqual(await command.retrieveRole(testControl, "28"), testRole);
|
||||
assert.deepEqual(await libCommand.retrieveRole(testControl, "28"), testRole);
|
||||
});
|
||||
it("should retrieve a role by name from a string", async function() {
|
||||
assert.deepEqual(await command.retrieveRole(testControl, "Test Role"), testRole);
|
||||
assert.deepEqual(await libCommand.retrieveRole(testControl, "Test Role"), testRole);
|
||||
});
|
||||
it("should throw if role is not found", async function() {
|
||||
await assert.rejects(
|
||||
command.retrieveRole(testControl, "invalid"),
|
||||
new errors.CommandError("No role named invalid")
|
||||
libCommand.retrieveRole(testControl, "invalid"),
|
||||
new libErrors.CommandError("No role named invalid")
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
+34
-34
@@ -3,24 +3,24 @@ const assert = require("assert").strict;
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const database = require("@clusterio/lib/database");
|
||||
const libDatabase = require("@clusterio/lib/database");
|
||||
|
||||
describe("lib/database", function() {
|
||||
describe("mapToObject()", function() {
|
||||
it("should throw on non-string key", function() {
|
||||
assert.throws(
|
||||
() => database.mapToObject(new Map([[1, 1]])),
|
||||
() => libDatabase.mapToObject(new Map([[1, 1]])),
|
||||
new Error("Expected all keys to be string but got number")
|
||||
);
|
||||
assert.throws(
|
||||
() => database.mapToObject(new Map([[Symbol("test"), 1]])),
|
||||
() => libDatabase.mapToObject(new Map([[Symbol("test"), 1]])),
|
||||
new Error("Expected all keys to be string but got symbol")
|
||||
);
|
||||
});
|
||||
|
||||
it("should throw convert a map to an object", function() {
|
||||
assert.deepEqual(
|
||||
database.mapToObject(new Map([["a", 1], ["b", true]])),
|
||||
libDatabase.mapToObject(new Map([["a", 1], ["b", true]])),
|
||||
{ "a": 1, "b": true }
|
||||
);
|
||||
});
|
||||
@@ -32,7 +32,7 @@ describe("lib/database", function() {
|
||||
for (let type of badTypes) {
|
||||
it(`should reject on ${type} JSON`, async function() {
|
||||
await assert.rejects(
|
||||
database.loadJsonAsMap(path.join("test", "file", "json", `${type}.json`)),
|
||||
libDatabase.loadJsonAsMap(path.join("test", "file", "json", `${type}.json`)),
|
||||
new Error(`Expected object but got ${type}`)
|
||||
);
|
||||
});
|
||||
@@ -40,21 +40,21 @@ describe("lib/database", function() {
|
||||
|
||||
it("should work on empty object JSON", async function() {
|
||||
assert.deepEqual(
|
||||
await database.loadJsonAsMap(path.join("test", "file", "json", "object.json")),
|
||||
await libDatabase.loadJsonAsMap(path.join("test", "file", "json", "object.json")),
|
||||
new Map()
|
||||
);
|
||||
});
|
||||
|
||||
it("should work on object JSON", async function() {
|
||||
assert.deepEqual(
|
||||
await database.loadJsonAsMap(path.join("test", "file", "json", "load_map.json")),
|
||||
await libDatabase.loadJsonAsMap(path.join("test", "file", "json", "load_map.json")),
|
||||
new Map([["a", 1], ["b", true]])
|
||||
);
|
||||
});
|
||||
|
||||
it("should give an empty Map for non-existant file", async function() {
|
||||
assert.deepEqual(
|
||||
await database.loadJsonAsMap(path.join("test", "file", "json", "does-not-exist")),
|
||||
await libDatabase.loadJsonAsMap(path.join("test", "file", "json", "does-not-exist")),
|
||||
new Map()
|
||||
);
|
||||
});
|
||||
@@ -75,7 +75,7 @@ describe("lib/database", function() {
|
||||
}
|
||||
|
||||
await deleteTestFile();
|
||||
await database.saveMapAsJson(
|
||||
await libDatabase.saveMapAsJson(
|
||||
testFile, new Map([["c", {}], ["d", "foo"]])
|
||||
);
|
||||
|
||||
@@ -92,7 +92,7 @@ describe("lib/database", function() {
|
||||
for (let type of badTypes) {
|
||||
it(`should reject on ${type} JSON`, async function() {
|
||||
await assert.rejects(
|
||||
database.loadJsonArrayAsMap(path.join("test", "file", "json", `${type}.json`)),
|
||||
libDatabase.loadJsonArrayAsMap(path.join("test", "file", "json", `${type}.json`)),
|
||||
new Error(`Expected array but got ${type}`)
|
||||
);
|
||||
});
|
||||
@@ -100,35 +100,35 @@ describe("lib/database", function() {
|
||||
|
||||
it("should reject on null element", async function() {
|
||||
await assert.rejects(
|
||||
database.loadJsonArrayAsMap(path.join("test", "file", "json", "array_null.json")),
|
||||
libDatabase.loadJsonArrayAsMap(path.join("test", "file", "json", "array_null.json")),
|
||||
new Error("Expected all elements to be objects")
|
||||
);
|
||||
});
|
||||
|
||||
it("should reject on element missing id", async function() {
|
||||
await assert.rejects(
|
||||
database.loadJsonArrayAsMap(path.join("test", "file", "json", "array_object.json")),
|
||||
libDatabase.loadJsonArrayAsMap(path.join("test", "file", "json", "array_object.json")),
|
||||
new Error("Expected all elements to have an id property")
|
||||
);
|
||||
});
|
||||
|
||||
it("should work on empty array JSON", async function() {
|
||||
assert.deepEqual(
|
||||
await database.loadJsonArrayAsMap(path.join("test", "file", "json", "array.json")),
|
||||
await libDatabase.loadJsonArrayAsMap(path.join("test", "file", "json", "array.json")),
|
||||
new Map()
|
||||
);
|
||||
});
|
||||
|
||||
it("should work on array JSON", async function() {
|
||||
assert.deepEqual(
|
||||
await database.loadJsonArrayAsMap(path.join("test", "file", "json", "load_array_map.json")),
|
||||
await libDatabase.loadJsonArrayAsMap(path.join("test", "file", "json", "load_array_map.json")),
|
||||
new Map([["a", { id: "a" }], ["b", { id: "b" }]])
|
||||
);
|
||||
});
|
||||
|
||||
it("should give an empty Map for non-existant file", async function() {
|
||||
assert.deepEqual(
|
||||
await database.loadJsonArrayAsMap(path.join("test", "file", "json", "does-not-exist")),
|
||||
await libDatabase.loadJsonArrayAsMap(path.join("test", "file", "json", "does-not-exist")),
|
||||
new Map()
|
||||
);
|
||||
});
|
||||
@@ -149,7 +149,7 @@ describe("lib/database", function() {
|
||||
}
|
||||
|
||||
await deleteTestFile();
|
||||
await database.saveMapAsJsonArray(
|
||||
await libDatabase.saveMapAsJsonArray(
|
||||
testFile, new Map([["c", { id: "c" }], ["d", { id: "d" }]])
|
||||
);
|
||||
|
||||
@@ -163,23 +163,23 @@ describe("lib/database", function() {
|
||||
describe("class ItemDatabase", function() {
|
||||
describe("constructor()", function() {
|
||||
it("should create an empty database with no args", function() {
|
||||
let items = new database.ItemDatabase();
|
||||
let items = new libDatabase.ItemDatabase();
|
||||
assert.deepEqual(items._items, new Map());
|
||||
});
|
||||
|
||||
it("should restore the passed serialized database", function() {
|
||||
let items = new database.ItemDatabase({ "a": 1, "b": 2 });
|
||||
let items = new libDatabase.ItemDatabase({ "a": 1, "b": 2 });
|
||||
assert.deepEqual(items._items, new Map([["a", 1], ["b", 2]]));
|
||||
});
|
||||
|
||||
it("should throw on invalid serialized database", function() {
|
||||
assert.throws(
|
||||
() => new database.ItemDatabase({ "a": NaN }),
|
||||
() => new libDatabase.ItemDatabase({ "a": NaN }),
|
||||
new Error("count must be a number")
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
() => new database.ItemDatabase({ "a": "a" }),
|
||||
() => new libDatabase.ItemDatabase({ "a": "a" }),
|
||||
new Error("count must be a number")
|
||||
);
|
||||
});
|
||||
@@ -187,36 +187,36 @@ describe("lib/database", function() {
|
||||
|
||||
describe(".serialize()", function() {
|
||||
it("should return a serialized database", function() {
|
||||
let items = new database.ItemDatabase({ "a": 10 });
|
||||
let items = new libDatabase.ItemDatabase({ "a": 10 });
|
||||
assert.deepEqual(items.serialize(), { "a": 10 });
|
||||
});
|
||||
|
||||
it("should remove zero count entries", function() {
|
||||
let items = new database.ItemDatabase({ "a": 0 });
|
||||
let items = new libDatabase.ItemDatabase({ "a": 0 });
|
||||
assert.deepEqual(items.serialize(), {});
|
||||
});
|
||||
});
|
||||
|
||||
describe(".size", function() {
|
||||
it("should give an approximate size of the database", function() {
|
||||
let items = new database.ItemDatabase({ "a": 10 });
|
||||
let items = new libDatabase.ItemDatabase({ "a": 10 });
|
||||
assert.equal(items.size, 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe(".getItemCount()", function() {
|
||||
it("should return the count of the given item", function() {
|
||||
let items = new database.ItemDatabase({ "a": 10 });
|
||||
let items = new libDatabase.ItemDatabase({ "a": 10 });
|
||||
assert.equal(items.getItemCount("a"), 10);
|
||||
});
|
||||
|
||||
it("should return zero if item does not exist", function() {
|
||||
let items = new database.ItemDatabase();
|
||||
let items = new libDatabase.ItemDatabase();
|
||||
assert.equal(items.getItemCount("b"), 0);
|
||||
});
|
||||
|
||||
it("should throw on invalid name", function() {
|
||||
let items = new database.ItemDatabase();
|
||||
let items = new libDatabase.ItemDatabase();
|
||||
assert.throws(
|
||||
() => items.getItemCount(2),
|
||||
new Error("name must be a string")
|
||||
@@ -226,19 +226,19 @@ describe("lib/database", function() {
|
||||
|
||||
describe(".addItem()", function() {
|
||||
it("should add a new item", function() {
|
||||
let items = new database.ItemDatabase();
|
||||
let items = new libDatabase.ItemDatabase();
|
||||
items.addItem("a", 10);
|
||||
assert.deepEqual(items._items, new Map([["a", 10]]));
|
||||
});
|
||||
|
||||
it("should add an existing item", function() {
|
||||
let items = new database.ItemDatabase({ "a": 10 });
|
||||
let items = new libDatabase.ItemDatabase({ "a": 10 });
|
||||
items.addItem("a", 10);
|
||||
assert.deepEqual(items._items, new Map([["a", 20]]));
|
||||
});
|
||||
|
||||
it("should throw on invalid name", function() {
|
||||
let items = new database.ItemDatabase();
|
||||
let items = new libDatabase.ItemDatabase();
|
||||
assert.throws(
|
||||
() => items.addItem(2, 10),
|
||||
new Error("name must be a string")
|
||||
@@ -246,7 +246,7 @@ describe("lib/database", function() {
|
||||
});
|
||||
|
||||
it("should throw on invalid count", function() {
|
||||
let items = new database.ItemDatabase();
|
||||
let items = new libDatabase.ItemDatabase();
|
||||
assert.throws(
|
||||
() => items.addItem("a", NaN),
|
||||
new Error("count must be a number")
|
||||
@@ -260,19 +260,19 @@ describe("lib/database", function() {
|
||||
|
||||
describe(".removeItem()", function() {
|
||||
it("should remove an existing item", function() {
|
||||
let items = new database.ItemDatabase({ "a": 20 });
|
||||
let items = new libDatabase.ItemDatabase({ "a": 20 });
|
||||
items.removeItem("a", 10);
|
||||
assert.deepEqual(items._items, new Map([["a", 10]]));
|
||||
});
|
||||
|
||||
it("should turn a non-existing item negative", function() {
|
||||
let items = new database.ItemDatabase();
|
||||
let items = new libDatabase.ItemDatabase();
|
||||
items.removeItem("a", 10);
|
||||
assert.deepEqual(items._items, new Map([["a", -10]]));
|
||||
});
|
||||
|
||||
it("should throw on invalid name", function() {
|
||||
let items = new database.ItemDatabase();
|
||||
let items = new libDatabase.ItemDatabase();
|
||||
assert.throws(
|
||||
() => items.removeItem(2, 10),
|
||||
new Error("name must be a string")
|
||||
@@ -280,7 +280,7 @@ describe("lib/database", function() {
|
||||
});
|
||||
|
||||
it("should throw on invalid count", function() {
|
||||
let items = new database.ItemDatabase();
|
||||
let items = new libDatabase.ItemDatabase();
|
||||
assert.throws(
|
||||
() => items.removeItem("a", "b"),
|
||||
new Error("count must be a number")
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
const assert = require("assert").strict;
|
||||
const path = require("path");
|
||||
|
||||
const factorio = require("@clusterio/lib/factorio");
|
||||
const libFactorio = require("@clusterio/lib/factorio");
|
||||
|
||||
|
||||
describe("lib/factorio/export", function() {
|
||||
@@ -10,12 +10,12 @@ describe("lib/factorio/export", function() {
|
||||
let testServer;
|
||||
before(async function() {
|
||||
let writePath = path.join("temp", "test", "server");
|
||||
testServer = new factorio.FactorioServer(path.join("test", "file", "factorio"), writePath, {});
|
||||
testServer = new libFactorio.FactorioServer(path.join("test", "file", "factorio"), writePath, {});
|
||||
await testServer.init();
|
||||
});
|
||||
|
||||
it("returns a flattened mapping with locale definitions", async function() {
|
||||
let locale = await factorio._exportLocale(testServer, new Map(), ["base"], "en");
|
||||
let locale = await libFactorio._exportLocale(testServer, new Map(), ["base"], "en");
|
||||
assert.deepEqual(locale, new Map([["test.key-a", "1"], ["test.key-b", "2"]]));
|
||||
});
|
||||
});
|
||||
|
||||
+16
-16
@@ -4,7 +4,7 @@ const fs = require("fs-extra");
|
||||
const jszip = require("jszip");
|
||||
const path = require("path");
|
||||
|
||||
const factorio = require("@clusterio/lib/factorio");
|
||||
const libFactorio = require("@clusterio/lib/factorio");
|
||||
|
||||
|
||||
describe("lib/factorio", function() {
|
||||
@@ -14,7 +14,7 @@ describe("lib/factorio", function() {
|
||||
zip.file("root/foo.txt", "");
|
||||
zip.file("root/bar.txt", "");
|
||||
|
||||
assert.equal(factorio._findRoot(zip), "root");
|
||||
assert.equal(libFactorio._findRoot(zip), "root");
|
||||
});
|
||||
|
||||
it("should throw if files are at the root of the zip", function() {
|
||||
@@ -23,7 +23,7 @@ describe("lib/factorio", function() {
|
||||
zip.file("bar.txt", "");
|
||||
|
||||
assert.throws(
|
||||
() => factorio._findRoot(zip),
|
||||
() => libFactorio._findRoot(zip),
|
||||
new Error("Zip contains file 'bar.txt' in root dir")
|
||||
);
|
||||
});
|
||||
@@ -34,7 +34,7 @@ describe("lib/factorio", function() {
|
||||
zip.file("root-2/bar.txt", "");
|
||||
|
||||
assert.throws(
|
||||
() => factorio._findRoot(zip),
|
||||
() => libFactorio._findRoot(zip),
|
||||
new Error("Zip contains multiple root folders")
|
||||
);
|
||||
});
|
||||
@@ -43,7 +43,7 @@ describe("lib/factorio", function() {
|
||||
let zip = new jszip();
|
||||
|
||||
assert.throws(
|
||||
() => factorio._findRoot(zip),
|
||||
() => libFactorio._findRoot(zip),
|
||||
new Error("Empty zip file")
|
||||
);
|
||||
});
|
||||
@@ -79,7 +79,7 @@ describe("lib/factorio", function() {
|
||||
};
|
||||
|
||||
it("should produce output matching the reference", function() {
|
||||
assert.equal(factorio._generateLoader(patchInfo), reference);
|
||||
assert.equal(libFactorio._generateLoader(patchInfo), reference);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -89,7 +89,7 @@ describe("lib/factorio", function() {
|
||||
{ name: "a", version: "1.0.0", dependencies: {"b": "*"} },
|
||||
{ name: "b", version: "1.0.0", dependencies: {} },
|
||||
];
|
||||
factorio._reorderDependencies(modules);
|
||||
libFactorio._reorderDependencies(modules);
|
||||
assert(modules[0].name === "b", "Dependency was not reorederd");
|
||||
});
|
||||
it("should throw on invalid version", function() {
|
||||
@@ -97,7 +97,7 @@ describe("lib/factorio", function() {
|
||||
{ name: "a", version: "foo", dependencies: {} },
|
||||
];
|
||||
assert.throws(
|
||||
() => factorio._reorderDependencies(modules),
|
||||
() => libFactorio._reorderDependencies(modules),
|
||||
new Error("Invalid version 'foo' for module a")
|
||||
);
|
||||
});
|
||||
@@ -106,7 +106,7 @@ describe("lib/factorio", function() {
|
||||
{ name: "a", version: "1.0.0", dependencies: {"b": "invalid"} },
|
||||
];
|
||||
assert.throws(
|
||||
() => factorio._reorderDependencies(modules),
|
||||
() => libFactorio._reorderDependencies(modules),
|
||||
new Error("Invalid version range 'invalid' for dependency b on module a")
|
||||
);
|
||||
});
|
||||
@@ -115,7 +115,7 @@ describe("lib/factorio", function() {
|
||||
{ name: "a", version: "1.0.0", dependencies: {"b": "*"} },
|
||||
];
|
||||
assert.throws(
|
||||
() => factorio._reorderDependencies(modules),
|
||||
() => libFactorio._reorderDependencies(modules),
|
||||
new Error("Missing dependency b for module a")
|
||||
);
|
||||
modules = [
|
||||
@@ -124,7 +124,7 @@ describe("lib/factorio", function() {
|
||||
{ name: "c", version: "1.0.0", dependencies: {"d": "*"} },
|
||||
];
|
||||
assert.throws(
|
||||
() => factorio._reorderDependencies(modules),
|
||||
() => libFactorio._reorderDependencies(modules),
|
||||
new Error("Missing dependency d for module c")
|
||||
);
|
||||
});
|
||||
@@ -134,7 +134,7 @@ describe("lib/factorio", function() {
|
||||
{ name: "b", version: "1.0.0", dependencies: {"a": ">=2"} },
|
||||
];
|
||||
assert.throws(
|
||||
() => factorio._reorderDependencies(modules),
|
||||
() => libFactorio._reorderDependencies(modules),
|
||||
new Error("Module b requires a >=2")
|
||||
);
|
||||
});
|
||||
@@ -144,7 +144,7 @@ describe("lib/factorio", function() {
|
||||
{ name: "b", version: "1.0.0", dependencies: {"a": "*"} },
|
||||
];
|
||||
assert.throws(
|
||||
() => factorio._reorderDependencies(modules),
|
||||
() => libFactorio._reorderDependencies(modules),
|
||||
new Error("Module dependency loop detected: a -> b -> a")
|
||||
);
|
||||
modules = [
|
||||
@@ -154,7 +154,7 @@ describe("lib/factorio", function() {
|
||||
{ name: "c", version: "1.0.0", dependencies: {"a": "*"} },
|
||||
];
|
||||
assert.throws(
|
||||
() => factorio._reorderDependencies(modules),
|
||||
() => libFactorio._reorderDependencies(modules),
|
||||
new Error("Module dependency loop detected: b -> c -> a -> b")
|
||||
);
|
||||
});
|
||||
@@ -194,7 +194,7 @@ describe("lib/factorio", function() {
|
||||
}
|
||||
let success = false;
|
||||
try {
|
||||
factorio._reorderDependencies(modules);
|
||||
libFactorio._reorderDependencies(modules);
|
||||
success = true;
|
||||
} catch (err) { }
|
||||
if (success) {
|
||||
@@ -217,7 +217,7 @@ describe("lib/factorio", function() {
|
||||
await fs.outputFile(zipPath, await zip.generateAsync({ type: "nodebuffer" }));
|
||||
|
||||
await assert.rejects(
|
||||
factorio.patch(zipPath, []),
|
||||
libFactorio.patch(zipPath, []),
|
||||
new Error("Unable to patch save, unknown scenario (3acc3be3861144e55604f5ac2f2555071885ebc4)")
|
||||
);
|
||||
});
|
||||
|
||||
+20
-20
@@ -4,22 +4,22 @@ const events = require("events");
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const factorio = require("@clusterio/lib/factorio");
|
||||
const libFactorio = require("@clusterio/lib/factorio");
|
||||
const { testLines } = require("./lines");
|
||||
|
||||
|
||||
describe("lib/factorio/server", function() {
|
||||
describe("_getVersion()", function() {
|
||||
it("should get the version from a changelog", async function() {
|
||||
let version = await factorio._getVersion(path.join("test", "file", "changelog-test.txt"));
|
||||
let version = await libFactorio._getVersion(path.join("test", "file", "changelog-test.txt"));
|
||||
assert.equal(version, "0.1.1");
|
||||
});
|
||||
it("should return null if unable to find the version", async function() {
|
||||
let version = await factorio._getVersion(path.join("test", "file", "changelog-bad.txt"));
|
||||
let version = await libFactorio._getVersion(path.join("test", "file", "changelog-bad.txt"));
|
||||
assert.equal(version, null);
|
||||
});
|
||||
it("should return null if file does not exist", async function() {
|
||||
let version = await factorio._getVersion(path.join("test", "file", "does-not-exist.txt"));
|
||||
let version = await libFactorio._getVersion(path.join("test", "file", "does-not-exist.txt"));
|
||||
assert.equal(version, null);
|
||||
});
|
||||
});
|
||||
@@ -27,7 +27,7 @@ describe("lib/factorio/server", function() {
|
||||
describe("_versionOrder()", function() {
|
||||
it("should sort an array of versions", function() {
|
||||
let versions = ["1.2.3", "0.1.4", "0.1.2", "1.2.3", "0.1.5", "1.10.2"];
|
||||
versions.sort(factorio._versionOrder);
|
||||
versions.sort(libFactorio._versionOrder);
|
||||
assert.deepEqual(
|
||||
versions,
|
||||
["1.10.2", "1.2.3", "1.2.3", "0.1.5", "0.1.4", "0.1.2"]
|
||||
@@ -38,46 +38,46 @@ describe("lib/factorio/server", function() {
|
||||
describe("_findVersion()", function() {
|
||||
it("should find a given install dir with latest as target", async function() {
|
||||
let installDir = path.join("test", "file", "factorio");
|
||||
let [dir, version] = await factorio._findVersion(installDir, "latest");
|
||||
let [dir, version] = await libFactorio._findVersion(installDir, "latest");
|
||||
assert.equal(dir, path.join(installDir, "data"));
|
||||
assert.equal(version, "0.1.1");
|
||||
});
|
||||
it("should find a given install dir with correct version as target", async function() {
|
||||
let installDir = path.join("test", "file", "factorio");
|
||||
let [dir, version] = await factorio._findVersion(installDir, "0.1.1");
|
||||
let [dir, version] = await libFactorio._findVersion(installDir, "0.1.1");
|
||||
assert.equal(dir, path.join(installDir, "data"));
|
||||
assert.equal(version, "0.1.1");
|
||||
});
|
||||
it("should reject if the install dir version does not match target version", async function() {
|
||||
let installDir = path.join("test", "file", "factorio");
|
||||
await assert.rejects(
|
||||
factorio._findVersion(installDir, "0.1.2"),
|
||||
libFactorio._findVersion(installDir, "0.1.2"),
|
||||
new Error("Factorio version 0.1.2 was requested, but install directory contains 0.1.1")
|
||||
);
|
||||
});
|
||||
it("should search given directory for latest Factorio install", async function() {
|
||||
let installDir = path.join("test", "file");
|
||||
let [dir, version] = await factorio._findVersion(installDir, "latest");
|
||||
let [dir, version] = await libFactorio._findVersion(installDir, "latest");
|
||||
assert.equal(dir, path.join(installDir, "factorio", "data"));
|
||||
assert.equal(version, "0.1.1");
|
||||
});
|
||||
it("should search given directory for given Factorio install", async function() {
|
||||
let installDir = path.join("test", "file");
|
||||
let [dir, version] = await factorio._findVersion(installDir, "0.1.1");
|
||||
let [dir, version] = await libFactorio._findVersion(installDir, "0.1.1");
|
||||
assert.equal(dir, path.join(installDir, "factorio", "data"));
|
||||
assert.equal(version, "0.1.1");
|
||||
});
|
||||
it("should reject if no factorio install with the given version was found", async function() {
|
||||
let installDir = path.join("test", "file");
|
||||
await assert.rejects(
|
||||
factorio._findVersion(installDir, "0.1.2"),
|
||||
libFactorio._findVersion(installDir, "0.1.2"),
|
||||
new Error("Unable to find Factorio version 0.1.2")
|
||||
);
|
||||
});
|
||||
it("should reject if no factorio install was found", async function() {
|
||||
let installDir = path.join("test", "file", "instances");
|
||||
await assert.rejects(
|
||||
factorio._findVersion(installDir, "latest"),
|
||||
libFactorio._findVersion(installDir, "latest"),
|
||||
new Error(`Unable to find any Factorio install in ${installDir}`)
|
||||
);
|
||||
});
|
||||
@@ -85,7 +85,7 @@ describe("lib/factorio/server", function() {
|
||||
|
||||
describe("randomDynamicPort()", function() {
|
||||
it("should return a port number", function() {
|
||||
let port = factorio._randomDynamicPort();
|
||||
let port = libFactorio._randomDynamicPort();
|
||||
assert.equal(typeof port, "number");
|
||||
assert(Number.isInteger(port));
|
||||
assert(0 <= port && port < 2**16);
|
||||
@@ -96,31 +96,31 @@ describe("lib/factorio/server", function() {
|
||||
return (49152 <= port && port <= 65535);
|
||||
}
|
||||
for (let i=0; i < 20; i++) {
|
||||
assert(validate(factorio._randomDynamicPort()));
|
||||
assert(validate(libFactorio._randomDynamicPort()));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("generatePassword()", function() {
|
||||
it("should return a string", async function() {
|
||||
let password = await factorio._generatePassword(1);
|
||||
let password = await libFactorio._generatePassword(1);
|
||||
assert.equal(typeof password, "string");
|
||||
});
|
||||
|
||||
it("should return a string of the given length", async function() {
|
||||
let password = await factorio._generatePassword(10);
|
||||
let password = await libFactorio._generatePassword(10);
|
||||
assert.equal(password.length, 10);
|
||||
});
|
||||
|
||||
it("should contain only a-z, A-Z, 0-9", async function() {
|
||||
let password = await factorio._generatePassword(10);
|
||||
let password = await libFactorio._generatePassword(10);
|
||||
assert(/^[a-zA-Z0-9]+$/.test(password), `${password} failed test`);
|
||||
});
|
||||
});
|
||||
|
||||
describe("class LineSplitter", function() {
|
||||
function createSplitter(lines) {
|
||||
return new factorio._LineSplitter(line => lines.push(line.toString("utf-8")));
|
||||
return new libFactorio._LineSplitter(line => lines.push(line.toString("utf-8")));
|
||||
}
|
||||
|
||||
it("should split three lines", function() {
|
||||
@@ -159,7 +159,7 @@ describe("lib/factorio/server", function() {
|
||||
it("should parse the test lines", function() {
|
||||
for (let [line, reference] of testLines) {
|
||||
reference.source = "test";
|
||||
let output = factorio._parseOutput(line, "test");
|
||||
let output = libFactorio._parseOutput(line, "test");
|
||||
delete output.received;
|
||||
assert.deepEqual(output, reference);
|
||||
}
|
||||
@@ -168,7 +168,7 @@ describe("lib/factorio/server", function() {
|
||||
|
||||
describe("class FactorioServer", function() {
|
||||
let writePath = path.join("temp", "test", "server");
|
||||
let server = new factorio.FactorioServer(path.join("test", "file", "factorio"), writePath, {});
|
||||
let server = new libFactorio.FactorioServer(path.join("test", "file", "factorio"), writePath, {});
|
||||
|
||||
describe(".init()", function() {
|
||||
it("should not throw on first call", async function() {
|
||||
|
||||
@@ -3,10 +3,10 @@ const assert = require("assert").strict;
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const fileOps = require("@clusterio/lib/fileOps");
|
||||
const libFileOps = require("@clusterio/lib/file_ops");
|
||||
|
||||
describe("fileOps.js", function(){
|
||||
let baseDir = path.join("temp", "test", "fileOps");
|
||||
describe("lib/file_ops", function() {
|
||||
let baseDir = path.join("temp", "test", "file_ops");
|
||||
async function setupTestingEnv() {
|
||||
await fs.ensureDir(path.join(baseDir, "test", "folder"));
|
||||
await fs.ensureDir(path.join(baseDir, "test", "another folder"));
|
||||
@@ -17,17 +17,17 @@ describe("fileOps.js", function(){
|
||||
|
||||
before(setupTestingEnv);
|
||||
|
||||
describe("fileOps.getNewestFile()", function(){
|
||||
describe("getNewestFile()", function() {
|
||||
it("returns a string in a directory with files", async function() {
|
||||
let newest = await fileOps.getNewestFile(path.join(baseDir, "test"));
|
||||
let newest = await libFileOps.getNewestFile(path.join(baseDir, "test"));
|
||||
assert.equal(typeof newest, "string");
|
||||
});
|
||||
it("returns null if all entries were filtered out", async function() {
|
||||
let newest = await fileOps.getNewestFile(path.join(baseDir, "test"), (name) => !name.endsWith(".txt"));
|
||||
let newest = await libFileOps.getNewestFile(path.join(baseDir, "test"), (name) => !name.endsWith(".txt"));
|
||||
assert.equal(newest, null);
|
||||
});
|
||||
it("returns null if directory is empty", async function() {
|
||||
let newest = await fileOps.getNewestFile(path.join(baseDir, "test", "folder"));
|
||||
let newest = await libFileOps.getNewestFile(path.join(baseDir, "test", "folder"));
|
||||
assert.equal(newest, null);
|
||||
});
|
||||
});
|
||||
+3
-3
@@ -4,21 +4,21 @@ const fs = require("fs");
|
||||
const path = require("path");
|
||||
const stream = require("stream");
|
||||
|
||||
const hash = require("@clusterio/lib/hash");
|
||||
const libHash = require("@clusterio/lib/hash");
|
||||
|
||||
|
||||
describe("lib/hash", function() {
|
||||
describe("hashStream()", function() {
|
||||
it("should hash a stream of bytes", async function() {
|
||||
let stream = fs.createReadStream(path.join("test", "file", "hash.txt"));
|
||||
let result = await hash.hashStream(stream);
|
||||
let result = await libHash.hashStream(stream);
|
||||
assert.equal(result, "be417768b5c3c5c1d9bcb2e7c119196dd76b5570");
|
||||
});
|
||||
});
|
||||
|
||||
describe("hashFile()", function() {
|
||||
it("should hash a file", async function() {
|
||||
let result = await hash.hashFile(path.join("test", "file", "hash.txt"));
|
||||
let result = await libHash.hashFile(path.join("test", "file", "hash.txt"));
|
||||
assert.equal(result, "be417768b5c3c5c1d9bcb2e7c119196dd76b5570");
|
||||
});
|
||||
});
|
||||
|
||||
+7
-7
@@ -1,18 +1,18 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
|
||||
const helpers = require("@clusterio/lib/helpers");
|
||||
const libHelpers = require("@clusterio/lib/helpers");
|
||||
|
||||
|
||||
describe("lib/helpers", function() {
|
||||
describe("basicType()", function() {
|
||||
it("should return the expected values", function() {
|
||||
assert.equal(helpers.basicType("s"), "string");
|
||||
assert.equal(helpers.basicType(null), "null");
|
||||
assert.equal(helpers.basicType(undefined), "undefined");
|
||||
assert.equal(helpers.basicType([1, 2]), "array");
|
||||
assert.equal(helpers.basicType(7), "number");
|
||||
assert.equal(helpers.basicType({ a: 1 }), "object");
|
||||
assert.equal(libHelpers.basicType("s"), "string");
|
||||
assert.equal(libHelpers.basicType(null), "null");
|
||||
assert.equal(libHelpers.basicType(undefined), "undefined");
|
||||
assert.equal(libHelpers.basicType([1, 2]), "array");
|
||||
assert.equal(libHelpers.basicType(7), "number");
|
||||
assert.equal(libHelpers.basicType({ a: 1 }), "object");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -3,12 +3,12 @@ const assert = require("assert").strict;
|
||||
const events = require("events");
|
||||
|
||||
const mock = require("../../mock");
|
||||
const link = require("@clusterio/lib/link");
|
||||
const libLink = require("@clusterio/lib/link");
|
||||
|
||||
|
||||
describe("lib/link/connectors", function() {
|
||||
describe("class WebSocketBaseConnector", function() {
|
||||
let testConnector = new link.WebSocketBaseConnector();
|
||||
let testConnector = new libLink.WebSocketBaseConnector();
|
||||
|
||||
describe("._dropSendBufferSeq()", function() {
|
||||
beforeEach(function() {
|
||||
@@ -34,7 +34,7 @@ describe("lib/link/connectors", function() {
|
||||
});
|
||||
|
||||
describe("class WebSocketClientConnector", function() {
|
||||
let testConnector = new link.WebSocketClientConnector("url", 1);
|
||||
let testConnector = new libLink.WebSocketClientConnector("url", 1);
|
||||
testConnector._socket = new mock.MockSocket();
|
||||
|
||||
describe(".register()", function() {
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
const assert = require("assert").strict;
|
||||
const events = require("events");
|
||||
|
||||
const link = require("@clusterio/lib/link");
|
||||
const errors = require("@clusterio/lib/errors");
|
||||
const schema = require("@clusterio/lib/schema");
|
||||
const libLink = require("@clusterio/lib/link");
|
||||
const libErrors = require("@clusterio/lib/errors");
|
||||
const libSchema = require("@clusterio/lib/schema");
|
||||
const mock = require("../../mock");
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ describe("lib/link/link", function() {
|
||||
|
||||
before(function() {
|
||||
testConnector = new mock.MockConnector();
|
||||
testLink = new link.Link("source", "target", testConnector);
|
||||
testLink.setValidator("simple", schema.compile({
|
||||
testLink = new libLink.Link("source", "target", testConnector);
|
||||
testLink.setValidator("simple", libSchema.compile({
|
||||
properties: {
|
||||
"data": {
|
||||
type: "object",
|
||||
@@ -78,7 +78,7 @@ describe("lib/link/link", function() {
|
||||
it("should throw on message without validator", function() {
|
||||
assert.throws(
|
||||
() => testLink.processMessage({ seq: 1, type: "no_validator", data: {} }),
|
||||
new errors.InvalidMessage("No validator for no_validator on source-target")
|
||||
new libErrors.InvalidMessage("No validator for no_validator on source-target")
|
||||
);
|
||||
});
|
||||
it("should throw on message failing validation", function() {
|
||||
@@ -90,7 +90,7 @@ describe("lib/link/link", function() {
|
||||
it("should throw on unhandled message", function() {
|
||||
assert.throws(
|
||||
() => testLink.processMessage({ seq: 1, type: "simple", data: { string: "a" }}),
|
||||
new errors.InvalidMessage("Unhandled message simple")
|
||||
new libErrors.InvalidMessage("Unhandled message simple")
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
+11
-11
@@ -1,20 +1,20 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
|
||||
const link = require("@clusterio/lib/link");
|
||||
const errors = require("@clusterio/lib/errors");
|
||||
const libLink = require("@clusterio/lib/link");
|
||||
const libErrors = require("@clusterio/lib/errors");
|
||||
const mock = require("../../mock");
|
||||
|
||||
|
||||
describe("lib/link/messages", function() {
|
||||
let testSourceLink = new link.Link("source", "target", new mock.MockConnector());
|
||||
let testTargetLink = new link.Link("target", "source", new mock.MockConnector());
|
||||
let testSourceLink = new libLink.Link("source", "target", new mock.MockConnector());
|
||||
let testTargetLink = new libLink.Link("target", "source", new mock.MockConnector());
|
||||
|
||||
let lastTargetSent;
|
||||
testTargetLink.send = (type, data) => { lastTargetSent = { type, data }; };
|
||||
|
||||
describe("class Request", function() {
|
||||
let testRequest = new link.Request({
|
||||
let testRequest = new libLink.Request({
|
||||
type: "test",
|
||||
links: ["source-target"],
|
||||
requestProperties: {
|
||||
@@ -25,7 +25,7 @@ describe("lib/link/messages", function() {
|
||||
describe("constructor", function() {
|
||||
it("should throw on invalid forwardTo", function() {
|
||||
assert.throws(
|
||||
() => new link.Request({ links: [], forwardTo: "invalid" }),
|
||||
() => new libLink.Request({ links: [], forwardTo: "invalid" }),
|
||||
new Error("Invalid forwardTo value invalid")
|
||||
);
|
||||
});
|
||||
@@ -95,7 +95,7 @@ describe("lib/link/messages", function() {
|
||||
testSourceLink.waitFor = (type, condition) => ({ data: { error: "test error" }});
|
||||
await assert.rejects(
|
||||
testRequest.send(testSourceLink, { test: "blah" }),
|
||||
new errors.RequestError("test error")
|
||||
new libErrors.RequestError("test error")
|
||||
);
|
||||
delete testSourceLink.waitFor;
|
||||
});
|
||||
@@ -103,7 +103,7 @@ describe("lib/link/messages", function() {
|
||||
});
|
||||
|
||||
describe("class Event", function() {
|
||||
let testEvent = new link.Event({
|
||||
let testEvent = new libLink.Event({
|
||||
type: "test",
|
||||
links: ["source-target"],
|
||||
eventProperties: {
|
||||
@@ -114,13 +114,13 @@ describe("lib/link/messages", function() {
|
||||
describe("constructor", function() {
|
||||
it("should throw on invalid forwardTo", function() {
|
||||
assert.throws(
|
||||
() => new link.Event({ forwardTo: "invalid" }),
|
||||
() => new libLink.Event({ forwardTo: "invalid" }),
|
||||
new Error("Invalid forwardTo value invalid")
|
||||
);
|
||||
});
|
||||
it("should throw on invalid broadcastTo", function() {
|
||||
assert.throws(
|
||||
() => new link.Event({ broadcastTo: "invalid" }),
|
||||
() => new libLink.Event({ broadcastTo: "invalid" }),
|
||||
new Error("Invalid broadcastTo value invalid")
|
||||
);
|
||||
});
|
||||
@@ -159,7 +159,7 @@ describe("lib/link/messages", function() {
|
||||
|
||||
describe("attachAllMessages()", function() {
|
||||
it("does not throw", function() {
|
||||
link.attachAllMessages(testSourceLink);
|
||||
libLink.attachAllMessages(testSourceLink);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,31 +0,0 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
|
||||
const luaTools = require("@clusterio/lib/luaTools");
|
||||
|
||||
|
||||
describe("lib/luaTools", function() {
|
||||
describe("escapeString()", function() {
|
||||
it("should escape backslashes", function() {
|
||||
assert.equal(luaTools.escapeString("\\a"), "\\\\a");
|
||||
});
|
||||
it("should escape double quotes", function() {
|
||||
assert.equal(luaTools.escapeString('"a"'), '\\"a\\"');
|
||||
});
|
||||
it("should escape single quotes", function() {
|
||||
assert.equal(luaTools.escapeString("'a'"), "\\'a\\'");
|
||||
});
|
||||
it("should escape nul bytes", function() {
|
||||
assert.equal(luaTools.escapeString("a\0b"), "a\\0b");
|
||||
});
|
||||
it("should escape newlines", function() {
|
||||
assert.equal(luaTools.escapeString("a\nb"), "a\\nb");
|
||||
});
|
||||
it("should escape carriage return", function() {
|
||||
assert.equal(luaTools.escapeString("a\rb"), "a\\rb");
|
||||
});
|
||||
it("should escape all combined", function() {
|
||||
assert.equal(luaTools.escapeString("a\\b\"c'd\0e\nf\rg"), "a\\\\b\\\"c\\'d\\0e\\nf\\rg");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
|
||||
const libLuaTools = require("@clusterio/lib/lua_tools");
|
||||
|
||||
|
||||
describe("lib/lua_tools", function() {
|
||||
describe("escapeString()", function() {
|
||||
it("should escape backslashes", function() {
|
||||
assert.equal(libLuaTools.escapeString("\\a"), "\\\\a");
|
||||
});
|
||||
it("should escape double quotes", function() {
|
||||
assert.equal(libLuaTools.escapeString('"a"'), '\\"a\\"');
|
||||
});
|
||||
it("should escape single quotes", function() {
|
||||
assert.equal(libLuaTools.escapeString("'a'"), "\\'a\\'");
|
||||
});
|
||||
it("should escape nul bytes", function() {
|
||||
assert.equal(libLuaTools.escapeString("a\0b"), "a\\0b");
|
||||
});
|
||||
it("should escape newlines", function() {
|
||||
assert.equal(libLuaTools.escapeString("a\nb"), "a\\nb");
|
||||
});
|
||||
it("should escape carriage return", function() {
|
||||
assert.equal(libLuaTools.escapeString("a\rb"), "a\\rb");
|
||||
});
|
||||
it("should escape all combined", function() {
|
||||
assert.equal(libLuaTools.escapeString("a\\b\"c'd\0e\nf\rg"), "a\\\\b\\\"c\\'d\\0e\\nf\\rg");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,13 +1,13 @@
|
||||
"use strict";
|
||||
var assert = require("assert");
|
||||
var objectOps = require("@clusterio/lib/objectOps");
|
||||
var libObjectOps = require("@clusterio/lib/object_ops");
|
||||
|
||||
describe("objectOps.js", function(){
|
||||
describe("objectOps.deepclone()", function(){
|
||||
describe("lib/object_ops", function(){
|
||||
describe("deepclone()", function(){
|
||||
it("deep clones javascript objects", function(){
|
||||
var obj1 = { hello: "world", cat: { legs: 4, name: "Kitty", colors: ["brown", "yellow", "purple"] }};
|
||||
var obj2 = {};
|
||||
obj2 = objectOps.deepclone(obj1);
|
||||
obj2 = libObjectOps.deepclone(obj1);
|
||||
|
||||
obj1.cat.colors = "black";
|
||||
assert.equal(obj1.cat.colors, "black");
|
||||
@@ -15,7 +15,7 @@ describe("objectOps.js", function(){
|
||||
});
|
||||
it("throws on non JSON parameters", function(){
|
||||
assert.throws(function(){
|
||||
let y = objectOps.deepclone(objectOps.deepclone);
|
||||
let y = libObjectOps.deepclone(libObjectOps.deepclone);
|
||||
});
|
||||
});
|
||||
});
|
||||
+19
-18
@@ -4,16 +4,15 @@ const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const mock = require("../mock");
|
||||
const link = require("@clusterio/lib/link");
|
||||
const plugin = require("@clusterio/lib/plugin");
|
||||
const errors = require("@clusterio/lib/errors");
|
||||
const libLink = require("@clusterio/lib/link");
|
||||
const libPlugin = require("@clusterio/lib/plugin");
|
||||
|
||||
|
||||
describe("lib/plugin", function() {
|
||||
describe("class BaseInstancePlugin", function() {
|
||||
let instancePlugin;
|
||||
it("should be constructible", async function() {
|
||||
instancePlugin = new plugin.BaseInstancePlugin();
|
||||
instancePlugin = new libPlugin.BaseInstancePlugin();
|
||||
await instancePlugin.init();
|
||||
});
|
||||
it("should define defaults for hooks", async function() {
|
||||
@@ -30,7 +29,7 @@ describe("lib/plugin", function() {
|
||||
describe("class BaseMasterPlugin", function() {
|
||||
let masterPlugin;
|
||||
it("should be constructible", async function() {
|
||||
masterPlugin = new plugin.BaseMasterPlugin();
|
||||
masterPlugin = new libPlugin.BaseMasterPlugin();
|
||||
await masterPlugin.init();
|
||||
});
|
||||
it("should define defaults for hooks", async function() {
|
||||
@@ -68,50 +67,52 @@ describe("lib/plugin", function() {
|
||||
|
||||
it("should throw on missing plugin", async function() {
|
||||
await assert.rejects(
|
||||
plugin.loadPluginInfos(new Map([["missing", missingPlugin]]), []),
|
||||
libPlugin.loadPluginInfos(new Map([["missing", missingPlugin]]), []),
|
||||
new RegExp(`^Error: PluginError: Cannot find module '${missingPlugin}/info'`)
|
||||
);
|
||||
});
|
||||
it("should load test plugin", async function() {
|
||||
assert.deepEqual(
|
||||
await plugin.loadPluginInfos(new Map([["test", path.resolve(testPlugin)]])),
|
||||
await libPlugin.loadPluginInfos(new Map([["test", path.resolve(testPlugin)]])),
|
||||
[{ name: "test", version: "0.0.1", requirePath: path.resolve(testPlugin) }]
|
||||
);
|
||||
});
|
||||
it("should reject on broken plugin", async function() {
|
||||
await assert.rejects(
|
||||
plugin.loadPluginInfos(new Map([["broken", path.resolve(brokenPlugin)]])),
|
||||
libPlugin.loadPluginInfos(new Map([["broken", path.resolve(brokenPlugin)]])),
|
||||
{ message: "PluginError: Unexpected identifier" }
|
||||
);
|
||||
});
|
||||
it("should reject on invalid plugin", async function() {
|
||||
await assert.rejects(
|
||||
plugin.loadPluginInfos(new Map([["invalid", path.resolve(invalidPlugin)]])),
|
||||
libPlugin.loadPluginInfos(new Map([["invalid", path.resolve(invalidPlugin)]])),
|
||||
{ message: `Expected plugin at ${path.resolve(invalidPlugin)} to be named invalid but got wrong` }
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("attachPluginMessages()", function() {
|
||||
let mockLink = new link.Link("source", "target", new mock.MockConnector());
|
||||
let mockEvent = new link.Event({ type: "test:test", links: ["target-source"] });
|
||||
let mockLink = new libLink.Link("source", "target", new mock.MockConnector());
|
||||
let mockEvent = new libLink.Event({ type: "test:test", links: ["target-source"] });
|
||||
it("should accept pluginInfo without messages", function() {
|
||||
plugin.attachPluginMessages(mockLink, {}, null);
|
||||
libPlugin.attachPluginMessages(mockLink, {}, null);
|
||||
});
|
||||
it("should attach handler for the given message", function() {
|
||||
function mockEventEventHandler() { };
|
||||
plugin.attachPluginMessages(mockLink, { name: "test", messages: { mockEvent }}, { mockEventEventHandler });
|
||||
libPlugin.attachPluginMessages(
|
||||
mockLink, { name: "test", messages: { mockEvent }}, { mockEventEventHandler }
|
||||
);
|
||||
assert(mockLink._handlers.get("test:test_event"), "handler was not registered");
|
||||
});
|
||||
it("should throw if missing handler for the given message", function() {
|
||||
assert.throws(
|
||||
() => plugin.attachPluginMessages(mockLink, { name: "test", messages: { mockEvent }}, {}),
|
||||
() => libPlugin.attachPluginMessages(mockLink, { name: "test", messages: { mockEvent }}, {}),
|
||||
new Error("Missing handler for test:test_event on source-target link")
|
||||
);
|
||||
});
|
||||
it("should throw if message starts with the wrong prefix", function() {
|
||||
assert.throws(
|
||||
() => plugin.attachPluginMessages(mockLink, { name: "foo", messages: { mockEvent }}, {}),
|
||||
() => libPlugin.attachPluginMessages(mockLink, { name: "foo", messages: { mockEvent }}, {}),
|
||||
new Error('Type of mockEvent message must start with "foo:"')
|
||||
);
|
||||
});
|
||||
@@ -132,15 +133,15 @@ describe("lib/plugin", function() {
|
||||
}],
|
||||
]);
|
||||
it("should invoke the hook on the plugin", async function() {
|
||||
await plugin.invokeHook(plugins, "test");
|
||||
await libPlugin.invokeHook(plugins, "test");
|
||||
assert(betaTestCalled, "Hook was not called");
|
||||
});
|
||||
it("should pass and return args", async function() {
|
||||
let result = await plugin.invokeHook(plugins, "pass", 1234);
|
||||
let result = await libPlugin.invokeHook(plugins, "pass", 1234);
|
||||
assert.deepEqual(result, [1234]);
|
||||
});
|
||||
it("should ignore errors", async function() {
|
||||
await plugin.invokeHook(plugins, "error");
|
||||
await libPlugin.invokeHook(plugins, "error");
|
||||
});
|
||||
});
|
||||
});
|
||||
+30
-28
@@ -1,34 +1,36 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const users = require("@clusterio/lib/users");
|
||||
const libUsers = require("@clusterio/lib/users");
|
||||
|
||||
|
||||
describe("lib/users", function() {
|
||||
describe("definePermission()", function() {
|
||||
it("should validate the types of its arguments", function() {
|
||||
assert.throws(
|
||||
() => users.definePermission({ name: 123, title: "Test", description: "A test" }),
|
||||
() => libUsers.definePermission({ name: 123, title: "Test", description: "A test" }),
|
||||
new Error("Expected name to be a non-empty string")
|
||||
);
|
||||
assert.throws(
|
||||
() => users.definePermission({ name: "test", title: 123, description: "A test" }),
|
||||
() => libUsers.definePermission({ name: "test", title: 123, description: "A test" }),
|
||||
new Error("Expected title to be a non-empty string")
|
||||
);
|
||||
assert.throws(
|
||||
() => users.definePermission({ name: "test", title: "Test", description: 123 }),
|
||||
() => libUsers.definePermission({ name: "test", title: "Test", description: 123 }),
|
||||
new Error("Expected description to be a non-empty string")
|
||||
);
|
||||
assert.throws(
|
||||
() => users.definePermission({ name: "test", title: "Test", description: "A test", grantByDefault: 1 }),
|
||||
() => libUsers.definePermission({
|
||||
name: "test", title: "Test", description: "A test", grantByDefault: 1,
|
||||
}),
|
||||
new Error("Expected grantByDefault to be a boolean")
|
||||
);
|
||||
});
|
||||
|
||||
it("should define a permission", function() {
|
||||
users.definePermission({ name: "test", title: "Test", description: "A test" });
|
||||
assert(users.permissions.has("test"), "Permission was not defined");
|
||||
libUsers.definePermission({ name: "test", title: "Test", description: "A test" });
|
||||
assert(libUsers.permissions.has("test"), "Permission was not defined");
|
||||
|
||||
let test = users.permissions.get("test");
|
||||
let test = libUsers.permissions.get("test");
|
||||
assert.equal(test.name, "test");
|
||||
assert.equal(test.title, "Test");
|
||||
assert.equal(test.description, "A test");
|
||||
@@ -37,7 +39,7 @@ describe("lib/users", function() {
|
||||
|
||||
it("should throw on already defined permission", function() {
|
||||
assert.throws(
|
||||
() => users.definePermission({ name: "test", title: "Test", description: "A test" }),
|
||||
() => libUsers.definePermission({ name: "test", title: "Test", description: "A test" }),
|
||||
new Error("Permission 'test' is already defined")
|
||||
);
|
||||
});
|
||||
@@ -45,19 +47,19 @@ describe("lib/users", function() {
|
||||
|
||||
describe("class Role", function() {
|
||||
it("should round trip serialize", function() {
|
||||
let orig = new users.Role({ id: 11, name: "Role", description: "My Role", permissions: ["test"] });
|
||||
let copy = new users.Role(orig.serialize());
|
||||
let orig = new libUsers.Role({ id: 11, name: "Role", description: "My Role", permissions: ["test"] });
|
||||
let copy = new libUsers.Role(orig.serialize());
|
||||
assert.deepEqual(copy, orig);
|
||||
});
|
||||
|
||||
describe(".grantDefaultRoles()", function() {
|
||||
it("should only grant permissions with grantByDefault", function() {
|
||||
let role = new users.Role({ id: 11, name: "Role", description: "My Role" });
|
||||
let role = new libUsers.Role({ id: 11, name: "Role", description: "My Role" });
|
||||
role.grantDefaultPermissions();
|
||||
assert(role.permissions.size > 0, "No permissions were granted");
|
||||
for (let permission of role.permissions) {
|
||||
assert(
|
||||
users.permissions.get(permission).grantByDefault === true,
|
||||
libUsers.permissions.get(permission).grantByDefault === true,
|
||||
"Non-default permission granted"
|
||||
);
|
||||
}
|
||||
@@ -67,15 +69,15 @@ describe("lib/users", function() {
|
||||
|
||||
describe("class User", function() {
|
||||
let roles = new Map([
|
||||
[1, new users.Role({ id: 1, name: "a", description: "a role", permissions: ["core.admin"] })],
|
||||
[2, new users.Role({ id: 2, name: "b", description: "b role", permissions: ["test"] })],
|
||||
[1, new libUsers.Role({ id: 1, name: "a", description: "a role", permissions: ["core.admin"] })],
|
||||
[2, new libUsers.Role({ id: 2, name: "b", description: "b role", permissions: ["test"] })],
|
||||
]);
|
||||
it("should round trip serialize", function() {
|
||||
function test_roundtrip(serialized) {
|
||||
let user = new users.User(serialized, roles);
|
||||
let user = new libUsers.User(serialized, roles);
|
||||
let user_serialized = user.serialize();
|
||||
assert.deepEqual(user_serialized, serialized);
|
||||
let user_deserialized = new users.User(user_serialized, roles);
|
||||
let user_deserialized = new libUsers.User(user_serialized, roles);
|
||||
assert.deepEqual(user_deserialized, user);
|
||||
}
|
||||
|
||||
@@ -85,40 +87,40 @@ describe("lib/users", function() {
|
||||
test_roundtrip({ name: "user", is_banned: true, ban_reason: "Bad user" });
|
||||
});
|
||||
it("should ignore invalid roles", function() {
|
||||
let user = new users.User({ name: "test", roles: [1, 4, 55] }, roles);
|
||||
let user = new libUsers.User({ name: "test", roles: [1, 4, 55] }, roles);
|
||||
assert.equal(user.roles.size, 1, "Unexpected count of roles");
|
||||
});
|
||||
it("should track online users", function() {
|
||||
let user = new users.User({ name: "admin", roles: [1] }, roles);
|
||||
assert(!users.User.onlineUsers.has(user));
|
||||
let user = new libUsers.User({ name: "admin", roles: [1] }, roles);
|
||||
assert(!libUsers.User.onlineUsers.has(user));
|
||||
assert.deepEqual(user.instances, new Set());
|
||||
|
||||
user.notifyJoin(12);
|
||||
assert(users.User.onlineUsers.has(user));
|
||||
assert(libUsers.User.onlineUsers.has(user));
|
||||
assert.deepEqual(user.instances, new Set([12]));
|
||||
|
||||
user.notifyJoin(8);
|
||||
assert(users.User.onlineUsers.has(user));
|
||||
assert(libUsers.User.onlineUsers.has(user));
|
||||
assert.deepEqual(user.instances, new Set([12, 8]));
|
||||
|
||||
user.notifyLeave(11);
|
||||
assert(users.User.onlineUsers.has(user));
|
||||
assert(libUsers.User.onlineUsers.has(user));
|
||||
assert.deepEqual(user.instances, new Set([12, 8]));
|
||||
|
||||
user.notifyLeave(12);
|
||||
assert(users.User.onlineUsers.has(user));
|
||||
assert(libUsers.User.onlineUsers.has(user));
|
||||
assert.deepEqual(user.instances, new Set([8]));
|
||||
|
||||
user.notifyLeave(8);
|
||||
assert(!users.User.onlineUsers.has(user));
|
||||
assert(!libUsers.User.onlineUsers.has(user));
|
||||
assert.deepEqual(user.instances, new Set());
|
||||
});
|
||||
|
||||
describe(".checkPermission()", function() {
|
||||
it("should correctly resolve permissions", function() {
|
||||
let a = new users.User({ name: "admin", roles: [1] }, roles);
|
||||
let b = new users.User({ name: "user", roles: [2] }, roles);
|
||||
let c = new users.User({ name: "null", roles: [] }, roles);
|
||||
let a = new libUsers.User({ name: "admin", roles: [1] }, roles);
|
||||
let b = new libUsers.User({ name: "user", roles: [2] }, roles);
|
||||
let c = new libUsers.User({ name: "null", roles: [] }, roles);
|
||||
|
||||
a.checkPermission("core.control.connect");
|
||||
assert.throws(() => b.checkPermission("core.control.connect"), new Error("Permission denied"));
|
||||
|
||||
@@ -3,9 +3,9 @@ const assert = require("assert");
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const generateSSLcert = require("@clusterio/master/src/generate_ssl_cert");
|
||||
const generateSslCert = require("@clusterio/master/src/generate_ssl_cert");
|
||||
|
||||
describe("generateSSLcert.js(options)", function() {
|
||||
describe("generate_ssl_cert", function() {
|
||||
let testDir = path.join("temp", "test", "certTest");
|
||||
before(async function() {
|
||||
await fs.remove(testDir);
|
||||
@@ -21,7 +21,7 @@ describe("generateSSLcert.js(options)", function() {
|
||||
let certPath = path.join(testDir, "cert.crt");
|
||||
let privKeyPath = path.join(testDir, "cert.key");
|
||||
|
||||
await generateSSLcert({
|
||||
await generateSslCert({
|
||||
bits: 512, // This is too small for real world usage, but faster to test
|
||||
sslCertPath: certPath,
|
||||
sslPrivKeyPath: privKeyPath,
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
const events = require("events");
|
||||
|
||||
const link = require("@clusterio/lib/link");
|
||||
const libLink = require("@clusterio/lib/link");
|
||||
|
||||
|
||||
class MockSocket {
|
||||
@@ -77,7 +77,7 @@ class MockServer {
|
||||
}
|
||||
}
|
||||
|
||||
class MockInstance extends link.Link {
|
||||
class MockInstance extends libLink.Link {
|
||||
constructor() {
|
||||
super("instance", "slave", new MockConnector());
|
||||
this.server = new MockServer();
|
||||
@@ -92,13 +92,13 @@ class MockInstance extends link.Link {
|
||||
}
|
||||
}
|
||||
|
||||
class MockSlave extends link.Link {
|
||||
class MockSlave extends libLink.Link {
|
||||
constructor() {
|
||||
super("slave", "master", new MockConnector());
|
||||
}
|
||||
}
|
||||
|
||||
class MockControl extends link.Link {
|
||||
class MockControl extends libLink.Link {
|
||||
constructor(connector) {
|
||||
super("control", "master", connector);
|
||||
}
|
||||
|
||||
+8
-8
@@ -3,22 +3,22 @@ const assert = require("assert").strict;
|
||||
const path = require("path");
|
||||
const fs = require("fs-extra");
|
||||
|
||||
const link = require("@clusterio/lib/link");
|
||||
const config = require("@clusterio/lib/config");
|
||||
const libLink = require("@clusterio/lib/link");
|
||||
const libConfig = require("@clusterio/lib/config");
|
||||
const slave = require("@clusterio/slave/slave");
|
||||
|
||||
describe("Slave testing", function() {
|
||||
before(function() {
|
||||
config.InstanceConfig.finalize();
|
||||
libConfig.InstanceConfig.finalize();
|
||||
});
|
||||
|
||||
describe("class Instance", function() {
|
||||
let instance;
|
||||
before(async function() {
|
||||
let instanceConfig = new config.InstanceConfig();
|
||||
let instanceConfig = new libConfig.InstanceConfig();
|
||||
await instanceConfig.init();
|
||||
instanceConfig.set("instance.name", "foo");
|
||||
instance = new slave._Instance({}, new link.VirtualConnector(), "dir", "factorioDir", instanceConfig);
|
||||
instance = new slave._Instance({}, new libLink.VirtualConnector(), "dir", "factorioDir", instanceConfig);
|
||||
});
|
||||
|
||||
describe(".name", function() {
|
||||
@@ -106,11 +106,11 @@ describe("Slave testing", function() {
|
||||
await fs.outputFile(path.join(testDir, "shared", "mod_b.zip"), "b");
|
||||
await fs.outputFile(path.join(testDir, "shared", "mod.dat"), "c");
|
||||
|
||||
let instanceConfig = new config.InstanceConfig();
|
||||
let instanceConfig = new libConfig.InstanceConfig();
|
||||
await instanceConfig.init();
|
||||
instanceConfig.set("instance.name", "test");
|
||||
instance = new slave._Instance(
|
||||
{}, new link.VirtualConnector(), path.join(testDir, "instance"), "factorioDir", instanceConfig
|
||||
{}, new libLink.VirtualConnector(), path.join(testDir, "instance"), "factorioDir", instanceConfig
|
||||
);
|
||||
await fs.outputFile(instance.path("mods", "mod_i.zip"), "i");
|
||||
});
|
||||
@@ -161,7 +161,7 @@ describe("Slave testing", function() {
|
||||
let instanceInfos = new Map();
|
||||
await slave._discoverInstances(instanceInfos, instancePath, logger);
|
||||
|
||||
let referenceConfig = new config.InstanceConfig();
|
||||
let referenceConfig = new libConfig.InstanceConfig();
|
||||
await referenceConfig.init();
|
||||
referenceConfig.set("instance.id", 1);
|
||||
referenceConfig.set("instance.name", "test");
|
||||
|
||||
Reference in new issue
Block a user