Add pg test container

This commit is contained in:
adrinr 2023-02-06 13:07:21 +00:00
parent 9bb1a2fa18
commit 7d3c24d257
3 changed files with 30 additions and 9 deletions

View File

@ -45,3 +45,11 @@ 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}

View File

@ -10,20 +10,29 @@ function getTestContainerSettings(serverName: string, key: string) {
return entry[1] return entry[1]
} }
function getCouchConfig() { function getContainerInfo(containerName: string, port: number) {
const port = getTestContainerSettings("COUCHDB-SERVICE", "PORT_5984") const assignedPort = getTestContainerSettings(
containerName.toUpperCase(),
`PORT_${port}`
)
const host = getTestContainerSettings(containerName.toUpperCase(), "IP")
return { return {
port, port: assignedPort,
url: `http://${getTestContainerSettings("COUCHDB-SERVICE", "IP")}:${port}`, host,
url: `http://${host}:${assignedPort}`,
} }
} }
function getCouchConfig() {
return getContainerInfo("couchdb-service", 5984)
}
function getMinioConfig() { function getMinioConfig() {
const port = getTestContainerSettings("MINIO-SERVICE", "PORT_9000") return getContainerInfo("minio-service", 9000)
return { }
port,
url: `http://${getTestContainerSettings("MINIO-SERVICE", "IP")}:${port}`, function getPostgresConfig() {
} return getContainerInfo("postgres", 5432)
} }
export function setupEnv(...envs: any[]) { export function setupEnv(...envs: any[]) {
@ -32,6 +41,8 @@ export function setupEnv(...envs: any[]) {
{ 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 !== null)) {

View File

@ -3,6 +3,8 @@ 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()