1
0
Fork 0
mirror of synced 2024-06-14 08:24:48 +12:00
budibase/qa-core/src/integrations/validators/postgres.integration.spec.ts

55 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-05-11 04:23:52 +12:00
import { GenericContainer } from "testcontainers"
2023-06-13 21:04:53 +12:00
import postgres from "../../../../packages/server/src/integrations/postgres"
2023-05-11 04:23:52 +12:00
jest.unmock("pg")
describe("datasource validators", () => {
describe("postgres", () => {
let host: string
let port: number
beforeAll(async () => {
const container = await new GenericContainer("postgres:16.1-bullseye")
2023-05-11 04:23:52 +12:00
.withExposedPorts(5432)
.withEnv("POSTGRES_PASSWORD", "password")
.start()
host = container.getContainerIpAddress()
port = container.getMappedPort(5432)
})
it("test valid connection string", async () => {
const integration = new postgres.integration({
2023-05-11 04:23:52 +12:00
host,
port,
database: "postgres",
user: "postgres",
password: "password",
schema: "public",
ssl: false,
rejectUnauthorized: false,
})
const result = await integration.testConnection()
2023-05-17 19:57:43 +12:00
expect(result).toEqual({ connected: true })
2023-05-11 04:23:52 +12:00
})
it("test invalid connection string", async () => {
const integration = new postgres.integration({
2023-05-11 04:27:40 +12:00
host,
port,
database: "postgres",
user: "wrong",
password: "password",
schema: "public",
ssl: false,
rejectUnauthorized: false,
})
const result = await integration.testConnection()
2023-05-11 04:27:40 +12:00
expect(result).toEqual({
2023-05-17 19:57:43 +12:00
connected: false,
2023-05-11 04:27:40 +12:00
error: 'password authentication failed for user "wrong"',
})
2023-05-11 04:23:52 +12:00
})
})
})