Looking for testcontainer config
This commit is contained in:
parent
2b8190418c
commit
dd2a05fdcb
|
@ -1,18 +1,4 @@
|
||||||
import env from "../src/environment"
|
import env from "../src/environment"
|
||||||
|
import { testContainerUtils } from "./utilities"
|
||||||
|
|
||||||
const globalSafe = global as any
|
testContainerUtils.setupEnv(env)
|
||||||
|
|
||||||
console.error(global)
|
|
||||||
|
|
||||||
env._set(
|
|
||||||
"COUCH_DB_PORT",
|
|
||||||
globalSafe["__TESTCONTAINERS_COUCHDB-SERVICE-1_PORT_5984__"]
|
|
||||||
)
|
|
||||||
env._set(
|
|
||||||
"COUCH_DB_URL",
|
|
||||||
`http://${globalSafe["__TESTCONTAINERS_COUCHDB-SERVICE-1_IP__"]}:${globalSafe["__TESTCONTAINERS_COUCHDB-SERVICE-1_PORT_5984__"]}`
|
|
||||||
)
|
|
||||||
env._set(
|
|
||||||
"MINIO_URL",
|
|
||||||
`http://${globalSafe["__TESTCONTAINERS_MINIO-SERVICE-1_IP__"]}:${globalSafe["__TESTCONTAINERS_MINIO-SERVICE-1_PORT_9000__"]}`
|
|
||||||
)
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ export * as mocks from "./mocks"
|
||||||
export * as structures from "./structures"
|
export * as structures from "./structures"
|
||||||
export { generator } from "./structures"
|
export { generator } from "./structures"
|
||||||
export * as testEnv from "./testEnv"
|
export * as testEnv from "./testEnv"
|
||||||
|
export * as testContainerUtils from "./testContainerUtils"
|
||||||
|
|
||||||
import * as dbConfig from "./db"
|
import * as dbConfig from "./db"
|
||||||
dbConfig.init()
|
dbConfig.init()
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
function getTestContainerSettings(serverName: string, key: string) {
|
||||||
|
const [_, value] = Object.entries(global).find(
|
||||||
|
([k]) =>
|
||||||
|
k.includes(`_${serverName.toUpperCase()}`) &&
|
||||||
|
k.includes(`_${key.toUpperCase()}__`)
|
||||||
|
)!
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCouchConfig() {
|
||||||
|
const port = getTestContainerSettings("COUCHDB-SERVICE", "PORT_5984")
|
||||||
|
return {
|
||||||
|
port,
|
||||||
|
url: `http://${getTestContainerSettings("COUCHDB-SERVICE", "IP")}:${port}`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMinioConfig() {
|
||||||
|
const port = getTestContainerSettings("MINIO-SERVICE", "PORT_9000")
|
||||||
|
return {
|
||||||
|
port,
|
||||||
|
url: `http://${getTestContainerSettings("MINIO-SERVICE", "IP")}:${port}`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 },
|
||||||
|
]
|
||||||
|
|
||||||
|
for (const config of configs) {
|
||||||
|
for (const env of envs) {
|
||||||
|
env._set(config.key, config.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
import env from "../environment"
|
import env from "../environment"
|
||||||
import { env as coreEnv } from "@budibase/backend-core"
|
import { env as coreEnv } from "@budibase/backend-core"
|
||||||
|
import { testContainerUtils } from "@budibase/backend-core/tests"
|
||||||
|
|
||||||
if (!process.env.DEBUG) {
|
if (!process.env.DEBUG) {
|
||||||
global.console.log = jest.fn() // console.log are ignored in tests
|
global.console.log = jest.fn() // console.log are ignored in tests
|
||||||
|
@ -12,25 +13,4 @@ if (!process.env.CI) {
|
||||||
jest.setTimeout(100000)
|
jest.setTimeout(100000)
|
||||||
}
|
}
|
||||||
|
|
||||||
function overrideConfigValue(key: string, value: string) {
|
testContainerUtils.setupEnv(env, coreEnv)
|
||||||
env._set(key, value)
|
|
||||||
coreEnv._set(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
const globalSafe = global as any
|
|
||||||
|
|
||||||
console.error(global)
|
|
||||||
|
|
||||||
overrideConfigValue(
|
|
||||||
"COUCH_DB_PORT",
|
|
||||||
globalSafe["__TESTCONTAINERS_COUCHDB-SERVICE-1_PORT_5984__"]
|
|
||||||
)
|
|
||||||
overrideConfigValue(
|
|
||||||
"COUCH_DB_URL",
|
|
||||||
`http://${globalSafe["__TESTCONTAINERS_COUCHDB-SERVICE-1_IP__"]}:${globalSafe["__TESTCONTAINERS_COUCHDB-SERVICE-1_PORT_5984__"]}`
|
|
||||||
)
|
|
||||||
|
|
||||||
overrideConfigValue(
|
|
||||||
"MINIO_URL",
|
|
||||||
`http://${globalSafe["__TESTCONTAINERS_MINIO-SERVICE-1_IP__"]}:${globalSafe["__TESTCONTAINERS_MINIO-SERVICE-1_PORT_9000__"]}`
|
|
||||||
)
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { mocks } from "@budibase/backend-core/tests"
|
import { mocks, testContainerUtils } from "@budibase/backend-core/tests"
|
||||||
|
|
||||||
import env from "../environment"
|
import env from "../environment"
|
||||||
import { env as coreEnv } from "@budibase/backend-core"
|
import { env as coreEnv } from "@budibase/backend-core"
|
||||||
|
@ -21,25 +21,4 @@ if (!process.env.CI) {
|
||||||
jest.setTimeout(100000)
|
jest.setTimeout(100000)
|
||||||
}
|
}
|
||||||
|
|
||||||
function overrideConfigValue(key: string, value: string) {
|
testContainerUtils.setupEnv(env, coreEnv)
|
||||||
env._set(key, value)
|
|
||||||
coreEnv._set(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
const globalSafe = global as any
|
|
||||||
|
|
||||||
console.error(global)
|
|
||||||
|
|
||||||
overrideConfigValue(
|
|
||||||
"COUCH_DB_PORT",
|
|
||||||
globalSafe["__TESTCONTAINERS_COUCHDB-SERVICE-1_PORT_5984__"]
|
|
||||||
)
|
|
||||||
overrideConfigValue(
|
|
||||||
"COUCH_DB_URL",
|
|
||||||
`http://${globalSafe["__TESTCONTAINERS_COUCHDB-SERVICE-1_IP__"]}:${globalSafe["__TESTCONTAINERS_COUCHDB-SERVICE-1_PORT_5984__"]}`
|
|
||||||
)
|
|
||||||
|
|
||||||
overrideConfigValue(
|
|
||||||
"MINIO_URL",
|
|
||||||
`http://${globalSafe["__TESTCONTAINERS_MINIO-SERVICE-1_IP__"]}:${globalSafe["__TESTCONTAINERS_MINIO-SERVICE-1_PORT_9000__"]}`
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in New Issue