From 2327e24bce8095d55e82c5f281589aa360e3a6bc Mon Sep 17 00:00:00 2001 From: adrinr Date: Mon, 6 Feb 2023 13:07:21 +0000 Subject: [PATCH] Add pg test container --- hosting/docker-compose.test.yaml | 8 +++++ .../tests/utilities/testContainerUtils.ts | 29 +++++++++++++------ packages/server/jest-testcontainers-config.js | 2 ++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/hosting/docker-compose.test.yaml b/hosting/docker-compose.test.yaml index dfd78621c5..58936d233a 100644 --- a/hosting/docker-compose.test.yaml +++ b/hosting/docker-compose.test.yaml @@ -45,3 +45,11 @@ services: - 6379 healthcheck: test: ["CMD", "redis-cli", "ping"] + + postgres: + image: postgres + restart: on-failure + ports: + - 5432 + environment: + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} diff --git a/packages/backend-core/tests/utilities/testContainerUtils.ts b/packages/backend-core/tests/utilities/testContainerUtils.ts index a5a779a00b..f7f1b34b73 100644 --- a/packages/backend-core/tests/utilities/testContainerUtils.ts +++ b/packages/backend-core/tests/utilities/testContainerUtils.ts @@ -10,20 +10,29 @@ function getTestContainerSettings(serverName: string, key: string) { return entry[1] } -function getCouchConfig() { - const port = getTestContainerSettings("COUCHDB-SERVICE", "PORT_5984") +function getContainerInfo(containerName: string, port: number) { + const assignedPort = getTestContainerSettings( + containerName.toUpperCase(), + `PORT_${port}` + ) + const host = getTestContainerSettings(containerName.toUpperCase(), "IP") return { - port, - url: `http://${getTestContainerSettings("COUCHDB-SERVICE", "IP")}:${port}`, + port: assignedPort, + host, + url: `http://${host}:${assignedPort}`, } } +function getCouchConfig() { + return getContainerInfo("couchdb-service", 5984) +} + function getMinioConfig() { - const port = getTestContainerSettings("MINIO-SERVICE", "PORT_9000") - return { - port, - url: `http://${getTestContainerSettings("MINIO-SERVICE", "IP")}:${port}`, - } + return getContainerInfo("minio-service", 9000) +} + +function getPostgresConfig() { + return getContainerInfo("postgres", 5432) } export function setupEnv(...envs: any[]) { @@ -32,6 +41,8 @@ export function setupEnv(...envs: any[]) { { 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)) { diff --git a/packages/server/jest-testcontainers-config.js b/packages/server/jest-testcontainers-config.js index 8ac0f0cd9d..48f9a9b21b 100644 --- a/packages/server/jest-testcontainers-config.js +++ b/packages/server/jest-testcontainers-config.js @@ -3,6 +3,8 @@ require("dotenv").config({ path: join(__dirname, "..", "..", "hosting", ".env"), }) +process.env.POSTGRES_PASSWORD = "password" + const jestTestcontainersConfigGenerator = require("../../jestTestcontainersConfigGenerator") module.exports = jestTestcontainersConfigGenerator()