Skip to content

Instantly share code, notes, and snippets.

@dustymabe
Created October 23, 2025 17:37
Show Gist options
  • Select an option

  • Save dustymabe/20f86dc4b7a1447078940685b3336013 to your computer and use it in GitHub Desktop.

Select an option

Save dustymabe/20f86dc4b7a1447078940685b3336013 to your computer and use it in GitHub Desktop.
test/mod/test_util_containers.py
# cat test/mod/test_util_containers.py
#
# Test for util/containers.py
#
import textwrap
import pytest
import osbuild.testutil
from osbuild.util import containers
def test_container_mount_error():
fake_podman = textwrap.dedent("""\
#!/bin/sh
echo "some msg on stdout"
echo "other error on stderr" >&2
exit 1
""")
input_image = {
"filepath": "path",
"manifest-list": "manifest-list-path",
"data": {'name': 'foo', 'format': 'containers-storage'},
"checksum": "sha256:abcdabcd"
}
with tempfile.TemporaryDirectory(prefix='test-util-containers') as tmpd:
with osbuild.testutil.make_container(tmpd, {
"file1": "file1 content",
}) as base_tag:
image_id = subprocess.check_output(["podman", "inspect", "-f", "{{ .Id }}", base_tag],
universal_newlines=True).strip()
input_image['checksum'] = f"sha256:{image_id}"
with osbuild.testutil.mock_command("podman", fake_podman):
with pytest.raises(RuntimeError) as exp:
with containers.container_mount(input_image):
pass
assert "some msg on stdout" not in str(exp.value)
assert "other error on stderr" in str(exp.value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment