stage,test: extract make_container() test helper
This commit is contained in:
parent
119172e8dd
commit
f7e4febb2c
2 changed files with 19 additions and 18 deletions
|
|
@ -6,6 +6,7 @@ import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -77,3 +78,20 @@ def mock_command(cmd_name: str, script: str):
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
os.environ["PATH"] = original_path
|
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,
|
||||||
|
])
|
||||||
|
|
|
||||||
|
|
@ -11,28 +11,11 @@ from unittest.mock import call, patch
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import osbuild.testutil
|
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"
|
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(os.getuid() != 0, reason="needs root")
|
||||||
@pytest.mark.skipif(not has_executable("podman"), reason="no podman executable")
|
@pytest.mark.skipif(not has_executable("podman"), reason="no podman executable")
|
||||||
def test_container_deploy_integration(tmp_path, stage_module):
|
def test_container_deploy_integration(tmp_path, stage_module):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue