Skip to content
Snippets Groups Projects
Commit e777ecfb authored by Sushil Khanchi's avatar Sushil Khanchi :koala:
Browse files

tests: add gitaly comparison tests for DiffStats

parent a3e49ad4
No related branches found
No related tags found
1 merge request!43DiffService: implement DiffStats
Pipeline #20256 passed
......@@ -11,6 +11,7 @@
from hgitaly.stub.diff_pb2 import (
CommitDeltaRequest,
CommitDiffRequest,
DiffStatsRequest,
RawDiffRequest,
)
from hgitaly.stub.diff_pb2_grpc import DiffServiceStub
......@@ -402,3 +403,67 @@
do_rpc('git', sha_not_exists, git_shas[sha3])
assert exc_info_hg.value.code() == exc_info_git.value.code()
assert exc_info_hg.value.details() == exc_info_git.value.details()
def test_compare_diff_stats(gitaly_comparison):
fixture = gitaly_comparison
gitaly_repo = fixture.gitaly_repo
git_repo = fixture.git_repo
wrapper = fixture.hg_repo_wrapper
gl_branch = b'branch/default'
ctx0 = wrapper.commit_file('bar',
content="first_line\n"
"second_line\n"
"third_line\n",
message="Add bar")
git_sha0 = git_repo.branches()[gl_branch]['sha']
wrapper.commit_file('bar',
content="first_line\n"
"second_line\n"
"third_line_updated\n",
message="Changes bar")
wrapper.command(b'mv', wrapper.repo.root + b'/bar',
wrapper.repo.root + b'/zar')
wrapper.commit([b'zar', b'bar'], message=b"Rename bar to zar")
ctx3 = wrapper.commit_file('zoo', content="I am in zoo\n",
message="Added zoo")
git_sha3 = git_repo.branches()[gl_branch]['sha']
# Repo structure:
#
# @ 3 Added zoo
# |
# o 2 Rename bar to zar
# |
# o 1 Changes bar
# |
# o 0 Add bar
#
def do_rpc(vcs, left_cid, right_cid, **opts):
request = DiffStatsRequest(
repository=gitaly_repo,
left_commit_id=left_cid,
right_commit_id=right_cid,
**opts,
)
diff_stubs = dict(git=DiffServiceStub(fixture.gitaly_channel),
hg=DiffServiceStub(fixture.hgitaly_channel))
response = diff_stubs[vcs].DiffStats(request)
return [resp.stats for resp in response]
# case 1: actual test
hg_resp = do_rpc('hg', left_cid=ctx0.hex(),
right_cid=ctx3.hex())
git_resp = do_rpc('git', left_cid=git_sha0,
right_cid=git_sha3)
assert hg_resp == git_resp
# case 2: when commit_id does not correspond to a commit
sha_not_exists = b'deadnode' * 5
with pytest.raises(grpc.RpcError) as exc_info_hg:
do_rpc('hg', sha_not_exists, ctx3.hex())
with pytest.raises(grpc.RpcError) as exc_info_git:
do_rpc('git', sha_not_exists, git_sha3)
assert exc_info_hg.value.code() == exc_info_git.value.code()
assert exc_info_hg.value.details() == exc_info_git.value.details()
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