Add config migrations (#693)

Co-authored-by: Danielv123 <danielv@danielv.no>
This commit is contained in:
Cooldude2606andDanielv123 authored and GitHub committed 2024-11-26 23:14:56 +00:00
1 parent 05ca4eb25e
commit 4248e57dcb
7 files changed
+43 -9

No files matched your search

+15
View File
@@ -7,6 +7,14 @@ const CA = lib.ConfigAccess;
describe("lib/config/classes", function() {
describe("Config", function() {
class TestConfig extends lib.Config {
static migrations(config) {
if (config.hasOwnProperty("test.migration")) {
config["alpha.foo"] = config["test.migration"];
delete config["test.migration"];
}
return config;
}
static fieldDefinitions = {
"alpha.foo": { type: "string", optional: true },
"beta.bar": { type: "object", initialValue: {} },
@@ -60,6 +68,13 @@ describe("lib/config/classes", function() {
assert.equal(testInstance.fields["test.enum"], "b");
assert.equal(testInstance.fields["test.priv"], undefined);
});
it("should apply migrations", function() {
const config = new TestConfig("local", {
"test.migration": "foo",
});
assert.equal(config.get("alpha.foo"), "foo");
assert.equal(config.fields["test.migration"], undefined);
});
});
describe(".toJSON()", function() {
+1 -1
View File
@@ -160,7 +160,7 @@ class MockController {
this.app.locals.controller = this;
this.app.locals.streams = new Map();
this.mockConfigEntries = new Map([
["controller.external_address", "test"],
["controller.public_url", "test"],
["controller.auth_secret", "TestSecretDoNotUse"],
["controller.proxy_stream_timeout", 1],
]);