From 2f892b20e7e626dcb726d39eb241ca7fa52d8330 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 25 Nov 2024 10:52:53 +0100 Subject: [PATCH] sources: fix ostree_sources test to work without `/var/empty` Not all distros ship `/var/empty` so just create an empty dir on demand as needed. This also tweaks `test_ostree_source_exists()` into calling `make_repo()` instead of duplicating that code. --- sources/test/test_ostree_source.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sources/test/test_ostree_source.py b/sources/test/test_ostree_source.py index cfa990c0..6909390d 100644 --- a/sources/test/test_ostree_source.py +++ b/sources/test/test_ostree_source.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 import pathlib +import tempfile from osbuild.testutil.net import http_serve_directory, https_serve_directory from osbuild.util import ostree @@ -16,9 +17,9 @@ def test_ostree_source_not_exists(tmp_path, sources_service): def test_ostree_source_exists(tmp_path, sources_service): sources_service.setup({"cache": tmp_path, "options": {}}) - repo = tmp_path / "org.osbuild.ostree" / "repo" - commit = ostree.cli("commit", f"--repo={repo}", "--orphan", "/var/empty") - assert sources_service.exists("sha256:" + commit.stdout, None) + root = tmp_path / "org.osbuild.ostree" / "repo" + commit = make_repo(root) + assert sources_service.exists("sha256:" + commit, None) def make_test_sources(proto, port, fake_commit, **secrets): @@ -35,8 +36,9 @@ def make_test_sources(proto, port, fake_commit, **secrets): def make_repo(root): - ostree.cli("init", f"--repo={root}") - return ostree.cli("commit", f"--repo={root}", "--orphan", "/var/empty").stdout.rstrip() + with tempfile.TemporaryDirectory() as empty_tmpdir: + ostree.cli("init", f"--repo={root}") + return ostree.cli("commit", f"--repo={root}", "--orphan", empty_tmpdir).stdout.rstrip() def test_ostree_pull_plain(tmp_path, sources_service):