Skip to content

Commit

Permalink
Fix Jenkins Cobertura badge and tests (#2468)
Browse files Browse the repository at this point in the history
  • Loading branch information
calebcartwright authored and PyvesB committed Dec 6, 2018
1 parent e9b1941 commit a5bbe9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions services/jenkins/jenkins-coverage.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ const coberturaCoverageSchema = Joi.object({
elements: Joi.array()
.items(
Joi.object({
name: 'Lines',
name: Joi.string().required(),
ratio: Joi.number()
.min(0)
.max(100)
.required(),
})
)
.has(Joi.object({ name: 'Lines' }))
.min(1)
.required(),
}).required(),
Expand Down Expand Up @@ -130,8 +131,11 @@ class CoberturaJenkinsCoverage extends BaseJenkinsCoverage {
options,
schema: coberturaCoverageSchema,
})
const lineCoverage = json.results.elements.filter(
element => element.name === 'Lines'
)[0]
return this.constructor.render({
coverage: json.results.elements[0].ratio,
coverage: lineCoverage.ratio,
})
}

Expand Down
8 changes: 8 additions & 0 deletions services/jenkins/jenkins-coverage.tester.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const Joi = require('joi')
const { isIntegerPercentage } = require('../test-validators')
const ServiceTester = require('../service-tester')

const t = new ServiceTester({
Expand Down Expand Up @@ -168,3 +170,9 @@ t.create('cobertura: invalid data response (missing line coverage)')
t.create('cobertura: job not found')
.get('/c/https/updates.jenkins-ci.org/job/does-not-exist.json')
.expectJSON({ name: 'coverage', value: 'job or coverage not found' })

t.create('cobertura: job found')
.get('/c/https/builds.apache.org/job/olingo-odata4-cobertura.json')
.expectJSONTypes(
Joi.object().keys({ name: 'coverage', value: isIntegerPercentage })
)

0 comments on commit a5bbe9a

Please sign in to comment.