Files
factorio-clusterio/test/controller/InstanceInfo.js
T
Hornwitser 001db4befe Refactor config to JSON data class pattern
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.
2024-01-06 19:53:32 +01:00

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"));
});
});
});