Send instance status in listInstances request

Send the status of the instance in the repsonse to the listInstances
request and use this status in the integration tests to check if the
instance was started/stopped.
This commit is contained in:
Hornwitser committed 2020-09-29 01:28:00 +02:00
1 parent b82de23876
commit 003b035abd
4 files changed
+29 -7

No files matched your search

+4 -1
View File
@@ -290,11 +290,14 @@ messages.listInstances = new Request({
type: "array",
items: {
additionalProperties: false,
required: ["name", "id", "assigned_slave"],
required: ["name", "id", "assigned_slave", "status"],
properties: {
"name": { type: "string" },
"id": { type: "integer" },
"assigned_slave": { type: ["null", "integer"] },
"status": { enum: [
"unknown", "unassigned", "stopped", "starting", "running", "creating_save", "exporting_data",
]},
},
},
},
+1
View File
@@ -612,6 +612,7 @@ class ControlConnection extends BaseConnection {
id: instance.config.get("instance.id"),
name: instance.config.get("instance.name"),
assigned_slave: instance.config.get("instance.assigned_slave"),
status: instance.status,
});
}
return { list };
+23 -5
View File
@@ -8,6 +8,16 @@ const link = require("@clusterio/lib/link");
const { slowTest, get, execCtl, sendRcon, getControl, instancesDir } = require("./index");
async function getInstances() {
let result = await link.messages.listInstances.send(getControl());
return new Map(result.list.map(instance => [instance.id, instance]));
}
async function checkInstanceStatus(id, status) {
let instances = await getInstances();
assert.equal(instances.get(44).status, status, "incorrect instance status");
}
describe("Integration of Clusterio", function() {
describe("clusterioctl", function() {
describe("slave list", function() {
@@ -22,15 +32,19 @@ describe("Integration of Clusterio", function() {
});
describe("instance create", function() {
it("runs", async function() {
it("creates the instance", async function() {
await execCtl("instance create test --id 44");
let instances = await getInstances();
assert(instances.has(44), "instance was not created");
assert.equal(instances.get(44).status, "unassigned", "incorrect instance status");
});
});
describe("instance assign", function() {
it("creates the instance files", async function() {
await execCtl("instance assign test 4");
assert(await fs.exists(path.join(instancesDir, "test")), "Instance was not created");
assert(await fs.exists(path.join(instancesDir, "test")), "Instance directory was not created");
await checkInstanceStatus(44, "stopped");
});
});
@@ -38,6 +52,7 @@ describe("Integration of Clusterio", function() {
it("creates a save", async function() {
slowTest(this);
await execCtl("instance create-save test");
await checkInstanceStatus(44, "stopped");
});
});
@@ -46,6 +61,7 @@ describe("Integration of Clusterio", function() {
slowTest(this);
await execCtl("instance export-data test");
assert(await fs.exists(path.join("static", "export", "locale.json")), "Export was not created");
await checkInstanceStatus(44, "stopped");
});
});
@@ -53,7 +69,7 @@ describe("Integration of Clusterio", function() {
it("starts the instance", async function() {
slowTest(this);
await execCtl("instance start test");
// TODO check that the instance actually started
await checkInstanceStatus(44, "running");
});
});
@@ -200,7 +216,7 @@ describe("Integration of Clusterio", function() {
it("stops the instance", async function() {
slowTest(this);
await execCtl("instance stop test");
// TODO check that the instance actually stopped
await checkInstanceStatus(44, "stopped");
});
});
@@ -208,7 +224,9 @@ describe("Integration of Clusterio", function() {
it("deletes the instance", async function() {
slowTest(this);
await execCtl("instance delete test");
assert(!await fs.exists(path.join(instancesDir, "test")), "Instance was not deleted");
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");
});
});
+1 -1
View File
@@ -24,7 +24,7 @@ describe("lib/command", function() {
seq: 1, type: "list_instances_response",
data: {
seq: message.seq,
list: [{ id: 57, assigned_slave: 4, name: "Test Instance" }],
list: [{ id: 57, assigned_slave: 4, name: "Test Instance", status: "stopped" }],
},
});
} else if (message.type === "list_roles_request") {