import { GenericContainer } from "testcontainers" import postgres from "../../../../packages/server/src/integrations/postgres" 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") .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({ host, port, database: "postgres", user: "postgres", password: "password", schema: "public", ssl: false, rejectUnauthorized: false, }) const result = await integration.testConnection() expect(result).toEqual({ connected: true }) }) it("test invalid connection string", async () => { const integration = new postgres.integration({ host, port, database: "postgres", user: "wrong", password: "password", schema: "public", ssl: false, rejectUnauthorized: false, }) const result = await integration.testConnection() expect(result).toEqual({ connected: false, error: 'password authentication failed for user "wrong"', }) }) }) })