Skip to content
Snippets Groups Projects
Commit 463b3a78 authored by Georges Racinet's avatar Georges Racinet
Browse files

RepositoryService.SetFullPath: modernized Gitaly comparison test

Less boilerplate with `RpcHelper`, now that it can normalize error
details.
parent 311ed039
No related branches found
No related tags found
1 merge request!131RepositoryService.FullPath and cleanup
Pipeline #59411 passed
......@@ -218,15 +218,6 @@
def test_set_full_path(gitaly_comparison, server_repos_root):
fixture = gitaly_comparison
repo_stubs = dict(
hg=RepositoryServiceStub(fixture.hgitaly_channel),
git=RepositoryServiceStub(fixture.gitaly_channel)
)
def do_rpc(vcs, path, grpc_repo=fixture.gitaly_repo):
return repo_stubs[vcs].SetFullPath(
SetFullPathRequest(repository=grpc_repo, path=path))
def assert_compare(path):
assert do_rpc('hg', path) == do_rpc('git', path)
def normalize_repo_not_found(msg, **kw):
return msg.replace('git repo', 'Mercurial repo')
......@@ -232,15 +223,11 @@
def assert_error_compare(path,
grpc_repo=None,
msg_normalizer=lambda m: m):
kwargs = dict(grpc_repo=grpc_repo) if grpc_repo is not None else {}
with pytest.raises(Exception) as hg_exc_info:
do_rpc('hg', path, **kwargs)
with pytest.raises(Exception) as git_exc_info:
do_rpc('git', path, **kwargs)
hg_exc, git_exc = hg_exc_info.value, git_exc_info.value
assert hg_exc.code() == git_exc.code()
hg_msg, git_msg = hg_exc.details(), git_exc.details()
assert msg_normalizer(hg_msg) == msg_normalizer(git_msg)
rpc_helper = fixture.rpc_helper(
stub_cls=RepositoryServiceStub,
method_name='SetFullPath',
request_cls=SetFullPathRequest,
error_details_normalizer=normalize_repo_not_found,
)
assert_compare = rpc_helper.assert_compare
assert_error_compare = rpc_helper.assert_compare_errors
# success case
......@@ -245,7 +232,7 @@
# success case
assert_compare('group/project')
assert_compare(path='group/project')
# error cases
assert_error_compare('')
......@@ -248,11 +235,8 @@
# error cases
assert_error_compare('')
def normalize_repo_not_found(msg):
return msg.replace('git repo', 'Mercurial repo')
assert_error_compare('some/full/path',
grpc_repo=Repository(
assert_error_compare(path='some/full/path',
repository=Repository(
storage_name=fixture.gitaly_repo.storage_name,
relative_path='no/such/repo'),
......@@ -257,5 +241,4 @@
storage_name=fixture.gitaly_repo.storage_name,
relative_path='no/such/repo'),
msg_normalizer=normalize_repo_not_found,
)
......@@ -260,7 +243,7 @@
)
assert_error_compare('some/full/path',
grpc_repo=Repository(
assert_error_compare(path='some/full/path',
repository=Repository(
relative_path=fixture.gitaly_repo.relative_path,
storage_name='unknown'))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment