util: Fix offline resolving for scm dict

For scm dict resolving the return value should be git ref (or source
branch for offline mode).

JIRA: COMPOSE-3614
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2019-06-11 16:01:30 +02:00
parent 2a9490526a
commit f784bbd519
2 changed files with 19 additions and 5 deletions

View File

@ -309,8 +309,9 @@ def resolve_git_url(url):
class GitUrlResolver(object):
"""A wrapper for resolve_git_url that checks each url only once. In offline
mode it does not actually do anything, returning original input urls.
"""A caching resolver for git references. As input it can either take repo
URL with fragment describing reference, or url and refname. It will return
either url with changed fragment or just resolved ref.
"""
def __init__(self, offline=False):
self.offline = offline
@ -318,7 +319,7 @@ class GitUrlResolver(object):
def __call__(self, url, branch=None):
if self.offline:
return url
return branch or url
key = (url, branch)
if key not in self.cache:
try:

View File

@ -130,14 +130,27 @@ class TestGitRefResolver(unittest.TestCase):
[mock.call(['git', 'ls-remote', 'https://git.example.com/repo.git', 'HEAD'],
universal_newlines=True)] * 2)
@mock.patch("pungi.util.resolve_git_ref")
@mock.patch("pungi.util.resolve_git_url")
def test_resolver_offline(self, mock_resolve):
def test_resolver_offline(self, mock_resolve_url, mock_resolve_ref):
resolver = util.GitUrlResolver(offline=True)
self.assertEqual(
resolver("http://example.com/repo.git#HEAD"),
"http://example.com/repo.git#HEAD",
)
self.assertEqual(mock_resolve.call_args_list, [])
self.assertEqual(mock_resolve_url.call_args_list, [])
self.assertEqual(mock_resolve_ref.call_args_list, [])
@mock.patch("pungi.util.resolve_git_ref")
@mock.patch("pungi.util.resolve_git_url")
def test_resolver_offline_branch(self, mock_resolve_url, mock_resolve_ref):
resolver = util.GitUrlResolver(offline=True)
self.assertEqual(
resolver("http://example.com/repo.git", "master"),
"master",
)
self.assertEqual(mock_resolve_url.call_args_list, [])
self.assertEqual(mock_resolve_ref.call_args_list, [])
@mock.patch("pungi.util.resolve_git_ref")
@mock.patch("pungi.util.resolve_git_url")