diff options
| -rw-r--r-- | git_trace2_event_log.py | 12 | ||||
| -rwxr-xr-x | main.py | 1 | ||||
| -rw-r--r-- | tests/test_git_trace2_event_log.py | 24 |
3 files changed, 37 insertions, 0 deletions
diff --git a/git_trace2_event_log.py b/git_trace2_event_log.py index 8c33d80b..8f12d1a9 100644 --- a/git_trace2_event_log.py +++ b/git_trace2_event_log.py | |||
| @@ -132,6 +132,18 @@ class EventLog(object): | |||
| 132 | exit_event['code'] = result | 132 | exit_event['code'] = result |
| 133 | self._log.append(exit_event) | 133 | self._log.append(exit_event) |
| 134 | 134 | ||
| 135 | def CommandEvent(self, name, subcommands): | ||
| 136 | """Append a 'command' event to the current log. | ||
| 137 | |||
| 138 | Args: | ||
| 139 | name: Name of the primary command (ex: repo, git) | ||
| 140 | subcommands: List of the sub-commands (ex: version, init, sync) | ||
| 141 | """ | ||
| 142 | command_event = self._CreateEventDict('command') | ||
| 143 | command_event['name'] = name | ||
| 144 | command_event['subcommands'] = subcommands | ||
| 145 | self._log.append(command_event) | ||
| 146 | |||
| 135 | def DefParamRepoEvents(self, config): | 147 | def DefParamRepoEvents(self, config): |
| 136 | """Append a 'def_param' event for each repo.* config key to the current log. | 148 | """Append a 'def_param' event for each repo.* config key to the current log. |
| 137 | 149 | ||
| @@ -254,6 +254,7 @@ class _Repo(object): | |||
| 254 | cmd_event = cmd.event_log.Add(name, event_log.TASK_COMMAND, start) | 254 | cmd_event = cmd.event_log.Add(name, event_log.TASK_COMMAND, start) |
| 255 | cmd.event_log.SetParent(cmd_event) | 255 | cmd.event_log.SetParent(cmd_event) |
| 256 | git_trace2_event_log.StartEvent() | 256 | git_trace2_event_log.StartEvent() |
| 257 | git_trace2_event_log.CommandEvent(name='repo', subcommands=[name]) | ||
| 257 | 258 | ||
| 258 | try: | 259 | try: |
| 259 | cmd.ValidateOptions(copts, cargs) | 260 | cmd.ValidateOptions(copts, cargs) |
diff --git a/tests/test_git_trace2_event_log.py b/tests/test_git_trace2_event_log.py index 3c5cb150..4a3a4c48 100644 --- a/tests/test_git_trace2_event_log.py +++ b/tests/test_git_trace2_event_log.py | |||
| @@ -161,6 +161,30 @@ class EventLogTestCase(unittest.TestCase): | |||
| 161 | self.assertIn('code', exit_event) | 161 | self.assertIn('code', exit_event) |
| 162 | self.assertEqual(exit_event['code'], 2) | 162 | self.assertEqual(exit_event['code'], 2) |
| 163 | 163 | ||
| 164 | def test_command_event(self): | ||
| 165 | """Test and validate 'command' event data is valid. | ||
| 166 | |||
| 167 | Expected event log: | ||
| 168 | <version event> | ||
| 169 | <command event> | ||
| 170 | """ | ||
| 171 | name = 'repo' | ||
| 172 | subcommands = ['init' 'this'] | ||
| 173 | self._event_log_module.CommandEvent(name='repo', subcommands=subcommands) | ||
| 174 | with tempfile.TemporaryDirectory(prefix='event_log_tests') as tempdir: | ||
| 175 | log_path = self._event_log_module.Write(path=tempdir) | ||
| 176 | self._log_data = self.readLog(log_path) | ||
| 177 | |||
| 178 | self.assertEqual(len(self._log_data), 2) | ||
| 179 | command_event = self._log_data[1] | ||
| 180 | self.verifyCommonKeys(self._log_data[0], expected_event_name='version') | ||
| 181 | self.verifyCommonKeys(command_event, expected_event_name='command') | ||
| 182 | # Check for 'command' event specific fields. | ||
| 183 | self.assertIn('name', command_event) | ||
| 184 | self.assertIn('subcommands', command_event) | ||
| 185 | self.assertEqual(command_event['name'], name) | ||
| 186 | self.assertEqual(command_event['subcommands'], subcommands) | ||
| 187 | |||
| 164 | def test_def_params_event_repo_config(self): | 188 | def test_def_params_event_repo_config(self): |
| 165 | """Test 'def_params' event data outputs only repo config keys. | 189 | """Test 'def_params' event data outputs only repo config keys. |
| 166 | 190 | ||
