From cda7d2070ce9a22e1a5dcfe721d6b192dc85bc5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Tue, 2 Jan 2024 10:47:59 +0000 Subject: [PATCH] test: specify custom config in dbm (#5550) Was having some trouble running these migration tests locally due to `dbm` not correctly picking up the passed in config. This fixes it by setting the custom config property after it has been initialized, always overriding any wrong values. PS: I think I found the issue. `dbm` was prioritizing my `DATABASE_URL` for some reason, as I started having issues when it was set, and stopped having issues when I unset it. I still think this is a good change, as it prevents similar hard-to-debug issues in the future. To help clarify this, running this locally: - `export DATABASE_URL=postgres://unleash_user:passord@localhost:5432/unleash` - `yarn test dedupe-permissions` Fails on `main`, but passes on this branch. For some reason the `dbm` instance prioritizes whatever is set in `DATABASE_URL` instead of the options that are passed in `getInstance`. --- src/test/e2e/dedupe-permissions.e2e.test.ts | 8 +++++--- src/test/e2e/favor-permission-name-over-id.e2e.test.ts | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/test/e2e/dedupe-permissions.e2e.test.ts b/src/test/e2e/dedupe-permissions.e2e.test.ts index 20f26eba0a24..a02632f7ee6f 100644 --- a/src/test/e2e/dedupe-permissions.e2e.test.ts +++ b/src/test/e2e/dedupe-permissions.e2e.test.ts @@ -28,7 +28,7 @@ test('Dedupe permissions migration correctly dedupes permissions', async () => { await initSchema(config.db); - const e2e = { + const custom = { ...config.db, connectionTimeoutMillis: 2000, }; @@ -37,10 +37,12 @@ test('Dedupe permissions migration correctly dedupes permissions', async () => { process.argv = process.argv.filter((it) => !it.includes('--verbose')); const dbm = getInstance(true, { cwd: `${__dirname}/../../`, // relative to src/test/e2e - config: { e2e }, - env: 'e2e', + config: { custom }, + env: 'custom', }); + dbm.config.custom = custom; + // Run all migrations up to, and including, this one, the last one before the dedupe migration await dbm.up('20231121153304-add-permission-create-tag-type.js'); diff --git a/src/test/e2e/favor-permission-name-over-id.e2e.test.ts b/src/test/e2e/favor-permission-name-over-id.e2e.test.ts index b522c96fb7a0..f8c4198996bf 100644 --- a/src/test/e2e/favor-permission-name-over-id.e2e.test.ts +++ b/src/test/e2e/favor-permission-name-over-id.e2e.test.ts @@ -28,7 +28,7 @@ test('Favor permission name over id migration correctly assigns permissions by n await initSchema(config.db); - const e2e = { + const custom = { ...config.db, connectionTimeoutMillis: 2000, }; @@ -37,10 +37,12 @@ test('Favor permission name over id migration correctly assigns permissions by n process.argv = process.argv.filter((it) => !it.includes('--verbose')); const dbm = getInstance(true, { cwd: `${__dirname}/../../`, // relative to src/test/e2e - config: { e2e }, - env: 'e2e', + config: { custom }, + env: 'custom', }); + dbm.config.custom = custom; + // Run all migrations up to, and including, this one, the last one before the favor permission name over id migration await dbm.up('20231123100052-drop-last-seen-foreign-key.js');