testcontainers-rs icon indicating copy to clipboard operation
testcontainers-rs copied to clipboard

Support exec in container

Open JamesGuthrie opened this issue 3 years ago • 5 comments

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.

JamesGuthrie avatar Mar 10 '22 10:03 JamesGuthrie

Does this function work for you?

https://github.com/testcontainers/testcontainers-rs/blob/dev/src/core/container.rs#L143-L155

thomaseizinger avatar Mar 10 '22 13:03 thomaseizinger

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.

JamesGuthrie avatar Mar 10 '22 13:03 JamesGuthrie

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?

thomaseizinger avatar Mar 14 '22 23:03 thomaseizinger

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.

JamesGuthrie avatar Mar 15 '22 08:03 JamesGuthrie

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 avatar Mar 24 '22 22:03 thomaseizinger

@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

DDtKey avatar Nov 25 '22 15:11 DDtKey