mirror of
https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git
synced 2025-07-13 11:29:46 +03:00
fix tests
Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
This commit is contained in:
parent
88afc10e95
commit
e44ef84b4b
9 changed files with 27 additions and 17 deletions
|
@ -10,6 +10,9 @@ if [ "$(id -u)" = 0 ]; then
|
||||||
openssl \
|
openssl \
|
||||||
py3-pytest \
|
py3-pytest \
|
||||||
py3-pytest-cov \
|
py3-pytest-cov \
|
||||||
|
kpartx \
|
||||||
|
losetup \
|
||||||
|
android-tools \
|
||||||
sudo
|
sudo
|
||||||
exec su "${TESTUSER:-build}" -c "sh -e $0"
|
exec su "${TESTUSER:-build}" -c "sh -e $0"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -78,7 +78,7 @@ def apk_mocks(monkeypatch) -> dict | None:
|
||||||
|
|
||||||
|
|
||||||
def create_apk(pkgname: str, arch: Arch) -> Path:
|
def create_apk(pkgname: str, arch: Arch) -> Path:
|
||||||
apk_file = get_context().config.work / "packages" / "edge" / arch / f"{pkgname}-5.5-r0.apk"
|
apk_file = get_context().config.cache / "packages" / "edge" / arch / f"{pkgname}-5.5-r0.apk"
|
||||||
apk_file.parent.mkdir(parents=True, exist_ok=True)
|
apk_file.parent.mkdir(parents=True, exist_ok=True)
|
||||||
apk_file.touch()
|
apk_file.touch()
|
||||||
return apk_file
|
return apk_file
|
||||||
|
|
|
@ -24,4 +24,4 @@ def test_load(config_file):
|
||||||
assert config.ui == "gnome"
|
assert config.ui == "gnome"
|
||||||
assert config.providers == {}
|
assert config.providers == {}
|
||||||
assert config.mirrors["pmaports"] is not None
|
assert config.mirrors["pmaports"] is not None
|
||||||
assert ".pytest_tmp" in config.work.parts
|
assert ".pytest_tmp" in config.cache.parts
|
||||||
|
|
|
@ -148,10 +148,10 @@ def pmb_args(config_file, mock_context, logfile):
|
||||||
|
|
||||||
init_args(args)
|
init_args(args)
|
||||||
|
|
||||||
print(f"WORK: {get_context().config.work}")
|
print(f"WORK: {get_context().config.cache}")
|
||||||
|
|
||||||
# Sanity check
|
# Sanity check
|
||||||
assert ".pytest_tmp" in get_context().config.work.parts
|
assert ".pytest_tmp" in get_context().config.cache.parts
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
|
@ -8,26 +8,26 @@ from pmb.core.context import get_context
|
||||||
from pmb.core.chroot import Chroot, ChrootType
|
from pmb.core.chroot import Chroot, ChrootType
|
||||||
|
|
||||||
|
|
||||||
def test_valid_chroots(pmb_args, mock_devices_find_path):
|
def test_valid_chroots(pmb_args, mock_devices_find_path, foreign_arch):
|
||||||
"""Test that Chroot objects work as expected"""
|
"""Test that Chroot objects work as expected"""
|
||||||
|
|
||||||
work = get_context().config.work
|
localdir = get_context().config.work
|
||||||
|
|
||||||
chroot = Chroot.native()
|
chroot = Chroot.native()
|
||||||
assert chroot.type == ChrootType.NATIVE
|
assert chroot.type == ChrootType.NATIVE
|
||||||
assert chroot.name == ""
|
assert chroot.name == ""
|
||||||
assert chroot.arch in Arch.supported()
|
assert chroot.arch in Arch.supported()
|
||||||
assert not chroot.exists() # Shouldn't be created
|
assert not chroot.exists() # Shouldn't be created
|
||||||
assert chroot.path == work / "chroot_native"
|
assert chroot.path == localdir / "chroot_native"
|
||||||
assert str(chroot) == "native"
|
assert str(chroot) == "native"
|
||||||
|
|
||||||
chroot = Chroot.buildroot(Arch.aarch64)
|
chroot = Chroot.buildroot(foreign_arch)
|
||||||
assert chroot.type == ChrootType.BUILDROOT
|
assert chroot.type == ChrootType.BUILDROOT
|
||||||
assert chroot.name == "aarch64"
|
assert chroot.name == f"{foreign_arch}"
|
||||||
assert chroot.arch == Arch.aarch64
|
assert chroot.arch == foreign_arch
|
||||||
assert not chroot.exists() # Shouldn't be created
|
assert not chroot.exists() # Shouldn't be created
|
||||||
assert chroot.path == work / "chroot_buildroot_aarch64"
|
assert chroot.path == localdir / f"chroot_buildroot_{foreign_arch}"
|
||||||
assert str(chroot) == "buildroot_aarch64"
|
assert str(chroot) == f"buildroot_{foreign_arch}"
|
||||||
|
|
||||||
# FIXME: implicily assumes that we're mocking the qemu-amd64 deviceinfo
|
# FIXME: implicily assumes that we're mocking the qemu-amd64 deviceinfo
|
||||||
chroot = Chroot(ChrootType.ROOTFS, "qemu-amd64")
|
chroot = Chroot(ChrootType.ROOTFS, "qemu-amd64")
|
||||||
|
@ -35,7 +35,7 @@ def test_valid_chroots(pmb_args, mock_devices_find_path):
|
||||||
assert chroot.name == "qemu-amd64"
|
assert chroot.name == "qemu-amd64"
|
||||||
assert chroot.arch == Arch.x86_64
|
assert chroot.arch == Arch.x86_64
|
||||||
assert not chroot.exists() # Shouldn't be created
|
assert not chroot.exists() # Shouldn't be created
|
||||||
assert chroot.path == work / "chroot_rootfs_qemu-amd64"
|
assert chroot.path == localdir / "chroot_rootfs_qemu-amd64"
|
||||||
assert str(chroot) == "rootfs_qemu-amd64"
|
assert str(chroot) == "rootfs_qemu-amd64"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ def test_pkgrepo_pmaports(pmaports, monkeypatch):
|
||||||
pkgrepo_paths.cache_disable()
|
pkgrepo_paths.cache_disable()
|
||||||
pkgrepo_default_path.cache_disable()
|
pkgrepo_default_path.cache_disable()
|
||||||
|
|
||||||
paths = pkgrepo_paths()
|
paths = pkgrepo_paths(with_extra_repos="disabled")
|
||||||
print(f"[master] pkgrepo_paths: {paths}")
|
print(f"[master] pkgrepo_paths: {paths}")
|
||||||
assert len(paths) == 1
|
assert len(paths) == 1
|
||||||
assert "pmaports" in paths[0].name
|
assert "pmaports" in paths[0].name
|
||||||
|
@ -32,9 +32,6 @@ def test_pkgrepo_pmaports(pmaports, monkeypatch):
|
||||||
assert default_path.name == "pmaports"
|
assert default_path.name == "pmaports"
|
||||||
|
|
||||||
# Test extra-repos
|
# Test extra-repos
|
||||||
paths = pkgrepo_paths(with_extra_repos="disabled")
|
|
||||||
assert len(paths) == 1
|
|
||||||
|
|
||||||
paths = pkgrepo_paths(with_extra_repos="enabled")
|
paths = pkgrepo_paths(with_extra_repos="enabled")
|
||||||
assert len(paths) == 2
|
assert len(paths) == 2
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ systemd = always
|
||||||
timezone = Europe/Berlin
|
timezone = Europe/Berlin
|
||||||
ui = gnome
|
ui = gnome
|
||||||
work = {0}
|
work = {0}
|
||||||
|
cache = {0}/cache
|
||||||
|
|
||||||
[providers]
|
[providers]
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,9 @@ def progs() -> dict[str, str]:
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def bootimg(progs: dict[str, str], tmp_path: Path) -> Callable:
|
def bootimg(progs: dict[str, str], tmp_path: Path) -> Callable:
|
||||||
|
if Path("/in-pmbootstrap").exists():
|
||||||
|
pytest.skip("Nested chroot unsupported")
|
||||||
|
|
||||||
path: Path = tmp_path / "boot.img"
|
path: Path = tmp_path / "boot.img"
|
||||||
cmd = [
|
cmd = [
|
||||||
progs["mkbootimg"],
|
progs["mkbootimg"],
|
||||||
|
|
|
@ -175,6 +175,12 @@ def random_valid_deviceinfo(tmp_path):
|
||||||
info["codename"] = tmp_path.name[7:]
|
info["codename"] = tmp_path.name[7:]
|
||||||
info["chassis"] = random.choice(deviceinfo_chassis_types)
|
info["chassis"] = random.choice(deviceinfo_chassis_types)
|
||||||
info["arch"] = random.choice(["armhf", "aarch64", "x86_64"])
|
info["arch"] = random.choice(["armhf", "aarch64", "x86_64"])
|
||||||
|
# FIXME: we can't keep adding properties here manually as we make more of them
|
||||||
|
# discrete types..
|
||||||
|
if "rootfs_image_sector_size" in info:
|
||||||
|
info["rootfs_image_sector_size"] = random.choice([512, 2048, 4096])
|
||||||
|
if "boot_part_start" in info:
|
||||||
|
info["boot_part_start"] = random.choice([0, 2048, 4096])
|
||||||
|
|
||||||
# Now write it all out to a file
|
# Now write it all out to a file
|
||||||
with open(path, "w") as f:
|
with open(path, "w") as f:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue