mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-25 16:33:12 +09:00
Test that fromConfig saves instances changed while loading
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d7fc3aaec4
commit
ee097bfa6f
1 file changed
+40
@@ -14,6 +14,7 @@ import {
|
|||||||
addPluginConfigFields, renamePermissionPrefix,
|
addPluginConfigFields, renamePermissionPrefix,
|
||||||
} from "@clusterio/lib";
|
} from "@clusterio/lib";
|
||||||
|
|
||||||
|
import * as lib from "@clusterio/lib";
|
||||||
import "../setup_logging.js";
|
import "../setup_logging.js";
|
||||||
|
|
||||||
class MockEvent {}
|
class MockEvent {}
|
||||||
@@ -88,6 +89,45 @@ describe("controller/src/Controller", function() {
|
|||||||
assert(loaded.modPacks.size > 0, "default mod packs were not added");
|
assert(loaded.modPacks.size > 0, "default mod packs were not added");
|
||||||
await fs.access(modsDirectory);
|
await fs.access(modsDirectory);
|
||||||
});
|
});
|
||||||
|
describe("with a plugin version change", function() {
|
||||||
|
before(function() {
|
||||||
|
addPluginConfigFields([{ name: "from_config_plugin", version: "1.2.0", instanceEntrypoint: "x" }]);
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
lib.Config.pluginVersions.clear();
|
||||||
|
});
|
||||||
|
after(function() {
|
||||||
|
for (const Config of [lib.ControllerConfig, lib.HostConfig, lib.InstanceConfig]) {
|
||||||
|
for (const name of Object.keys(Config.fieldDefinitions)) {
|
||||||
|
if (name.startsWith("from_config_plugin.")) {
|
||||||
|
delete Config.fieldDefinitions[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it("should save instances whose config changed while loading", async function() {
|
||||||
|
const databaseDirectory = path.join(dir, "database");
|
||||||
|
const instancesPath = path.join(databaseDirectory, "instances.json");
|
||||||
|
await fs.mkdir(databaseDirectory);
|
||||||
|
const instanceConfig = new InstanceConfig("controller", {
|
||||||
|
"instance.id": 7, "from_config_plugin.version": "1.0.0",
|
||||||
|
});
|
||||||
|
await fs.writeFile(instancesPath, JSON.stringify([
|
||||||
|
{ config: instanceConfig.toJSON(), status: "unassigned" },
|
||||||
|
]));
|
||||||
|
lib.Config.pluginVersions.set("from_config_plugin", "1.2.0");
|
||||||
|
const config = new ControllerConfig("controller", {
|
||||||
|
"controller.version": controllerVersion,
|
||||||
|
"controller.database_directory": databaseDirectory,
|
||||||
|
"controller.mods_directory": path.join(dir, "mods"),
|
||||||
|
});
|
||||||
|
|
||||||
|
const loaded = await Controller.fromConfig({}, [], config);
|
||||||
|
await loaded.instances.records.save();
|
||||||
|
const [saved] = JSON.parse(await fs.readFile(instancesPath, "utf8"));
|
||||||
|
assert.equal(saved.config["from_config_plugin.version"], "1.2.0");
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe(".loadJsonObject()", function() {
|
describe(".loadJsonObject()", function() {
|
||||||
let dir;
|
let dir;
|
||||||
|
|||||||
Reference in new issue
Block a user