diff --git a/tests_with_gitaly/conftest.py b/tests_with_gitaly/conftest.py index 42fb2ee5dc24abad47bf9a89ac767b5a41273c15_dGVzdHNfd2l0aF9naXRhbHkvY29uZnRlc3QucHk=..c7d863a582d149a4f266fcfd625c58064d7ca000_dGVzdHNfd2l0aF9naXRhbHkvY29uZnRlc3QucHk= 100644 --- a/tests_with_gitaly/conftest.py +++ b/tests_with_gitaly/conftest.py @@ -32,6 +32,7 @@ from .gitaly import GitalyServer from .rhgitaly import RHGitalyServer from .comparison import gitaly_comparison_fixture +from .hgitaly_rhgitaly_comparison import hgitaly_rhgitaly_comparison_fixture @pytest.fixture(scope='module') @@ -74,3 +75,17 @@ rhgitaly_channel=rhgitaly_channel, ) as comparison: yield comparison + + +@pytest.fixture() +def hgitaly_rhgitaly_comparison(server_repos_root, # module scope + rhgitaly_channel, # module scope + grpc_channel, # module scope + monkeypatch, # function scope + ): + with hgitaly_rhgitaly_comparison_fixture( + server_repos_root, + hgitaly_channel=grpc_channel, + rhgitaly_channel=rhgitaly_channel, + ) as comparison: + yield comparison diff --git a/tests_with_gitaly/hgitaly_rhgitaly_comparison.py b/tests_with_gitaly/hgitaly_rhgitaly_comparison.py new file mode 100644 index 0000000000000000000000000000000000000000..c7d863a582d149a4f266fcfd625c58064d7ca000_dGVzdHNfd2l0aF9naXRhbHkvaGdpdGFseV9yaGdpdGFseV9jb21wYXJpc29uLnB5 --- /dev/null +++ b/tests_with_gitaly/hgitaly_rhgitaly_comparison.py @@ -0,0 +1,50 @@ +# Copyright 2023 Georges Racinet <georges.racinet@octobus.net> +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2 or any later version. +# +# SPDX-License-Identifier: GPL-2.0-or-later +import attr +import contextlib +from .comparison import BaseRpcHelper + + +@attr.s +class HGitalyRHGitalyComparison(): + """This fixture is for comparison between HGitaly and RHGitaly. + + Gitaly itself is not involved at all, so this is for HGitaly-specific + calls, often but not necessarily involving the Mercurial services. + """ + hgitaly_channel = attr.ib() + rhgitaly_channel = attr.ib() + + server_repos_root = attr.ib(default=None) # not used yet + + def rpc_helper(self, **kw): + return RpcHelper(self, **kw) + + +class RpcHelper(BaseRpcHelper): + """Encapsulates a comparison fixture with call and compare helpers. + + This is derived from :class:`hgitaly.comparison.RpcHelper`, but it is + very much simpler. + """ + def init_stubs(self): + comparison, stub_cls = self.comparison, self.stub_cls + self.stubs = dict(hgitaly=stub_cls(comparison.hgitaly_channel), + rhgitaly=stub_cls(comparison.rhgitaly_channel)) + + def assert_compare(self, **kwargs): + self.apply_request_defaults(kwargs) + assert self.rpc('hgitaly', **kwargs) == self.rpc('rhgitaly', **kwargs) + + +@contextlib.contextmanager +def hgitaly_rhgitaly_comparison_fixture(server_repos_root, + hgitaly_channel, + rhgitaly_channel, + ): + yield HGitalyRHGitalyComparison(hgitaly_channel=hgitaly_channel, + rhgitaly_channel=rhgitaly_channel) diff --git a/tests_with_gitaly/test_server.py b/tests_with_gitaly/test_server.py new file mode 100644 index 0000000000000000000000000000000000000000..c7d863a582d149a4f266fcfd625c58064d7ca000_dGVzdHNfd2l0aF9naXRhbHkvdGVzdF9zZXJ2ZXIucHk= --- /dev/null +++ b/tests_with_gitaly/test_server.py @@ -0,0 +1,29 @@ +# Copyright 2023 Georges Racinet <georges.racinet@octobus.net> +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2 or any later version. +# +# SPDX-License-Identifier: GPL-2.0-or-later +import pytest + +from hgitaly.stub.server_pb2 import ( + ServerInfoRequest, +) +from hgitaly.stub.server_pb2_grpc import ServerServiceStub + +from . import skip_comparison_tests + +if skip_comparison_tests(): # pragma no cover + pytestmark = pytest.mark.skip + + +def test_compare_server_info(hgitaly_rhgitaly_comparison): + fixture = hgitaly_rhgitaly_comparison + rpc_helper = fixture.rpc_helper( + stub_cls=ServerServiceStub, + method_name='ServerInfo', + request_cls=ServerInfoRequest, + repository_arg=False, + ) + + rpc_helper.assert_compare()