diff --git a/packages/server/src/integrations/tests/utils/index.ts b/packages/server/src/integrations/tests/utils/index.ts new file mode 100644 index 0000000000..2c8c583fd4 --- /dev/null +++ b/packages/server/src/integrations/tests/utils/index.ts @@ -0,0 +1,5 @@ +import * as postgres from "./postgres" + +export const testDatasourceConfig = { + postgres: postgres.getDatasourceConfig, +} diff --git a/packages/server/src/integrations/tests/utils/postgres.ts b/packages/server/src/integrations/tests/utils/postgres.ts new file mode 100644 index 0000000000..9f9e98fe17 --- /dev/null +++ b/packages/server/src/integrations/tests/utils/postgres.ts @@ -0,0 +1,34 @@ +import { Datasource, SourceName } from "@budibase/types" +import { GenericContainer, Wait } from "testcontainers" + +export async function getDatasourceConfig(): Promise { + const containerPostgres = await new GenericContainer("postgres") + .withExposedPorts(5432) + .withEnv("POSTGRES_PASSWORD", "password") + .withWaitStrategy( + Wait.forLogMessage( + "PostgreSQL init process complete; ready for start up." + ) + ) + .start() + + const host = containerPostgres.getContainerIpAddress() + const port = containerPostgres.getMappedPort(5432) + + return { + type: "datasource_plus", + source: SourceName.POSTGRES, + plus: true, + config: { + host, + port, + database: "postgres", + user: "postgres", + password: "password", + schema: "public", + ssl: false, + rejectUnauthorized: false, + ca: false, + }, + } +}