Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
hgitaly
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
heptapod
hgitaly
Commits
a692fac8
Commit
a692fac8
authored
4 years ago
by
Sushil Khanchi
Browse files
Options
Downloads
Patches
Plain Diff
diffService: some cleanup in test_compare_raw_diff
parent
65bf455f
No related branches found
Branches containing commit
Tags
0.8.1
Tags containing commit
1 merge request
!52
diff-service: some cleanup
Pipeline
#20609
passed
4 years ago
Stage: main
Stage: compat
Changes
1
Pipelines
12
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests_with_gitaly/test_diff.py
+31
-43
31 additions, 43 deletions
tests_with_gitaly/test_diff.py
with
31 additions
and
43 deletions
tests_with_gitaly/test_diff.py
+
31
−
43
View file @
a692fac8
...
...
@@ -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
\n
rab
\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
\n
rab
\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
\n
bar
\n
"
,
message
=
"
Changes bar
"
)
...
...
@@ -38,5 +39,5 @@
ctx1
=
wrapper
.
commit_file
(
'
bar
'
,
content
=
"
I am in
\n
bar
\n
"
,
message
=
"
Changes bar
"
)
git_sha
1
=
git_repo
.
branches
()[
gl_branch
][
'
sha
'
]
git_sha
s
[
ctx1
.
hex
()]
=
git_repo
.
branches
()[
gl_branch
][
'
sha
'
]
ctx2
=
wrapper
.
commit_file
(
'
zoo
'
,
content
=
"
I am in
\n
zoo
\n
"
,
message
=
"
Added zoo
"
)
...
...
@@ -41,7 +42,7 @@
ctx2
=
wrapper
.
commit_file
(
'
zoo
'
,
content
=
"
I am in
\n
zoo
\n
"
,
message
=
"
Added zoo
"
)
git_sha
2
=
git_repo
.
branches
()[
gl_branch
][
'
sha
'
]
git_sha
s
[
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_sha
3
=
git_repo
.
branches
()[
gl_branch
][
'
sha
'
]
git_sha
s
[
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
_
git
aly
(
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
]
==
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment