mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 23:33:12 +09:00
Merge pull request #1183 from bbassie/fix/save-patching-plugin-default
Default load_plugin to off when the instance lacks required features
This commit is contained in:
1 parent
308cca9b7d
commit
4a2c164188
9 files changed
+99
-42
No files matched your search
@@ -145,6 +145,20 @@ describe("lib/config/classes", function() {
|
||||
assert.equal(testInstance.get("test.func"), 42);
|
||||
assert.equal(testInstance.get("test.priv"), null);
|
||||
});
|
||||
it("should call initialValue functions with the loaded config", function() {
|
||||
class DerivedConfig extends lib.Config {
|
||||
static defaultAccess = ["local"];
|
||||
static fieldDefinitions = {
|
||||
"test.base": { type: "number", initialValue: 1 },
|
||||
"test.derived": { type: "number", initialValue: config => config.get("test.base") * 2 },
|
||||
};
|
||||
}
|
||||
assert.equal(new DerivedConfig("local").get("test.derived"), 2);
|
||||
assert.equal(new DerivedConfig("local", { "test.base": 5 }).get("test.derived"), 10);
|
||||
assert.equal(new DerivedConfig("local", { "test.base": 5, "test.derived": 3 }).get("test.derived"), 3);
|
||||
const invalid = new DerivedConfig("local", { "test.base": 5, "test.derived": "x" });
|
||||
assert.equal(invalid.get("test.derived"), 10);
|
||||
});
|
||||
it("should not initalize inaccessible fields", function() {
|
||||
let testInstance = new TestConfig("remote");
|
||||
assert.equal(testInstance.fields["test.enum"], "b");
|
||||
|
||||
@@ -369,6 +369,49 @@ describe("lib/config/definitions/validators", function() {
|
||||
assert.doesNotThrow(() => config.set("factorio.enable_lua_udp", true));
|
||||
assert.doesNotThrow(() => config.set("lua_udp.load_plugin", true));
|
||||
});
|
||||
it("should default load_plugin to false when a required feature is disabled", function() {
|
||||
class TestInstanceConfig extends InstanceConfig {
|
||||
static fieldDefinitions = { ...InstanceConfig.fieldDefinitions };
|
||||
}
|
||||
|
||||
lib.addPluginFieldDefinitions(
|
||||
{ name: "requires_features", features: ["SavePatching", "ScriptCommands"] },
|
||||
"instanceConfigFields", TestInstanceConfig
|
||||
);
|
||||
|
||||
assert.equal(new TestInstanceConfig("controller").get("requires_features.load_plugin"), true);
|
||||
for (const field of ["factorio.enable_save_patching", "factorio.enable_script_commands"]) {
|
||||
const config = new TestInstanceConfig("controller", { [field]: false });
|
||||
assert.equal(config.get("requires_features.load_plugin"), false);
|
||||
// Other fields can be edited since the config is valid
|
||||
assert.doesNotThrow(() => config.set("instance.name", "test"));
|
||||
}
|
||||
|
||||
// An explicit value is kept
|
||||
const config = new TestInstanceConfig("controller", {
|
||||
"factorio.enable_save_patching": false,
|
||||
"requires_features.load_plugin": true,
|
||||
});
|
||||
assert.equal(config.get("requires_features.load_plugin"), true);
|
||||
});
|
||||
it("should reject disabling a feature required by a loaded plugin", function() {
|
||||
class TestInstanceConfig extends InstanceConfig {
|
||||
static fieldDefinitions = { ...InstanceConfig.fieldDefinitions };
|
||||
static _fieldDependents; // Don't reuse the cache from InstanceConfig
|
||||
}
|
||||
|
||||
lib.addPluginFieldDefinitions(
|
||||
{ name: "save_patching", features: ["SavePatching"] },
|
||||
"instanceConfigFields", TestInstanceConfig
|
||||
);
|
||||
|
||||
const config = new TestInstanceConfig("controller");
|
||||
assert.throws(
|
||||
() => config.set("factorio.enable_save_patching", false),
|
||||
/requires save patching/
|
||||
);
|
||||
assert.equal(config.get("factorio.enable_save_patching"), true);
|
||||
});
|
||||
it("should allow when no feature flags are present", function() {
|
||||
class TestInstanceConfig extends InstanceConfig {
|
||||
static fieldDefinitions = { ...InstanceConfig.fieldDefinitions };
|
||||
|
||||
Reference in new issue
Block a user