diff --git a/osbuild/testutil/__init__.py b/osbuild/testutil/__init__.py index 00531972..c008ab13 100644 --- a/osbuild/testutil/__init__.py +++ b/osbuild/testutil/__init__.py @@ -6,6 +6,7 @@ import os import pathlib import re import shutil +import subprocess import tempfile @@ -77,3 +78,20 @@ def mock_command(cmd_name: str, script: str): yield finally: os.environ["PATH"] = original_path + + +def make_container(tmp_path, tag, fake_content, base="scratch"): + fake_container_src = tmp_path / "fake-container-src" + make_fake_tree(fake_container_src, fake_content) + fake_containerfile_path = fake_container_src / "Containerfile" + container_file_content = f""" + FROM {base} + COPY . . + """ + fake_containerfile_path.write_text(container_file_content, encoding="utf8") + subprocess.check_call([ + "podman", "build", + "--no-cache", + "-f", os.fspath(fake_containerfile_path), + "-t", tag, + ]) diff --git a/stages/test/test_container_deploy.py b/stages/test/test_container_deploy.py index b280b002..67cdf42b 100644 --- a/stages/test/test_container_deploy.py +++ b/stages/test/test_container_deploy.py @@ -11,28 +11,11 @@ from unittest.mock import call, patch import pytest import osbuild.testutil -from osbuild.testutil import has_executable, make_fake_tree +from osbuild.testutil import has_executable, make_container, make_fake_tree STAGE_NAME = "org.osbuild.container-deploy" -def make_container(tmp_path, tag, fake_content, base="scratch"): - fake_container_src = tmp_path / "fake-container-src" - make_fake_tree(fake_container_src, fake_content) - fake_containerfile_path = fake_container_src / "Containerfile" - container_file_content = f""" - FROM {base} - COPY . . - """ - fake_containerfile_path.write_text(container_file_content, encoding="utf8") - subprocess.check_call([ - "podman", "build", - "--no-cache", - "-f", os.fspath(fake_containerfile_path), - "-t", tag, - ]) - - @pytest.mark.skipif(os.getuid() != 0, reason="needs root") @pytest.mark.skipif(not has_executable("podman"), reason="no podman executable") def test_container_deploy_integration(tmp_path, stage_module):