Read about our upcoming Code of Conduct on this issue

Commit 91379b16 authored by Sushil Khanchi's avatar Sushil Khanchi 🐨
Browse files

DiffService-FindChangedPaths: add gitaly comparison tests

parent d05c10cb3f8d
Pipeline #23705 passed with stages
in 1 minute and 14 seconds
......@@ -12,6 +12,7 @@ from hgitaly.stub.diff_pb2 import (
CommitDeltaRequest,
CommitDiffRequest,
DiffStatsRequest,
FindChangedPathsRequest,
RawDiffRequest,
RawPatchRequest,
)
......@@ -457,3 +458,60 @@ def test_compare_diff_stats(gitaly_comparison):
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()
def test_compare_find_changed_paths(gitaly_comparison):
fixture = gitaly_comparison
wrapper_repo = fixture.gitaly_repo
git_repo = fixture.git_repo
wrapper = fixture.hg_repo_wrapper
gl_branch = b'branch/default'
(wrapper.path / 'foo').write_text('foo content')
(wrapper.path / 'bar').write_text('bar content')
ctx0 = wrapper.commit(rel_paths=['foo', 'bar'],
add_remove=True)
git_sha0 = git_repo.branches()[gl_branch]['sha']
(wrapper.path / 'zoo').write_text('zoo content')
(wrapper.path / 'foo').write_text('foo content modified')
(wrapper.path / 'bar').unlink()
wrapper.command(b'rm', wrapper.repo.root + b'/bar')
ctx1 = wrapper.commit(rel_paths=['foo', 'bar', 'zoo'],
add_remove=True)
git_sha1 = git_repo.branches()[gl_branch]['sha']
diff_stubs = dict(
git=DiffServiceStub(fixture.gitaly_channel),
hg=DiffServiceStub(fixture.hgitaly_channel)
)
def do_rpc(vcs, commits):
request = FindChangedPathsRequest(
repository=wrapper_repo,
commits=commits,
)
response = diff_stubs[vcs].FindChangedPaths(request)
final = []
for resp in response:
paths = sorted(resp.paths, key=lambda o: o.path)
final.append(paths)
return final
# case 1: actual test
assert do_rpc('git', [git_sha1]) == do_rpc('hg', [ctx1.hex()])
# Note: khanchi97: As per the command used by gitaly for FindChangedPaths
# cmd: `git diff-tree --stdin -z -m -r --name-status --no-renames`
# `--no-commit-id --diff-filter=AMDTC`
# -> git doesn't return anything for the first commit, although I assume
# it should, so not testing for ctx0 for now.
# 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', [ctx0.hex(), sha_not_exists])
with pytest.raises(grpc.RpcError) as exc_info_git:
do_rpc('git', [git_sha0, sha_not_exists])
assert exc_info_hg.value.code() == exc_info_git.value.code()
assert exc_info_hg.value.details() == exc_info_git.value.details()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment