mirror of https://github.com/google/oss-fuzz.git
Add coverage_test module and fmt/lnt
This commit is contained in:
parent
9935321c0d
commit
913962ba54
|
@ -482,32 +482,6 @@ class GetTargetCoverageReportTest(unittest.TestCase):
|
||||||
self.example_fuzzer))
|
self.example_fuzzer))
|
||||||
|
|
||||||
|
|
||||||
class GetLatestCoverageReportTest(unittest.TestCase):
|
|
||||||
"""Tests get_latest_cov_report_info."""
|
|
||||||
|
|
||||||
test_project = 'curl'
|
|
||||||
|
|
||||||
def test_get_valid_project(self):
|
|
||||||
"""Tests that a project's coverage report can be downloaded and parsed.
|
|
||||||
|
|
||||||
NOTE: This test relies on the test_project repo's coverage report.
|
|
||||||
The "example" project was not used because it has no coverage reports.
|
|
||||||
"""
|
|
||||||
with mock.patch.object(cifuzz, 'get_json_from_url',
|
|
||||||
return_value='{}') as mock_fun:
|
|
||||||
|
|
||||||
cifuzz.get_latest_cov_report_info(self.test_project)
|
|
||||||
(url,), _ = mock_fun.call_args
|
|
||||||
self.assertEqual(
|
|
||||||
'https://storage.googleapis.com/oss-fuzz-coverage/'
|
|
||||||
'latest_report_info/curl.json', url)
|
|
||||||
|
|
||||||
def test_get_invalid_project(self):
|
|
||||||
"""Tests that passing a bad project returns None."""
|
|
||||||
self.assertIsNone(cifuzz.get_latest_cov_report_info('not-a-proj'))
|
|
||||||
self.assertIsNone(cifuzz.get_latest_cov_report_info(''))
|
|
||||||
|
|
||||||
|
|
||||||
EXAMPLE_FILE_CHANGED = 'test.txt'
|
EXAMPLE_FILE_CHANGED = 'test.txt'
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ def _get_fuzzer_stats_dir_url(project_name):
|
||||||
Returns:
|
Returns:
|
||||||
The projects coverage report info in json dict or None on failure.
|
The projects coverage report info in json dict or None on failure.
|
||||||
"""
|
"""
|
||||||
latest_report_info_url = utils.url_join(utils.GCS_DOMAIN_NAME,
|
latest_report_info_url = utils.url_join(utils.GCS_BASE_URL,
|
||||||
LATEST_REPORT_INFO_PATH,
|
LATEST_REPORT_INFO_PATH,
|
||||||
project_name + '.json')
|
project_name + '.json')
|
||||||
latest_cov_info = get_json_from_url(latest_report_info_url)
|
latest_cov_info = get_json_from_url(latest_report_info_url)
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
# Copyright 2021 Google LLC
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
"""Tests for coverage.py"""
|
||||||
|
import unittest
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
import coverage
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class GetFuzzerStatsDirUrlTest(unittest.TestCase):
|
||||||
|
"""Tests _get_fuzzer_stats_dir_url."""
|
||||||
|
|
||||||
|
TEST_PROJECT = 'curl'
|
||||||
|
|
||||||
|
@mock.patch('coverage.get_json_from_url', return_value={})
|
||||||
|
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 TEST_PROJECT repo's coverage report.
|
||||||
|
The "example" project was not used because it has no coverage reports.
|
||||||
|
"""
|
||||||
|
coverage._get_fuzzer_stats_dir_url(self.TEST_PROJECT)
|
||||||
|
(url,), _ = mocked_get_json_from_url.call_args
|
||||||
|
self.assertEqual(
|
||||||
|
'https://storage.googleapis.com/oss-fuzz-coverage/'
|
||||||
|
'latest_report_info/curl.json', url)
|
||||||
|
|
||||||
|
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'))
|
||||||
|
self.assertIsNone(coverage._get_fuzzer_stats_dir_url(''))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue