From 98ef64b45d63ab0e7293458cdb437894e6c80862 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Thu, 28 Apr 2022 14:21:37 +0200 Subject: [PATCH] test with postgres and sqlite Signed-off-by: Johan Haals --- packages/e2e-test/src/commands/run.ts | 60 +++++++++++++++++---------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/packages/e2e-test/src/commands/run.ts b/packages/e2e-test/src/commands/run.ts index b6df9f61dd..3e5b546225 100644 --- a/packages/e2e-test/src/commands/run.ts +++ b/packages/e2e-test/src/commands/run.ts @@ -21,6 +21,7 @@ import handlebars from 'handlebars'; import killTree from 'tree-kill'; import { resolve as resolvePath, join as joinPath } from 'path'; import puppeteer from 'puppeteer'; +import path from 'path'; import { spawnPiped, @@ -49,7 +50,6 @@ export async function run() { print('Building dist workspace'); const workspaceDir = await buildDistWorkspace('workspace', rootDir); - const isPostgres = Boolean(process.env.POSTGRES_USER); print('Creating a Backstage App'); const appDir = await createApp('test-app', workspaceDir, rootDir); @@ -62,8 +62,21 @@ export async function run() { print('Starting the app'); await testAppServe(pluginName, appDir); - print('Testing the backend startup'); - await testBackendStart(appDir, isPostgres); + const appConfig = path.resolve(appDir, 'app-config.yaml'); + if (Boolean(process.env.POSTGRES_USER)) { + print('Testing the PostgreSQL backend startup'); + await preCleanPostgres(); + const productionConfig = path.resolve(appDir, 'app-config.production.yaml'); + await testBackendStart( + appDir, + '--config', + appConfig, + '--config', + productionConfig, + ); + } + print('Testing the SQLite backend startup'); + await testBackendStart(appDir, '--config', appConfig); if (process.env.CI) { // Cleanup actually takes significant time, so skip it in CI since the @@ -100,8 +113,8 @@ async function buildDistWorkspace(workspaceName: string, rootDir: string) { } for (const pkgJsonPath of templatePackagePaths) { - const path = paths.resolveOwnRoot(pkgJsonPath); - const pkgTemplate = await fs.readFile(path, 'utf8'); + const jsonPath = paths.resolveOwnRoot(pkgJsonPath); + const pkgTemplate = await fs.readFile(jsonPath, 'utf8'); const pkg = JSON.parse( handlebars.compile(pkgTemplate)( { @@ -401,27 +414,28 @@ async function dropDB(database: string) { } } +/** Clean remnants from prior e2e runs */ +async function preCleanPostgres() { + print('Dropping old DBs'); + await Promise.all( + [ + 'catalog', + 'scaffolder', + 'auth', + 'identity', + 'proxy', + 'techdocs', + 'search', + ].map(name => dropDB(`backstage_plugin_${name}`)), + ); + print('Created DBs'); +} + /** * Start serving the newly created backend and make sure that all db migrations works correctly */ -async function testBackendStart(appDir: string, isPostgres: boolean) { - if (isPostgres) { - print('Dropping old DBs'); - await Promise.all( - [ - 'catalog', - 'scaffolder', - 'auth', - 'identity', - 'proxy', - 'techdocs', - 'search', - ].map(name => dropDB(`backstage_plugin_${name}`)), - ); - print('Created DBs'); - } - - const child = spawnPiped(['yarn', 'workspace', 'backend', 'start'], { +async function testBackendStart(appDir: string, ...args: string[]) { + const child = spawnPiped(['yarn', 'workspace', 'backend', 'start', ...args], { cwd: appDir, env: { ...process.env,