mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 07:04:53 +09:00
Merge pull request #1075 from bbassie/fix/ctl-config-fields
Register plugin ctl config fields
This commit is contained in:
1 parent
70dff9ef68
commit
e33d06a5cc
2 files changed
+34
No files matched your search
@@ -842,6 +842,10 @@ export function addPluginConfigFields(pluginInfos: PluginNodeEnvInfo[] | PluginW
|
||||
if (pluginInfo.instanceEntrypoint) {
|
||||
addPluginFieldDefinitions(pluginInfo, "instanceConfigFields", InstanceConfig);
|
||||
}
|
||||
if (pluginInfo.ctlConfigFields) {
|
||||
validateFieldNames(pluginInfo.name, pluginInfo.ctlConfigFields);
|
||||
Object.assign(CtlConfig.fieldDefinitions, pluginInfo.ctlConfigFields);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import * as lib from "@clusterio/lib";
|
||||
|
||||
|
||||
describe("lib/config/definitions", function() {
|
||||
describe("addPluginConfigFields()", function() {
|
||||
after(function() {
|
||||
delete lib.CtlConfig.fieldDefinitions["ctl_test.field"];
|
||||
});
|
||||
|
||||
it("should add ctl config fields", function() {
|
||||
lib.addPluginConfigFields([{
|
||||
name: "ctl_test",
|
||||
ctlConfigFields: { "ctl_test.field": { type: "string", initialValue: "value" } },
|
||||
}]);
|
||||
const config = new lib.CtlConfig("control");
|
||||
assert.equal(config.get("ctl_test.field"), "value");
|
||||
});
|
||||
it("should reject ctl config fields not named after the plugin", function() {
|
||||
assert.throws(
|
||||
() => lib.addPluginConfigFields([{
|
||||
name: "ctl_test",
|
||||
ctlConfigFields: { "other.field": { type: "string" } },
|
||||
}]),
|
||||
new Error("Expected name of config field 'other.field' for ctl_test to start with 'ctl_test.'")
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user