Skip to content

Commit 26bad52

Browse files
authored
test(vanir): capture expected error logs in test_process_batch_failure (#5849)
`test_process_batch_failure` tests GCS upload error handling by simulating an exception, however `vanir_signatures.process_batch` calls `logging.exception()` and an expected traceback was sent to `stderr` in CI and appearing as a test failure. - Wrap `process_batch()` in `self.assertLogs(level='ERROR')` to capture the log output. - Assert that `Failed upload for VULN-1` is recorded. - Suppress misleading error tracebacks.
1 parent 9be83fe commit 26bad52

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎gcp/workers/vanir_signatures/vanir_signatures_test.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,14 @@ def test_process_batch_failure(self, mock_gen_signatures, mock_upload,
216216
vuln_entity.put()
217217
initial_modified = vuln_entity.modified
218218

219-
result, failed_ids = vanir_signatures.process_batch([vuln_id],
220-
'fake_git_working_dir')
219+
with self.assertLogs(level='ERROR') as cm:
220+
result, failed_ids = vanir_signatures.process_batch(
221+
[vuln_id], 'fake_git_working_dir')
221222

222223
# Result should be 0 because upload failed
223224
self.assertEqual(result, 0)
224225
self.assertEqual(failed_ids, [vuln_id])
226+
self.assertTrue(any('Failed upload for VULN-1' in log for log in cm.output))
225227

226228
# Verify Datastore was NOT updated
227229
updated_vuln = osv.Vulnerability.get_by_id(vuln_id, use_cache=False)

0 commit comments

Comments
 (0)