Skip to content

Commit

Permalink
test: add integration test for Chroot.run()
Browse files Browse the repository at this point in the history
This commit adds a test that is more "integration"-ish in style
to make sure that the actual return code of a command is returned
via chroot.
  • Loading branch information
mvo5 authored and supakeen committed Oct 24, 2024
1 parent 1b3e956 commit ad7c646
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/mod/test_util_chroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
from unittest.mock import call, patch

from osbuild.testutil import mock_command
from osbuild.util.chroot import Chroot


Expand Down Expand Up @@ -41,3 +42,15 @@ def test_chroot_context(mocked_run, tmp_path):
call(["umount", "--lazy", os.fspath(tmp_path / "dev")], check=False),
call(["umount", "--lazy", os.fspath(tmp_path / "sys")], check=False),
]


def test_chroot_integration(tmp_path):
# drop the first two arguments ("chroot", "target-dir") from our fake
# chroot
fake_chroot = r'exec "${@:2}"'
with mock_command("mount", ""), mock_command("umount", ""), mock_command("chroot", fake_chroot):
with Chroot(os.fspath(tmp_path)) as chroot:
ret = chroot.run(["/bin/true"], check=True)
assert ret.returncode == 0
ret = chroot.run(["/bin/false"], check=False)
assert ret.returncode == 1

0 comments on commit ad7c646

Please sign in to comment.