Redo helpers
This commit is contained in:
parent
57801b5bcc
commit
b27899b1e6
|
@ -17,7 +17,7 @@ import {
|
||||||
import _ from "lodash"
|
import _ from "lodash"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
import { utils } from "@budibase/backend-core"
|
import { utils } from "@budibase/backend-core"
|
||||||
import { testDatasourceConfig } from "../integrations/tests/utils"
|
import { PostgresProvider } from "../integrations/tests/utils"
|
||||||
|
|
||||||
const config = setup.getConfig()!
|
const config = setup.getConfig()!
|
||||||
|
|
||||||
|
@ -34,10 +34,10 @@ describe("postgres integrations", () => {
|
||||||
manyToOneRelationshipInfo: ForeignTableInfo,
|
manyToOneRelationshipInfo: ForeignTableInfo,
|
||||||
manyToManyRelationshipInfo: ForeignTableInfo
|
manyToManyRelationshipInfo: ForeignTableInfo
|
||||||
|
|
||||||
let pgDatasourceConfig: Datasource
|
let provider: PostgresProvider
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
pgDatasourceConfig = await testDatasourceConfig.postgres()
|
provider = await PostgresProvider.init()
|
||||||
|
|
||||||
await config.init()
|
await config.init()
|
||||||
const apiKey = await config.generateApiKey()
|
const apiKey = await config.generateApiKey()
|
||||||
|
@ -46,7 +46,9 @@ describe("postgres integrations", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
postgresDatasource = await config.api.datasource.create(pgDatasourceConfig)
|
postgresDatasource = await config.api.datasource.create(
|
||||||
|
provider.getDsConfig()
|
||||||
|
)
|
||||||
|
|
||||||
async function createAuxTable(prefix: string) {
|
async function createAuxTable(prefix: string) {
|
||||||
return await config.createTable({
|
return await config.createTable({
|
||||||
|
@ -1004,17 +1006,21 @@ describe("postgres integrations", () => {
|
||||||
describe("POST /api/datasources/verify", () => {
|
describe("POST /api/datasources/verify", () => {
|
||||||
it("should be able to verify the connection", async () => {
|
it("should be able to verify the connection", async () => {
|
||||||
const response = await config.api.datasource.verify({
|
const response = await config.api.datasource.verify({
|
||||||
datasource: pgDatasourceConfig,
|
datasource: provider.getDsConfig(),
|
||||||
})
|
})
|
||||||
expect(response.status).toBe(200)
|
expect(response.status).toBe(200)
|
||||||
expect(response.body.connected).toBe(true)
|
expect(response.body.connected).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should state an invalid datasource cannot connect", async () => {
|
it("should state an invalid datasource cannot connect", async () => {
|
||||||
|
const dbConfig = provider.getDsConfig()
|
||||||
const response = await config.api.datasource.verify({
|
const response = await config.api.datasource.verify({
|
||||||
datasource: {
|
datasource: {
|
||||||
...pgDatasourceConfig,
|
...dbConfig,
|
||||||
config: { ...pgDatasourceConfig.config, password: "wrongpassword" },
|
config: {
|
||||||
|
...dbConfig.config,
|
||||||
|
password: "wrongpassword",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import * as postgres from "./postgres"
|
import { Datasource } from "@budibase/types"
|
||||||
|
export * from "./postgres"
|
||||||
|
|
||||||
export const testDatasourceConfig = {
|
export interface DatabasePlusTestProvider {
|
||||||
postgres: postgres.getDatasourceConfig,
|
getDsConfig(): Datasource
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,51 @@
|
||||||
import { Datasource, SourceName } from "@budibase/types"
|
import { Datasource, SourceName } from "@budibase/types"
|
||||||
import { GenericContainer, Wait } from "testcontainers"
|
import { GenericContainer, Wait } from "testcontainers"
|
||||||
|
import { DatabasePlusTestProvider } from "."
|
||||||
|
|
||||||
|
export class PostgresProvider implements DatabasePlusTestProvider {
|
||||||
|
private host: string
|
||||||
|
private port: number
|
||||||
|
|
||||||
|
private constructor(host: string, port: number) {
|
||||||
|
this.host = host
|
||||||
|
this.port = port
|
||||||
|
}
|
||||||
|
|
||||||
|
static async init() {
|
||||||
|
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 new PostgresProvider(host, port)
|
||||||
|
}
|
||||||
|
|
||||||
|
getDsConfig(): Datasource {
|
||||||
|
return {
|
||||||
|
type: "datasource_plus",
|
||||||
|
source: SourceName.POSTGRES,
|
||||||
|
plus: true,
|
||||||
|
config: {
|
||||||
|
host: this.host,
|
||||||
|
port: this.port,
|
||||||
|
database: "postgres",
|
||||||
|
user: "postgres",
|
||||||
|
password: "password",
|
||||||
|
schema: "public",
|
||||||
|
ssl: false,
|
||||||
|
rejectUnauthorized: false,
|
||||||
|
ca: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function getDatasourceConfig(): Promise<Datasource> {
|
export async function getDatasourceConfig(): Promise<Datasource> {
|
||||||
const containerPostgres = await new GenericContainer("postgres")
|
const containerPostgres = await new GenericContainer("postgres")
|
||||||
|
|
Loading…
Reference in New Issue