test: return container_id in make_container

The current `make_container()` helper is a bit silly (which is
entirely my fault). It requires a container tag as input but all
tests end up creating a random number for this input. So instead
just remove the input and return the container_id from the podman
build in the contextmanager and use that.
This commit is contained in:
Michael Vogt 2024-03-11 19:16:30 +01:00 committed by Achilleas Koutsou
parent df224fb32b
commit fd0167f130
5 changed files with 49 additions and 24 deletions

View file

@ -0,0 +1,29 @@
#
# Tests for the 'osbuild.util.testutil.make_container'.
#
import subprocess
import textwrap
import pytest
from osbuild.testutil import has_executable, make_container, mock_command
def test_make_container_bad_podman_prints_podman_output(tmp_path, capsys):
fake_broken_podman = textwrap.dedent("""\
#!/bin/sh
echo fake-broken-podman
exit 1
""")
with mock_command("podman", fake_broken_podman):
with pytest.raises(subprocess.CalledProcessError):
with make_container(tmp_path, {}) as _:
pass
assert "fake-broken-podman" in capsys.readouterr().out
@pytest.mark.skipif(not has_executable("podman"), reason="no podman executable")
def test_make_container_integration(tmp_path, capsys):
with make_container(tmp_path, {"/etc/foo": "foo-content"}) as cref:
assert len(cref) == 64
assert "COMMIT" in capsys.readouterr().out