Add url configs and util to get pages

This commit is contained in:
Jonathan Budzenski 2015-10-14 14:48:51 -05:00
parent c9cc607230
commit 7153162af4
5 changed files with 53 additions and 3 deletions

View file

@ -7,6 +7,7 @@ module.exports = {
},
all: {
src: [
'test/**/__tests__/**/*.js',
'src/**/__tests__/**/*.js',
'test/fixtures/__tests__/*.js',
'!src/**/public/**',

View file

@ -1,14 +1,14 @@
define(function (require) {
var registerSuite = require('intern!object');
var expect = require('intern/dojo/node!expect.js');
var config = require('intern').config;
var getPage = require('intern/dojo/node!../utils/getPage');
registerSuite(function () {
var url = 'http://localhost:5620/status';
return {
'status': function () {
return this.remote
.get(url)
.refresh()
.get(getPage(config.kibana, 'status'))
.setFindTimeout(60000)
.findByCssSelector('.plugin_status_breakdown')
.getVisibleText()

View file

@ -12,6 +12,16 @@ define({
host: 'localhost',
port: 4444
},
kibana: {
protocol: 'http',
hostname: 'localhost',
port: 5620
},
elasticsearch: {
protocol: 'http',
hostname: 'localhost',
port: 9220
},
functionalSuites: ['test/functional/status.js'],
excludeInstrumentation: /(fixtures|node_modules)\//
});

View file

@ -0,0 +1,18 @@
var expect = require('expect.js');
var getPage = require('../getPage');
describe('getPage', function () {
it('should be able to convert a config and a path to a url', function() {
expect(getPage({
protocol: 'http',
hostname: 'localhost',
port: 9220
}, 'foo')).to.be('http://localhost:9220/foo');
expect(getPage({
protocol: 'https',
hostname: 'localhost',
}, 'foo')).to.be('https://localhost/foo');
});
});

21
test/utils/getPage.js Normal file
View file

@ -0,0 +1,21 @@
var _ = require('lodash');
var url = require('url');
/**
* Converts a config and a pathname to a url
* @param {object} config A url config
* example:
* {
* protocol: 'http',
* hostname: 'localhost',
* port: 9220
* }
* @param {string} pathname The requested path
* @return {string}
*/
module.exports = function getPage(config, pathname) {
return url.format(_.assign(config, {
pathname: pathname
}));
};