summaryrefslogtreecommitdiffstats
path: root/tests/test_wrapper.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_wrapper.py')
-rw-r--r--tests/test_wrapper.py50
1 files changed, 45 insertions, 5 deletions
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 @@
19from __future__ import print_function 19from __future__ import print_function
20 20
21import os 21import os
22import re
22import unittest 23import unittest
23 24
25from pyversion import is_python3
24import wrapper 26import wrapper
25 27
26 28
@@ -30,16 +32,22 @@ def fixture(*paths):
30 return os.path.join(os.path.dirname(__file__), 'fixtures', *paths) 32 return os.path.join(os.path.dirname(__file__), 'fixtures', *paths)
31 33
32 34
33class RepoWrapperUnitTest(unittest.TestCase): 35class RepoWrapperTestCase(unittest.TestCase):
34 """Tests helper functions in the repo wrapper 36 """TestCase for the wrapper module."""
35 """
36 37
37 def setUp(self): 38 def setUp(self):
38 """Load the wrapper module every time 39 """Load the wrapper module every time."""
39 """
40 wrapper._wrapper_module = None 40 wrapper._wrapper_module = None
41 self.wrapper = wrapper.Wrapper() 41 self.wrapper = wrapper.Wrapper()
42 42
43 if not is_python3():
44 self.assertRegex = self.assertRegexpMatches
45
46
47class RepoWrapperUnitTest(RepoWrapperTestCase):
48 """Tests helper functions in the repo wrapper
49 """
50
43 def test_get_gitc_manifest_dir_no_gitc(self): 51 def test_get_gitc_manifest_dir_no_gitc(self):
44 """ 52 """
45 Test reading a missing gitc config file 53 Test reading a missing gitc config file
@@ -80,5 +88,37 @@ class RepoWrapperUnitTest(unittest.TestCase):
80 self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/'), None) 88 self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/'), None)
81 89
82 90
91class SetGitTrace2ParentSid(RepoWrapperTestCase):
92 """Check SetGitTrace2ParentSid behavior."""
93
94 KEY = 'GIT_TRACE2_PARENT_SID'
95 VALID_FORMAT = re.compile(r'^repo-[0-9]{8}T[0-9]{6}Z-P[0-9a-f]{8}$')
96
97 def test_first_set(self):
98 """Test env var not yet set."""
99 env = {}
100 self.wrapper.SetGitTrace2ParentSid(env)
101 self.assertIn(self.KEY, env)
102 value = env[self.KEY]
103 self.assertRegex(value, self.VALID_FORMAT)
104
105 def test_append(self):
106 """Test env var is appended."""
107 env = {self.KEY: 'pfx'}
108 self.wrapper.SetGitTrace2ParentSid(env)
109 self.assertIn(self.KEY, env)
110 value = env[self.KEY]
111 self.assertTrue(value.startswith('pfx/'))
112 self.assertRegex(value[4:], self.VALID_FORMAT)
113
114 def test_global_context(self):
115 """Check os.environ gets updated by default."""
116 os.environ.pop(self.KEY, None)
117 self.wrapper.SetGitTrace2ParentSid()
118 self.assertIn(self.KEY, os.environ)
119 value = os.environ[self.KEY]
120 self.assertRegex(value, self.VALID_FORMAT)
121
122
83if __name__ == '__main__': 123if __name__ == '__main__':
84 unittest.main() 124 unittest.main()