diff --git a/swh/lister/opam/lister.py b/swh/lister/opam/lister.py --- a/swh/lister/opam/lister.py +++ b/swh/lister/opam/lister.py @@ -8,7 +8,7 @@ import os from subprocess import PIPE, Popen, call import tempfile -from typing import Iterator +from typing import Iterator, Optional from swh.lister.pattern import StatelessLister from swh.scheduler.interface import SchedulerInterface @@ -44,7 +44,7 @@ self, scheduler: SchedulerInterface, url: str, - instance: str, + instance: Optional[str] = None, credentials: CredentialsType = None, ): super().__init__( diff --git a/swh/lister/opam/tests/test_lister.py b/swh/lister/opam/tests/test_lister.py --- a/swh/lister/opam/tests/test_lister.py +++ b/swh/lister/opam/tests/test_lister.py @@ -27,12 +27,22 @@ return mock_init, mock_open +def test_lister_opam_optional_instance(swh_scheduler): + """Instance name should be optional and default to be built out of the netloc.""" + netloc = "opam.ocaml.org" + instance_url = f"https://{netloc}" + + lister = OpamLister(swh_scheduler, url=instance_url) + assert lister.instance == netloc + + def test_urls(swh_scheduler, mock_opam): mock_init, mock_popen = mock_opam instance_url = "https://opam.ocaml.org" lister = OpamLister(swh_scheduler, url=instance_url, instance="opam") + assert lister.instance == "opam" # call the lister and get all listed origins urls stats = lister.run()