test: compare full arg_list in chroot context test
- Add an extra call to `/bin/false` and explicitly set the `check` argument for both `run()` calls. - Compare full call_args_list. This checks that all the options are as expected, that the `check` argument is set properly, and that the full order of all the calls is as expected, including the chroot path. Co-authored-by: Michael Vogt <michael.vogt@gmail.com>
This commit is contained in:
parent
1093b5eeb2
commit
83fcc8a0b1
1 changed files with 19 additions and 12 deletions
|
|
@ -2,7 +2,8 @@
|
||||||
# Test for util/chroot.py
|
# Test for util/chroot.py
|
||||||
#
|
#
|
||||||
|
|
||||||
from unittest.mock import patch
|
import os
|
||||||
|
from unittest.mock import call, patch
|
||||||
|
|
||||||
from osbuild.util.chroot import Chroot
|
from osbuild.util.chroot import Chroot
|
||||||
|
|
||||||
|
|
@ -18,18 +19,24 @@ class RunReturn:
|
||||||
|
|
||||||
|
|
||||||
@patch("subprocess.run", return_value=RunReturn())
|
@patch("subprocess.run", return_value=RunReturn())
|
||||||
def test_chroot_context(mocked_run):
|
def test_chroot_context(mocked_run, tmp_path):
|
||||||
|
|
||||||
with Chroot("") as chroot: # the path doesn't matter since nothing is actually running
|
with Chroot(os.fspath(tmp_path)) as chroot:
|
||||||
chroot.run(["/bin/true"])
|
chroot.run(["/bin/true"], check=True)
|
||||||
|
chroot.run(["/bin/false"], check=False)
|
||||||
|
|
||||||
# We expect 7 calls to run(): 3 mount + chroot + 3 umount
|
assert mocked_run.call_args_list == [
|
||||||
expected_cmds = ["/usr/bin/mount"] * 3 + ["/usr/sbin/chroot"] + ["/usr/bin/umount"] * 3
|
call(["/usr/bin/mount", "-t", "proc", "-o", "nosuid,noexec,nodev",
|
||||||
assert mocked_run.call_count == len(expected_cmds)
|
"proc", os.fspath(tmp_path / "proc")], check=True),
|
||||||
|
call(["/usr/bin/mount", "-t", "devtmpfs", "-o", "mode=0755,noexec,nosuid,strictatime",
|
||||||
|
"devtmpfs", os.fspath(tmp_path / "dev")], check=True),
|
||||||
|
call(["/usr/bin/mount", "-t", "sysfs", "-o", "nosuid,noexec,nodev",
|
||||||
|
"sysfs", os.fspath(tmp_path / "sys")], check=True),
|
||||||
|
|
||||||
cmds = []
|
call(["/usr/sbin/chroot", os.fspath(tmp_path), "/bin/true"], check=True),
|
||||||
for call in mocked_run.call_args_list:
|
call(["/usr/sbin/chroot", os.fspath(tmp_path), "/bin/false"], check=False),
|
||||||
argv = call.args[0]
|
|
||||||
cmds.append(argv[0])
|
|
||||||
|
|
||||||
assert cmds == expected_cmds
|
call(["/usr/bin/umount", "--lazy", os.fspath(tmp_path / "proc")], check=False),
|
||||||
|
call(["/usr/bin/umount", "--lazy", os.fspath(tmp_path / "dev")], check=False),
|
||||||
|
call(["/usr/bin/umount", "--lazy", os.fspath(tmp_path / "sys")], check=False),
|
||||||
|
]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue