From c7c2cb48e8180a5e9cdd678e504de1cc2456616f Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 23 Jul 2024 14:41:34 +0100 Subject: [PATCH] wip --- .../src/api/routes/tests/search.spec.ts | 17 ++--- .../src/integrations/tests/utils/index.ts | 6 ++ .../src/integrations/tests/utils/oracle.ts | 62 +++++++++++++++++++ 3 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 packages/server/src/integrations/tests/utils/oracle.ts diff --git a/packages/server/src/api/routes/tests/search.spec.ts b/packages/server/src/api/routes/tests/search.spec.ts index e774158c23..6e685b13ab 100644 --- a/packages/server/src/api/routes/tests/search.spec.ts +++ b/packages/server/src/api/routes/tests/search.spec.ts @@ -40,13 +40,14 @@ import { structures } from "@budibase/backend-core/tests" import { DEFAULT_EMPLOYEE_TABLE_SCHEMA } from "../../../db/defaultData/datasource_bb_default" describe.each([ - ["in-memory", undefined], - ["lucene", undefined], - ["sqs", undefined], - [DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)], - [DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)], - [DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)], - [DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)], + //["in-memory", undefined], + //["lucene", undefined], + //["sqs", undefined], + //[DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)], + //[DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)], + //[DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)], + //[DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)], + [DatabaseName.ORACLE, getDatasource(DatabaseName.ORACLE)], ])("search (%s)", (name, dsProvider) => { const isSqs = name === "sqs" const isLucene = name === "lucene" @@ -291,7 +292,7 @@ describe.each([ }) describe("equal", () => { - it("successfully finds true row", async () => { + it.only("successfully finds true row", async () => { await expectQuery({ equal: { isTrue: true } }).toMatchExactly([ { isTrue: true }, ]) diff --git a/packages/server/src/integrations/tests/utils/index.ts b/packages/server/src/integrations/tests/utils/index.ts index b888f1adc1..da7d0d8666 100644 --- a/packages/server/src/integrations/tests/utils/index.ts +++ b/packages/server/src/integrations/tests/utils/index.ts @@ -4,6 +4,7 @@ import * as mongodb from "./mongodb" import * as mysql from "./mysql" import * as mssql from "./mssql" import * as mariadb from "./mariadb" +import * as oracle from "./oracle" import { GenericContainer, StartedTestContainer } from "testcontainers" import { testContainerUtils } from "@budibase/backend-core/tests" import cloneDeep from "lodash/cloneDeep" @@ -16,6 +17,7 @@ export enum DatabaseName { MYSQL = "mysql", SQL_SERVER = "mssql", MARIADB = "mariadb", + ORACLE = "oracle", } const providers: Record = { @@ -24,6 +26,7 @@ const providers: Record = { [DatabaseName.MYSQL]: mysql.getDatasource, [DatabaseName.SQL_SERVER]: mssql.getDatasource, [DatabaseName.MARIADB]: mariadb.getDatasource, + [DatabaseName.ORACLE]: oracle.getDatasource, } export function getDatasourceProviders( @@ -59,6 +62,9 @@ export async function knexClient(ds: Datasource) { case SourceName.SQL_SERVER: { return mssql.knexClient(ds) } + case SourceName.ORACLE: { + return oracle.knexClient(ds) + } default: { throw new Error(`Unsupported source: ${ds.source}`) } diff --git a/packages/server/src/integrations/tests/utils/oracle.ts b/packages/server/src/integrations/tests/utils/oracle.ts new file mode 100644 index 0000000000..a4f294d7ba --- /dev/null +++ b/packages/server/src/integrations/tests/utils/oracle.ts @@ -0,0 +1,62 @@ +import { Datasource, SourceName } from "@budibase/types" +import { GenericContainer, Wait } from "testcontainers" +import { generator, testContainerUtils } from "@budibase/backend-core/tests" +import { startContainer } from "." +import knex from "knex" + +let ports: Promise + +export async function getDatasource(): Promise { + if (!ports) { + let image = "oracle/database:19.3.0.0-ee" + if (process.arch.startsWith("arm")) { + image = "samhuang78/oracle-database:19.3.0-ee-slim-faststart" + } + + ports = startContainer( + new GenericContainer(image) + .withExposedPorts(1521) + .withEnvironment({ ORACLE_PASSWORD: "password" }) + .withWaitStrategy(Wait.forHealthCheck().withStartupTimeout(10000)) + ) + } + + const port = (await ports).find(x => x.container === 1521)?.host + if (!port) { + throw new Error("Oracle port not found") + } + + const datasource: Datasource = { + type: "datasource_plus", + source: SourceName.ORACLE, + plus: true, + config: { + host: "127.0.0.1", + port, + database: "postgres", + user: "SYS", + password: "password", + }, + } + + const database = generator.guid().replaceAll("-", "") + const client = await knexClient(datasource) + await client.raw(`CREATE DATABASE "${database}"`) + datasource.config!.database = database + + return datasource +} + +export async function knexClient(ds: Datasource) { + if (!ds.config) { + throw new Error("Datasource config is missing") + } + if (ds.source !== SourceName.ORACLE) { + throw new Error("Datasource source is not Oracle") + } + + return knex({ + client: "oracledb", + connection: ds.config, + }) +}