mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23:04:52 +09:00
Refactor away the config group concept and simplyfy the way config fields are defined. Fields are defined directly as properties of the static field fieldDefinitions on the class itself with a separate interface to declare the types of fields. This makes it possible to easily make accessing the config fields type checked in a way that lets plugins extend the interfaces with their own config options by adding additional fields to the interface via declation merging.
37 lines
1.1 KiB
JavaScript
37 lines
1.1 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);
|
|
}
|
|
|
|
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"));
|
|
});
|
|
});
|
|
});
|