Skip to content

Commit

Permalink
Auto-annotate live and mock tests (#3661)
Browse files Browse the repository at this point in the history
Close #2555
  • Loading branch information
paulmelnikow authored Jul 7, 2019
1 parent 3bf97a6 commit aa135d3
Show file tree
Hide file tree
Showing 26 changed files with 79 additions and 76 deletions.
3 changes: 3 additions & 0 deletions core/service-test-runner/service-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ class ServiceTester {
// eslint-disable-next-line mocha/prefer-arrow-callback
fn(this.title, function() {
specs.forEach(spec => {
spec._message = `[${spec.hasIntercept ? 'mocked' : 'live'}] ${
spec._message
}`
if (!skipIntercepted || !spec.intercepted) {
spec.baseUri(testerBaseUrl)
spec.toss()
Expand Down
4 changes: 2 additions & 2 deletions doc/service-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ static render({ status, result }) {
We can also use nock to intercept API calls to return a known response body.

```js
t.create('Build passed (mocked)')
t.create('Build passed')
.get('/build/wercker/go-wercker-api.json')
.intercept(nock =>
nock('https://app.wercker.com/api/v3/applications/')
Expand All @@ -234,7 +234,7 @@ t.create('Build passed (mocked)')
color: 'brightgreen',
})

t.create('Build failed (mocked)')
t.create('Build failed')
.get('/build/wercker/go-wercker-api.json')
.intercept(nock =>
nock('https://app.wercker.com/api/v3/applications/')
Expand Down
2 changes: 1 addition & 1 deletion services/archlinux/archlinux.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ t.create('Arch Linux package (valid)')
message: isVPlusDottedVersionNClausesWithOptionalSuffixAndEpoch,
})

t.create('Arch Linux package (valid, mocked response)')
t.create('Arch Linux package (valid)')
.get('/core/x86_64/pacman.json')
.intercept(nock =>
nock('https://www.archlinux.org')
Expand Down
8 changes: 4 additions & 4 deletions services/cii-best-practices/cii-best-practices.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
const { withRegex } = require('../test-validators')
const t = (module.exports = require('../tester').createServiceTester())

t.create('live: level known project')
t.create('level known project')
.get(`/level/1.json`)
.expectBadge({
label: 'cii',
message: withRegex(/in progress|passing|silver|gold/),
})

t.create('live: percentage known project')
t.create('percentage known project')
.get(`/percentage/29.json`)
.expectBadge({
label: 'cii',
message: withRegex(/([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-9][0-9]|300)%/),
})

t.create('live: summary known project')
t.create('summary known project')
.get(`/summary/33.json`)
.expectBadge({
label: 'cii',
message: withRegex(/(in progress [0-9]|[1-9][0-9]%)|passing|silver|gold/),
})

t.create('live: unknown project')
t.create('unknown project')
.get(`/level/abc.json`)
.expectBadge({ label: 'cii', message: 'project not found' })

Expand Down
2 changes: 1 addition & 1 deletion services/cookbook/cookbook.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ t.create('version')
message: isVPlusDottedVersionAtLeastOne,
})

t.create('version (mocked)')
t.create('version')
.get('/chef-sugar.json')
.intercept(nock =>
nock('https://supermarket.getchef.com')
Expand Down
4 changes: 2 additions & 2 deletions services/coverity/coverity-scan.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
const Joi = require('@hapi/joi')
const t = (module.exports = require('../tester').createServiceTester())

t.create('live: known project id')
t.create('known project id')
.get('/3997.json')
.expectBadge({
label: 'coverity',
message: Joi.string().regex(/passing|passed .* new defects|pending|failed/),
})

t.create('live: unknown project id')
t.create('unknown project id')
.get('/abc.json')
// Coverity actually returns an HTTP 200 status with an HTML page when the project is not found.
.expectBadge({ label: 'coverity', message: 'unparseable json response' })
Expand Down
2 changes: 1 addition & 1 deletion services/ctan/ctan.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ t.create('version')
message: isVPlusDottedVersionAtLeastOne,
})

t.create('version (mocked)')
t.create('version')
.get('/v/novel.json')
.intercept(nock =>
nock('http://www.ctan.org')
Expand Down
2 changes: 1 addition & 1 deletion services/debian/debian.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ t.create('Debian package (default distribution, valid, query unsafe chars)')
message: isVPlusDottedVersionNClausesWithOptionalSuffixAndEpoch,
})

t.create('Debian package (valid, mocked response)')
t.create('Debian package (valid)')
.get('/apt/unstable.json')
.intercept(nock =>
nock('https://api.ftp-master.debian.org')
Expand Down
10 changes: 5 additions & 5 deletions services/discourse/discourse.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,34 +93,34 @@ t.create('Invalid Host')
)
.expectBadge({ label: 'discourse', message: 'not found' })

t.create('Topics (live)')
t.create('Topics')
.get('/https/meta.discourse.org/topics.json')
.expectBadge({
label: 'discourse',
message: Joi.string().regex(/^[0-9]+[kMGTPEZY]? topics$/),
})

t.create('Posts (live)')
t.create('Posts')
.get('/https/meta.discourse.org/posts.json')
.expectBadge({
label: 'discourse',
message: Joi.string().regex(/^[0-9]+[kMGTPEZY]? posts$/),
})

t.create('Users (live)')
t.create('Users')
.get('/https/meta.discourse.org/users.json')
.expectBadge({
label: 'discourse',
message: Joi.string().regex(/^[0-9]+[kMGTPEZY]? users$/),
})

t.create('Likes (live)')
t.create('Likes')
.get('/https/meta.discourse.org/likes.json')
.expectBadge({
label: 'discourse',
message: Joi.string().regex(/^[0-9]+[kMGTPEZY]? likes$/),
})

t.create('Status (live)')
t.create('Status')
.get('/https/meta.discourse.org/status.json')
.expectBadge({ label: 'discourse', message: 'online' })
6 changes: 3 additions & 3 deletions services/endpoint/endpoint.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { expect } = require('chai')
const { getShieldsIcon } = require('../../lib/logos')
const t = (module.exports = require('../tester').createServiceTester())

t.create('Valid schema (mocked)')
t.create('Valid schema')
.get('.json?url=https://example.com/badge')
.intercept(nock =>
nock('https://example.com/')
Expand Down Expand Up @@ -133,7 +133,7 @@ t.create('logoWidth')
logoWidth: 30,
})

t.create('Invalid schema (mocked)')
t.create('Invalid schema)')
.get('.json?url=https://example.com/badge')
.intercept(nock =>
nock('https://example.com/')
Expand All @@ -147,7 +147,7 @@ t.create('Invalid schema (mocked)')
message: 'invalid properties: schemaVersion',
})

t.create('Invalid schema (mocked)')
t.create('Invalid schema)')
.get('.json?url=https://example.com/badge')
.intercept(nock =>
nock('https://example.com/')
Expand Down
2 changes: 1 addition & 1 deletion services/homebrew/homebrew.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ t.create('homebrew (valid)')
message: isVPlusTripleDottedVersion,
})

t.create('homebrew (valid, mocked response)')
t.create('homebrew (valid)')
.get('/cake.json')
.intercept(nock =>
nock('https://formulae.brew.sh')
Expand Down
4 changes: 2 additions & 2 deletions services/jetbrains/jetbrains.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ t.create('downloads (user friendly plugin id)')
.get('/plugin/d/1347-scala.json')
.expectBadge({ label: 'downloads', message: isMetric })

t.create('downloads (mocked)')
t.create('downloads')
.get('/plugin/d/9435.json')
.intercept(
nock =>
Expand Down Expand Up @@ -275,7 +275,7 @@ t.create('version (number as a plugin id)')
message: isVPlusDottedVersionNClauses,
})

t.create('version (mocked)')
t.create('version)')
.get('/plugin/v/9435.json')
.intercept(
nock =>
Expand Down
12 changes: 6 additions & 6 deletions services/myget/myget.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ t.create('total downloads (tenant)')
message: isVPlusDottedVersionNClausesWithOptionalSuffix,
})

t.create('version (mocked, yellow badge)')
t.create('version (yellow badge)')
.get('/myget/mongodb/v/MongoDB.Driver.Core.json')
.intercept(nock =>
nock('https://www.myget.org')
Expand All @@ -97,7 +97,7 @@ t.create('version (mocked, yellow badge)')
color: 'yellow',
})

t.create('version (mocked, orange badge)')
t.create('version (orange badge)')
.get('/myget/mongodb/v/MongoDB.Driver.Core.json')
.intercept(nock =>
nock('https://www.myget.org')
Expand All @@ -117,7 +117,7 @@ t.create('version (mocked, orange badge)')
color: 'orange',
})

t.create('version (mocked, blue badge)')
t.create('version (blue badge)')
.get('/myget/mongodb/v/MongoDB.Driver.Core.json')
.intercept(nock =>
nock('https://www.myget.org')
Expand Down Expand Up @@ -150,7 +150,7 @@ t.create('version (pre) (valid)')
message: isVPlusDottedVersionNClausesWithOptionalSuffix,
})

t.create('version (pre) (mocked, yellow badge)')
t.create('version (pre) (yellow badge)')
.get('/myget/mongodb/vpre/MongoDB.Driver.Core.json')
.intercept(nock =>
nock('https://www.myget.org')
Expand All @@ -170,7 +170,7 @@ t.create('version (pre) (mocked, yellow badge)')
color: 'yellow',
})

t.create('version (pre) (mocked, orange badge)')
t.create('version (pre) (orange badge)')
.get('/myget/mongodb/vpre/MongoDB.Driver.Core.json')
.intercept(nock =>
nock('https://www.myget.org')
Expand All @@ -190,7 +190,7 @@ t.create('version (pre) (mocked, orange badge)')
color: 'orange',
})

t.create('version (pre) (mocked, blue badge)')
t.create('version (pre) (blue badge)')
.get('/myget/mongodb/vpre/MongoDB.Driver.Core.json')
.intercept(nock =>
nock('https://www.myget.org')
Expand Down
6 changes: 3 additions & 3 deletions services/nodeping/nodeping-status.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
const Joi = require('@hapi/joi')
const t = (module.exports = require('../tester').createServiceTester())

t.create('NodePing status - live')
t.create('NodePing status')
.get('/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei.json')
.expectBadge({
label: 'Status',
message: Joi.equal('up', 'down').required(),
})

t.create('NodePing status - up (mock)')
t.create('NodePing status - up')
.get('/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei.json')
.intercept(nock =>
nock('https://nodeping.com')
Expand All @@ -24,7 +24,7 @@ t.create('NodePing status - up (mock)')
message: 'up',
})

t.create('NodePing status - down (mock)')
t.create('NodePing status - down')
.get('/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei.json')
.intercept(nock =>
nock('https://nodeping.com')
Expand Down
10 changes: 5 additions & 5 deletions services/nodeping/nodeping-uptime.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
const t = (module.exports = require('../tester').createServiceTester())
const { isPercentage } = require('../test-validators')

t.create('NodePing uptime - live')
t.create('NodePing uptime')
.get('/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei.json')
.expectBadge({
label: 'Uptime',
message: isPercentage,
})

t.create('NodePing uptime - 100% (mock)')
t.create('NodePing uptime - 100%')
.get('/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei.json')
.intercept(nock =>
nock('https://nodeping.com')
Expand All @@ -29,7 +29,7 @@ t.create('NodePing uptime - 100% (mock)')
color: 'brightgreen',
})

t.create('NodePing uptime - 99.999% (mock)')
t.create('NodePing uptime - 99.999%')
.get('/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei.json')
.intercept(nock =>
nock('https://nodeping.com')
Expand All @@ -48,7 +48,7 @@ t.create('NodePing uptime - 99.999% (mock)')
color: 'green',
})

t.create('NodePing uptime - 99.001% (mock)')
t.create('NodePing uptime - 99.001%')
.get('/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei.json')
.intercept(nock =>
nock('https://nodeping.com')
Expand All @@ -67,7 +67,7 @@ t.create('NodePing uptime - 99.001% (mock)')
color: 'yellow',
})

t.create('NodePing uptime - 90.001% (mock)')
t.create('NodePing uptime - 90.001%')
.get('/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei.json')
.intercept(nock =>
nock('https://nodeping.com')
Expand Down
12 changes: 6 additions & 6 deletions services/nuget/nuget.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ t.create('version (valid)')
message: isVPlusDottedVersionNClauses,
})

t.create('version (mocked, yellow badge)')
t.create('version (yellow badge)')
.get('/v/Microsoft.AspNetCore.Mvc.json')
.intercept(nock =>
nock('https://api.nuget.org')
Expand All @@ -74,7 +74,7 @@ t.create('version (mocked, yellow badge)')
color: 'yellow',
})

t.create('version (mocked, orange badge)')
t.create('version (orange badge)')
.get('/v/Microsoft.AspNetCore.Mvc.json')
.intercept(nock =>
nock('https://api.nuget.org')
Expand All @@ -94,7 +94,7 @@ t.create('version (mocked, orange badge)')
color: 'orange',
})

t.create('version (mocked, blue badge)')
t.create('version (blue badge)')
.get('/v/Microsoft.AspNetCore.Mvc.json')
.intercept(nock =>
nock('https://api.nuget.org')
Expand Down Expand Up @@ -143,7 +143,7 @@ t.create('version (pre) (valid)')
message: isVPlusDottedVersionNClausesWithOptionalSuffix,
})

t.create('version (pre) (mocked, yellow badge)')
t.create('version (pre) (yellow badge)')
.get('/vpre/Microsoft.AspNetCore.Mvc.json')
.intercept(nock =>
nock('https://api.nuget.org')
Expand All @@ -163,7 +163,7 @@ t.create('version (pre) (mocked, yellow badge)')
color: 'yellow',
})

t.create('version (pre) (mocked, orange badge)')
t.create('version (pre) (orange badge)')
.get('/vpre/Microsoft.AspNetCore.Mvc.json')
.intercept(nock =>
nock('https://api.nuget.org')
Expand All @@ -183,7 +183,7 @@ t.create('version (pre) (mocked, orange badge)')
color: 'orange',
})

t.create('version (pre) (mocked, blue badge)')
t.create('version (pre) (blue badge)')
.get('/vpre/Microsoft.AspNetCore.Mvc.json')
.intercept(nock =>
nock('https://api.nuget.org')
Expand Down
Loading

0 comments on commit aa135d3

Please sign in to comment.