testcontainers-rs
testcontainers-rs copied to clipboard
Support exec in container
It would be great to have an equivalent to execInContainer as described here: https://www.testcontainers.org/features/commands/.
Not only with the ability to execute a command in a container, but also to obtain the stdout/stderr of that execution.
Does this function work for you?
https://github.com/testcontainers/testcontainers-rs/blob/dev/src/core/container.rs#L143-L155
Kind of. From what I can tell, it doesn't allow me to capture only the output of that exec command. But maybe I don't understand the API.
What goal are you trying to achieve in capturing the output? You can somewhat access it through WaitFor::message_on_stdout.
The API was designed to allow for executing commands and blocking until they are complete. Perhaps we should generalize it a bit more?
What I would like to do is capture just the output of a psql command executed inside of a postgres container and use it in a snapshot test.
Okay, I am afraid that isn't particularly well supported at the moment but I think we could extend the exec API to make that work. Let me know if you are willing to send a PR for this, unfortunately I don't have the bandwidth to do so at the moment.
@thomaseizinger I tried to extend exec api to support either container's conditions or exec ones, I believe it covers the issue. Please review when it's possible