From 0a6afb447877e9b9d973146be65cb1b23fe7e588 Mon Sep 17 00:00:00 2001 From: Pierre-Yves B Date: Sun, 2 Dec 2018 17:41:01 +0000 Subject: [PATCH] Added tests for Sourcegraph service (#2439) --- services/sourcegraph/sourcegraph.service.js | 2 +- services/sourcegraph/sourcegraph.tester.js | 28 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 services/sourcegraph/sourcegraph.tester.js diff --git a/services/sourcegraph/sourcegraph.service.js b/services/sourcegraph/sourcegraph.service.js index eb50753fd9..a901dd2e68 100644 --- a/services/sourcegraph/sourcegraph.service.js +++ b/services/sourcegraph/sourcegraph.service.js @@ -40,7 +40,7 @@ module.exports = class Sourcegraph extends LegacyService { try { badgeData.colorscheme = 'brightgreen' const data = JSON.parse(buffer) - badgeData.text[1] = data.value + badgeData.text[1] = data.value.trim() // The value generally comes with a leading space. sendBadge(format, badgeData) } catch (e) { badgeData.text[1] = 'invalid' diff --git a/services/sourcegraph/sourcegraph.tester.js b/services/sourcegraph/sourcegraph.tester.js new file mode 100644 index 0000000000..626124869f --- /dev/null +++ b/services/sourcegraph/sourcegraph.tester.js @@ -0,0 +1,28 @@ +'use strict' + +const Joi = require('joi') +const ServiceTester = require('../service-tester') +const { withRegex } = require('../test-validators') + +// Matches API responses such as "0 projects", "1 projects", "182 projects", "14.0k projects". +// There may be other cases not covered by this regex, but hopefully the tested projects won't vary much. +const projectsCount = withRegex(/^[0-9]*(\.[0-9]k)?\sprojects$/) + +const t = new ServiceTester({ id: 'sourcegraph', title: 'Sourcegraph' }) +module.exports = t + +t.create('project usage count') + .get('/rrc/github.com/theupdateframework/notary.json') + .expectJSONTypes( + Joi.object().keys({ + name: 'used by', + value: projectsCount, + }) + ) + +t.create('project without any available information') + .get('/rrc/github.com/PyvesB/EmptyRepo.json') + .expectJSON({ + name: 'used by', + value: 'invalid', + })