Skip to content

Commit 5dd92bc

Browse files
committed
tests: add ebuild repo metadata generation tests
1 parent eefe1ec commit 5dd92bc

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

tests/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
pytest_plugins = ["pkgcraft._pytest"]
1414

1515
from pkgcraft.config import Config
16+
from pkgcraft.error import InvalidRepo
1617

1718
DATADIR = Path(__file__).parent.parent / "testdata"
1819

@@ -34,5 +35,9 @@ def testdata_config():
3435
"""All repo test data loaded into a Config object."""
3536
config = Config()
3637
for path in sorted(glob.glob(f"{DATADIR}/repos/*")):
37-
config.add_repo(path, id=os.path.basename(path), external=False)
38+
try:
39+
config.add_repo(path, id=os.path.basename(path), external=False)
40+
except InvalidRepo:
41+
# ignore purposely broken repos
42+
pass
3843
return config

tests/repo/test_ebuild.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
import shutil
13
from pathlib import Path
24

35
import pytest
@@ -104,6 +106,30 @@ def test_masters(self, testdata_config):
104106
secondary_repo = testdata_config.repos["dependent-secondary"]
105107
assert secondary_repo.masters == (primary_repo,)
106108

109+
def test_pkg_metadata_regen(self, testdata_config, tmpdir):
110+
orig_repo = testdata_config.repos["metadata-gen"]
111+
# copy original repo to a temp dir
112+
repo_path = shutil.copytree(orig_repo.path, tmpdir.join("repo"))
113+
repo = EbuildRepo(repo_path)
114+
metadata_path = repo.path.joinpath("metadata/md5-cache")
115+
116+
def metadata_content():
117+
"""Yield metadata file names and content."""
118+
for root, _dirs, files in os.walk(metadata_path):
119+
for name in files:
120+
with open(os.path.join(root, name)) as f:
121+
yield (name, f.read())
122+
123+
# record expected metadata file content
124+
expected = sorted(metadata_content())
125+
# wipe metadata
126+
shutil.rmtree(metadata_path)
127+
# regenerate metadata
128+
repo.pkg_metadata_regen()
129+
# verify new data matches original
130+
data = sorted(metadata_content())
131+
assert data == expected
132+
107133

108134
class TestEbuildRepoMetadata:
109135
def test_arches(self, make_ebuild_repo):

0 commit comments

Comments
 (0)