1
0
Fork 0
mirror of synced 2024-07-04 22:11:23 +12:00

Spin up postgres only on the postgres test

This commit is contained in:
Adria Navarro 2023-02-06 19:43:08 +00:00
parent c87efb7866
commit 4908cc5387
4 changed files with 18 additions and 22 deletions

View file

@ -45,11 +45,3 @@ services:
- 6379
healthcheck:
test: ["CMD", "redis-cli", "ping"]
postgres:
image: postgres
restart: on-failure
ports:
- 5432
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}

View file

@ -1,4 +1,7 @@
function getTestContainerSettings(serverName: string, key: string) {
function getTestContainerSettings(
serverName: string,
key: string
): string | null {
const entry = Object.entries(global).find(
([k]) =>
k.includes(`_${serverName.toUpperCase()}`) &&
@ -19,7 +22,7 @@ function getContainerInfo(containerName: string, port: number) {
return {
port: assignedPort,
host,
url: `http://${host}:${assignedPort}`,
url: host && assignedPort && `http://${host}:${assignedPort}`,
}
}
@ -31,21 +34,15 @@ function getMinioConfig() {
return getContainerInfo("minio-service", 9000)
}
function getPostgresConfig() {
return getContainerInfo("postgres", 5432)
}
export function setupEnv(...envs: any[]) {
const configs = [
{ key: "COUCH_DB_PORT", value: getCouchConfig().port },
{ key: "COUCH_DB_URL", value: getCouchConfig().url },
{ key: "MINIO_PORT", value: getMinioConfig().port },
{ key: "MINIO_URL", value: getMinioConfig().url },
{ key: "POSTGRES_HOST", value: getPostgresConfig().host },
{ key: "POSTGRES_PORT", value: getPostgresConfig().port },
]
for (const config of configs.filter(x => x.value !== null)) {
for (const config of configs.filter(x => !!x.value)) {
for (const env of envs) {
env._set(config.key, config.value)
}

View file

@ -3,8 +3,6 @@ require("dotenv").config({
path: join(__dirname, "..", "..", "hosting", ".env"),
})
process.env.POSTGRES_PASSWORD = "password"
const jestTestcontainersConfigGenerator = require("../../jestTestcontainersConfigGenerator")
module.exports = jestTestcontainersConfigGenerator()

View file

@ -13,8 +13,9 @@ import {
Table,
} from "@budibase/types"
import _ from "lodash"
import { generator, structures } from "@budibase/backend-core/tests"
import { generator } from "@budibase/backend-core/tests"
import { utils } from "@budibase/backend-core"
import { GenericContainer } from "testcontainers"
const config = setup.getConfig()!
@ -26,10 +27,18 @@ describe("row api - postgres", () => {
postgresTable: Table,
auxPostgresTable: Table
const host = process.env.POSTGRES_HOST!
const port = process.env.POSTGRES_PORT!
let host: string
let port: number
beforeAll(async () => {
const container = await new GenericContainer("postgres")
.withExposedPorts(5432)
.withEnv("POSTGRES_PASSWORD", "password")
.start()
host = container.getContainerIpAddress()
port = container.getMappedPort(5432)
await config.init()
const apiKey = await config.generateApiKey()