mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 15:04:52 +09:00
Fix usage of assert.rejects
This commit is contained in:
8 files changed
+47
-47
No files matched your search
@@ -277,9 +277,9 @@ describe("Integration of Clusterio", function() {
|
||||
describe("controller plugin update", function() {
|
||||
it("runs", async function() {
|
||||
// In dev plugins have no npm package, so best we can do is get an error from the controller
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
execCtl("controller plugin update foo"),
|
||||
"Plugin foo is not installed on this machine"
|
||||
/Plugin foo is not installed on this machine/
|
||||
);
|
||||
});
|
||||
// Update always fails, we can not test restart option
|
||||
@@ -289,9 +289,9 @@ describe("Integration of Clusterio", function() {
|
||||
it("runs", async function() {
|
||||
// Default is to disallow updates, changing this value would require a restart
|
||||
// Additionally, it can not be changed via ctl, so best we can do is get an error from the controller
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
execCtl("controller plugin install foo"),
|
||||
"Plugin installs are disabled on this machine"
|
||||
/Plugin installs are disabled on this machine/
|
||||
);
|
||||
});
|
||||
// Install always fails, we can not test restart option
|
||||
@@ -303,9 +303,9 @@ describe("Integration of Clusterio", function() {
|
||||
});
|
||||
it("accepts --restart", async function() {
|
||||
// We cannot restart the controller, so we check for controller error instead
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
execCtl("controller update --restart"),
|
||||
"Cannot restart, controller does not have a process monitor to restart it."
|
||||
/Cannot restart, controller does not have a process monitor to restart it./
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -313,9 +313,9 @@ describe("Integration of Clusterio", function() {
|
||||
describe("controller restart", function() {
|
||||
it("runs", async function() {
|
||||
// We cannot restart the controller, so we check for controller error instead
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
execCtl("controller restart"),
|
||||
"Cannot restart, controller does not have a process monitor to restart it."
|
||||
/Cannot restart, controller does not have a process monitor to restart it./
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -359,9 +359,9 @@ describe("Integration of Clusterio", function() {
|
||||
describe("host plugin update", function() {
|
||||
it("runs", async function() {
|
||||
// In dev plugins have no npm package, so best we can do is get an error from the host
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
execCtl("host plugin update 4 foo"),
|
||||
"Plugin foo is not installed on this machine"
|
||||
/Plugin foo is not installed on this machine/
|
||||
);
|
||||
});
|
||||
// Update always fails, we can not test restart option
|
||||
@@ -371,9 +371,9 @@ describe("Integration of Clusterio", function() {
|
||||
it("runs", async function() {
|
||||
// Default is to disallow updates, changing this value would require a restart
|
||||
// Additionally, it can not be changed via ctl, so best we can do is get an error from the host
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
execCtl("host plugin install 4 foo"),
|
||||
"Plugin installs are disabled on this machine"
|
||||
/Plugin installs are disabled on this machine/
|
||||
);
|
||||
});
|
||||
// Install always fails, we can not test restart option
|
||||
@@ -385,9 +385,9 @@ describe("Integration of Clusterio", function() {
|
||||
});
|
||||
it("accepts --restart", async function() {
|
||||
// We cannot restart the host, so we check for host error instead
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
execCtl("host update 4 --restart"),
|
||||
"Cannot restart, host does not have a process monitor to restart it."
|
||||
/Cannot restart, host does not have a process monitor to restart it./
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -395,9 +395,9 @@ describe("Integration of Clusterio", function() {
|
||||
describe("host restart", function() {
|
||||
it("runs", async function() {
|
||||
// We cannot restart the host, so we check for host error instead
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
execCtl("host restart 4"),
|
||||
"Cannot restart, host does not have a process monitor to restart it."
|
||||
/Cannot restart, host does not have a process monitor to restart it./
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -466,7 +466,7 @@ describe("Integration of Clusterio", function() {
|
||||
});
|
||||
it("errors when cloning an invalid instance", async function() {
|
||||
slowTest(this);
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
execCtl("instance create testClone --id 440 --from 441"),
|
||||
new lib.RequestError("Instance with ID 441 does not exist")
|
||||
);
|
||||
@@ -615,7 +615,7 @@ describe("Integration of Clusterio", function() {
|
||||
assert(r1.log.some(info => /\[COMMAND\]/.test(info.message)), "Command was not sent");
|
||||
await execCtl("instance config set test factorio.enable_script_commands false");
|
||||
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
execCtl("instance send-rcon test /c"),
|
||||
new Error(
|
||||
"Attempted to use script command while disabled. " +
|
||||
@@ -1648,7 +1648,7 @@ describe("Integration of Clusterio", function() {
|
||||
);
|
||||
});
|
||||
it("should reject multiple provided options", async function() {
|
||||
assert.rejects(execCtl("user import --bans --admins import-admins.json"));
|
||||
await assert.rejects(execCtl("user import --bans --admins import-admins.json"));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1779,7 +1779,7 @@ describe("Integration of Clusterio", function() {
|
||||
assert(data.indexOf("restore_control") >= 0, "restore_control is missing");
|
||||
});
|
||||
it("should reject multiple provided options", async function() {
|
||||
assert.rejects(execCtl("user restore --bans --admins restore-admins.json"));
|
||||
await assert.rejects(execCtl("user restore --bans --admins restore-admins.json"));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -75,12 +75,12 @@ describe("Clusterio Instance", function() {
|
||||
if (savePatchingEnabled) {
|
||||
// IPC expects save patching to be enabled
|
||||
it("should do nothing for an unknown type", async function() {
|
||||
assert.rejects(getUser("DoesNotExist"), "User should not exist");
|
||||
await assert.rejects(getUser("DoesNotExist"), "User should not exist");
|
||||
await sendRcon(instId,
|
||||
`/sc ${requireApi} api.send_json("player_event",` +
|
||||
"{ type='invalid type', name='DoesNotExist' })"
|
||||
);
|
||||
assert.rejects(getUser("DoesNotExist"), "User was created");
|
||||
await assert.rejects(getUser("DoesNotExist"), "User was created");
|
||||
});
|
||||
it("should respond to a player join and leave event", async function() {
|
||||
await sendRcon(instId,
|
||||
|
||||
@@ -201,13 +201,13 @@ describe("lib/config/classes", function() {
|
||||
const filepath = path.join("temp", "test", "config_test.json");
|
||||
it("should throw for file and json errors", async function() {
|
||||
await fs.writeFile(filepath, "abc");
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
TestConfig.fromFile("local", filepath),
|
||||
new Error(
|
||||
`${filepath}: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data`
|
||||
)
|
||||
);
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
TestConfig.fromFile("local", `${filepath}.notExist`),
|
||||
);
|
||||
});
|
||||
@@ -218,12 +218,12 @@ describe("lib/config/classes", function() {
|
||||
new Error("Invalid config")
|
||||
);
|
||||
await fs.writeFile(filepath, "undefined");
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
TestConfig.fromFile("local", filepath),
|
||||
new Error("Invalid config")
|
||||
);
|
||||
await fs.writeFile(filepath, "[]");
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
TestConfig.fromFile("local", filepath),
|
||||
new Error("Invalid config")
|
||||
);
|
||||
|
||||
+5
-5
@@ -22,9 +22,9 @@ describe("rce_ops", function() {
|
||||
await lib.handlePluginUpdate("foo", [{ npmPackage: "foo" }]);
|
||||
});
|
||||
it("rejects when plugin not installed", async function() {
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
lib.handlePluginUpdate("foo", []),
|
||||
"Plugin foo is not installed on this machine"
|
||||
/Plugin foo is not installed on this machine/
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -50,14 +50,14 @@ describe("rce_ops", function() {
|
||||
});
|
||||
it("rejects when name too long", async function() {
|
||||
const pluginName = "a".repeat(215);
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
lib.handlePluginInstall(pluginName),
|
||||
`Invalid plugin name: ${pluginName}`
|
||||
);
|
||||
});
|
||||
it("rejects when invalid symbol present", async function() {
|
||||
const pluginName = "?";
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
lib.handlePluginInstall(pluginName),
|
||||
`Invalid plugin name: ${pluginName}`
|
||||
);
|
||||
@@ -69,7 +69,7 @@ describe("rce_ops", function() {
|
||||
return { ok: false };
|
||||
};
|
||||
|
||||
assert.rejects(lib.handlePluginInstall("foo"), "Unknown plugin: foo");
|
||||
await assert.rejects(lib.handlePluginInstall("foo"), /Unknown plugin: foo/);
|
||||
assert.equal(calledWith, "https://registry.npmjs.com/foo");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -240,18 +240,18 @@ describe("lib/subscriptions", function() {
|
||||
subscriptions.handle(RegisteredEvent);
|
||||
});
|
||||
|
||||
it("should not accept subscriptions to unregistered events", function() {
|
||||
it("should not accept subscriptions to unregistered events", async function() {
|
||||
const request = new lib.SubscriptionRequest(RegisteredEvent.name, true);
|
||||
request.eventName = UnregisteredEvent.name;
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
subscriptions.handleRequest(getLink(0), request, addr({ controlId: 0 }), addr("controller")),
|
||||
new Error(`Unregistered Event class ${UnregisteredEvent.name}`)
|
||||
);
|
||||
});
|
||||
it("should not accept subscriptions to events not handled by the class", function() {
|
||||
it("should not accept subscriptions to events not handled by the class", async function() {
|
||||
const request = new lib.SubscriptionRequest(RegisteredEvent.name, true);
|
||||
request.eventName = StringPermissionEvent.name;
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
subscriptions.handleRequest(getLink(0), request, addr({ controlId: 0 }), addr("controller")),
|
||||
new Error(`Event ${StringPermissionEvent.eventName} is not a registered as subscribable`)
|
||||
);
|
||||
|
||||
@@ -28,9 +28,9 @@ describe("messages/controller", function() {
|
||||
});
|
||||
it("rejects if updates are disabled", async function() {
|
||||
controller.config.set("controller.allow_remote_updates", false);
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
controlConnection.handleControllerUpdateRequest(new lib.ControllerUpdateRequest()),
|
||||
"Remote updates are disabled on this machine"
|
||||
/Remote updates are disabled on this machine/
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -24,9 +24,9 @@ describe("messages/controller", function() {
|
||||
});
|
||||
it("rejects if updates are disabled", async function() {
|
||||
host.config.set("host.allow_remote_updates", false);
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
host.handleHostUpdateRequest(new lib.HostUpdateRequest()),
|
||||
"Remote updates are disabled on this machine"
|
||||
/Remote updates are disabled on this machine/
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -115,9 +115,9 @@ describe("messages/plugin", function() {
|
||||
});
|
||||
it("rejects if updates are disabled on the controller", async function() {
|
||||
controller.config.set("controller.allow_plugin_updates", false);
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
controlConnection.handlePluginUpdateRequest(new lib.PluginUpdateRequest("foo")),
|
||||
"Plugin updates are disabled on this machine"
|
||||
/Plugin updates are disabled on this machine/
|
||||
);
|
||||
});
|
||||
it("runs on a host", async function() {
|
||||
@@ -127,9 +127,9 @@ describe("messages/plugin", function() {
|
||||
});
|
||||
it("rejects if updates are disabled on the host", async function() {
|
||||
host.config.set("host.allow_plugin_updates", false);
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
host.handlePluginUpdateRequest(new lib.PluginUpdateRequest("foo")),
|
||||
"Plugin updates are disabled on this machine"
|
||||
/Plugin updates are disabled on this machine/
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -156,9 +156,9 @@ describe("messages/plugin", function() {
|
||||
});
|
||||
it("rejects if updates are disabled on the controller", async function() {
|
||||
controller.config.set("controller.allow_plugin_install", false);
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
controlConnection.handlePluginInstallRequest(new lib.PluginInstallRequest("foo")),
|
||||
"Plugin updates are disabled on this machine"
|
||||
/Plugin updates are disabled on this machine/
|
||||
);
|
||||
});
|
||||
it("runs on a host", async function() {
|
||||
@@ -167,9 +167,9 @@ describe("messages/plugin", function() {
|
||||
});
|
||||
it("rejects if updates are disabled on the host", async function() {
|
||||
host.config.set("host.allow_plugin_install", false);
|
||||
assert.rejects(
|
||||
await assert.rejects(
|
||||
host.handlePluginInstallRequest(new lib.PluginInstallRequest("foo")),
|
||||
"Plugin updates are disabled on this machine"
|
||||
/Plugin updates are disabled on this machine/
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user