mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 23:14:53 +09:00
Add roundtrip test for InstanceInfo
This commit is contained in:
1 parent
699ef2c3cb
commit
ede150d80f
1 file changed
+40
@@ -0,0 +1,40 @@
|
||||
"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", async 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, info.config), info);
|
||||
}
|
||||
|
||||
if (!lib.InstanceConfig._finalized) {
|
||||
lib.InstanceConfig.finalize();
|
||||
}
|
||||
const config = new lib.InstanceConfig("controller");
|
||||
await config.init();
|
||||
|
||||
check(InstanceInfo.fromJSON({ config, status: "stopped" }, config));
|
||||
check(InstanceInfo.fromJSON({ config, status: "running" }, config));
|
||||
check(InstanceInfo.fromJSON({ config, status: "running", gamePort: 34197 }, config));
|
||||
check(InstanceInfo.fromJSON({ config, status: "running", updatedAt: Date.now() }, config));
|
||||
|
||||
// All at once
|
||||
check(InstanceInfo.fromJSON({
|
||||
config,
|
||||
status: "unknown",
|
||||
gamePort: 10000,
|
||||
updateAt: 20000,
|
||||
}, config));
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user