mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 23:14:53 +09:00
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.
This commit is contained in:
1 parent
27af142a87
commit
001db4befe
24 files changed
+269
-334
No files matched your search
@@ -14,19 +14,18 @@ describe("controller/InstanceInfo", function() {
|
||||
if (!validate(json)) {
|
||||
throw validate.errors;
|
||||
}
|
||||
assert.deepEqual(InstanceInfo.fromJSON(json, info.config), info);
|
||||
assert.deepEqual(InstanceInfo.fromJSON(json, "controller"), info);
|
||||
}
|
||||
|
||||
if (!lib.InstanceConfig._finalized) {
|
||||
lib.InstanceConfig.finalize();
|
||||
}
|
||||
const config = new lib.InstanceConfig("controller");
|
||||
config.init();
|
||||
const config = new lib.InstanceConfig("controller").toJSON();
|
||||
|
||||
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));
|
||||
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({
|
||||
@@ -34,7 +33,7 @@ describe("controller/InstanceInfo", function() {
|
||||
status: "unknown",
|
||||
gamePort: 10000,
|
||||
updateAt: 20000,
|
||||
}, config));
|
||||
}, "controller"));
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user