stage,test: extract make_container() test helper

This commit is contained in:
Michael Vogt 2024-02-13 13:30:35 +01:00 committed by Ondřej Budai
parent 119172e8dd
commit f7e4febb2c
2 changed files with 19 additions and 18 deletions

View file

@ -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,
])

View file

@ -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):