Spin up postgres only on the postgres test
This commit is contained in:
parent
c87efb7866
commit
4908cc5387
|
@ -45,11 +45,3 @@ services:
|
||||||
- 6379
|
- 6379
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "redis-cli", "ping"]
|
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(
|
const entry = Object.entries(global).find(
|
||||||
([k]) =>
|
([k]) =>
|
||||||
k.includes(`_${serverName.toUpperCase()}`) &&
|
k.includes(`_${serverName.toUpperCase()}`) &&
|
||||||
|
@ -19,7 +22,7 @@ function getContainerInfo(containerName: string, port: number) {
|
||||||
return {
|
return {
|
||||||
port: assignedPort,
|
port: assignedPort,
|
||||||
host,
|
host,
|
||||||
url: `http://${host}:${assignedPort}`,
|
url: host && assignedPort && `http://${host}:${assignedPort}`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,21 +34,15 @@ function getMinioConfig() {
|
||||||
return getContainerInfo("minio-service", 9000)
|
return getContainerInfo("minio-service", 9000)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPostgresConfig() {
|
|
||||||
return getContainerInfo("postgres", 5432)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setupEnv(...envs: any[]) {
|
export function setupEnv(...envs: any[]) {
|
||||||
const configs = [
|
const configs = [
|
||||||
{ key: "COUCH_DB_PORT", value: getCouchConfig().port },
|
{ key: "COUCH_DB_PORT", value: getCouchConfig().port },
|
||||||
{ key: "COUCH_DB_URL", value: getCouchConfig().url },
|
{ key: "COUCH_DB_URL", value: getCouchConfig().url },
|
||||||
{ key: "MINIO_PORT", value: getMinioConfig().port },
|
{ key: "MINIO_PORT", value: getMinioConfig().port },
|
||||||
{ key: "MINIO_URL", value: getMinioConfig().url },
|
{ 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) {
|
for (const env of envs) {
|
||||||
env._set(config.key, config.value)
|
env._set(config.key, config.value)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,6 @@ require("dotenv").config({
|
||||||
path: join(__dirname, "..", "..", "hosting", ".env"),
|
path: join(__dirname, "..", "..", "hosting", ".env"),
|
||||||
})
|
})
|
||||||
|
|
||||||
process.env.POSTGRES_PASSWORD = "password"
|
|
||||||
|
|
||||||
const jestTestcontainersConfigGenerator = require("../../jestTestcontainersConfigGenerator")
|
const jestTestcontainersConfigGenerator = require("../../jestTestcontainersConfigGenerator")
|
||||||
|
|
||||||
module.exports = jestTestcontainersConfigGenerator()
|
module.exports = jestTestcontainersConfigGenerator()
|
||||||
|
|
|
@ -13,8 +13,9 @@ import {
|
||||||
Table,
|
Table,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import _ from "lodash"
|
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 { utils } from "@budibase/backend-core"
|
||||||
|
import { GenericContainer } from "testcontainers"
|
||||||
|
|
||||||
const config = setup.getConfig()!
|
const config = setup.getConfig()!
|
||||||
|
|
||||||
|
@ -26,10 +27,18 @@ describe("row api - postgres", () => {
|
||||||
postgresTable: Table,
|
postgresTable: Table,
|
||||||
auxPostgresTable: Table
|
auxPostgresTable: Table
|
||||||
|
|
||||||
const host = process.env.POSTGRES_HOST!
|
let host: string
|
||||||
const port = process.env.POSTGRES_PORT!
|
let port: number
|
||||||
|
|
||||||
beforeAll(async () => {
|
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()
|
await config.init()
|
||||||
const apiKey = await config.generateApiKey()
|
const apiKey = await config.generateApiKey()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue