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

add gitaly comparison tests for creating bundle and restoration methods

Rebased and amended by gracinet
parent f64a4dbd
No related branches found
No related tags found
1 merge request!71repository-service: implement CreateBundle and CreateRepositoryFromBundle
......@@ -15,7 +15,9 @@
from hgitaly.stub.shared_pb2 import Repository
from hgitaly.stub.repository_service_pb2 import (
CreateRepositoryRequest,
CreateBundleRequest,
CreateRepositoryFromBundleRequest,
FindMergeBaseRequest,
SetFullPathRequest,
)
from hgitaly.stub.repository_service_pb2_grpc import RepositoryServiceStub
......@@ -18,8 +20,12 @@
FindMergeBaseRequest,
SetFullPathRequest,
)
from hgitaly.stub.repository_service_pb2_grpc import RepositoryServiceStub
from heptapod.testhelpers import (
LocalRepoWrapper,
git,
)
from . import skip_comparison_tests
if skip_comparison_tests(): # pragma no cover
pytestmark = pytest.mark.skip
......@@ -22,7 +28,8 @@
from . import skip_comparison_tests
if skip_comparison_tests(): # pragma no cover
pytestmark = pytest.mark.skip
TIP_TAG_NAME = b'tip'
def test_compare_find_merge_base(gitaly_comparison):
......@@ -205,3 +212,99 @@
grpc_repo=Repository(
relative_path=fixture.gitaly_repo.relative_path,
storage_name='unknown'))
def test_compare_create_bundle_and_create_repository_from_bundle(
gitaly_comparison, tmpdir, server_repos_root):
default_storage = 'default'
fixture = gitaly_comparison
gitaly_repo = fixture.gitaly_repo
wrapper = fixture.hg_repo_wrapper
# repo structure:
#
# @ 3 zoo (phase: draft) (amended) (branch:feature)
# |
# | o 1 bar (phase: public) (tag: v1.2.3)
# |/
# o 0 foo (phase: public)
#
ctx0 = wrapper.commit_file('foo')
sha0 = ctx0.hex()
sha1 = wrapper.commit_file('bar').hex()
wrapper.commit_file('zoo', parent=ctx0, branch='feature')
wrapper.amend_file('zoo')
wrapper.set_phase('public', [sha0, sha1])
wrapper.update(sha1)
wrapper.command('tag', b'v1.2.3', rev=sha1)
wrapper.command('gitlab-mirror')
hg_rel_path = 'target_hg_repo'
git_rel_path = 'target_git_repo'
hgrepo_fullpath = server_repos_root / default_storage / hg_rel_path
gitrepo_fullpath = server_repos_root / default_storage / git_rel_path
target_repo_msg = dict(
hg=Repository(relative_path=hg_rel_path,
storage_name=default_storage),
git=Repository(relative_path=git_rel_path,
storage_name=default_storage))
bundle_path = dict(
hg=tmpdir / 'hg.bundle',
git=tmpdir / 'git.bundle')
repo_stub = dict(
hg=RepositoryServiceStub(fixture.hgitaly_channel),
git=RepositoryServiceStub(fixture.gitaly_channel))
def rpc_create_bundle(vcs):
request = CreateBundleRequest(repository=gitaly_repo)
response = repo_stub[vcs].CreateBundle(request)
with open(bundle_path[vcs], 'wb') as fobj:
for chunk in response:
fobj.write(chunk.data)
def rpc_create_repository_from_bundle(vcs):
with open(bundle_path[vcs], 'rb') as fobj:
data = fobj.read()
first_req_data_size = len(data) // 2
request1 = CreateRepositoryFromBundleRequest(
repository=target_repo_msg[vcs],
data=data[:first_req_data_size])
request2 = CreateRepositoryFromBundleRequest(
data=data[first_req_data_size:])
# create an iterator of requests
request = (req for req in [request1, request2])
return repo_stub[vcs].CreateRepositoryFromBundle(request)
# Actual test
rpc_create_bundle('hg')
rpc_create_bundle('git')
rpc_create_repository_from_bundle('hg')
rpc_create_repository_from_bundle('git')
target_hgrepo = LocalRepoWrapper.load(hgrepo_fullpath).repo
target_gitrepo = git.GitRepo(gitrepo_fullpath)
def assert_compare_hg_git_created_repos(target_hgrepo, target_gitrepo):
# assert branches
br_prefix = b'branch/'
hgbranches = set(
[br[0] for br in target_hgrepo.branchmap().iterbranches()])
gitbranches = set(
[br[len(br_prefix):] for br in target_gitrepo.branches().keys()])
assert hgbranches == gitbranches
# assert tags
hg_tags = set(target_hgrepo.tags().keys())
hg_tags.remove(TIP_TAG_NAME)
git_tags = set(target_gitrepo.tags())
assert hg_tags == git_tags
assert_compare_hg_git_created_repos(target_hgrepo, target_gitrepo)
# test error case: when repo already exists
with pytest.raises(grpc.RpcError) as exc_info_git:
rpc_create_repository_from_bundle('git')
with pytest.raises(grpc.RpcError) as exc_info_hg:
rpc_create_repository_from_bundle('hg')
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