Update service tests for [Scrutinizer Microbadger jsDelivr] (#4145)

* fix: support scrutinizer branches with only failed builds

* tests: increase timeout for microbadger tests

* tests: increase timeouts for jsdelivr and microbadger tests
This commit is contained in:
Caleb Cartwright
2019-10-07 07:19:07 -05:00
committed by GitHub
parent dde66ca383
commit b05f0e8d0b
8 changed files with 37 additions and 14 deletions

View File

@@ -28,7 +28,7 @@ t.create('jquery/jquery hits/month')
})
t.create('jquery/jquery hits/year')
.timeout(10000)
.timeout(25000)
.get('/hy/jquery/jquery.json')
.expectBadge({
label: 'jsdelivr',

View File

@@ -28,7 +28,7 @@ t.create('jquery hits/month')
})
t.create('jquery hits/year')
.timeout(10000)
.timeout(25000)
.get('/hy/ky.json')
.expectBadge({
label: 'jsdelivr',

View File

@@ -1,24 +1,22 @@
'use strict'
const Joi = require('@hapi/joi')
const { nonNegativeInteger } = require('../validators')
const t = (module.exports = require('../tester').createServiceTester())
t.create('layers without a specified tag')
.get('/_/alpine.json')
.timeout(150000)
.expectBadge({
label: 'layers',
message: Joi.number()
.integer()
.positive(),
message: nonNegativeInteger,
})
t.create('layers with a specified tag')
.get('/_/alpine/2.7.json')
.timeout(150000)
.expectBadge({
label: 'layers',
message: Joi.number()
.integer()
.positive(),
message: nonNegativeInteger,
})
t.create('specified tag when repository has only one')

View File

@@ -5,6 +5,7 @@ const t = (module.exports = require('../tester').createServiceTester())
t.create('image size without a specified tag')
.get('/fedora/apache.json')
.timeout(150000)
.expectBadge({
label: 'image size',
message: isFileSize,
@@ -12,6 +13,7 @@ t.create('image size without a specified tag')
t.create('image size with a specified tag')
.get('/fedora/apache/latest.json')
.timeout(150000)
.expectBadge({
label: 'image size',
message: isFileSize,

View File

@@ -1,6 +1,6 @@
'use strict'
const { BaseJsonService, NotFound } = require('..')
const { BaseJsonService, NotFound, InvalidResponse } = require('..')
module.exports = class ScrutinizerBase extends BaseJsonService {
// https://scrutinizer-ci.com/docs/api/#repository-details
@@ -30,13 +30,17 @@ module.exports = class ScrutinizerBase extends BaseJsonService {
}
transformBranchInfoMetricValue({ json, branch, metric }) {
const branchInfo = this.transformBranchInfo({ json, wantedBranch: branch })
if (!branchInfo.index) {
throw new InvalidResponse({ prettyMessage: 'metrics missing for branch' })
}
const {
index: {
_embedded: {
project: { metric_values: metricValues },
},
},
} = this.transformBranchInfo({ json, wantedBranch: branch })
} = branchInfo
return { value: metricValues[metric] }
}

View File

@@ -19,7 +19,7 @@ const schema = Joi.object({
}).required(),
}).required(),
}).required(),
}).required(),
}),
})
)
.required(),

View File

@@ -3,7 +3,7 @@
const { expect } = require('chai')
const { test, given } = require('sazerac')
const [ScrutinizerCoverage] = require('./scrutinizer-coverage.service')
const { NotFound } = require('..')
const { InvalidResponse, NotFound } = require('..')
describe('ScrutinizerCoverage', function() {
test(ScrutinizerCoverage.render, () => {
@@ -50,5 +50,24 @@ describe('ScrutinizerCoverage', function() {
expect(e.prettyMessage).to.equal('coverage not found')
}
})
it('throws InvalidResponse error when branch is missing statistics', function() {
expect(() =>
ScrutinizerCoverage.prototype.transform({
branch: 'gh-pages',
json: {
applications: {
master: { index: {} },
'gh-pages': {
build_status: {
status: 'unknown',
},
},
},
},
})
)
.to.throw(InvalidResponse)
.with.property('prettyMessage', 'metrics missing for branch')
})
})
})

View File

@@ -18,7 +18,7 @@ const schema = Joi.object({
}).required(),
}).required(),
}).required(),
}).required(),
}),
})
)
.required(),