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

diffService: some cleanup in test_compare_raw_diff

parent 65bf455f
No related branches found
Tags 0.8.1
1 merge request!52diff-service: some cleanup
Pipeline #20609 passed
......@@ -26,11 +26,10 @@
def test_compare_raw_diff(gitaly_comparison):
fixture = gitaly_comparison
hgitaly_repo = fixture.hgitaly_repo
gitaly_repo = fixture.gitaly_repo
wrapper_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="I am in\nrab\n",
message="Some bar")
......@@ -31,9 +30,11 @@
git_repo = fixture.git_repo
wrapper = fixture.hg_repo_wrapper
gl_branch = b'branch/default'
ctx0 = wrapper.commit_file('bar', content="I am in\nrab\n",
message="Some bar")
git_sha0 = git_repo.branches()[gl_branch]['sha']
git_shas = {
ctx0.hex(): git_repo.branches()[gl_branch]['sha']
}
ctx1 = wrapper.commit_file('bar', content="I am in\nbar\n",
message="Changes bar")
......@@ -38,5 +39,5 @@
ctx1 = wrapper.commit_file('bar', content="I am in\nbar\n",
message="Changes bar")
git_sha1 = git_repo.branches()[gl_branch]['sha']
git_shas[ctx1.hex()] = git_repo.branches()[gl_branch]['sha']
ctx2 = wrapper.commit_file('zoo', content="I am in\nzoo\n",
message="Added zoo")
......@@ -41,7 +42,7 @@
ctx2 = wrapper.commit_file('zoo', content="I am in\nzoo\n",
message="Added zoo")
git_sha2 = git_repo.branches()[gl_branch]['sha']
git_shas[ctx2.hex()] = git_repo.branches()[gl_branch]['sha']
wrapper.command(b'mv', wrapper.repo.root + b'/bar',
wrapper.repo.root + b'/zar')
wrapper.command(b'ci', message=b"Rename bar to zar")
ctx3 = wrapper.repo[b'.']
......@@ -44,8 +45,8 @@
wrapper.command(b'mv', wrapper.repo.root + b'/bar',
wrapper.repo.root + b'/zar')
wrapper.command(b'ci', message=b"Rename bar to zar")
ctx3 = wrapper.repo[b'.']
git_sha3 = git_repo.branches()[gl_branch]['sha']
git_shas[ctx3.hex()] = git_repo.branches()[gl_branch]['sha']
# Repo structure:
#
# @ 3 Rename bar to zar
......@@ -57,9 +58,17 @@
# o 0 Some bar
#
def do_rpc_hgitaly(left_cid, right_cid):
hgitaly_request = RawDiffRequest(
repository=hgitaly_repo,
diff_stubs = dict(
git=DiffServiceStub(fixture.gitaly_channel),
hg=DiffServiceStub(fixture.hgitaly_channel)
)
def do_rpc(vcs, left_cid, right_cid):
if vcs == 'git':
left_cid = git_shas.get(left_cid, left_cid)
right_cid = git_shas.get(right_cid, right_cid)
request = RawDiffRequest(
repository=wrapper_repo,
left_commit_id=left_cid,
right_commit_id=right_cid,
)
......@@ -63,18 +72,7 @@
left_commit_id=left_cid,
right_commit_id=right_cid,
)
hgitaly_diff_stub = DiffServiceStub(fixture.hgitaly_channel)
response = hgitaly_diff_stub.RawDiff(hgitaly_request)
return b''.join(resp.data for resp in response)
def do_rpc_gitaly(left_cid, right_cid):
gitaly_request = RawDiffRequest(
repository=gitaly_repo,
left_commit_id=left_cid,
right_commit_id=right_cid,
)
gitaly_diff_stub = DiffServiceStub(fixture.gitaly_channel)
response = gitaly_diff_stub.RawDiff(gitaly_request)
response = diff_stubs[vcs].RawDiff(request)
return b''.join(resp.data for resp in response)
# case 1: when indexline doesn't contain <mode>
......@@ -78,10 +76,8 @@
return b''.join(resp.data for resp in response)
# case 1: when indexline doesn't contain <mode>
hg_resp_lines = do_rpc_hgitaly(left_cid=ctx1.hex(),
right_cid=ctx2.hex()).split(b'\n')
git_resp_lines = do_rpc_gitaly(left_cid=git_sha1,
right_cid=git_sha2).split(b'\n')
hg_resp_lines = do_rpc('hg', ctx1.hex(), ctx2.hex()).split(b'\n')
git_resp_lines = do_rpc('git', ctx1.hex(), ctx2.hex()).split(b'\n')
INDEX_LINE_POSITION = 2
hg_indexline = hg_resp_lines[INDEX_LINE_POSITION]
git_indexline = git_resp_lines[INDEX_LINE_POSITION]
......@@ -94,10 +90,8 @@
assert hg_resp_lines == git_resp_lines
# case 2: when indexline has <mode> (it happens when mode didn't change)
hg_resp_lines = do_rpc_hgitaly(left_cid=ctx0.hex(),
right_cid=ctx1.hex()).split(b'\n')
git_resp_lines = do_rpc_gitaly(left_cid=git_sha0,
right_cid=git_sha1).split(b'\n')
hg_resp_lines = do_rpc('hg', ctx0.hex(), ctx1.hex()).split(b'\n')
git_resp_lines = do_rpc('git', ctx0.hex(), ctx1.hex()).split(b'\n')
INDEX_LINE_POSITION = 1
hg_indexline = hg_resp_lines[INDEX_LINE_POSITION]
git_indexline = git_resp_lines[INDEX_LINE_POSITION]
......@@ -106,13 +100,11 @@
assert INDEX_LINE_REGEXP.match(git_indexline).group(1) == b' 100644'
# case 3: test with file renaming
hg_resp = do_rpc_hgitaly(left_cid=ctx2.hex(),
right_cid=ctx3.hex())
git_resp = do_rpc_gitaly(left_cid=git_sha2,
right_cid=git_sha3)
hg_resp = do_rpc('hg', ctx2.hex(), ctx3.hex())
git_resp = do_rpc('git', ctx2.hex(), ctx3.hex())
assert hg_resp is not None
assert hg_resp == git_resp
# case 4: when commit_id does not correspond to a commit
sha_not_exists = b'deadnode' * 5
with pytest.raises(grpc.RpcError) as exc_info:
......@@ -113,9 +105,9 @@
assert hg_resp is not None
assert hg_resp == git_resp
# case 4: when commit_id does not correspond to a commit
sha_not_exists = b'deadnode' * 5
with pytest.raises(grpc.RpcError) as exc_info:
do_rpc_hgitaly(sha_not_exists, ctx2.hex())
do_rpc('hg', sha_not_exists, ctx2.hex())
assert exc_info.value.code() == grpc.StatusCode.UNKNOWN
with pytest.raises(grpc.RpcError) as exc_info:
......@@ -120,6 +112,6 @@
assert exc_info.value.code() == grpc.StatusCode.UNKNOWN
with pytest.raises(grpc.RpcError) as exc_info:
do_rpc_gitaly(sha_not_exists, git_sha2)
do_rpc('git', sha_not_exists, ctx2.hex())
assert exc_info.value.code() == grpc.StatusCode.UNKNOWN
# case 5: EMPTY_TREE_OID to represent null commit on the left
......@@ -123,10 +115,8 @@
assert exc_info.value.code() == grpc.StatusCode.UNKNOWN
# case 5: EMPTY_TREE_OID to represent null commit on the left
hg_resp_lines = do_rpc_hgitaly(left_cid=EMPTY_TREE_OID,
right_cid=ctx0.hex()).split(b'\n')
git_resp_lines = do_rpc_gitaly(left_cid=EMPTY_TREE_OID,
right_cid=git_sha0).split(b'\n')
hg_resp_lines = do_rpc('hg', EMPTY_TREE_OID, ctx0.hex()).split(b'\n')
git_resp_lines = do_rpc('git', EMPTY_TREE_OID, ctx0.hex()).split(b'\n')
INDEX_LINE_POSITION = 2
assert (hg_resp_lines[INDEX_LINE_POSITION].split(b'..')[0]
==
......@@ -136,10 +126,8 @@
assert hg_resp_lines == git_resp_lines
# case 6: EMPTY_TREE_OID to represent null commit on the right
git_resp_lines = do_rpc_gitaly(right_cid=EMPTY_TREE_OID,
left_cid=git_sha0).split(b'\n')
hg_resp_lines = do_rpc_hgitaly(right_cid=EMPTY_TREE_OID,
left_cid=ctx0.hex()).split(b'\n')
git_resp_lines = do_rpc('git', ctx0.hex(), EMPTY_TREE_OID).split(b'\n')
hg_resp_lines = do_rpc('hg', ctx0.hex(), EMPTY_TREE_OID).split(b'\n')
INDEX_LINE_POSITION = 2
assert (hg_resp_lines[INDEX_LINE_POSITION].rsplit(b'..')[-1]
==
......
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