-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Cobertura Jenkins plugin as possible source for the 'test line …
…coverage', 'test branch coverage', and 'source up-to-dateness' metrics. Closes #1520.
- Loading branch information
Showing
11 changed files
with
197 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
components/collector/src/source_collectors/api_source_collectors/cobertura_jenkins_plugin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Cobertura Jenkins plugin coverage report collector.""" | ||
|
||
from base_collectors import JenkinsPluginSourceUpToDatenessCollector, SourceCollector | ||
from collector_utilities.type import URL | ||
from source_model import SourceMeasurement, SourceResponses | ||
|
||
|
||
class CoberturaJenkinsPluginBaseClass(SourceCollector): | ||
"""Base class for Cobertura Jenkins plugin collectors.""" | ||
|
||
async def _landing_url(self, responses: SourceResponses) -> URL: | ||
return URL(f"{await super()._api_url()}/lastSuccessfulBuild/cobertura") | ||
|
||
|
||
class CoberturaJenkinsPluginCoverageBaseClass(CoberturaJenkinsPluginBaseClass): | ||
"""Base class for Cobertura Jenkins plugin coverage collectors.""" | ||
|
||
coverage_type = "subclass responsibility" | ||
|
||
async def _api_url(self) -> URL: | ||
return URL(f"{await super()._api_url()}/lastSuccessfulBuild/cobertura/api/json?depth=2") | ||
|
||
async def _parse_source_responses(self, responses: SourceResponses) -> SourceMeasurement: | ||
elements = (await responses[0].json())["results"]["elements"] | ||
coverage = [element for element in elements if element["name"].lower() == self.coverage_type][0] | ||
total = int(coverage["denominator"]) | ||
return SourceMeasurement(value=str(total - int(coverage["numerator"])), total=str(total)) | ||
|
||
|
||
class CoberturaJenkinsPluginUncoveredLines(CoberturaJenkinsPluginCoverageBaseClass): | ||
"""Collector for Cobertura Jenkins plugin uncovered lines.""" | ||
|
||
coverage_type = "lines" | ||
|
||
|
||
class CoberturaJenkinsPluginUncoveredBranches(CoberturaJenkinsPluginCoverageBaseClass): | ||
"""Collector for Cobertura Jenkins plugin uncovered branches.""" | ||
|
||
coverage_type = "conditionals" | ||
|
||
|
||
class CoberturaJenkinsPluginSourceUpToDateness( | ||
CoberturaJenkinsPluginBaseClass, JenkinsPluginSourceUpToDatenessCollector): | ||
"""Collector for the up to dateness of the Cobertura Jenkins plugin coverage report.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...nents/collector/tests/source_collectors/api_source_collectors/jenkins_plugin_test_case.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Generic unit tests for Jenkins plugin sources.""" | ||
|
||
from datetime import datetime | ||
|
||
from tests.source_collectors.source_collector_test_case import SourceCollectorTestCase | ||
|
||
from collector_utilities.functions import days_ago | ||
|
||
|
||
class JenkinsPluginTestCase(SourceCollectorTestCase): | ||
"""Test case for Jenkins plugin sources.""" | ||
|
||
source_type = "subclass responsbility" | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.sources = dict(source_id=dict(type=self.source_type, parameters=dict(url="https://jenkins/job"))) | ||
|
||
|
||
class JenkinsPluginTestsMixin: # pylint: disable=too-few-public-methods | ||
"""Generic unit tests for Jenkins plugin sources to be mixed in.""" | ||
|
||
async def test_source_up_to_dateness(self): | ||
"""Test that the source up to dateness is returned.""" | ||
metric = dict(type="source_up_to_dateness", addition="max", sources=self.sources) | ||
response = await self.collect(metric, get_request_json_return_value=dict(timestamp="1565284457173")) | ||
expected_age = days_ago(datetime.fromtimestamp(1565284457173 / 1000.)) | ||
self.assert_measurement(response, value=str(expected_age)) |
27 changes: 27 additions & 0 deletions
27
.../collector/tests/source_collectors/api_source_collectors/test_cobertura_jenkins_plugin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Unit tests for the Cobertura Jenkins plugin source.""" | ||
|
||
from .jenkins_plugin_test_case import JenkinsPluginTestCase, JenkinsPluginTestsMixin | ||
|
||
|
||
class CoberturaJenkinsPluginTest(JenkinsPluginTestCase, JenkinsPluginTestsMixin): | ||
"""Unit tests for the Cobertura Jenkins plugin metrics.""" | ||
|
||
source_type = "cobertura_jenkins_plugin" | ||
|
||
async def test_uncovered_lines(self): | ||
"""Test that the number of uncovered lines and the total number of lines are returned.""" | ||
metric = dict(type="uncovered_lines", sources=self.sources, addition="sum") | ||
response = await self.collect( | ||
metric, | ||
get_request_json_return_value=dict( | ||
results=dict(elements=[dict(denominator=15, numerator=13, name="Lines")]))) | ||
self.assert_measurement(response, value="2", total="15") | ||
|
||
async def test_uncovered_branches(self): | ||
"""Test that the number of uncovered branches and the total number of branches are returned.""" | ||
metric = dict(type="uncovered_branches", sources=self.sources, addition="sum") | ||
response = await self.collect( | ||
metric, | ||
get_request_json_return_value=dict( | ||
results=dict(elements=[dict(denominator=15, numerator=15, name="Conditionals")]))) | ||
self.assert_measurement(response, value="0", total="15") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file removed
BIN
-7.58 KB
components/frontend/src/logos/owasp_dependency_check_jenkins_plugin.png
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.