test with postgres and sqlite

Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
Johan Haals
2022-04-28 14:21:37 +02:00
parent ab17c3bbcd
commit 98ef64b45d
+37 -23
View File
@@ -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,