Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests and dependencies #1

Merged
merged 3 commits into from Jul 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions .travis.yml
@@ -1,7 +1,8 @@
language: node_js
node_js:
- "0.11"
- "0.10"
- '4.8.3'
- '4.3.0'
- '6.11.0'
script:
- npm run coverage
after_script:
Expand Down
62 changes: 33 additions & 29 deletions lib/server.js
@@ -1,26 +1,28 @@
var package = require('../package');
var util = require('util');
var restify = require('restify');
var through2 = require('through2');
'use strict';

const pack = require('../package');
const util = require('util');
const restify = require('restify');
const through2 = require('through2');

module.exports = function(proboscis, config, done) {

/* istanbul ignore next */
var log = config.log || console.log;
let log = config.log || console.log;

var server = restify.createServer({
name: package.name,
version: package.version
let server = restify.createServer({
name: pack.name,
version: pack.version
});
server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.use(restify.bodyParser());
server.use(restify.plugins.acceptParser(server.acceptable));
server.use(restify.plugins.queryParser());
server.use(restify.plugins.bodyParser());
server.killProcessTimeout = 3000;

server.get('/', function(req, res, next) {
res.send({
name: package.name,
version: package.version
name: pack.name,
version: pack.version
});
return next();
});
Expand All @@ -36,9 +38,9 @@ module.exports = function(proboscis, config, done) {
});

server.get('/running-processes', function(req, res, next) {
var output = {};
var configs = proboscis.getConfig();
var name = null;
let output = {};
let configs = proboscis.getConfig();
let name = null;
for (name in proboscis.getChildren()) {
output[name] = configs[name];
}
Expand All @@ -47,14 +49,14 @@ module.exports = function(proboscis, config, done) {
});

server.del('/running-processes/:name', function(req, res, next) {
var children = proboscis.getChildren();
var name = req.params.name;
let children = proboscis.getChildren();
let name = req.params.name;
if (!children[name]) {
res.writeHead(404);
return res.end();
}
var timeout = null;
var closeListener = function() {
let timeout = null;
let closeListener = function() {
res.send({message: util.format('Process `%s` stopped', name)});
clearTimeout(timeout);
}
Expand All @@ -68,18 +70,20 @@ module.exports = function(proboscis, config, done) {
});

server.post('/running-processes/:name', function(req, res, next) {
if (!req.params.command) {
if (!req.body || !req.body.command) {
res.writeHead(400);
res.end();
next();
return;
}
var args = req.params.args || [];
proboscis.runCommand(req.params.name, req.params.command, args);
let args = req.body.args || [];
proboscis.runCommand(req.params.name, req.body.command, args);
res.send({message: util.format('Process `%s` started', req.params.name)});
});

server.put('/processes/:name', function(req, res, next) {
var name = req.params.name;
var config = null;
let name = req.params.name;
let config = null;
if (config = proboscis.getConfig(name)) {
proboscis.runCommand(config.name, config.command, config.args);
res.writeHead(201);
Expand All @@ -91,7 +95,7 @@ module.exports = function(proboscis, config, done) {
});

server.listen(config.port, function() {
var message = {
let message = {
message: util.format('%s listening at %s', server.name, server.url)
};
log(JSON.stringify(message));
Expand All @@ -101,16 +105,16 @@ module.exports = function(proboscis, config, done) {
});

server.on('close', function() {
var message = {message: 'Server successfully shutdown'};
let message = {message: 'Server successfully shutdown'};
log(JSON.stringify(message));
});

if (!config.keepAlive) {
proboscis.on('allProcessesClosed', function() {
var message = {message: 'All processes closed, server stopping'};
let message = {message: 'All processes closed, server stopping'};
log(JSON.stringify(message));
server.close(function() {
var message = {message: 'Server exiting gracefully.'};
let message = {message: 'Server exiting gracefully.'};
log(JSON.stringify(message));
});
});
Expand Down
43 changes: 21 additions & 22 deletions package.json
Expand Up @@ -23,30 +23,29 @@
"url": "https://github.com/ProboCI/proboscis/issues"
},
"dependencies": {
"async": "~0.8.0",
"json-stream-formatter": "0.0.7",
"prettyjson": "^1.0.0",
"request": "^2.47.0",
"restify": "^2.8.2",
"shell-quote": "~1.4.1",
"split2": "^0.2.1",
"through2": "^0.6.5",
"yaml-config-loader": "0.0.11",
"yargs": "~1.2.1"
"async": "^2.5.0",
"event-stream": "^3.3.4",
"json-stream-formatter": "0.0.9",
"prettyjson": "^1.2.1",
"request": "^2.81.0",
"restify": "^5.0.0",
"shell-quote": "^1.6.1",
"split2": "^2.1.1",
"through2": "^2.0.3",
"yaml-config-loader": "^2.0.1",
"yargs": "^8.0.2"
},
"devDependencies": {
"comandante": "0.0.1",
"coveralls": "~2.10.0",
"event-stream": "^3.1.7",
"gulp": "~3.6.2",
"gulp-jshint": "~1.5.5",
"gulp-mocha": "^1.1.1",
"istanbul": "^0.3.2",
"jscs": "^1.6.2",
"jshint": "^2.5.6",
"mocha": "~2.2.4",
"portfinder": "^0.2.1",
"request": "^2.45.0",
"should": "~3.3.1"
"coveralls": "^2.13.1",
"gulp": "^3.9.1",
"gulp-jshint": "^2.0.4",
"gulp-mocha": "^4.3.1",
"istanbul": "^0.4.5",
"jscs": "^3.0.7",
"jshint": "^2.9.5",
"mocha": "^3.4.2",
"portfinder": "^1.0.13",
"should": "^11.2.1"
}
}
3 changes: 2 additions & 1 deletion test/fixtures/beeper.js
Expand Up @@ -22,7 +22,8 @@ var argv = yargs
.describe('E', 'The message to print on stderr')
.default('E', 'boop')
.alias('E', 'stderr-message')
.alias('X', 'exit', 'Exit code')
.alias('X', 'exit')
.describe('X', 'Exit code')
.default('X', 0)
.default('i', 2)
.alias('i', 'interval')
Expand Down
29 changes: 16 additions & 13 deletions test/testCommandLine.js
@@ -1,19 +1,22 @@
var path = require('path'),
'use strict';

const path = require('path'),
should = require('should'),
http = require('http'),
run = require('comandante'),
es = require('event-stream'),
async = require('async');

var filter = require('./helpers/filter');
const filter = require('./helpers/filter');

var beeperPath = path.join(__dirname, 'fixtures', 'beeper.js');
var proboscisBinPath = path.join(__dirname, '..', 'bin', 'proboscis');
const beeperPath = path.join(__dirname, 'fixtures', 'beeper.js');
const proboscisBinPath = path.join(__dirname, '..', 'bin', 'proboscis');

describe('proboscis executable', function() {
this.timeout(5000);
it('should display helptext', function(done) {
var stream = run(proboscisBinPath, ['-h']);
var output = '';
let stream = run(proboscisBinPath, ['-h']);
let output = '';
stream.stderr.pipe(es.through(
function(data) {
output += data;
Expand All @@ -26,7 +29,7 @@ describe('proboscis executable', function() {
.pipe(process.stdout);
});
it ('should print its own version number', function(done) {
var stream = run(proboscisBinPath, ['-v']);
let stream = run(proboscisBinPath, ['-v']);
stream
.pipe(es.split())
.pipe(es.writeArray(function(error, array) {
Expand All @@ -36,10 +39,10 @@ describe('proboscis executable', function() {
}));
});
it('should run a single command', function(done) {
var args = [
let args = [
'-c', beeperPath
];
var stream = run(proboscisBinPath, args);
let stream = run(proboscisBinPath, args);
stream
.pipe(es.split())
.pipe(es.parse())
Expand All @@ -53,13 +56,13 @@ describe('proboscis executable', function() {
}));
});
it('should run a multiple commands', function(done) {
var args = [
let args = [
'-c', 'echo foo',
'-c', beeperPath + ' -S jimmy -E hendrix'
];
var stream = run(proboscisBinPath, args);
var eventStream = es.through();
let stream = run(proboscisBinPath, args);

let eventStream = es.through();

stream
.pipe(es.split())
Expand Down