mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 07:33:12 +09:00
Rename Master to Controller
The role of the master server as the party controlling every part of the cluster is not well reflected in its name and has caused confusion among users on several occasions. Rename master to controller to better reflects its role.
This commit is contained in:
1 parent
6ae4c8ef46
commit
70ad295a89
119 files changed
+1394
-1376
No files matched your search
@@ -8,7 +8,7 @@ const util = require("util");
|
||||
const phin = require("phin");
|
||||
|
||||
const { wait } = require("@clusterio/lib/helpers");
|
||||
const HttpCloser = require("@clusterio/master/src/HttpCloser");
|
||||
const HttpCloser = require("@clusterio/controller/src/HttpCloser");
|
||||
|
||||
// Time to wait during async operations to ensure they happened in order.
|
||||
const tick = 20;
|
||||
@@ -190,7 +190,7 @@ function serverSuite(proto) {
|
||||
});
|
||||
}
|
||||
|
||||
describe("master/src/HttpCloser.js", function() {
|
||||
describe("controller/src/HttpCloser.js", function() {
|
||||
describe("class HttpCloser", function() {
|
||||
describe("constructor()", function() {
|
||||
it("should throw if not passed a Server instance", function() {
|
||||
@@ -7,18 +7,18 @@ const http = require("http");
|
||||
const phin = require("phin");
|
||||
|
||||
const { wait } = require("@clusterio/lib/helpers");
|
||||
const routes = require("@clusterio/master/src/routes");
|
||||
const routes = require("@clusterio/controller/src/routes");
|
||||
const mock = require("../mock");
|
||||
|
||||
|
||||
describe("master/src/routes", function() {
|
||||
let master;
|
||||
describe("controller/src/routes", function() {
|
||||
let controller;
|
||||
let server;
|
||||
let port;
|
||||
beforeEach(async function() {
|
||||
master = new mock.MockMaster();
|
||||
routes.addRouteHandlers(master.app);
|
||||
server = http.createServer(master.app);
|
||||
controller = new mock.MockController();
|
||||
routes.addRouteHandlers(controller.app);
|
||||
server = http.createServer(controller.app);
|
||||
server.listen(0, "localhost");
|
||||
await events.once(server, "listening");
|
||||
port = server.address().port;
|
||||
@@ -38,14 +38,14 @@ describe("master/src/routes", function() {
|
||||
assert.equal(response.statusCode, 404);
|
||||
});
|
||||
it("should respond with 500 if stream times out", async function() {
|
||||
let stream = await routes.createProxyStream(master.app);
|
||||
let stream = await routes.createProxyStream(controller.app);
|
||||
let response = await phin(`http://localhost:${port}/api/stream/${stream.id}`);
|
||||
assert.equal(response.statusCode, 500);
|
||||
});
|
||||
it("should passthrough a stream", async function() {
|
||||
let stream;
|
||||
let responses;
|
||||
stream = await routes.createProxyStream(master.app);
|
||||
stream = await routes.createProxyStream(controller.app);
|
||||
responses = await Promise.all([
|
||||
(async function() {
|
||||
await wait(100);
|
||||
@@ -59,7 +59,7 @@ describe("master/src/routes", function() {
|
||||
assert.equal(responses[0].statusCode, 200);
|
||||
assert.equal(responses[1].statusCode, 200);
|
||||
assert.equal(responses[1].body.toString(), "test content");
|
||||
stream = await routes.createProxyStream(master.app);
|
||||
stream = await routes.createProxyStream(controller.app);
|
||||
responses = await Promise.all([
|
||||
phin({
|
||||
url: `http://localhost:${port}/api/stream/${stream.id}`, method: "PUT",
|
||||
@@ -104,7 +104,7 @@ describe("master/src/routes", function() {
|
||||
data: "totally a zip file",
|
||||
});
|
||||
assert.equal(response.statusCode, 401);
|
||||
master.userManager.users.get("test").tokenValidAfter = Math.floor((Date.now() + 60e3) / 1000);
|
||||
controller.userManager.users.get("test").tokenValidAfter = Math.floor((Date.now() + 60e3) / 1000);
|
||||
response = await phin({
|
||||
url: `http://localhost:${port}/api/upload-save?instance_id=123&filename=file.zip`, method: "POST",
|
||||
headers: {
|
||||
@@ -266,7 +266,7 @@ describe("master/src/routes", function() {
|
||||
});
|
||||
|
||||
it("should respond with 500 if the transfer failed", async function() {
|
||||
master.forwardRequestToInstance = async (data, request) => {
|
||||
controller.forwardRequestToInstance = async (data, request) => {
|
||||
throw new Error("Something went wrong");
|
||||
};
|
||||
let response;
|
||||
@@ -294,7 +294,7 @@ describe("master/src/routes", function() {
|
||||
});
|
||||
assert.equal(response.statusCode, 500);
|
||||
assert.deepEqual(JSON.parse(response.body), { errors: ["Something went wrong"], request_errors: [] });
|
||||
master.forwardRequestToInstance = async (data, request) => {
|
||||
controller.forwardRequestToInstance = async (data, request) => {
|
||||
await new Promise(() => {});
|
||||
};
|
||||
response = await phin({
|
||||
@@ -312,7 +312,7 @@ describe("master/src/routes", function() {
|
||||
});
|
||||
|
||||
it("should complete a valid transfer", async function() {
|
||||
master.forwardRequestToInstance = async (request, data) => {
|
||||
controller.forwardRequestToInstance = async (request, data) => {
|
||||
let stream = await phin({
|
||||
url: `http://localhost:${port}/api/stream/${data.stream_id}`,
|
||||
});
|
||||
@@ -332,7 +332,7 @@ describe("master/src/routes", function() {
|
||||
assert.equal(response.statusCode, 200);
|
||||
});
|
||||
it("should complete a valid transfer with non-standerd mime type", async function() {
|
||||
master.forwardRequestToInstance = async (request, data) => {
|
||||
controller.forwardRequestToInstance = async (request, data) => {
|
||||
let stream = await phin({
|
||||
url: `http://localhost:${port}/api/stream/${data.stream_id}`,
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
{"timestamp":"2021-12-10T10:00:00.000Z","level":"verbose","message":"Master start"}
|
||||
{"timestamp":"2021-12-10T10:00:00.000Z","level":"verbose","message":"Controller start"}
|
||||
{"timestamp":"2021-12-10T10:00:01.000Z","level":"verbose","message":"Loading"}
|
||||
{"timestamp":"2021-12-10T10:00:03.000Z","level":"info","message":"Ready"}
|
||||
{"timestamp":"2021-12-10T10:00:10.000Z","slave_id":1,"level":"verbose","message":"Slave connected"}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{"timestamp":"2021-12-11T10:00:00.000Z","level":"verbose","message":"Master start"}
|
||||
{"timestamp":"2021-12-11T10:00:00.000Z","level":"verbose","message":"Controller start"}
|
||||
{"timestamp":"2021-12-11T10:00:01.000Z","level":"verbose","message":"Loading"}
|
||||
{"timestamp":"2021-12-11T10:00:03.000Z","level":"fatal","message":"An error occured"}
|
||||
@@ -49,15 +49,15 @@ async function deleteSave(instanceId, save) {
|
||||
}
|
||||
|
||||
describe("Integration of Clusterio", function() {
|
||||
describe("clusteriomaster", function() {
|
||||
describe("clusteriocontroller", function() {
|
||||
describe("bootstrap generate-user-token", function() {
|
||||
it("work for existing user", async function() {
|
||||
await exec("node ../../packages/master bootstrap generate-user-token test");
|
||||
await exec("node ../../packages/controller bootstrap generate-user-token test");
|
||||
});
|
||||
|
||||
it("fails if user does not exist", async function() {
|
||||
await assert.rejects(
|
||||
exec("node ../../packages/master bootstrap generate-user-token invalid")
|
||||
exec("node ../../packages/controller bootstrap generate-user-token invalid")
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -91,7 +91,7 @@ describe("Integration of Clusterio", function() {
|
||||
it("should honnor the limit", async function() {
|
||||
let result = await libLink.messages.queryLog.send(getControl(), {
|
||||
all: true,
|
||||
master: false,
|
||||
controller: false,
|
||||
slave_ids: [],
|
||||
instance_ids: [],
|
||||
max_level: null,
|
||||
@@ -103,7 +103,7 @@ describe("Integration of Clusterio", function() {
|
||||
it("should return entries by order", async function() {
|
||||
let first = await libLink.messages.queryLog.send(getControl(), {
|
||||
all: true,
|
||||
master: false,
|
||||
controller: false,
|
||||
slave_ids: [],
|
||||
instance_ids: [],
|
||||
max_level: null,
|
||||
@@ -112,7 +112,7 @@ describe("Integration of Clusterio", function() {
|
||||
});
|
||||
let last = await libLink.messages.queryLog.send(getControl(), {
|
||||
all: true,
|
||||
master: false,
|
||||
controller: false,
|
||||
slave_ids: [],
|
||||
instance_ids: [],
|
||||
max_level: null,
|
||||
@@ -191,45 +191,45 @@ describe("Integration of Clusterio", function() {
|
||||
});
|
||||
|
||||
describe("clusterioctl", function() {
|
||||
describe("master config list", function() {
|
||||
describe("controller config list", function() {
|
||||
it("runs", async function() {
|
||||
await execCtl("master config list");
|
||||
await execCtl("controller config list");
|
||||
});
|
||||
it("should not leak auth_secret", async function() {
|
||||
let result = await libLink.messages.getMasterConfig.send(getControl());
|
||||
let result = await libLink.messages.getControllerConfig.send(getControl());
|
||||
let done = false;
|
||||
for (let group of result.serialized_config.groups) {
|
||||
if (group.name === "master") {
|
||||
if (group.name === "controller") {
|
||||
assert.equal(Object.prototype.hasOwnProperty.call(group.fields, "auth_secret"), false);
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(done, "master group not found");
|
||||
assert(done, "controller group not found");
|
||||
});
|
||||
});
|
||||
describe("master config set", function() {
|
||||
describe("controller config set", function() {
|
||||
it("sets given config option", async function() {
|
||||
await execCtl('master config set master.name "Test Cluster"');
|
||||
let result = await libLink.messages.getMasterConfig.send(getControl());
|
||||
await execCtl('controller config set controller.name "Test Cluster"');
|
||||
let result = await libLink.messages.getControllerConfig.send(getControl());
|
||||
let done = false;
|
||||
for (let group of result.serialized_config.groups) {
|
||||
if (group.name === "master") {
|
||||
if (group.name === "controller") {
|
||||
assert.equal(group.fields.name, "Test Cluster");
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(done, "master group not found");
|
||||
assert(done, "controller group not found");
|
||||
});
|
||||
it("should not allow setting auth_secret", async function() {
|
||||
await assert.rejects(execCtl("master config set master.auth_secret root"));
|
||||
await assert.rejects(execCtl("controller config set controller.auth_secret root"));
|
||||
});
|
||||
});
|
||||
|
||||
describe("master plugin list", function() {
|
||||
describe("controller plugin list", function() {
|
||||
it("runs", async function() {
|
||||
await execCtl("master plugin list");
|
||||
await execCtl("controller plugin list");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -369,7 +369,7 @@ describe("Integration of Clusterio", function() {
|
||||
await execCtl("instance send-rcon test technobabble");
|
||||
let { log } = await libLink.messages.queryLog.send(getControl(), {
|
||||
all: false,
|
||||
master: false,
|
||||
controller: false,
|
||||
slave_ids: [],
|
||||
instance_ids: [44],
|
||||
max_level: null,
|
||||
@@ -807,7 +807,7 @@ describe("Integration of Clusterio", function() {
|
||||
await execCtl("instance delete test");
|
||||
assert(!await fs.exists(path.join(instancesDir, "test")), "Instance files was not deleted");
|
||||
let instances = await getInstances();
|
||||
assert(!instances.has(44), "instance was not deleted from master");
|
||||
assert(!instances.has(44), "instance was not deleted from controller");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+23
-21
@@ -24,7 +24,7 @@ require("../../plugins/subspace_storage/info");
|
||||
|
||||
class TestControl extends libLink.Link {
|
||||
constructor(connector) {
|
||||
super("control", "master", connector);
|
||||
super("control", "controller", connector);
|
||||
libLink.attachAllMessages(this);
|
||||
this.slaveUpdates = [];
|
||||
this.instanceUpdates = [];
|
||||
@@ -117,7 +117,7 @@ async function get(urlPath) {
|
||||
return res;
|
||||
}
|
||||
|
||||
let masterProcess;
|
||||
let controllerProcess;
|
||||
let slaveProcess;
|
||||
let control;
|
||||
|
||||
@@ -126,7 +126,7 @@ let controlToken = jwt.sign({ aud: "user", user: "test" }, Buffer.from("TestSecr
|
||||
let instancesDir = path.join("temp", "test", "instances");
|
||||
let databaseDir = path.join("temp", "test", "database");
|
||||
let pluginListPath = path.join("temp", "test", "plugin-list.json");
|
||||
let masterConfigPath = path.join("temp", "test", "config-master.json");
|
||||
let controllerConfigPath = path.join("temp", "test", "config-controller.json");
|
||||
let slaveConfigPath = path.join("temp", "test", "config-slave.json");
|
||||
let controlConfigPath = path.join("temp", "test", "config-control.json");
|
||||
|
||||
@@ -184,19 +184,19 @@ before(async function() {
|
||||
await fs.remove(instancesDir);
|
||||
|
||||
await fs.remove(pluginListPath);
|
||||
await fs.remove(masterConfigPath);
|
||||
await fs.remove(controllerConfigPath);
|
||||
await fs.remove(slaveConfigPath);
|
||||
await fs.remove(controlConfigPath);
|
||||
|
||||
await fs.ensureDir(path.join("temp", "test"));
|
||||
|
||||
await exec("node ../../packages/master config set master.auth_secret TestSecretDoNotUse");
|
||||
await exec("node ../../packages/master config set master.http_port 8880");
|
||||
await exec("node ../../packages/master config set master.https_port 4443");
|
||||
await exec("node ../../packages/master config set master.heartbeat_interval 0.25");
|
||||
await exec("node ../../packages/master config set master.session_timeout 2");
|
||||
await exec("node ../../packages/master config set master.tls_certificate ../../test/file/tls/cert.pem");
|
||||
await exec("node ../../packages/master config set master.tls_private_key ../../test/file/tls/key.pem");
|
||||
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");
|
||||
await exec("node ../../packages/controller config set controller.heartbeat_interval 0.25");
|
||||
await exec("node ../../packages/controller config set controller.session_timeout 2");
|
||||
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");
|
||||
|
||||
await exec("node ../../packages/ctl plugin add ../../plugins/global_chat");
|
||||
await exec("node ../../packages/ctl plugin add ../../plugins/research_sync");
|
||||
@@ -204,11 +204,11 @@ before(async function() {
|
||||
await exec("node ../../packages/ctl plugin add ../../plugins/subspace_storage");
|
||||
await exec("node ../../packages/ctl plugin add ../../plugins/player_auth");
|
||||
|
||||
await exec("node ../../packages/master bootstrap create-admin test");
|
||||
await exec("node ../../packages/master bootstrap create-ctl-config test");
|
||||
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");
|
||||
|
||||
masterProcess = await spawn("master:", "node ../../packages/master run", /Started master/);
|
||||
controllerProcess = await spawn("controller:", "node ../../packages/controller run", /Started controller/);
|
||||
|
||||
await execCtl("slave create-config --id 4 --name slave --generate-token");
|
||||
await exec(`node ../../packages/slave config set slave.factorio_directory ${path.join("..", "..", "factorio")}`);
|
||||
@@ -229,7 +229,9 @@ before(async function() {
|
||||
testPack.mods.set("clusterio_lib", { name: "clusterio_lib", enabled: true, version: "0.1.2" });
|
||||
testPack.mods.set("subspace_storage", { name: "subspace_storage", enabled: true, version: "1.99.8" });
|
||||
await libLink.messages.createModPack.send(control, { mod_pack: testPack.toJSON() });
|
||||
await libLink.messages.setMasterConfigField.send(control, { field: "master.default_mod_pack_id", value: "12" });
|
||||
await libLink.messages.setControllerConfigField.send(
|
||||
control, { field: "controller.default_mod_pack_id", value: "12" }
|
||||
);
|
||||
});
|
||||
|
||||
after(async function() {
|
||||
@@ -239,10 +241,10 @@ after(async function() {
|
||||
slaveProcess.kill("SIGINT");
|
||||
await events.once(slaveProcess, "exit");
|
||||
}
|
||||
if (masterProcess) {
|
||||
console.log("Shutting down master");
|
||||
masterProcess.kill("SIGINT");
|
||||
await events.once(masterProcess, "exit");
|
||||
if (controllerProcess) {
|
||||
console.log("Shutting down controller");
|
||||
controllerProcess.kill("SIGINT");
|
||||
await events.once(controllerProcess, "exit");
|
||||
}
|
||||
if (control) {
|
||||
await control.connector.close();
|
||||
@@ -252,7 +254,7 @@ after(async function() {
|
||||
// Ensure the test processes are stopped.
|
||||
process.on("exit", () => {
|
||||
if (slaveProcess) { slaveProcess.kill(); }
|
||||
if (masterProcess) { masterProcess.kill(); }
|
||||
if (controllerProcess) { controllerProcess.kill(); }
|
||||
});
|
||||
|
||||
|
||||
@@ -271,7 +273,7 @@ module.exports = {
|
||||
controlToken,
|
||||
instancesDir,
|
||||
databaseDir,
|
||||
masterConfigPath,
|
||||
controllerConfigPath,
|
||||
slaveConfigPath,
|
||||
controlConfigPath,
|
||||
};
|
||||
+2
-2
@@ -47,7 +47,7 @@ describe("lib/command", function() {
|
||||
it("should pass an integer like string back", async function() {
|
||||
assert.equal(await libCommand.resolveSlave(null, "123"), 123);
|
||||
});
|
||||
it("should resolve a slave name with the master server", async function() {
|
||||
it("should resolve a slave name with the controller", async function() {
|
||||
assert.equal(await libCommand.resolveSlave(testControl, "Test Slave"), 11);
|
||||
});
|
||||
it("should throw if slave is not found", async function() {
|
||||
@@ -61,7 +61,7 @@ describe("lib/command", function() {
|
||||
it("should pass an integer like string back", async function() {
|
||||
assert.equal(await libCommand.resolveInstance(null, "123"), 123);
|
||||
});
|
||||
it("should resolve an instance name with the master server", async function() {
|
||||
it("should resolve an instance name with the controller", async function() {
|
||||
assert.equal(await libCommand.resolveInstance(testControl, "Test Instance"), 57);
|
||||
});
|
||||
it("should throw if instance is not found", async function() {
|
||||
|
||||
@@ -108,8 +108,8 @@ describe("lib/logging_utils.js", function() {
|
||||
info => ["fatal"].includes(info.level)
|
||||
));
|
||||
});
|
||||
it("should filter by master", async function() {
|
||||
let log = await libLoggingUtils.queryLog(logDir, { master: true }, index());
|
||||
it("should filter by controller", async function() {
|
||||
let log = await libLoggingUtils.queryLog(logDir, { controller: true }, index());
|
||||
assert.deepEqual(log, allLines.filter(
|
||||
info => info.slave_id === undefined && info.instance_id === undefined
|
||||
));
|
||||
|
||||
+13
-13
@@ -19,8 +19,8 @@ describe("lib/plugin", function() {
|
||||
await instancePlugin.onStop();
|
||||
instancePlugin.onExit();
|
||||
await instancePlugin.onOutput({});
|
||||
instancePlugin.onMasterConnectionEvent("connect");
|
||||
await instancePlugin.onPrepareMasterDisconnect();
|
||||
instancePlugin.onControllerConnectionEvent("connect");
|
||||
await instancePlugin.onPrepareControllerDisconnect();
|
||||
});
|
||||
describe("sendRcon", function() {
|
||||
it("should send commands out of order", async function() {
|
||||
@@ -54,20 +54,20 @@ describe("lib/plugin", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("class BaseMasterPlugin", function() {
|
||||
let masterPlugin;
|
||||
describe("class BaseControllerPlugin", function() {
|
||||
let controllerPlugin;
|
||||
it("should be constructible", async function() {
|
||||
masterPlugin = new libPlugin.BaseMasterPlugin({}, {}, {}, new mock.MockLogger());
|
||||
await masterPlugin.init();
|
||||
controllerPlugin = new libPlugin.BaseControllerPlugin({}, {}, {}, new mock.MockLogger());
|
||||
await controllerPlugin.init();
|
||||
});
|
||||
it("should define defaults for hooks", async function() {
|
||||
await masterPlugin.onInstanceStatusChanged({}, "running", "initialized");
|
||||
await masterPlugin.onMasterConfigFieldChanged({}, "foo", null);
|
||||
await masterPlugin.onInstanceConfigFieldChanged({}, {}, "foo", null);
|
||||
await masterPlugin.onMetrics();
|
||||
await masterPlugin.onShutdown();
|
||||
masterPlugin.onSlaveConnectionEvent({}, "connect");
|
||||
await masterPlugin.onPrepareSlaveDisconnect({});
|
||||
await controllerPlugin.onInstanceStatusChanged({}, "running", "initialized");
|
||||
await controllerPlugin.onControllerConfigFieldChanged({}, "foo", null);
|
||||
await controllerPlugin.onInstanceConfigFieldChanged({}, {}, "foo", null);
|
||||
await controllerPlugin.onMetrics();
|
||||
await controllerPlugin.onShutdown();
|
||||
controllerPlugin.onSlaveConnectionEvent({}, "connect");
|
||||
await controllerPlugin.onPrepareSlaveDisconnect({});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+14
-12
@@ -64,43 +64,45 @@ describe("lib/plugin_loader", function() {
|
||||
);
|
||||
});
|
||||
});
|
||||
describe("loadMasterPluginClass()", function() {
|
||||
describe("loadControllerPluginClass()", function() {
|
||||
let baseDir = path.join("temp", "test", "plugin");
|
||||
let missingClass = path.join(baseDir, "missing_class_plugin");
|
||||
let wrongParentClass = path.join(baseDir, "wrong_parent_class_plugin");
|
||||
before(async function() {
|
||||
async function writeEntrypoint(pluginPath, content) {
|
||||
await fs.outputFile(path.join(pluginPath, "master.js"), content);
|
||||
await fs.outputFile(path.join(pluginPath, "controller.js"), content);
|
||||
}
|
||||
|
||||
await writeEntrypoint(missingClass, "");
|
||||
await writeEntrypoint(wrongParentClass, "class MasterPlugin {}\n module.exports = { MasterPlugin };\n");
|
||||
await writeEntrypoint(
|
||||
wrongParentClass, "class ControllerPlugin {}\n module.exports = { ControllerPlugin };\n"
|
||||
);
|
||||
});
|
||||
it("should throw if class is missing from entrypoint", async function() {
|
||||
await assert.rejects(
|
||||
libPluginLoader.loadMasterPluginClass({
|
||||
libPluginLoader.loadControllerPluginClass({
|
||||
name: "test",
|
||||
masterEntrypoint: "master",
|
||||
controllerEntrypoint: "controller",
|
||||
requirePath: path.resolve(missingClass),
|
||||
}),
|
||||
{
|
||||
message:
|
||||
`PluginError: Expected ${path.resolve(missingClass, "master")} ` +
|
||||
"to export a class named MasterPlugin",
|
||||
`PluginError: Expected ${path.resolve(missingClass, "controller")} ` +
|
||||
"to export a class named ControllerPlugin",
|
||||
}
|
||||
);
|
||||
});
|
||||
it("should throw if class is not a subclass of BaseMasterPlugin", async function() {
|
||||
it("should throw if class is not a subclass of BaseControllerPlugin", async function() {
|
||||
await assert.rejects(
|
||||
libPluginLoader.loadMasterPluginClass({
|
||||
libPluginLoader.loadControllerPluginClass({
|
||||
name: "test",
|
||||
masterEntrypoint: "master",
|
||||
controllerEntrypoint: "controller",
|
||||
requirePath: path.resolve(wrongParentClass),
|
||||
}),
|
||||
{
|
||||
message:
|
||||
"PluginError: Expected MasterPlugin exported from " +
|
||||
`${path.resolve(wrongParentClass, "master")} to be a subclass of BaseMasterPlugin`,
|
||||
"PluginError: Expected ControllerPlugin exported from " +
|
||||
`${path.resolve(wrongParentClass, "controller")} to be a subclass of BaseControllerPlugin`,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
+15
-15
@@ -9,7 +9,7 @@ const libPlugin = require("@clusterio/lib/plugin");
|
||||
const libUsers = require("@clusterio/lib/users");
|
||||
const libPrometheus = require("@clusterio/lib/prometheus");
|
||||
|
||||
const UserManager = require("@clusterio/master/src/UserManager");
|
||||
const UserManager = require("@clusterio/controller/src/UserManager");
|
||||
|
||||
|
||||
class MockLogger {
|
||||
@@ -152,25 +152,25 @@ class MockInstance extends libLink.Link {
|
||||
|
||||
class MockSlave extends libLink.Link {
|
||||
constructor() {
|
||||
super("slave", "master", new MockConnector());
|
||||
super("slave", "controller", new MockConnector());
|
||||
}
|
||||
}
|
||||
|
||||
class MockControl extends libLink.Link {
|
||||
constructor(connector) {
|
||||
super("control", "master", connector);
|
||||
super("control", "controller", connector);
|
||||
}
|
||||
}
|
||||
|
||||
class MockMaster {
|
||||
class MockController {
|
||||
constructor() {
|
||||
this.app = express();
|
||||
this.app.locals.master = this;
|
||||
this.app.locals.controller = this;
|
||||
this.app.locals.streams = new Map();
|
||||
this.mockConfigEntries = new Map([
|
||||
["master.external_address", "test"],
|
||||
["master.auth_secret", "TestSecretDoNotUse"],
|
||||
["master.proxy_stream_timeout", 1],
|
||||
["controller.external_address", "test"],
|
||||
["controller.auth_secret", "TestSecretDoNotUse"],
|
||||
["controller.proxy_stream_timeout", 1],
|
||||
]);
|
||||
this.config = {
|
||||
get: (name) => {
|
||||
@@ -196,8 +196,8 @@ class MockMaster {
|
||||
this.slaves = new Map();
|
||||
}
|
||||
|
||||
getMasterUrl() {
|
||||
return "http://master.example/";
|
||||
getControllerUrl() {
|
||||
return "http://controller.example/";
|
||||
}
|
||||
|
||||
async startServer() {
|
||||
@@ -217,11 +217,11 @@ class MockMaster {
|
||||
}
|
||||
}
|
||||
|
||||
async function createMasterPlugin(MasterPluginClass, info) {
|
||||
let master = new MockMaster();
|
||||
async function createControllerPlugin(ControllerPluginClass, info) {
|
||||
let controller = new MockController();
|
||||
let metrics = {};
|
||||
let logger = new MockLogger();
|
||||
let plugin = new MasterPluginClass(info, master, metrics, logger);
|
||||
let plugin = new ControllerPluginClass(info, controller, metrics, logger);
|
||||
await plugin.init();
|
||||
return plugin;
|
||||
}
|
||||
@@ -244,8 +244,8 @@ module.exports = {
|
||||
MockInstance,
|
||||
MockSlave,
|
||||
MockControl,
|
||||
MockMaster,
|
||||
MockController,
|
||||
|
||||
createMasterPlugin,
|
||||
createControllerPlugin,
|
||||
createInstancePlugin,
|
||||
};
|
||||
Reference in new issue
Block a user