Skip to content
Snippets Groups Projects
Commit a5fd743bb615 authored by Georges Racinet's avatar Georges Racinet :squid:
Browse files

test helpers: separate functions to activate state maintaining

Two helpers for in-RAM activation on the Mercurial `localrepo` object
and in config dicts of our testhelpers for persistence in `.hg/hgrc`.

This makes it easier to use in HGitaly test fixtures, reducing hardcoding
and duplication.
parent a1831e878bd4
No related branches found
No related tags found
1 merge request!111More test helpers
Pipeline #96940 passed
......@@ -24,6 +24,11 @@
from .git import GitRepo
logger = logging.getLogger(__name__)
STATE_MAINTAINER_ACTIVATION_CONFIG = (
b'hooks', b'pretxnclose.testcase',
b'python:heptapod.hooks.gitlab_mirror.mirror',
)
def patch_gitlab_hooks(monkeypatch, records, action=None):
......@@ -43,6 +48,26 @@
monkeypatch.setattr(hooks.PostReceive, '__call__', call)
def activate_gitlab_state_maintainer(hg_repo_wrapper):
"""Make state maintaining or mirroring to Git repo automatic.
This is essential to get the state maintaining happen in-transaction.
If the repository is configured with `native=False` (legacy hg-git based
projects), this triggers the mirroring to Git.
"""
hg_repo_wrapper.repo.ui.setconfig(*STATE_MAINTAINER_ACTIVATION_CONFIG)
def activate_gitlab_state_maintainer_in_dict(config): # pragma no cover
"""Activation in config dicts used before persisting configuration.
This is used in HGitaly tests, as py-heptapod tests tend to do it
after repo creation, in non-persistent form.
"""
section, key, value = STATE_MAINTAINER_ACTIVATION_CONFIG
config[section] = {key: value}
@attr.s
class GitLabStateMaintainerFixture:
"""Helper class to create fixtures for GitLab state maintainers.
......@@ -97,13 +122,7 @@
del self.gitlab_notifs[:]
def activate_mirror(self):
"""Make mirroring from Mercurial to Git repo automatic.
This is essential to get the mirroring code to run in-transaction.
"""
self.hg_repo_wrapper.repo.ui.setconfig(
b'hooks', b'pretxnclose.testcase',
b'python:heptapod.hooks.gitlab_mirror.mirror')
activate_gitlab_state_maintainer(self.hg_repo_wrapper)
def delete(self):
hg_path = self.hg_repo_wrapper.repo.root
......
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