From 9a0f2ee7d7676deffe4fadf80b1c11f46873e8fc Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 27 Jan 2025 17:24:09 +0100 Subject: [PATCH] test: copied build_fake_container_fixture() from bib This is a very sad commit, it copies the code to make a fake container with a faked osbuild. The bright side is that the plan is to rewrite these helpers in go and then we can just have a shared testutil module that can be imported from both bib/ibcli. And/or the two repos will merge and its just a (simple) test helper. But I do not feel good (at all) about this. --- test/conftest.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/conftest.py b/test/conftest.py index 793cc5c..075f8d6 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,4 +1,5 @@ import subprocess +import textwrap import pytest @@ -15,3 +16,39 @@ def build_container_fixture(): "-t", container_tag, ]) return container_tag + + +# XXX: copied from bib +@pytest.fixture(name="build_fake_container", scope="session") +def build_fake_container_fixture(tmpdir_factory, build_container): + """Build a container with a fake osbuild and returns the name""" + tmp_path = tmpdir_factory.mktemp("build-fake-container") + + fake_osbuild_path = tmp_path / "fake-osbuild" + fake_osbuild_path.write_text(textwrap.dedent("""\ + #!/bin/bash -e + + # injest generated manifest from the images library, if we do not + # do this images may fail with "broken" pipe errors + cat - >/dev/null + + mkdir -p /output/qcow2 + echo "fake-disk.qcow2" > /output/qcow2/disk.qcow2 + + """), encoding="utf8") + + cntf_path = tmp_path / "Containerfile" + + cntf_path.write_text(textwrap.dedent(f"""\n + FROM {build_container} + COPY fake-osbuild /usr/bin/osbuild + RUN chmod 755 /usr/bin/osbuild + """), encoding="utf8") + + container_tag = "bootc-image-builder-test-faked-osbuild" + subprocess.check_call([ + "podman", "build", + "-t", container_tag, + tmp_path, + ]) + return container_tag