"""Tests for the RPM filename tools/build reconstructs when probing artifactapi. The expected values below were captured from the real nfpm; they are the names the publish step actually uploads, so the existence probe has to ask for exactly these or it 404s and rebuilds forever. """ import importlib.machinery import importlib.util from pathlib import Path import pytest REPO_ROOT = Path(__file__).parent.parent _loader = importlib.machinery.SourceFileLoader( "rpmbuilder_build", str(REPO_ROOT / "tools" / "build") ) _spec = importlib.util.spec_from_loader(_loader.name, _loader) build = importlib.util.module_from_spec(_spec) _loader.exec_module(build) # nfpm output for `version: ` with release 1, arch amd64 NFPM_VERSIONS = [ ("2025.08.03", "2025.8.3"), ("2025.07.13", "2025.7.13"), ("1.05.0", "1.5.0"), ("10.02.01", "10.2.1"), ("0.0.09", "0.0.9"), ("0.6.1", "0.6.1"), ("1.2.3", "1.2.3"), ("1.05", "1.5.0"), ("08", "8.0.0"), ("1.0.0-rc1", "1.0.0~rc1"), ("1.05.0-rc1", "1.5.0~rc1"), ("1.0.0-rc.1", "1.0.0~rc.1"), # not semver: nfpm leaves these verbatim, so we must too ("1.02.3.4", "1.02.3.4"), ("2025.08.03.01", "2025.08.03.01"), ("1.2.3.4", "1.2.3.4"), ("1.0.0-rc.01", "1.0.0-rc.01"), ] @pytest.mark.parametrize("version,expected", NFPM_VERSIONS) def test_nfpm_rpm_version(version, expected): assert build.nfpm_rpm_version(version) == expected def test_rpm_file_name_matches_nfpm_output(): assert ( build.rpm_file_name("nzbget_exporter", "2025.08.03", "1.el9", "amd64") == "nzbget_exporter-2025.8.3-1.el9.x86_64.rpm" ) def test_check_package_exists_probes_published_filename(monkeypatch): """A zero-padded version must not probe a filename nfpm can never produce.""" probed = [] class _Session: def get(self, url, timeout=None): probed.append(url) return type("R", (), {"status_code": 404})() monkeypatch.setattr(build, "_artifactapi_session", _Session()) assert not build.check_package_exists( "nzbget_exporter", "2025.08.03", "1.el9", "almalinux/el9", "amd64" ) expected = ( "https://artifactapi.k8s.syd1.au.unkin.net/api/v2/remotes/rpm-vendor-el9" "/files/Packages/nzbget_exporter-2025.8.3-1.el9.x86_64.rpm" ) assert probed == [expected]