Skip to content

Commit

Permalink
chore(test-utils): improve handling of running docker containers (#1695)
Browse files Browse the repository at this point in the history
- Convert the output of run commands to a string that is readable.
- No need to `docker rm ...` test containers for `npm run test:local` usage
  because the `docker run --rm ...` option will remove them when stopped.
  • Loading branch information
trentm authored Sep 24, 2023
1 parent 5675c49 commit f64fddf
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/opentelemetry-test-utils/src/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ export function startDocker(db: keyof typeof dockerRunCmds) {

export function cleanUpDocker(db: keyof typeof dockerRunCmds) {
run(`docker stop otel-${db}`);
run(`docker rm otel-${db}`);
}

function run(cmd: string) {
try {
const proc = childProcess.spawnSync(cmd, {
shell: true,
});
const output = Buffer.concat(
proc.output.filter(c => c) as Buffer[]
).toString('utf8');
if (proc.status !== 0) {
console.error('Failed run command:', cmd);
console.error(proc.output);
console.error(output);
}
return {
code: proc.status,
output: proc.output
.map(v => String.fromCharCode.apply(null, v as any))
.join(''),
output,
};
} catch (e) {
console.log(e);
Expand Down

0 comments on commit f64fddf

Please sign in to comment.