Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/arch/tests/test_lister.py
- This file was added.
# Copyright (C) 2022 The Software Heritage developers | |||||
# See the AUTHORS file at the top-level directory of this distribution | |||||
# License: GNU General Public License version 3, or any later version | |||||
# See top-level LICENSE file for more information | |||||
from pathlib import Path | |||||
from swh.lister.arch.lister import ArchLister, pkgbuild_get_versions, pkgbuild_parser | |||||
from swh.lister.arch.tests import prepare_repository_from_archive | |||||
expected_pkgbuild = { | |||||
"mercurial": { | |||||
"maintainer": ["Bartłomiej Piotrowski <bpiotrowski@archlinux.org>"], | |||||
"contributor": [ | |||||
"Giovanni Scafora <giovanni@archlinux.org>", | |||||
"Douglas Soares de Andrade <douglas@archlinux.org>", | |||||
], | |||||
"pkgname": "mercurial", | |||||
"pkgver": "6.1.2", | |||||
"pkgrel": "1", | |||||
"pkgdesc": "A scalable distributed SCM tool", | |||||
"url": "https://www.mercurial-scm.org/", | |||||
"arch": ["x86_64"], | |||||
"license": ["GPL"], | |||||
"source": [ | |||||
"https://www.mercurial-scm.org/release/mercurial-6.1.2.tar.gz", | |||||
"https://www.mercurial-scm.org/release/mercurial-6.1.2.tar.gz.asc", | |||||
"mercurial.profile", | |||||
], | |||||
"cksums": [], | |||||
"md5sums": [], | |||||
"sha1sums": [], | |||||
"sha224sums": [], | |||||
"sha256sums": [], | |||||
"sha384sums": [], | |||||
"sha512sums": [ | |||||
"4adb8299747601d4c38b5ee83105f83810348357e244b6380b063c5ab25ea2ea2756fb0caf7f980d7cc707c27dee709b206894417aab9e6aee0818ddfe3aaf2b", # noqa: B950 | |||||
"SKIP", | |||||
"710dcddb24d928efc97370e869d9caa083107929ed9a1086dd2a3ae0caaf2c71e2f29060597e29315b6b15b1616251c42412e268ce737109c48ae4d7aa1b9555", # noqa: B950 | |||||
], | |||||
"b2sums": [], | |||||
} | |||||
} | |||||
expected_versions = { | |||||
"mercurial": [ | |||||
{"date": "2022-05-10T13:55:17+02:00", "pkgver": "6.1.2"}, | |||||
{"date": "2022-05-10T13:55:17+02:00", "pkgver": "6.1.1"}, | |||||
{"date": "2022-05-10T13:55:17+02:00", "pkgver": "6.1"}, | |||||
] | |||||
} | |||||
expected_origins = [ | |||||
{"url": "https://archlinux.org/packages/extra/x86_64/mercurial/json"}, | |||||
{"url": "https://archlinux.org/packages/core/x86_64/gzip/json"}, | |||||
] | |||||
def test_arch_pkgbuild_file_parser(datadir, tmp_path): | |||||
archive_path = Path(datadir, "fake-archlinux-svntogit-packages-index.tar.gz") | |||||
prepare_repository_from_archive( | |||||
archive_path, "archlinux-svntogit-packages-index", tmp_path | |||||
) | |||||
pkgbuild_file_path = Path( | |||||
tmp_path, | |||||
"archlinux-svntogit-packages-index", | |||||
"mercurial", | |||||
"repos", | |||||
"extra-x86_64", | |||||
"PKGBUILD", | |||||
) | |||||
with pkgbuild_file_path.open("rb") as content: | |||||
assert ( | |||||
pkgbuild_parser(content=content.read().decode()) | |||||
== expected_pkgbuild["mercurial"] | |||||
) | |||||
def test_arch_pkgbuild_get_versions(datadir, tmp_path): | |||||
archive_path = Path(datadir, "fake-archlinux-svntogit-packages-index.tar.gz") | |||||
prepare_repository_from_archive( | |||||
archive_path, "archlinux-svntogit-packages-index", tmp_path | |||||
) | |||||
repository_path = Path( | |||||
tmp_path, | |||||
"archlinux-svntogit-packages-index", | |||||
) | |||||
pkgbuild_file_path = Path( | |||||
repository_path, | |||||
"mercurial", | |||||
"repos", | |||||
"extra-x86_64", | |||||
"PKGBUILD", | |||||
) | |||||
assert ( | |||||
pkgbuild_get_versions( | |||||
repository_path=repository_path, pkgbuild_path=pkgbuild_file_path | |||||
) | |||||
== expected_versions["mercurial"] | |||||
) | |||||
def test_arch_lister(datadir, tmp_path, swh_scheduler): | |||||
archive_path = Path(datadir, "fake-archlinux-svntogit-packages-index.tar.gz") | |||||
repo_url = prepare_repository_from_archive( | |||||
archive_path, "archlinux-svntogit-packages-index", tmp_path | |||||
) | |||||
lister = ArchLister(scheduler=swh_scheduler) | |||||
lister.INDEX_REPOSITORY_URL = repo_url | |||||
lister.DESTINATION_PATH = tmp_path.parent / "archlinux-packages-index-tests" | |||||
res = lister.run() | |||||
assert res.pages == 2 | |||||
assert res.origins == 2 | |||||
expected_origins_sorted = sorted(expected_origins, key=lambda x: x.get("url")) | |||||
scheduler_origins_sorted = sorted( | |||||
swh_scheduler.get_listed_origins(lister.lister_obj.id).results, | |||||
key=lambda x: x.url, | |||||
) | |||||
for scheduled, expected in zip(scheduler_origins_sorted, expected_origins_sorted): | |||||
assert scheduled.visit_type == "arch" | |||||
assert scheduled.url == expected.get("url") | |||||
# TODO: Check artifacts | |||||
assert len(scheduler_origins_sorted) == len(expected_origins_sorted) |