aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar jonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com>2021-03-03 14:46:51 -0800
committerGravatar GitHub <noreply@github.com>2021-03-03 14:46:51 -0800
commitc8ca07752f3bfe53343c0ac11494b4c8e199398b (patch)
tree60bafa3fa84e27928e2ce1716f99a9e499b200d7
parent08448d8866c2cdf1401625e19a941a9cfb707a0b (diff)
[CIFuzz][coverage] Fix bug in getting coverage reports (#5284)
Also add tests.
-rw-r--r--infra/cifuzz/coverage.py2
-rw-r--r--infra/cifuzz/coverage_test.py42
2 files changed, 41 insertions, 3 deletions
diff --git a/infra/cifuzz/coverage.py b/infra/cifuzz/coverage.py
index b5c6fbf1..9a179c59 100644
--- a/infra/cifuzz/coverage.py
+++ b/infra/cifuzz/coverage.py
@@ -115,7 +115,7 @@ def _get_latest_cov_report_info(project_name):
LATEST_REPORT_INFO_PATH,
project_name + '.json')
latest_cov_info = get_json_from_url(latest_report_info_url)
- if not latest_cov_info is None:
+ if latest_cov_info is None:
logging.error('Could not get the coverage report json from url: %s.',
latest_report_info_url)
return None
diff --git a/infra/cifuzz/coverage_test.py b/infra/cifuzz/coverage_test.py
index 57120f5f..56269d73 100644
--- a/infra/cifuzz/coverage_test.py
+++ b/infra/cifuzz/coverage_test.py
@@ -39,19 +39,28 @@ with open(os.path.join(TEST_FILES_PATH,
class GetFuzzerStatsDirUrlTest(unittest.TestCase):
"""Tests _get_fuzzer_stats_dir_url."""
- @mock.patch('coverage.get_json_from_url', return_value={})
+ @mock.patch('coverage.get_json_from_url',
+ return_value={
+ 'fuzzer_stats_dir':
+ 'gs://oss-fuzz-coverage/systemd/fuzzer_stats/20210303'
+ })
def test_get_valid_project(self, mocked_get_json_from_url):
"""Tests that a project's coverage report can be downloaded and parsed.
NOTE: This test relies on the PROJECT_NAME repo's coverage report.
The "example" project was not used because it has no coverage reports.
"""
- coverage._get_fuzzer_stats_dir_url(PROJECT_NAME)
+ result = coverage._get_fuzzer_stats_dir_url(PROJECT_NAME)
(url,), _ = mocked_get_json_from_url.call_args
self.assertEqual(
'https://storage.googleapis.com/oss-fuzz-coverage/'
'latest_report_info/curl.json', url)
+ expected_result = (
+ 'https://storage.googleapis.com/oss-fuzz-coverage/systemd/fuzzer_stats/'
+ '20210303')
+ self.assertEqual(result, expected_result)
+
def test_get_invalid_project(self):
"""Tests that passing a bad project returns None."""
self.assertIsNone(coverage._get_fuzzer_stats_dir_url('not-a-proj'))
@@ -152,5 +161,34 @@ class IsFileCoveredTest(unittest.TestCase):
self.assertFalse(coverage.is_file_covered(file_coverage))
+class GetLatestCovReportInfo(unittest.TestCase):
+ """Tests that _get_latest_cov_report_info works as intended."""
+
+ PROJECT = 'project'
+ LATEST_REPORT_INFO_URL = ('https://storage.googleapis.com/oss-fuzz-coverage/'
+ 'latest_report_info/project.json')
+
+ @mock.patch('logging.error')
+ @mock.patch('coverage.get_json_from_url', return_value={'coverage': 1})
+ def test_get_latest_cov_report_info(self, mocked_get_json_from_url,
+ mocked_error):
+ """Tests that _get_latest_cov_report_info works as intended."""
+ result = coverage._get_latest_cov_report_info(self.PROJECT)
+ self.assertEqual(result, {'coverage': 1})
+ mocked_error.assert_not_called()
+ mocked_get_json_from_url.assert_called_with(self.LATEST_REPORT_INFO_URL)
+
+ @mock.patch('logging.error')
+ @mock.patch('coverage.get_json_from_url', return_value=None)
+ def test_get_latest_cov_report_info_fail(self, _, mocked_error):
+ """Tests that _get_latest_cov_report_info works as intended when we can't
+ get latest report info."""
+ result = coverage._get_latest_cov_report_info('project')
+ self.assertIsNone(result)
+ mocked_error.assert_called_with(
+ 'Could not get the coverage report json from url: %s.',
+ self.LATEST_REPORT_INFO_URL)
+
+
if __name__ == '__main__':
unittest.main()