Skip to content

Commit

Permalink
tests/exec: add test for exit code from exec
Browse files Browse the repository at this point in the history
Execs should return the exit code of the exec'd process, if it started.

Signed-off-by: Laura Brehm <[email protected]>
  • Loading branch information
laurazard committed Sep 30, 2024
1 parent 96ef4d3 commit b126547
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tests/integration/models_containers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,15 @@ def test_exec_run_success(self):
assert exec_output[0] == 0
assert exec_output[1] == b"hello\n"

def test_exec_run_error_code_from_exec(self):
client = docker.from_env(version=TEST_API_VERSION)
container = client.containers.run(
"alpine", "sh -c 'sleep 20'", detach=True
)
self.tmp_containers.append(container.id)
exec_output = container.exec_run("sh -c 'exit 42'")
assert exec_output[0] == 42

def test_exec_run_failed(self):
client = docker.from_env(version=TEST_API_VERSION)
container = client.containers.run(
Expand All @@ -363,7 +372,7 @@ def test_exec_run_failed(self):
# older versions of docker return `126` in the case that an exec cannot
# be started due to a missing executable. We're fixing this for the
# future, so accept both for now.
assert exec_output[0] == 127 or exec_output == 126
assert exec_output[0] == 127 or exec_output[0] == 126

def test_kill(self):
client = docker.from_env(version=TEST_API_VERSION)
Expand Down

0 comments on commit b126547

Please sign in to comment.