2023-02-06 20:43:08 +01:00
|
|
|
function getTestContainerSettings(
|
|
|
|
serverName: string,
|
|
|
|
key: string
|
|
|
|
): string | null {
|
2023-02-01 16:02:31 +01:00
|
|
|
const entry = Object.entries(global).find(
|
2023-01-31 12:23:26 +01:00
|
|
|
([k]) =>
|
|
|
|
k.includes(`_${serverName.toUpperCase()}`) &&
|
|
|
|
k.includes(`_${key.toUpperCase()}__`)
|
2023-02-01 16:02:31 +01:00
|
|
|
)
|
|
|
|
if (!entry) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
return entry[1]
|
2023-01-31 12:23:26 +01:00
|
|
|
}
|
|
|
|
|
2023-02-06 14:07:21 +01:00
|
|
|
function getContainerInfo(containerName: string, port: number) {
|
|
|
|
const assignedPort = getTestContainerSettings(
|
|
|
|
containerName.toUpperCase(),
|
|
|
|
`PORT_${port}`
|
|
|
|
)
|
|
|
|
const host = getTestContainerSettings(containerName.toUpperCase(), "IP")
|
2023-01-31 12:23:26 +01:00
|
|
|
return {
|
2023-02-06 14:07:21 +01:00
|
|
|
port: assignedPort,
|
|
|
|
host,
|
2023-02-06 20:43:08 +01:00
|
|
|
url: host && assignedPort && `http://${host}:${assignedPort}`,
|
2023-01-31 12:23:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-06 14:07:21 +01:00
|
|
|
function getCouchConfig() {
|
|
|
|
return getContainerInfo("couchdb-service", 5984)
|
|
|
|
}
|
|
|
|
|
2023-01-31 12:23:26 +01:00
|
|
|
function getMinioConfig() {
|
2023-02-06 14:07:21 +01:00
|
|
|
return getContainerInfo("minio-service", 9000)
|
|
|
|
}
|
|
|
|
|
2023-01-31 12:23:26 +01:00
|
|
|
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 },
|
|
|
|
]
|
|
|
|
|
2023-02-06 20:43:08 +01:00
|
|
|
for (const config of configs.filter(x => !!x.value)) {
|
2023-01-31 12:23:26 +01:00
|
|
|
for (const env of envs) {
|
|
|
|
env._set(config.key, config.value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|