summaryrefslogtreecommitdiffstats
path: root/tests/test_git_trace2_event_log.py
diff options
context:
space:
mode:
authorIan Kasprzak <iankaz@google.com>2021-01-06 16:26:31 -0800
committerIan Kasprzak <iankaz@google.com>2021-01-07 14:31:51 +0000
commit343d585ff99c5748d33823e92507fa06a037c608 (patch)
tree8f655c130e017872fc73530e9e63d92677c88b08 /tests/test_git_trace2_event_log.py
parentacf63b28928b33d1335dfed1af7e2d8fc6bb5fc4 (diff)
downloadgit-repo-343d585ff99c5748d33823e92507fa06a037c608.tar.gz
Fix bug in git trace2 event Write() function when no config present.
See https://bugs.chromium.org/p/gerrit/issues/detail?id=13706#c9 Added additional unit tests for Write() for additional test coverage. Testing: - Unit tests - Verified repo works with: - Valid trace2.eventtarget - Invalid trace2.eventtarget Bug: https://crbug.com/gerrit/13706 Tested-by: Ian Kasprzak <iankaz@google.com> Change-Id: I6b027cb2399bd03e453a132ad82e022a1f48476e Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/292762 Reviewed-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'tests/test_git_trace2_event_log.py')
-rw-r--r--tests/test_git_trace2_event_log.py29
1 files changed, 23 insertions, 6 deletions
diff --git a/tests/test_git_trace2_event_log.py b/tests/test_git_trace2_event_log.py
index 3905630f..686802ea 100644
--- a/tests/test_git_trace2_event_log.py
+++ b/tests/test_git_trace2_event_log.py
@@ -15,8 +15,10 @@
15"""Unittests for the git_trace2_event_log.py module.""" 15"""Unittests for the git_trace2_event_log.py module."""
16 16
17import json 17import json
18import os
18import tempfile 19import tempfile
19import unittest 20import unittest
21from unittest import mock
20 22
21import git_trace2_event_log 23import git_trace2_event_log
22 24
@@ -157,12 +159,27 @@ class EventLogTestCase(unittest.TestCase):
157 self.assertIn('code', exit_event) 159 self.assertIn('code', exit_event)
158 self.assertEqual(exit_event['code'], 2) 160 self.assertEqual(exit_event['code'], 2)
159 161
160 # TODO(https://crbug.com/gerrit/13706): Add additional test coverage for 162 def test_write_with_filename(self):
161 # Write() where: 163 """Test Write() with a path to a file exits with None."""
162 # - path=None (using git config call) 164 self.assertIsNone(self._event_log_module.Write(path='path/to/file'))
163 # - path=<Non-String type> (raises TypeError) 165
164 # - path=<Non-Directory> (should return None) 166 def test_write_with_git_config(self):
165 # - tempfile.NamedTemporaryFile errors with FileExistsError (should return None) 167 """Test Write() uses the git config path when 'git config' call succeeds."""
168 with tempfile.TemporaryDirectory(prefix='event_log_tests') as tempdir:
169 with mock.patch.object(self._event_log_module,
170 '_GetEventTargetPath', return_value=tempdir):
171 self.assertEqual(os.path.dirname(self._event_log_module.Write()), tempdir)
172
173 def test_write_no_git_config(self):
174 """Test Write() with no git config variable present exits with None."""
175 with mock.patch.object(self._event_log_module,
176 '_GetEventTargetPath', return_value=None):
177 self.assertIsNone(self._event_log_module.Write())
178
179 def test_write_non_string(self):
180 """Test Write() with non-string type for |path| throws TypeError."""
181 with self.assertRaises(TypeError):
182 self._event_log_module.Write(path=1234)
166 183
167 184
168if __name__ == '__main__': 185if __name__ == '__main__':