Extend `exec`: reject on failure, stdin, streaming output and a timeout
Maintainers usually reply within 4 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- docker, node.js, typescript
Research direction
Read ExecOptions in packages/testcontainers/src/types.ts and the two exec implementations in packages/testcontainers/src/generic-container/started-generic-container.ts and packages/testcontainers/src/container-runtime/clients/container/docker-container-client.ts. Check the dependency issues #1525, #1531, and #1532, then trace existing exec tests and callers. Done means the four optional behaviors work while defaults stay unchanged; the issue says the work can be split by option.
Written by the indexing model from the issue text.
Description
What happens
exec runs a command and resolves with { output, stdout, stderr, exitCode } once it finishes. Its options are workingDir, user and env. Four things are missing.
It never rejects on failure, so callers who expect success check every time:
const result = await container.exec(["psql", "-c", sql]);
if (result.exitCode !== 0) {
throw new Error(`Command failed with exit code ${result.exitCode}: ${result.output}`);
}
Seven module files carry this check, nine times in total, each with its own message. In tests it is easy to forget, and a failed setup command then surfaces later as an unrelated assertion failure.
It cannot be given input. Piping a SQL file or a dump into a command means copying the file into the container first.
Output is buffered in full and returned at the end. A long-running command shows nothing until it exits, and a large output is held in memory.
It has no timeout. A command that never exits never resolves.
Expected
await container.exec(["psql", "-U", "test"], {
throwOnError: true,
stdin: fs.createReadStream("./seed.sql"),
onOutput: (chunk, stream) => process.stdout.write(chunk),
timeout: 30_000,
});
throwOnErrorrejects on a non-zero exit code, with an error that carries the command, exit code, stdout and stderr.stdinaccepts a string,BufferorReadable.onOutputreceives output as it arrives.timeoutrejects and stops waiting for the command.
The defaults stay as they are.
Where
execinpackages/testcontainers/src/generic-container/started-generic-container.tsexecinpackages/testcontainers/src/container-runtime/clients/container/docker-container-client.tsExecOptionsinpackages/testcontainers/src/types.ts
Notes
- Java and Go return the exit code and leave the check to the caller, as this library does today. Go's
exec.ProcessOptioncovers user, working directory and environment. This goes further than either. - Can be split into one change per option.
Dependencies
- Stack on #1525, #1531: same function, and both change
ExecOptions. - Coordinate with #1532: for the error class.
- Dominant language
- TypeScript
- Stars
- 2.7k
- Forks
- 290
- Avg merge
- 4d 1h
- Merged PRs (30d)
- 22
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from testcontainers/testcontainers-node
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
testcontainers/testcontainers-node#1673 ·
Maintainers usually reply within 4 days
-
enhancement minor
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
testcontainers/testcontainers-node#1539 ·
Maintainers usually reply within 4 days
-
Let `Wait.forListeningPorts()` wait on specific portsPossibly taken @artbom claimed this 29 days ago. Openenhancement minor
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
testcontainers/testcontainers-node#1533 ·
Maintainers usually reply within 4 days
-
enhancement minor
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
testcontainers/testcontainers-node#1531 ·
Maintainers usually reply within 4 days
-
Export the types used in public method signaturesPossibly taken @artbom claimed this 29 days ago. Openenhancement minor
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
testcontainers/testcontainers-node#1528 ·
Maintainers usually reply within 4 days
All issues in testcontainers/testcontainers-node
Similar issues
-
prio:low scope:hud
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OliverRomhagen/vrigstad-joyride#953 ·
Maintainers usually reply within 1 day
-
review-followup
Difficulty 1/5 Under an hour Newbie friendliness 92/100
griffinwork40/agent-afk#5446 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
kacper-szewczyk/Ticknest#346 ·
Maintainers usually reply within 1 day
-
echarts geo: a GeoJSON URL that returns 200 with a body that is not JSON is fetched on each refreshOpenbug plugin/echarts/geo
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Yeachan-Heo/gajae-code#8230 ·
Maintainers usually reply within 1 day