tests: add a test for packages_get_locally_built_apks() (MR 2252)

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-06-14 04:22:42 +02:00 committed by Oliver Smith
parent c89b53a87e
commit d75f1cf525
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
2 changed files with 45 additions and 2 deletions

42
pmb/chroot/test_apk.py Normal file
View file

@ -0,0 +1,42 @@
import pytest
from pmb.core.arch import Arch
from pmb.core.context import get_context
from .apk import packages_get_locally_built_apks
import pmb.config.pmaports
@pytest.fixture
def apk_mocks(monkeypatch):
def _pmaports_config(_aports=None):
return {
"channel": "edge",
}
monkeypatch.setattr(pmb.config.pmaports, "read_config", _pmaports_config)
def _apkindex_package(_package, _arch, _must_exist=False, indexes=None):
return {
"name": _package,
"version": "5.5-r0",
"arch": str(_arch),
}
monkeypatch.setattr(pmb.parse.apkindex, "package", _apkindex_package)
def test_get_local_apks(pmb_args, apk_mocks):
"""Ensure packages_get_locally_built_apks() returns paths for local apks"""
pkgname = "hello-world"
arch = Arch.x86_64
apk_file = get_context().config.work / "packages" / "edge" / arch / f"{pkgname}-5.5-r0.apk"
apk_file.parent.mkdir(parents=True)
apk_file.touch()
local = packages_get_locally_built_apks([pkgname, "fake-package"], arch)
print(local)
assert len(local) == 1
assert local[0].parts[-2:] == apk_file.parts[-2:]

View file

@ -27,7 +27,7 @@ def config_file(tmp_path_factory, request):
"no-repos": "aports = "} "no-repos": "aports = "}
file = _testdir / "pmbootstrap.cfg" file = _testdir / "pmbootstrap.cfg"
print(f"config_file: {out_file}") print(f"CONFIG: {out_file}")
cfg = configs[flavour] cfg = configs[flavour]
contents = open(file).read().format(workdir, cfg) contents = open(file).read().format(workdir, cfg)
@ -122,8 +122,9 @@ def pmb_args(config_file, mock_context, logfile):
args.cross = False args.cross = False
args.log = logfile args.log = logfile
print("init_args")
init_args(args) init_args(args)
print(f"WORK: {get_context().config.work}")
# Sanity check # Sanity check
assert ".pytest_tmp" in get_context().config.work.parts assert ".pytest_tmp" in get_context().config.work.parts