From 39b6011d4ab29df06d62ed9b09282a87b3ae0804 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Mon, 15 Apr 2024 15:05:19 +0200 Subject: [PATCH 1/5] Add config def. loading test --- test/common/unit/config/Config.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/common/unit/config/Config.ts diff --git a/test/common/unit/config/Config.ts b/test/common/unit/config/Config.ts new file mode 100644 index 00000000..747d50a9 --- /dev/null +++ b/test/common/unit/config/Config.ts @@ -0,0 +1,16 @@ +import {expect} from 'chai'; +import { ConfigClassBuilder } from 'typeconfig/node'; +import {ExtensionConfigWrapper} from '../../../../src/backend/model/extension/ExtensionConfigWrapper'; + + +describe('Config', () => { + it('should load default from env', () => { + process.env['default-Media-tempFolder'] = 'test/test' + const conf = ExtensionConfigWrapper.originalSync(); + console.log(ConfigClassBuilder.attachPrivateInterface(conf.Media).__defaults); + expect(ConfigClassBuilder.attachPrivateInterface(conf.Media).__defaults.tempFolder).to.be.equal('test/test'); + expect(process.env['default-Media-tempFolder']).to.be.equal('test/test'); + const conf2 = ExtensionConfigWrapper.originalSync(); + expect(ConfigClassBuilder.attachPrivateInterface(conf2.Media).__defaults.tempFolder).to.be.equal('test/test'); + }); +}); From 796cbec521bf02a302dca77febe58423def4c51c Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Mon, 15 Apr 2024 17:25:33 +0200 Subject: [PATCH 2/5] some debug log.. --- src/common/config/private/Config.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/common/config/private/Config.ts b/src/common/config/private/Config.ts index 7a14e5c0..b568e1f0 100644 --- a/src/common/config/private/Config.ts +++ b/src/common/config/private/Config.ts @@ -12,4 +12,9 @@ try { } ExtensionConfigTemplateLoader.Instance.init(path.join(__dirname, '/../../../../', pre.Extensions.folder)); +console.log(process.env['default-Media-tempFolder']); +console.log(ConfigClassBuilder.attachPrivateInterface(pre.Media).__defaults.tempFolder); + export const Config = ExtensionConfigWrapper.originalSync(true); + +console.log(ConfigClassBuilder.attachPrivateInterface(Config.Media).__defaults.tempFolder); From e4c31c93480efe45ff4114ad155865122cb22a86 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Mon, 15 Apr 2024 17:27:35 +0200 Subject: [PATCH 3/5] more logs --- docker/alpine/Dockerfile.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/alpine/Dockerfile.build b/docker/alpine/Dockerfile.build index 42e0947f..76186153 100644 --- a/docker/alpine/Dockerfile.build +++ b/docker/alpine/Dockerfile.build @@ -16,7 +16,7 @@ RUN mkdir -p /app/data/config && \ #----------------------------------------- FROM node:18-alpine3.17 AS main WORKDIR /app -ENV NODE_ENV=production \ +ENV NODE_ENV=debug \ # overrides only the default value of the settings (the actualy value can be overwritten through config.json) default-Database-dbFolder=/app/data/db \ default-Media-folder=/app/data/images \ From 5222795ddc72951fbedd427ff5d63768be00dfb0 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Mon, 15 Apr 2024 21:03:03 +0200 Subject: [PATCH 4/5] fix default loading issue #888 --- .../model/extension/ExtensionConfigWrapper.ts | 5 ++--- src/common/config/private/PrivateConfigClass.ts | 2 +- test/common/unit/config/Config.ts | 15 ++++++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/backend/model/extension/ExtensionConfigWrapper.ts b/src/backend/model/extension/ExtensionConfigWrapper.ts index d96e4bc7..ec24c3a9 100644 --- a/src/backend/model/extension/ExtensionConfigWrapper.ts +++ b/src/backend/model/extension/ExtensionConfigWrapper.ts @@ -22,9 +22,8 @@ export class ExtensionConfigWrapper { // make sure the config file exists by the time we load it. // TODO: remove this once typeconfig is fixed and can properly load defaults in arrays if (!fs.existsSync((pc.__options as ConfigClassOptions).configPath)) { - await pc.save(); + await pc.load(); } - await pc.load(); // loading the basic configs, but we do not know the extension config hierarchy yet // TODO make sure that all extensions are present even after loading them from file @@ -47,7 +46,7 @@ export class ExtensionConfigWrapper { // make sure the config file exists by the time we load it. // TODO: remove this once typeconfig is fixed and can properly load defaults in arrays if (!fs.existsSync((pc.__options as ConfigClassOptions).configPath)) { - pc.saveSync(); + pc.loadSync(); } pc.loadSync(); // loading the basic configs, but we do not know the extension config hierarchy yet // TODO make sure that all extensions are present even after loading them from file diff --git a/src/common/config/private/PrivateConfigClass.ts b/src/common/config/private/PrivateConfigClass.ts index f9d34834..d7386684 100644 --- a/src/common/config/private/PrivateConfigClass.ts +++ b/src/common/config/private/PrivateConfigClass.ts @@ -15,7 +15,7 @@ const isTesting = process.env['NODE_ENV'] == true || ['afterEach', 'after', 'bef .every((fn) => (global as any)[fn] instanceof Function); @ConfigClass & ServerConfig>({ - configPath: path.join(__dirname, !isTesting ? './../../../../config.json' : './../../../../test/backend/tmp/config.json'), + configPath: path.join(__dirname, !isTesting ? './../../../../config.json' : './../../../../test/tmp/config.json'), crateConfigPathIfNotExists: isTesting, saveIfNotExist: true, attachDescription: true, diff --git a/test/common/unit/config/Config.ts b/test/common/unit/config/Config.ts index 747d50a9..f288d02f 100644 --- a/test/common/unit/config/Config.ts +++ b/test/common/unit/config/Config.ts @@ -1,16 +1,25 @@ import {expect} from 'chai'; -import { ConfigClassBuilder } from 'typeconfig/node'; +import {ConfigClassBuilder} from 'typeconfig/node'; import {ExtensionConfigWrapper} from '../../../../src/backend/model/extension/ExtensionConfigWrapper'; +import {TestHelper} from '../../../TestHelper'; +import * as fs from 'fs'; describe('Config', () => { + beforeEach(async () => { + await fs.promises.rm(TestHelper.TMP_DIR, {recursive: true, force: true}); + }); + afterEach(async () => { + await fs.promises.rm(TestHelper.TMP_DIR, {recursive: true, force: true}); + }); it('should load default from env', () => { - process.env['default-Media-tempFolder'] = 'test/test' + process.env['default-Media-tempFolder'] = 'test/test'; const conf = ExtensionConfigWrapper.originalSync(); - console.log(ConfigClassBuilder.attachPrivateInterface(conf.Media).__defaults); + expect(conf.Media.tempFolder).to.be.equal('test/test'); expect(ConfigClassBuilder.attachPrivateInterface(conf.Media).__defaults.tempFolder).to.be.equal('test/test'); expect(process.env['default-Media-tempFolder']).to.be.equal('test/test'); const conf2 = ExtensionConfigWrapper.originalSync(); expect(ConfigClassBuilder.attachPrivateInterface(conf2.Media).__defaults.tempFolder).to.be.equal('test/test'); + expect(conf2.Media.tempFolder).to.be.equal('test/test'); }); }); From e77fd910c20a3ba8a35af9bb90b6635873d186d4 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Mon, 15 Apr 2024 21:05:06 +0200 Subject: [PATCH 5/5] remove logs --- docker/alpine/Dockerfile.build | 2 +- src/common/config/private/Config.ts | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/docker/alpine/Dockerfile.build b/docker/alpine/Dockerfile.build index 76186153..42e0947f 100644 --- a/docker/alpine/Dockerfile.build +++ b/docker/alpine/Dockerfile.build @@ -16,7 +16,7 @@ RUN mkdir -p /app/data/config && \ #----------------------------------------- FROM node:18-alpine3.17 AS main WORKDIR /app -ENV NODE_ENV=debug \ +ENV NODE_ENV=production \ # overrides only the default value of the settings (the actualy value can be overwritten through config.json) default-Database-dbFolder=/app/data/db \ default-Media-folder=/app/data/images \ diff --git a/src/common/config/private/Config.ts b/src/common/config/private/Config.ts index b568e1f0..7a14e5c0 100644 --- a/src/common/config/private/Config.ts +++ b/src/common/config/private/Config.ts @@ -12,9 +12,4 @@ try { } ExtensionConfigTemplateLoader.Instance.init(path.join(__dirname, '/../../../../', pre.Extensions.folder)); -console.log(process.env['default-Media-tempFolder']); -console.log(ConfigClassBuilder.attachPrivateInterface(pre.Media).__defaults.tempFolder); - export const Config = ExtensionConfigWrapper.originalSync(true); - -console.log(ConfigClassBuilder.attachPrivateInterface(Config.Media).__defaults.tempFolder);