1
0
Fork 0
mirror of synced 2024-09-19 10:48:30 +12:00
budibase/packages/backend-core/tests/utilities/testContainerUtils.ts
2023-01-31 11:23:26 +00:00

39 lines
1.1 KiB
TypeScript

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)
}
}
}