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:
@@ -28,7 +28,7 @@ t.create('jquery/jquery hits/month')
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.create('jquery/jquery hits/year')
|
t.create('jquery/jquery hits/year')
|
||||||
.timeout(10000)
|
.timeout(25000)
|
||||||
.get('/hy/jquery/jquery.json')
|
.get('/hy/jquery/jquery.json')
|
||||||
.expectBadge({
|
.expectBadge({
|
||||||
label: 'jsdelivr',
|
label: 'jsdelivr',
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ t.create('jquery hits/month')
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.create('jquery hits/year')
|
t.create('jquery hits/year')
|
||||||
.timeout(10000)
|
.timeout(25000)
|
||||||
.get('/hy/ky.json')
|
.get('/hy/ky.json')
|
||||||
.expectBadge({
|
.expectBadge({
|
||||||
label: 'jsdelivr',
|
label: 'jsdelivr',
|
||||||
|
|||||||
@@ -1,24 +1,22 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const Joi = require('@hapi/joi')
|
const { nonNegativeInteger } = require('../validators')
|
||||||
const t = (module.exports = require('../tester').createServiceTester())
|
const t = (module.exports = require('../tester').createServiceTester())
|
||||||
|
|
||||||
t.create('layers without a specified tag')
|
t.create('layers without a specified tag')
|
||||||
.get('/_/alpine.json')
|
.get('/_/alpine.json')
|
||||||
|
.timeout(150000)
|
||||||
.expectBadge({
|
.expectBadge({
|
||||||
label: 'layers',
|
label: 'layers',
|
||||||
message: Joi.number()
|
message: nonNegativeInteger,
|
||||||
.integer()
|
|
||||||
.positive(),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.create('layers with a specified tag')
|
t.create('layers with a specified tag')
|
||||||
.get('/_/alpine/2.7.json')
|
.get('/_/alpine/2.7.json')
|
||||||
|
.timeout(150000)
|
||||||
.expectBadge({
|
.expectBadge({
|
||||||
label: 'layers',
|
label: 'layers',
|
||||||
message: Joi.number()
|
message: nonNegativeInteger,
|
||||||
.integer()
|
|
||||||
.positive(),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.create('specified tag when repository has only one')
|
t.create('specified tag when repository has only one')
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const t = (module.exports = require('../tester').createServiceTester())
|
|||||||
|
|
||||||
t.create('image size without a specified tag')
|
t.create('image size without a specified tag')
|
||||||
.get('/fedora/apache.json')
|
.get('/fedora/apache.json')
|
||||||
|
.timeout(150000)
|
||||||
.expectBadge({
|
.expectBadge({
|
||||||
label: 'image size',
|
label: 'image size',
|
||||||
message: isFileSize,
|
message: isFileSize,
|
||||||
@@ -12,6 +13,7 @@ t.create('image size without a specified tag')
|
|||||||
|
|
||||||
t.create('image size with a specified tag')
|
t.create('image size with a specified tag')
|
||||||
.get('/fedora/apache/latest.json')
|
.get('/fedora/apache/latest.json')
|
||||||
|
.timeout(150000)
|
||||||
.expectBadge({
|
.expectBadge({
|
||||||
label: 'image size',
|
label: 'image size',
|
||||||
message: isFileSize,
|
message: isFileSize,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const { BaseJsonService, NotFound } = require('..')
|
const { BaseJsonService, NotFound, InvalidResponse } = require('..')
|
||||||
|
|
||||||
module.exports = class ScrutinizerBase extends BaseJsonService {
|
module.exports = class ScrutinizerBase extends BaseJsonService {
|
||||||
// https://scrutinizer-ci.com/docs/api/#repository-details
|
// https://scrutinizer-ci.com/docs/api/#repository-details
|
||||||
@@ -30,13 +30,17 @@ module.exports = class ScrutinizerBase extends BaseJsonService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
transformBranchInfoMetricValue({ json, branch, metric }) {
|
transformBranchInfoMetricValue({ json, branch, metric }) {
|
||||||
|
const branchInfo = this.transformBranchInfo({ json, wantedBranch: branch })
|
||||||
|
if (!branchInfo.index) {
|
||||||
|
throw new InvalidResponse({ prettyMessage: 'metrics missing for branch' })
|
||||||
|
}
|
||||||
const {
|
const {
|
||||||
index: {
|
index: {
|
||||||
_embedded: {
|
_embedded: {
|
||||||
project: { metric_values: metricValues },
|
project: { metric_values: metricValues },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} = this.transformBranchInfo({ json, wantedBranch: branch })
|
} = branchInfo
|
||||||
|
|
||||||
return { value: metricValues[metric] }
|
return { value: metricValues[metric] }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const schema = Joi.object({
|
|||||||
}).required(),
|
}).required(),
|
||||||
}).required(),
|
}).required(),
|
||||||
}).required(),
|
}).required(),
|
||||||
}).required(),
|
}),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.required(),
|
.required(),
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
const { expect } = require('chai')
|
const { expect } = require('chai')
|
||||||
const { test, given } = require('sazerac')
|
const { test, given } = require('sazerac')
|
||||||
const [ScrutinizerCoverage] = require('./scrutinizer-coverage.service')
|
const [ScrutinizerCoverage] = require('./scrutinizer-coverage.service')
|
||||||
const { NotFound } = require('..')
|
const { InvalidResponse, NotFound } = require('..')
|
||||||
|
|
||||||
describe('ScrutinizerCoverage', function() {
|
describe('ScrutinizerCoverage', function() {
|
||||||
test(ScrutinizerCoverage.render, () => {
|
test(ScrutinizerCoverage.render, () => {
|
||||||
@@ -50,5 +50,24 @@ describe('ScrutinizerCoverage', function() {
|
|||||||
expect(e.prettyMessage).to.equal('coverage not found')
|
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')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const schema = Joi.object({
|
|||||||
}).required(),
|
}).required(),
|
||||||
}).required(),
|
}).required(),
|
||||||
}).required(),
|
}).required(),
|
||||||
}).required(),
|
}),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.required(),
|
.required(),
|
||||||
|
|||||||
Reference in New Issue
Block a user