opam: Make the instance optional and derived from the url

This matches how it's done for all other multi instances listers.

Related to T3590
This commit is contained in:
Antoine R. Dumont (@ardumont) 2021-09-20 17:47:29 +02:00
parent b69b0b7fd6
commit ff5e86ff48
No known key found for this signature in database
GPG key ID: 52E2E9840D10C3B8
2 changed files with 12 additions and 2 deletions

View file

@ -8,7 +8,7 @@ import logging
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 @@ class OpamLister(StatelessLister[PageType]):
self,
scheduler: SchedulerInterface,
url: str,
instance: str,
instance: Optional[str] = None,
credentials: CredentialsType = None,
):
super().__init__(

View file

@ -28,12 +28,22 @@ def mock_opam(mocker):
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()