mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23:04:52 +09:00
Refactor the Config and ConfigGroup classes to match the JSON data class pattern with toJSON, toRemote and fromJSON methods replacing the load, init, and serialize methods. Since fromJSON requires extra information the messages structures passes around the plain JSON representation of the configs instead of serialising instances of the config classes automatically.
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
"use strict";
|
|
const assert = require("assert").strict;
|
|
|
|
const { InstanceInfo } = require("@clusterio/controller");
|
|
const lib = require("@clusterio/lib");
|
|
|
|
|
|
describe("controller/InstanceInfo", function() {
|
|
describe("class InstanceInfo", function() {
|
|
it("should round trip serialize", function() {
|
|
const validate = lib.compile(InstanceInfo.jsonSchema);
|
|
function check(info) {
|
|
const json = JSON.parse(JSON.stringify(info));
|
|
if (!validate(json)) {
|
|
throw validate.errors;
|
|
}
|
|
assert.deepEqual(InstanceInfo.fromJSON(json, "controller"), info);
|
|
}
|
|
|
|
if (!lib.InstanceConfig._finalized) {
|
|
lib.InstanceConfig.finalize();
|
|
}
|
|
const config = new lib.InstanceConfig("controller").toJSON();
|
|
|
|
check(InstanceInfo.fromJSON({ config, status: "stopped" }, "controller"));
|
|
check(InstanceInfo.fromJSON({ config, status: "running" }, "controller"));
|
|
check(InstanceInfo.fromJSON({ config, status: "running", gamePort: 34197 }, "controller"));
|
|
check(InstanceInfo.fromJSON({ config, status: "running", updatedAt: Date.now() }, "controller"));
|
|
|
|
// All at once
|
|
check(InstanceInfo.fromJSON({
|
|
config,
|
|
status: "unknown",
|
|
gamePort: 10000,
|
|
updateAt: 20000,
|
|
}, "controller"));
|
|
});
|
|
});
|
|
});
|