From 8409410aa294cad68bf93679726e0a4465e1fe2b Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 11 Feb 2020 02:10:28 -0500 Subject: repo: export GIT_TRACE2_PARENT_SID This helps with people tracing repo/git execution. We use a similar format to git, but a little simpler since we always initialize the env var setting, and we want to avoid too much overhead. Bug: https://crbug.com/gerrit/12314 Change-Id: I75675b6cc4c6f7c4f5e09f54128eba9456364d04 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/254331 Reviewed-by: Josh Steadmon Reviewed-by: Mike Frysinger Tested-by: Mike Frysinger --- tests/test_wrapper.py | 50 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) (limited to 'tests/test_wrapper.py') diff --git a/tests/test_wrapper.py b/tests/test_wrapper.py index 38def512..e574946b 100644 --- a/tests/test_wrapper.py +++ b/tests/test_wrapper.py @@ -19,8 +19,10 @@ from __future__ import print_function import os +import re import unittest +from pyversion import is_python3 import wrapper @@ -30,16 +32,22 @@ def fixture(*paths): return os.path.join(os.path.dirname(__file__), 'fixtures', *paths) -class RepoWrapperUnitTest(unittest.TestCase): - """Tests helper functions in the repo wrapper - """ +class RepoWrapperTestCase(unittest.TestCase): + """TestCase for the wrapper module.""" def setUp(self): - """Load the wrapper module every time - """ + """Load the wrapper module every time.""" wrapper._wrapper_module = None self.wrapper = wrapper.Wrapper() + if not is_python3(): + self.assertRegex = self.assertRegexpMatches + + +class RepoWrapperUnitTest(RepoWrapperTestCase): + """Tests helper functions in the repo wrapper + """ + def test_get_gitc_manifest_dir_no_gitc(self): """ Test reading a missing gitc config file @@ -80,5 +88,37 @@ class RepoWrapperUnitTest(unittest.TestCase): self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/'), None) +class SetGitTrace2ParentSid(RepoWrapperTestCase): + """Check SetGitTrace2ParentSid behavior.""" + + KEY = 'GIT_TRACE2_PARENT_SID' + VALID_FORMAT = re.compile(r'^repo-[0-9]{8}T[0-9]{6}Z-P[0-9a-f]{8}$') + + def test_first_set(self): + """Test env var not yet set.""" + env = {} + self.wrapper.SetGitTrace2ParentSid(env) + self.assertIn(self.KEY, env) + value = env[self.KEY] + self.assertRegex(value, self.VALID_FORMAT) + + def test_append(self): + """Test env var is appended.""" + env = {self.KEY: 'pfx'} + self.wrapper.SetGitTrace2ParentSid(env) + self.assertIn(self.KEY, env) + value = env[self.KEY] + self.assertTrue(value.startswith('pfx/')) + self.assertRegex(value[4:], self.VALID_FORMAT) + + def test_global_context(self): + """Check os.environ gets updated by default.""" + os.environ.pop(self.KEY, None) + self.wrapper.SetGitTrace2ParentSid() + self.assertIn(self.KEY, os.environ) + value = os.environ[self.KEY] + self.assertRegex(value, self.VALID_FORMAT) + + if __name__ == '__main__': unittest.main() -- cgit v1.2.3-54-g00ecf