Spin up postgres only on the postgres test
This commit is contained in:
parent
c87efb7866
commit
4908cc5387
|
@ -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}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@ require("dotenv").config({
|
|||
path: join(__dirname, "..", "..", "hosting", ".env"),
|
||||
})
|
||||
|
||||
process.env.POSTGRES_PASSWORD = "password"
|
||||
|
||||
const jestTestcontainersConfigGenerator = require("../../jestTestcontainersConfigGenerator")
|
||||
|
||||
module.exports = jestTestcontainersConfigGenerator()
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue