forked from Mirror/pmbootstrap
With the new chroot type, we can now write fancy paths in the pythonic way. Convert most of the codebase over, as well as adding various other type hints. Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
74 lines
2.7 KiB
Python
74 lines
2.7 KiB
Python
# Copyright 2023 Oliver Smith
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
""" Test pmb.helpers.repo """
|
|
from pmb.core.types import PmbArgs
|
|
import pytest
|
|
import sys
|
|
|
|
import pmb_test # noqa
|
|
import pmb_test.const
|
|
import pmb.helpers.repo
|
|
|
|
|
|
@pytest.fixture
|
|
def args(tmpdir, request):
|
|
import pmb.parse
|
|
cfg = f"{pmb_test.const.testdata}/channels.cfg"
|
|
sys.argv = ["pmbootstrap.py", "--config-channels", cfg, "chroot"]
|
|
args = pmb.parse.arguments()
|
|
args.log = pmb.config.work / "log_testsuite.txt"
|
|
pmb.helpers.logging.init(args)
|
|
request.addfinalizer(pmb.helpers.logging.logfd.close)
|
|
return args
|
|
|
|
|
|
def test_hash():
|
|
url = "https://nl.alpinelinux.org/alpine/edge/testing"
|
|
hash = "865a153c"
|
|
assert pmb.helpers.repo.apkindex_hash(url, 8) == hash
|
|
|
|
|
|
def test_alpine_apkindex_path(args: PmbArgs):
|
|
func = pmb.helpers.repo.alpine_apkindex_path
|
|
args.mirror_alpine = "http://dl-cdn.alpinelinux.org/alpine/"
|
|
ret = pmb.config.work / "cache_apk_armhf/APKINDEX.30e6f5af.tar.gz"
|
|
assert func(args, "testing", "armhf") == ret
|
|
|
|
|
|
def test_urls(args: PmbArgs, monkeypatch):
|
|
func = pmb.helpers.repo.urls
|
|
channel = "v20.05"
|
|
args.mirror_alpine = "http://localhost/alpine/"
|
|
|
|
# Second mirror with /master at the end is legacy, gets fixed by func.
|
|
# Note that bpo uses multiple postmarketOS mirrors at the same time, so it
|
|
# can use its WIP repository together with the final repository.
|
|
args.mirrors_postmarketos = ["http://localhost/pmos1/",
|
|
"http://localhost/pmos2/master"]
|
|
|
|
# Pretend to have a certain channel in pmaports.cfg
|
|
def read_config(args):
|
|
return {"channel": channel}
|
|
monkeypatch.setattr(pmb.config.pmaports, "read_config", read_config)
|
|
|
|
# Channel: v20.05
|
|
assert func(args) == ["/mnt/pmbootstrap/packages",
|
|
"http://localhost/pmos1/v20.05",
|
|
"http://localhost/pmos2/v20.05",
|
|
"http://localhost/alpine/v3.11/main",
|
|
"http://localhost/alpine/v3.11/community"]
|
|
|
|
# Channel: edge (has Alpine's testing)
|
|
channel = "edge"
|
|
assert func(args) == ["/mnt/pmbootstrap/packages",
|
|
"http://localhost/pmos1/master",
|
|
"http://localhost/pmos2/master",
|
|
"http://localhost/alpine/edge/main",
|
|
"http://localhost/alpine/edge/community",
|
|
"http://localhost/alpine/edge/testing"]
|
|
|
|
# Only Alpine's URLs
|
|
exp = ["http://localhost/alpine/edge/main",
|
|
"http://localhost/alpine/edge/community",
|
|
"http://localhost/alpine/edge/testing"]
|
|
assert func(args, False, False) == exp
|