From d6cd4b93bafbf84adfba4aa2a887a91081c7e278 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 13 Feb 2024 13:41:56 +0100 Subject: [PATCH] test: add minimal test for ContainersStorageSource.from_args() --- sources/test/test_container_storage_source.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 sources/test/test_container_storage_source.py diff --git a/sources/test/test_container_storage_source.py b/sources/test/test_container_storage_source.py new file mode 100644 index 00000000..13920781 --- /dev/null +++ b/sources/test/test_container_storage_source.py @@ -0,0 +1,28 @@ +#!/usr/bin/python3 + +import os +import random +import socket +import string +import subprocess + +import pytest + +from osbuild.testutil import has_executable, make_container + +SOURCES_NAME = "org.osbuild.containers-storage" + + +@pytest.mark.skipif(not has_executable("podman"), reason="no podman executable") +@pytest.mark.skipif(os.getuid() != 0, reason="root only") +def test_containers_storage_integration(tmp_path, sources_module): + base_tag = "container-" + "".join(random.choices(string.digits, k=12)) + make_container(tmp_path, base_tag, { + "file1": "file1 content", + }) + image_id = subprocess.check_output(["podman", "inspect", "-f", "{{ .Id }}", base_tag], + universal_newlines=True).strip() + checksum = f"sha256:{image_id}" + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + cnt_storage = sources_module.ContainersStorageSource.from_args(["--service-fd", str(sock.fileno())]) + assert cnt_storage.exists(checksum, None)