remove unnecessary testing, fix columns, feedback

Signed-off-by: lpete@vmware.com <lpete@vmware.com>

fix issues with merge

Signed-off-by: lpete@vmware.com <lpete@vmware.com>
This commit is contained in:
lpete@vmware.com
2023-08-15 10:09:05 -04:00
parent 8f61efaea5
commit a2960b0667
9 changed files with 37 additions and 95 deletions
-25
View File
@@ -1,25 +0,0 @@
name: '!Test Databases'
on:
workflow_dispatch:
pull_request:
branches: ['mysql']
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- run: yarn install
- run: yarn tsc
- run: yarn build:all
- run: yarn test
+1 -1
View File
@@ -60,7 +60,7 @@ jobs:
- run: yarn backstage-cli repo build
- name: run E2E test
run: |
yarn e2e-test run
yarn e2e-test run --dbms=mysql
env:
BACKSTAGE_TEST_DISABLE_DOCKER: 1
BACKSTAGE_TEST_DATABASE_MYSQL8_CONNECTION_STRING: mysql://root:root@localhost:${{ job.services.mysql8.ports[3306] }}/ignored
@@ -1,29 +0,0 @@
app:
# Should be the same as backend.baseUrl when using the `app-backend` plugin.
baseUrl: http://localhost:7007
backend:
# Note that the baseUrl should be the URL that the browser and other clients
# should use when communicating with the backend, i.e. it needs to be
# reachable not just from within the backend host, but from all of your
# callers. When its value is "http://localhost:7007", it's strictly private
# and can't be reached by others.
baseUrl: http://localhost:7007
# The listener can also be expressed as a single <host>:<port> string. In this case we bind to
# all interfaces, the most permissive setting. The right value depends on your specific deployment.
listen: ':7007'
# config options including ssl: https://github.com/mysqljs/mysql#connection-options
database:
client: mysql2
connection:
host: ${MYSQL_HOST}
port: ${MYSQL_PORT}
user: ${MYSQL_USER}
password: ${MYSQL_PASSWORD}
catalog:
# Overrides the default list locations from app-config.yaml as these contain example data.
# See https://backstage.io/docs/features/software-catalog/#adding-components-to-the-catalog for more details
# on how to get entities into the catalog.
locations: []
+1 -1
View File
@@ -35,8 +35,8 @@
"cross-fetch": "^3.1.5",
"fs-extra": "10.1.0",
"handlebars": "^4.7.3",
"pgtools": "^1.0.0",
"mysql2": "^2.2.5",
"pgtools": "^1.0.0",
"puppeteer": "^17.0.0",
"tree-kill": "^1.2.2"
},
+8 -1
View File
@@ -18,5 +18,12 @@ import { Command } from 'commander';
import { run } from './run';
export function registerCommands(program: Command) {
program.command('run').description('Run e2e tests').action(run);
program
.command('run')
.description('Run e2e tests')
.option(
'-db, --dbms',
'Selected database management system for e2e testing, (eg. mysql, postgres)',
)
.action(run);
}
+15 -26
View File
@@ -46,7 +46,7 @@ const templatePackagePaths = [
'packages/create-app/templates/default-app/packages/backend/package.json.hbs',
];
export async function run() {
export async function run(dbms: string = 'postgres') {
const rootDir = await fs.mkdtemp(resolvePath(os.tmpdir(), 'backstage-e2e-'));
print(`CLI E2E test root: ${rootDir}\n`);
@@ -69,17 +69,15 @@ export async function run() {
print('Starting the app');
await testAppServe(pluginId, appDir);
if (Boolean(process.env.POSTGRES_USER) || Boolean(process.env.MYSQL_USER)) {
if (
Boolean(process.env.POSTGRES_USER) ||
Boolean(process.env.BACKSTAGE_TEST_DATABASE_MYSQL8_CONNECTION_STRING)
) {
print('Testing the datbase backend startup');
await preCleanDatabase();
await dropClientDatabases(dbms);
const appConfig = path.resolve(appDir, 'app-config.yaml');
let productionConfig = path.resolve(appDir, 'app-config.production.yaml');
if (Boolean(process.env.MYSQL_HOST)) {
productionConfig = path.resolve(
appDir,
'app-config.production.mysql.yaml',
);
}
const productionConfig = path.resolve(appDir, 'app-config.production.yaml');
await testBackendStart(
appDir,
'--config',
@@ -435,10 +433,10 @@ async function testAppServe(pluginId: string, appDir: string) {
}
}
/** Drops PG databases */
async function dropDB(database: string, client: string) {
/** Drops databases */
async function dropDB(database: string, dbms: string) {
try {
if (client === 'postgres') {
if (dbms === 'postgres') {
const config = {
host: process.env.POSTGRES_HOST ? process.env.POSTGRES_HOST : '',
port: process.env.POSTGRES_PORT ? process.env.POSTGRES_PORT : '',
@@ -448,7 +446,7 @@ async function dropDB(database: string, client: string) {
: '',
};
await pgtools.dropdb(config, database);
} else if (client === 'mysql') {
} else if (dbms === 'mysql') {
const connectionString =
process.env.BACKSTAGE_TEST_DATABASE_MYSQL8_CONNECTION_STRING ?? '';
const connection = await mysql.createConnection(connectionString);
@@ -460,18 +458,8 @@ async function dropDB(database: string, client: string) {
}
/** Clean remnants from prior e2e runs */
async function preCleanDatabase() {
async function dropClientDatabases(dbms: string) {
print('Dropping old DBs');
if (Boolean(process.env.POSTGRES_HOST)) {
await dropClientDatabases('postgres');
}
if (Boolean(process.env.BACKSTAGE_TEST_DATABASE_MYSQL8_CONNECTION_STRING)) {
await dropClientDatabases('mysql');
}
print('Created DBs');
}
async function dropClientDatabases(client: string) {
await Promise.all(
[
'catalog',
@@ -481,8 +469,9 @@ async function dropClientDatabases(client: string) {
'proxy',
'techdocs',
'search',
].map(name => dropDB(`backstage_plugin_${name}`, client)),
].map(name => dropDB(`backstage_plugin_${name}`, dbms)),
);
print('Created DBs');
}
/**
@@ -25,7 +25,7 @@ exports.up = async function up(knex) {
'A cache of static assets that where previously deployed and may still be lazy-loaded by clients',
);
table
.string('path')
.text('path', 'longtext')
.primary()
.notNullable()
.comment('The path of the file');
@@ -138,20 +138,20 @@ export class StaticAssetsStore implements StaticAssetProvider {
*/
async trimAssets(options: { maxAgeSeconds: number }) {
const { maxAgeSeconds } = options;
let lastModifiedInterval = `now() + interval '${-maxAgeSeconds} seconds'`;
let lastModifiedInterval = this.#db.raw(
`now() + interval '${-maxAgeSeconds} seconds'`,
);
if (this.#db.client.config.client.includes('mysql')) {
lastModifiedInterval = `date_sub(now(), interval ${maxAgeSeconds} second)`;
lastModifiedInterval = this.#db.raw(
`date_sub(now(), interval ${maxAgeSeconds} second)`,
);
} else if (this.#db.client.config.client.includes('sqlite3')) {
lastModifiedInterval = `datetime('now', ?)`;
lastModifiedInterval = this.#db.raw(`datetime('now', ?)`, [
`-${maxAgeSeconds} seconds`,
]);
}
await this.#db<StaticAssetRow>('static_assets_cache')
.where(
'last_modified_at',
'<=',
this.#db.client.config.client.includes('sqlite3')
? this.#db.raw(lastModifiedInterval, [`-${maxAgeSeconds} seconds`])
: this.#db.raw(lastModifiedInterval),
)
.where('last_modified_at', '<=', lastModifiedInterval)
.delete();
}
}
+1 -1
View File
@@ -23670,9 +23670,9 @@ __metadata:
cross-fetch: ^3.1.5
fs-extra: 10.1.0
handlebars: ^4.7.3
mysql2: ^2.2.5
nodemon: ^3.0.1
pgtools: ^1.0.0
mysql2: ^2.2.5
puppeteer: ^17.0.0
tree-kill: ^1.2.2
ts-node: ^10.0.0