exec method
Run command inside the container.
Throws ExecFailed when the command exits non-zero, unless
expectSuccess is false. That default is the opposite of
testcontainers, which hands back the result and leaves the check to the
caller. This library already shipped that version of the mistake once:
a cleanup step trusted an exit code it never looked at, and reported a
resource as removed when the removal had actually failed, destroying
the record that would have caught it. A result that can be ignored will
be, so opting out has to be spelled out at the call site rather than be
the default.
Implementation
Future<ExecResult> exec(
List<String> command, {
bool expectSuccess = true,
}) async {
final result = await _engineOf().exec(containerId, command);
if (expectSuccess && result.exitCode != 0) {
throw ExecFailed(
command: command,
exitCode: result.exitCode,
output: result.output,
);
}
return result;
}