Simplify
This commit is contained in:
parent
6240740a42
commit
887ebb2eeb
|
@ -17,7 +17,7 @@ import {
|
|||
import _ from "lodash"
|
||||
import { generator } from "@budibase/backend-core/tests"
|
||||
import { utils } from "@budibase/backend-core"
|
||||
import { PostgresProvider } from "../integrations/tests/utils"
|
||||
import { databaseTestProviders } from "../integrations/tests/utils"
|
||||
|
||||
const config = setup.getConfig()!
|
||||
|
||||
|
@ -26,8 +26,6 @@ jest.setTimeout(30000)
|
|||
jest.unmock("pg")
|
||||
jest.mock("../websockets")
|
||||
|
||||
const provider = new PostgresProvider()
|
||||
|
||||
describe("postgres integrations", () => {
|
||||
let makeRequest: MakeRequestResponse,
|
||||
postgresDatasource: Datasource,
|
||||
|
@ -45,7 +43,7 @@ describe("postgres integrations", () => {
|
|||
|
||||
beforeEach(async () => {
|
||||
postgresDatasource = await config.api.datasource.create(
|
||||
await provider.getDsConfig()
|
||||
await databaseTestProviders.postgres.getDsConfig()
|
||||
)
|
||||
|
||||
async function createAuxTable(prefix: string) {
|
||||
|
@ -1004,14 +1002,14 @@ describe("postgres integrations", () => {
|
|||
describe("POST /api/datasources/verify", () => {
|
||||
it("should be able to verify the connection", async () => {
|
||||
const response = await config.api.datasource.verify({
|
||||
datasource: await provider.getDsConfig(),
|
||||
datasource: await databaseTestProviders.postgres.getDsConfig(),
|
||||
})
|
||||
expect(response.status).toBe(200)
|
||||
expect(response.body.connected).toBe(true)
|
||||
})
|
||||
|
||||
it("should state an invalid datasource cannot connect", async () => {
|
||||
const dbConfig = await provider.getDsConfig()
|
||||
const dbConfig = await databaseTestProviders.postgres.getDsConfig()
|
||||
const response = await config.api.datasource.verify({
|
||||
datasource: {
|
||||
...dbConfig,
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
import { Datasource } from "@budibase/types"
|
||||
export * from "./postgres"
|
||||
import * as pg from "./postgres"
|
||||
|
||||
export interface DatabasePlusTestProvider {
|
||||
getDsConfig(): Promise<Datasource>
|
||||
}
|
||||
|
||||
export const databaseTestProviders = {
|
||||
postgres: pg,
|
||||
}
|
||||
|
|
|
@ -1,58 +1,23 @@
|
|||
import { Datasource, SourceName } from "@budibase/types"
|
||||
import { GenericContainer, Wait, StartedTestContainer } from "testcontainers"
|
||||
import { DatabasePlusTestProvider } from "."
|
||||
|
||||
export class PostgresProvider implements DatabasePlusTestProvider {
|
||||
private container?: StartedTestContainer
|
||||
let container: StartedTestContainer | undefined
|
||||
|
||||
async getDsConfig(): Promise<Datasource> {
|
||||
if (!this.container) {
|
||||
this.container = await new GenericContainer("postgres")
|
||||
.withExposedPorts(5432)
|
||||
.withEnv("POSTGRES_PASSWORD", "password")
|
||||
.withWaitStrategy(
|
||||
Wait.forLogMessage(
|
||||
"PostgreSQL init process complete; ready for start up."
|
||||
)
|
||||
export async function getDsConfig(): Promise<Datasource> {
|
||||
if (!container) {
|
||||
container = await new GenericContainer("postgres")
|
||||
.withExposedPorts(5432)
|
||||
.withEnv("POSTGRES_PASSWORD", "password")
|
||||
.withWaitStrategy(
|
||||
Wait.forLogMessage(
|
||||
"PostgreSQL init process complete; ready for start up."
|
||||
)
|
||||
.start()
|
||||
}
|
||||
|
||||
const host = this.container.getContainerIpAddress()
|
||||
const port = this.container.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,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function getDatasourceConfig(): Promise<Datasource> {
|
||||
const containerPostgres = await new GenericContainer("postgres")
|
||||
.withExposedPorts(5432)
|
||||
.withEnv("POSTGRES_PASSWORD", "password")
|
||||
.withWaitStrategy(
|
||||
Wait.forLogMessage(
|
||||
"PostgreSQL init process complete; ready for start up."
|
||||
)
|
||||
)
|
||||
.start()
|
||||
.start()
|
||||
}
|
||||
|
||||
const host = containerPostgres.getContainerIpAddress()
|
||||
const port = containerPostgres.getMappedPort(5432)
|
||||
const host = container.getContainerIpAddress()
|
||||
const port = container.getMappedPort(5432)
|
||||
|
||||
return {
|
||||
type: "datasource_plus",
|
||||
|
|
Loading…
Reference in New Issue