Allow passing a env when running processes.
This brings the libeufin-basic test to pass.
This commit is contained in:
parent
ca2943b270
commit
c3ca3aa7fc
@ -112,6 +112,21 @@ interface WaitResult {
|
|||||||
signal: NodeJS.Signals | null;
|
signal: NodeJS.Signals | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new object being the current environment
|
||||||
|
* plus the values given in the parameter.
|
||||||
|
*/
|
||||||
|
export function extendEnv(extension: {[index: string]: string}): {[index: string]: string | undefined} {
|
||||||
|
let ret: {[index: string]: string | undefined} = {};
|
||||||
|
for (let v in process.env) {
|
||||||
|
ret[v] = process.env[v];
|
||||||
|
}
|
||||||
|
for (let v in extension) {
|
||||||
|
ret[v] = extension[v];
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run a shell command, return stdout.
|
* Run a shell command, return stdout.
|
||||||
*/
|
*/
|
||||||
@ -175,6 +190,7 @@ export async function runCommand(
|
|||||||
logName: string,
|
logName: string,
|
||||||
command: string,
|
command: string,
|
||||||
args: string[],
|
args: string[],
|
||||||
|
env: {[index: string]: string | undefined} = process.env
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
console.log("runing command", shellescape([command, ...args]));
|
console.log("runing command", shellescape([command, ...args]));
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -182,6 +198,7 @@ export async function runCommand(
|
|||||||
const proc = spawn(command, args, {
|
const proc = spawn(command, args, {
|
||||||
stdio: ["inherit", "pipe", "pipe"],
|
stdio: ["inherit", "pipe", "pipe"],
|
||||||
shell: false,
|
shell: false,
|
||||||
|
env: env
|
||||||
});
|
});
|
||||||
proc.stdout.on("data", (x) => {
|
proc.stdout.on("data", (x) => {
|
||||||
if (x instanceof Buffer) {
|
if (x instanceof Buffer) {
|
||||||
@ -323,12 +340,14 @@ export class GlobalTestState {
|
|||||||
command: string,
|
command: string,
|
||||||
args: string[],
|
args: string[],
|
||||||
logName: string,
|
logName: string,
|
||||||
|
env: {[index: string] : string | undefined} = process.env
|
||||||
): ProcessWrapper {
|
): ProcessWrapper {
|
||||||
console.log(
|
console.log(
|
||||||
`spawning process (${logName}): ${shellescape([command, ...args])}`,
|
`spawning process (${logName}): ${shellescape([command, ...args])}`,
|
||||||
);
|
);
|
||||||
const proc = spawn(command, args, {
|
const proc = spawn(command, args, {
|
||||||
stdio: ["inherit", "pipe", "pipe"],
|
stdio: ["inherit", "pipe", "pipe"],
|
||||||
|
env: env
|
||||||
});
|
});
|
||||||
console.log(`spawned process (${logName}) with pid ${proc.pid}`);
|
console.log(`spawned process (${logName}) with pid ${proc.pid}`);
|
||||||
proc.on("error", (err) => {
|
proc.on("error", (err) => {
|
||||||
|
@ -24,6 +24,7 @@ import {
|
|||||||
pingProc,
|
pingProc,
|
||||||
ProcessWrapper,
|
ProcessWrapper,
|
||||||
runCommand,
|
runCommand,
|
||||||
|
extendEnv
|
||||||
} from "./harness";
|
} from "./harness";
|
||||||
|
|
||||||
export interface LibeufinSandboxServiceInterface {
|
export interface LibeufinSandboxServiceInterface {
|
||||||
@ -72,11 +73,10 @@ export class LibeufinSandboxService implements LibeufinSandboxServiceInterface {
|
|||||||
[
|
[
|
||||||
"serve",
|
"serve",
|
||||||
"--port",
|
"--port",
|
||||||
`${this.sandboxConfig.httpPort}`,
|
`${this.sandboxConfig.httpPort}`
|
||||||
"--db-conn-string",
|
|
||||||
this.sandboxConfig.databaseJdbcUri,
|
|
||||||
],
|
],
|
||||||
"libeufin-sandbox",
|
"libeufin-sandbox",
|
||||||
|
extendEnv({LIBEUFIN_SANDBOX_DB_CONNECTION: this.sandboxConfig.databaseJdbcUri})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,10 +114,9 @@ export class LibeufinNexusService {
|
|||||||
"superuser",
|
"superuser",
|
||||||
"admin",
|
"admin",
|
||||||
"--password",
|
"--password",
|
||||||
"test",
|
"test"
|
||||||
"--db-conn-string",
|
|
||||||
this.nexusConfig.databaseJdbcUri,
|
|
||||||
],
|
],
|
||||||
|
extendEnv({LIBEUFIN_NEXUS_DB_CONNECTION: this.nexusConfig.databaseJdbcUri})
|
||||||
);
|
);
|
||||||
|
|
||||||
this.nexusProc = this.globalTestState.spawnService(
|
this.nexusProc = this.globalTestState.spawnService(
|
||||||
@ -126,10 +125,9 @@ export class LibeufinNexusService {
|
|||||||
"serve",
|
"serve",
|
||||||
"--port",
|
"--port",
|
||||||
`${this.nexusConfig.httpPort}`,
|
`${this.nexusConfig.httpPort}`,
|
||||||
"--db-conn-string",
|
|
||||||
this.nexusConfig.databaseJdbcUri,
|
|
||||||
],
|
],
|
||||||
"libeufin-nexus",
|
"libeufin-nexus",
|
||||||
|
extendEnv({LIBEUFIN_NEXUS_DB_CONNECTION: this.nexusConfig.databaseJdbcUri})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user