Skip to content

Commit 16db6a8

Browse files
committed
tests: add openEuler source metalink test to mock-core-configs
The openEuler metalink service exposes source repos only via the ``path=openeuler/<dir>/...`` form, which (unlike the ``repo=`` form) does not translate the ``$releasever`` dnf variable into the full mirror directory name. A source metalink relying on ``$releasever`` therefore resolves to a non-existent path and silently breaks ``mock --sources``. Add a lightweight test that parses the shipped openEuler templates directly (no mock runtime, no network) and asserts that no ``path=`` metalink depends on ``$releasever``. The test lives in mock-core-configs, where the configs ship, so it runs in the package %check rather than depending on the mock source tree. BuildRequires python3-pytest and run the suite in %check. Assisted-By: pi
1 parent 49c9c94 commit 16db6a8

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

mock-core-configs/mock-core-configs.spec

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ URL: https://github.com/rpm-software-management/mock/
1616
# tito build --tgz
1717
Source: https://github.com/rpm-software-management/mock/releases/download/%{name}-%{version}-1/%{name}-%{version}.tar.gz
1818
BuildArch: noarch
19+
BuildRequires: python3-pytest
1920

2021
# The mock.rpm requires this. Other packages may provide this if they tend to
2122
# replace the mock-core-configs.rpm functionality.
@@ -82,6 +83,11 @@ mock_docs=${mock_docs//mock-core-configs/mock}
8283
mock_docs=${mock_docs//-%version/-*}
8384
sed -i "s~@MOCK_DOCS@~$mock_docs~" %{buildroot}%{_sysconfdir}/mock/site-defaults.cfg
8485

86+
%check
87+
# Validate the shipped templates directly from the source tree (the configs
88+
# live in mock-core-configs, not the mock package).
89+
PYTHONPATH=. python3 -m pytest tests
90+
8591
%post
8692
if [ -s /etc/os-release ]; then
8793
# fedora and rhel7+

mock-core-configs/tests/__init__.py

Whitespace-only changes.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
Tests for the openEuler chroot templates shipped in mock-core-configs.
3+
4+
The openEuler metalink service exposes source repos only via the
5+
``path=openeuler/<dir>/...`` form. Unlike the ``repo=`` form, ``path=`` does
6+
*not* translate the ``$releasever`` dnf variable into the full mirror
7+
directory name (e.g. ``24.03LTS_SP4`` -> ``openEuler-24.03-LTS-SP4``), so a
8+
source metalink that relies on ``$releasever`` resolves to a non-existent
9+
path and silently breaks ``mock --sources``.
10+
11+
These tests parse the shipped templates directly (no mock runtime, no
12+
network) and assert that no ``path=`` metalink depends on ``$releasever``.
13+
"""
14+
15+
import os
16+
17+
import pytest
18+
19+
# The tests live in mock-core-configs/tests/, the templates in
20+
# mock-core-configs/etc/mock/templates/.
21+
TEMPLATE_DIR = os.path.join(
22+
os.path.dirname(os.path.dirname(os.path.realpath(__file__))),
23+
"etc", "mock", "templates",
24+
)
25+
26+
OPENEULER_TEMPLATES = [
27+
f for f in os.listdir(TEMPLATE_DIR)
28+
if f.startswith("openeuler-") and f.endswith(".tpl")
29+
]
30+
31+
32+
@pytest.mark.parametrize("template", [pytest.param(t, id=t) for t in OPENEULER_TEMPLATES])
33+
def test_path_metalink_does_not_use_releasever(template):
34+
"""``path=`` metalinks must not depend on ``$releasever``.
35+
36+
The metalink ``path=`` form is taken literally and is never translated,
37+
so a ``$releasever`` in it would point at a path that does not exist.
38+
"""
39+
with open(os.path.join(TEMPLATE_DIR, template), encoding="utf-8") as handle:
40+
for line in handle:
41+
stripped = line.strip()
42+
if not stripped.startswith("metalink=") or "path=" not in stripped:
43+
continue
44+
assert "$releasever" not in line, (
45+
f"{template}: source metalink uses the untranslated "
46+
f"$releasever in a path= form, which the metalink service "
47+
f"does not translate:\n {stripped}"
48+
)

0 commit comments

Comments
 (0)