Mobrovac has submitted this change and it was merged. Change subject: Add the /_info routes and tests for it ......................................................................
Add the /_info routes and tests for it Services based on the service template should preserve the /_info end points since the health monitoring utility in production is using that as the default end point which should respond with a 200 OK. Change-Id: I0daa15be21e86219289fd0dac3aba7ed7ec80b57 --- A routes/info.js A test/features/info/info.js 2 files changed, 164 insertions(+), 0 deletions(-) Approvals: Mobrovac: Verified; Looks good to me, approved diff --git a/routes/info.js b/routes/info.js new file mode 100644 index 0000000..5dd2590 --- /dev/null +++ b/routes/info.js @@ -0,0 +1,90 @@ +'use strict'; + + +var sUtil = require('../lib/util'); + + +/** + * The main router object + */ +var router = sUtil.router(); + +/** + * The main application object reported when this module is require()d + */ +var app; + + +/** + * GET / + * Gets some basic info about this service + */ +router.get('/', function(req, res) { + + // simple sync return + res.json({ + name: app.info.name, + version: app.info.version, + description: app.info.description, + home: app.info.homepage + }); + +}); + + +/** + * GET /name + * Gets the service's name as defined in package.json + */ +router.get('/name', function(req, res) { + + // simple return + res.json({ name: app.info.name }); + +}); + + +/** + * GET /version + * Gets the service's version as defined in package.json + */ +router.get('/version', function(req, res) { + + // simple return + res.json({ version: app.info.version }); + +}); + + +/** + * ALL /home + * Redirects to the service's home page if one is given, + * returns a 404 otherwise + */ +router.all('/home', function(req, res) { + + var home = app.info.homepage; + if(home && /^http/.test(home)) { + // we have a home page URI defined, so send it + res.redirect(301, home); + return; + } else { + // no URI defined for the home page, error out + res.status(404).end('No home page URL defined for ' + app.info.name); + } + +}); + + +module.exports = function(appObj) { + + app = appObj; + + return { + path: '/_info', + skip_domain: true, + router: router + }; + +}; + diff --git a/test/features/info/info.js b/test/features/info/info.js new file mode 100644 index 0000000..3450aff --- /dev/null +++ b/test/features/info/info.js @@ -0,0 +1,74 @@ +'use strict'; + + +// mocha defines to avoid JSHint breakage +/* global describe, it, before, beforeEach, after, afterEach */ + + +var preq = require('preq'); +var assert = require('../../utils/assert.js'); +var server = require('../../utils/server.js'); + + +describe('service information', function() { + + this.timeout(20000); + + before(function () { return server.start(); }); + + // common URI prefix for info tests + var infoUri = server.config.uri + '_info/'; + + // common function used for generating requests + // and checking their return values + function checkRet(fieldName) { + return preq.get({ + uri: infoUri + fieldName + }).then(function(res) { + // check the returned Content-Type header + assert.contentType(res, 'application/json'); + // the status as well + assert.status(res, 200); + // finally, check the body has the specified field + assert.notDeepEqual(res.body, undefined, 'No body returned!'); + assert.notDeepEqual(res.body[fieldName], undefined, 'No ' + fieldName + ' field returned!'); + }); + } + + it('should get the service name', function() { + return checkRet('name'); + }); + + it('should get the service version', function() { + return checkRet('version'); + }); + + it('should redirect to the service home page', function() { + return preq.get({ + uri: infoUri + 'home', + followRedirect: false + }).then(function(res) { + // check the status + assert.status(res, 301); + }); + }); + + it('should get the service info', function() { + return preq.get({ + uri: infoUri + }).then(function(res) { + // check the status + assert.status(res, 200); + // check the returned Content-Type header + assert.contentType(res, 'application/json'); + // inspect the body + assert.notDeepEqual(res.body, undefined, 'No body returned!'); + assert.notDeepEqual(res.body.name, undefined, 'No name field returned!'); + assert.notDeepEqual(res.body.version, undefined, 'No version field returned!'); + assert.notDeepEqual(res.body.description, undefined, 'No description field returned!'); + assert.notDeepEqual(res.body.home, undefined, 'No home field returned!'); + }); + }); + +}); + -- To view, visit https://gerrit.wikimedia.org/r/207108 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I0daa15be21e86219289fd0dac3aba7ed7ec80b57 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/mobileapps Gerrit-Branch: master Gerrit-Owner: Mobrovac <mobro...@wikimedia.org> Gerrit-Reviewer: BearND <bsitzm...@wikimedia.org> Gerrit-Reviewer: Mobrovac <mobro...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits