diff --git a/.changeset/backend-like-a-tattoo.md b/.changeset/backend-like-a-tattoo.md new file mode 100644 index 0000000000..0d2edfa7a9 --- /dev/null +++ b/.changeset/backend-like-a-tattoo.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-test-utils': patch +--- + +Added `POSTGRES_11` and `POSTGRES_12` as supported test database IDs. diff --git a/packages/backend-test-utils/api-report.md b/packages/backend-test-utils/api-report.md index c13d1bb859..358b51071f 100644 --- a/packages/backend-test-utils/api-report.md +++ b/packages/backend-test-utils/api-report.md @@ -169,6 +169,8 @@ export interface TestBackendOptions< // @public export type TestDatabaseId = | 'POSTGRES_13' + | 'POSTGRES_12' + | 'POSTGRES_11' | 'POSTGRES_9' | 'MYSQL_8' | 'SQLITE_3'; diff --git a/packages/backend-test-utils/src/database/TestDatabases.test.ts b/packages/backend-test-utils/src/database/TestDatabases.test.ts index 691ac5259e..be29a42806 100644 --- a/packages/backend-test-utils/src/database/TestDatabases.test.ts +++ b/packages/backend-test-utils/src/database/TestDatabases.test.ts @@ -36,7 +36,7 @@ describe('TestDatabases', () => { process.env = OLD_ENV; }); - describe('each', () => { + describe('each create', () => { const dbs = TestDatabases.create(); it.each(dbs.eachSupportedId())( @@ -56,81 +56,160 @@ describe('TestDatabases', () => { ); }); - itIfDocker('obeys a provided connection string for postgres 13', async () => { + describe('each connect', () => { const dbs = TestDatabases.create(); - const { host, port, user, password, stop } = await startPostgresContainer( - 'postgres:13', + + itIfDocker( + 'obeys a provided connection string for postgres 13', + async () => { + const { host, port, user, password, stop } = + await startPostgresContainer('postgres:13'); + + try { + // Leave a mark + process.env.BACKSTAGE_TEST_DATABASE_POSTGRES13_CONNECTION_STRING = `postgresql://${user}:${password}@${host}:${port}`; + const input = await dbs.init('POSTGRES_13'); + await input.schema.createTable('a', table => + table.string('x').primary(), + ); + await input.insert({ x: 'y' }).into('a'); + + // Look for the mark + const database = input.client.config.connection.database; + const output = knexFactory({ + client: 'pg', + connection: { host, port, user, password, database }, + }); + // eslint-disable-next-line jest/no-standalone-expect + await expect(output.select('x').from('a')).resolves.toEqual([ + { x: 'y' }, + ]); + } finally { + await stop(); + } + }, ); - try { - // Leave a mark - process.env.BACKSTAGE_TEST_DATABASE_POSTGRES13_CONNECTION_STRING = `postgresql://${user}:${password}@${host}:${port}`; - const input = await dbs.init('POSTGRES_13'); - await input.schema.createTable('a', table => table.string('x').primary()); - await input.insert({ x: 'y' }).into('a'); + itIfDocker( + 'obeys a provided connection string for postgres 12', + async () => { + const { host, port, user, password, stop } = + await startPostgresContainer('postgres:12'); - // Look for the mark - const database = input.client.config.connection.database; - const output = knexFactory({ - client: 'pg', - connection: { host, port, user, password, database }, - }); - // eslint-disable-next-line jest/no-standalone-expect - await expect(output.select('x').from('a')).resolves.toEqual([{ x: 'y' }]); - } finally { - await stop(); - } - }); + try { + // Leave a mark + process.env.BACKSTAGE_TEST_DATABASE_POSTGRES12_CONNECTION_STRING = `postgresql://${user}:${password}@${host}:${port}`; + const input = await dbs.init('POSTGRES_12'); + await input.schema.createTable('a', table => + table.string('x').primary(), + ); + await input.insert({ x: 'y' }).into('a'); - itIfDocker('obeys a provided connection string for postgres 9', async () => { - const dbs = TestDatabases.create(); - const { host, port, user, password, stop } = await startPostgresContainer( - 'postgres:9', + // Look for the mark + const database = input.client.config.connection.database; + const output = knexFactory({ + client: 'pg', + connection: { host, port, user, password, database }, + }); + // eslint-disable-next-line jest/no-standalone-expect + await expect(output.select('x').from('a')).resolves.toEqual([ + { x: 'y' }, + ]); + } finally { + await stop(); + } + }, ); - try { - // Leave a mark - process.env.BACKSTAGE_TEST_DATABASE_POSTGRES9_CONNECTION_STRING = `postgresql://${user}:${password}@${host}:${port}`; - const input = await dbs.init('POSTGRES_9'); - await input.schema.createTable('a', table => table.string('x').primary()); - await input.insert({ x: 'y' }).into('a'); + itIfDocker( + 'obeys a provided connection string for postgres 11', + async () => { + const { host, port, user, password, stop } = + await startPostgresContainer('postgres:11'); - // Look for the mark - const database = input.client.config.connection.database; - const output = knexFactory({ - client: 'pg', - connection: { host, port, user, password, database }, - }); - // eslint-disable-next-line jest/no-standalone-expect - await expect(output.select('x').from('a')).resolves.toEqual([{ x: 'y' }]); - } finally { - await stop(); - } - }); + try { + // Leave a mark + process.env.BACKSTAGE_TEST_DATABASE_POSTGRES11_CONNECTION_STRING = `postgresql://${user}:${password}@${host}:${port}`; + const input = await dbs.init('POSTGRES_11'); + await input.schema.createTable('a', table => + table.string('x').primary(), + ); + await input.insert({ x: 'y' }).into('a'); - itIfDocker('obeys a provided connection string for mysql 8', async () => { - const dbs = TestDatabases.create(); - const { host, port, user, password, stop } = await startMysqlContainer( - 'mysql:8', + // Look for the mark + const database = input.client.config.connection.database; + const output = knexFactory({ + client: 'pg', + connection: { host, port, user, password, database }, + }); + // eslint-disable-next-line jest/no-standalone-expect + await expect(output.select('x').from('a')).resolves.toEqual([ + { x: 'y' }, + ]); + } finally { + await stop(); + } + }, ); - try { - // Leave a mark - process.env.BACKSTAGE_TEST_DATABASE_MYSQL8_CONNECTION_STRING = `mysql://${user}:${password}@${host}:${port}/ignored`; - const input = await dbs.init('MYSQL_8'); - await input.schema.createTable('a', table => table.string('x').primary()); - await input.insert({ x: 'y' }).into('a'); + itIfDocker( + 'obeys a provided connection string for postgres 9', + async () => { + const { host, port, user, password, stop } = + await startPostgresContainer('postgres:9'); - // Look for the mark - const database = input.client.config.connection.database; - const output = knexFactory({ - client: 'mysql2', - connection: { host, port, user, password, database }, - }); - // eslint-disable-next-line jest/no-standalone-expect - await expect(output.select('x').from('a')).resolves.toEqual([{ x: 'y' }]); - } finally { - await stop(); - } + try { + // Leave a mark + process.env.BACKSTAGE_TEST_DATABASE_POSTGRES9_CONNECTION_STRING = `postgresql://${user}:${password}@${host}:${port}`; + const input = await dbs.init('POSTGRES_9'); + await input.schema.createTable('a', table => + table.string('x').primary(), + ); + await input.insert({ x: 'y' }).into('a'); + + // Look for the mark + const database = input.client.config.connection.database; + const output = knexFactory({ + client: 'pg', + connection: { host, port, user, password, database }, + }); + // eslint-disable-next-line jest/no-standalone-expect + await expect(output.select('x').from('a')).resolves.toEqual([ + { x: 'y' }, + ]); + } finally { + await stop(); + } + }, + ); + + itIfDocker('obeys a provided connection string for mysql 8', async () => { + const { host, port, user, password, stop } = await startMysqlContainer( + 'mysql:8', + ); + + try { + // Leave a mark + process.env.BACKSTAGE_TEST_DATABASE_MYSQL8_CONNECTION_STRING = `mysql://${user}:${password}@${host}:${port}/ignored`; + const input = await dbs.init('MYSQL_8'); + await input.schema.createTable('a', table => + table.string('x').primary(), + ); + await input.insert({ x: 'y' }).into('a'); + + // Look for the mark + const database = input.client.config.connection.database; + const output = knexFactory({ + client: 'mysql2', + connection: { host, port, user, password, database }, + }); + // eslint-disable-next-line jest/no-standalone-expect + await expect(output.select('x').from('a')).resolves.toEqual([ + { x: 'y' }, + ]); + } finally { + await stop(); + } + }); }); }); diff --git a/packages/backend-test-utils/src/database/types.ts b/packages/backend-test-utils/src/database/types.ts index 083853ac78..89ec21e7cc 100644 --- a/packages/backend-test-utils/src/database/types.ts +++ b/packages/backend-test-utils/src/database/types.ts @@ -24,6 +24,8 @@ import { Knex } from 'knex'; */ export type TestDatabaseId = | 'POSTGRES_13' + | 'POSTGRES_12' + | 'POSTGRES_11' | 'POSTGRES_9' | 'MYSQL_8' | 'SQLITE_3'; @@ -50,6 +52,20 @@ export const allDatabases: Record = connectionStringEnvironmentVariableName: 'BACKSTAGE_TEST_DATABASE_POSTGRES13_CONNECTION_STRING', }, + POSTGRES_12: { + name: 'Postgres 12.x', + driver: 'pg', + dockerImageName: 'postgres:12', + connectionStringEnvironmentVariableName: + 'BACKSTAGE_TEST_DATABASE_POSTGRES12_CONNECTION_STRING', + }, + POSTGRES_11: { + name: 'Postgres 11.x', + driver: 'pg', + dockerImageName: 'postgres:11', + connectionStringEnvironmentVariableName: + 'BACKSTAGE_TEST_DATABASE_POSTGRES11_CONNECTION_STRING', + }, POSTGRES_9: { name: 'Postgres 9.x', driver: 'pg',