Skip to content

Commit

Permalink
Merge 3f74b93 into eb15a11
Browse files Browse the repository at this point in the history
  • Loading branch information
rmg committed May 2, 2016
2 parents eb15a11 + 3f74b93 commit 5f6f708
Show file tree
Hide file tree
Showing 50 changed files with 750 additions and 295 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -7,3 +7,5 @@ checkstyle.xml
tests.tap
.travis.yml
appveyor.yml
.nyc_output
sandbox
2 changes: 2 additions & 0 deletions .jshintignore
@@ -1 +1,3 @@
node_modules
coverage
.nyc_output
13 changes: 8 additions & 5 deletions .travis.yml
@@ -1,7 +1,10 @@
language: node_js
node_js:
- "6"
- "5"
- "4"
- "0.12"
- "0.10"
- '6'
- '5'
- '4'
- '0.12'
- '0.10'
env:
global:
secure: rxAxzXc6ff4UQIMYD46SZQP37fIDdZ2IlMtPx34dp61sIQj9dKAYmjtwr4J7Ra+qiisdia+szvfNLaPa6ThCWj6OOhdwNMd/vRsoGQGHHYMf2qU+uMwA+8TP9WzjLlEVtu3TiU+gNb8YEfMW6TzTRKSHGwC1aNYOa14PhhAygYY=
4 changes: 3 additions & 1 deletion appveyor.yml
@@ -1,4 +1,6 @@
environment:
COVERALLS_REPO_TOKEN:
secure: sxoCWFzAUW5WrH5KKKY38kZo1oB3Bu+WWJDshymilkDq/rKR4j9qXmrf6Ae/ekt8
matrix:
- nodejs_version: '6'
- nodejs_version: '5'
Expand All @@ -18,4 +20,4 @@ version: '{build}'
shallow_clone: true
clone_depth: 1
test_script:
- npm test -- -Rclassic --no-coverage --timeout=3600
- npm test -- --reporter=tap --no-coverage
4 changes: 3 additions & 1 deletion forward.js
Expand Up @@ -52,7 +52,9 @@ function startForward(proxy_port, proxy_host) {
res.end();
});

httpServer.listen(proxy_port);
httpServer.listen(proxy_port, '127.0.0.1', function() {
process.send({http: this.address().port});
});
}

startForward(process.env.PROXY_PORT, process.env.PROXY_HOST);
17 changes: 16 additions & 1 deletion lib/forward.js
Expand Up @@ -15,9 +15,24 @@ function startForward(port, hostname, emitter) {
} else {
cons.Alert('Intercepting ALL requests through forward proxy');
}
proc.on('message', function(msg) {
if ('http' in msg) {
cons.Alert('Forward Proxy Listening On Port %d', msg.http);
emitter.emit('http', msg.http);
}
});
emitter.once('killall', function(signal) {
cons.Done('Killing Forward Proxy Server on Port %d',port);
proc.kill(signal);
try {
proc.disconnect();
proc.kill(signal);
} catch(_e) {
cons.Warn('Proxy server already dead');
}
});

proc.on('exit', function(code, signal) {
emitter.emit('killall', 'SIGINT');
});
}

Expand Down
6 changes: 5 additions & 1 deletion lib/proc.js
Expand Up @@ -46,7 +46,11 @@ function run(key, proc, emitter) {
});

emitter.on('killall', function(signal) {
child.kill(signal);
try {
child.kill(signal);
} catch(_e) {
cons.Warn('Proxy server already dead');
}
});

}
Expand Down
13 changes: 7 additions & 6 deletions lib/procfile.js
Expand Up @@ -7,20 +7,21 @@ function procs(procdata){

var processes = {};

procdata.toString().split(/\n/).forEach(function(line) {
procdata.toString().split(/\n/).forEach(function(line, lineNo) {
if(!line || line[0] === '#') { return; }
lineNo += 1;

var tuple = /^([A-Za-z0-9_-]+):\s*(.+)$/m.exec(line);
var tuple = /^([^:]*):(.*)$/m.exec(line);

var prockey = tuple[1].trim();
var command = tuple[2].trim();
var prockey = tuple && tuple[1].trim();
var command = tuple && tuple[2].trim();

if(!prockey) {
throw new Error('Syntax Error in Procfile, Line %d: No Prockey Found');
throw new Error('Syntax Error in Procfile, Line ' + lineNo + ': No Prockey Found');
}

if(!command) {
throw new Error('Syntax Error in Procfile, Line %d: No Command Found');
throw new Error('Syntax Error in Procfile, Line ' + lineNo + ': No Command Found');
}

processes[prockey] = command;
Expand Down
9 changes: 7 additions & 2 deletions lib/proxy.js
Expand Up @@ -61,11 +61,16 @@ function f(key, j, ports, proc, reqs, portargs, localhost, emitter, ssl) {

emitter.once('killall', function(signal) {
cons.Done('Killing Proxy Server on Port %s', port);
proxy.kill(signal);
try {
proxy.disconnect();
proxy.kill(signal);
} catch(_e) {
cons.Warn('Proxy server already dead');
}
});

proxy.on('exit', function(code, signal) {
emitter.emit('killall', signal);
emitter.emit('killall', 'SIGINT');
});

}
Expand Down
2 changes: 1 addition & 1 deletion lib/smf/foreman-APP.xml
Expand Up @@ -55,4 +55,4 @@

</service>

</service_bundle>
</service_bundle>
13 changes: 6 additions & 7 deletions package.json
Expand Up @@ -23,13 +23,13 @@
],
"scripts": {
"pretest": "jshint .",
"test": "tap test/*.test.*"
"test": "tap --coverage test/*.test.*"
},
"dependencies": {
"commander": "~2.9.0",
"http-proxy": "~1.11.1",
"commander": "^2.9.0",
"http-proxy": "^1.13.2",
"mustache": "^2.2.1",
"shell-quote": "~1.4.2"
"shell-quote": "^1.6.0"
},
"repository": {
"type": "git",
Expand All @@ -44,9 +44,8 @@
},
"preferGlobal": true,
"devDependencies": {
"chai": "~1.9.1",
"jshint": "^2.6.3",
"rimraf": "~2.2.8",
"tap": "^0.7.1"
"rimraf": "^2.5.2",
"tap": "^5.7.1"
}
}
128 changes: 128 additions & 0 deletions test/common.sh
@@ -0,0 +1,128 @@
#!/bin/bash
fails=0
tests=0
skips=0

trap assert_report EXIT

function fail() {
local report=$1
local output=$2
fails=$((fails+1))
tests=$((tests+1))
echo "not ok $tests # $report" >&3
echo "# $report" >&2
echo "$output" >&2
}

function ok() {
cmd=$1
tests=$((tests+1))
echo "ok $tests # $cmd" >&3
}

function skip() {
comment=$1
tests=$((tests+1))
echo "ok $tests # SKIP $comment" >&3
}

function comment() {
echo "# $*" >&3
}

function assert_exit() {
expected="$1"
case $expected in
''|*[!0-9]*)
expected=0
cmd="$*"
;;
*)
shift
cmd="$*"
;;
esac
output=`$cmd 2>&1`
result=$?
report="exit $result should be $expected: '$cmd'"
if test $result -ne $expected; then
fail "$report" "$output"
else
ok "$report"
fi
}

function assert_file() {
local fname=$1
if test $# -gt 1; then
shift
found=$(grep -F -e "$*" $fname)
result=$?
if test $result -eq 0; then
ok "needle: '$*' in $fname"
else
fail "needle: '$*' NOT in $fname"
fi
else
report="file exists: $fname"
if test -f $fname; then
ok "$report"
else
fail "$report"
fi
fi
}

function assert_not_file() {
local fname=$1
if test $# -gt 1; then
shift
found=$(grep -F -e "$*" $fname)
result=$?
if test $result -eq 0; then
fail "needle: '$*' in $fname"
else
ok "needle: '$*' NOT in $fname"
fi
else
report="file exists: $fname"
if test -f $fname; then
fail "$report"
else
ok "$report"
fi
fi
}

function bailout() {
fail "$1"
echo "Bail out! $1" >&1
echo "Bail out! $1" >&2
echo "Bail out! $1" >&3
# exit 1
assert_report
}

function assert_report() {
if test -z $reported; then
echo "1..$tests" >&3
reported=1
fi
exit $fails
}

echo 'TAP version 13'

# make fd 3 the new fd 1 and redirect original fd 1 to fd 2
# this allows us to completely isolate the TAP output from these helpers
# to their own stream
if test -z "$DEBUG"; then
exec 3>&1 2>/dev/null 1>&2
comment "suppressing stderr, set DEBUG to restore"
else
exec 3>&1 1>&2
fi

comment "using npm registry $(npm config get registry)"
comment "using $(basename $(node -p process.execPath))-$(node -p process.version)"
66 changes: 35 additions & 31 deletions test/console-output.test.js
@@ -1,6 +1,6 @@
var assert = require('chai').assert;
var util = require('util');
var Console = require('../lib/console');
var tap = require('tap');

var logs = { log: [], warn: [], error: [] };
var logger = {
Expand All @@ -9,40 +9,44 @@ var logger = {
error: makeLogger(logs.error)
};

var c = new Console(logger);
resetLogs();
tap.test('log methods', function(t) {
var c = new Console(logger);
resetLogs();

assert.equal(logs.log.length, 0);
assert.equal(logs.warn.length, 0);
assert.equal(logs.error.length, 0);
t.equal(logs.log.length, 0);
t.equal(logs.warn.length, 0);
t.equal(logs.error.length, 0);

resetLogs();
c.Alert('ze message');
assertLogged('log', /\[OKAY\]/);
assertLogged('log', /ze message/);
resetLogs();
c.Alert('ze message');
assertLogged(t, 'log', /\[OKAY\]/);
assertLogged(t, 'log', /ze message/);

resetLogs();
c.Done('ze message');
assertLogged('log', /\[DONE\]/);
assertLogged('log', /ze message/);
resetLogs();
c.Done('ze message');
assertLogged(t, 'log', /\[DONE\]/);
assertLogged(t, 'log', /ze message/);

resetLogs();
c.Warn('ze warning');
assertLogged('warn', /\[WARN\]/);
assertLogged('warn', /ze warning/);
resetLogs();
c.Warn('ze warning');
assertLogged(t, 'warn', /\[WARN\]/);
assertLogged(t, 'warn', /ze warning/);

resetLogs();
c.Error('such an error');
assertLogged('error', /\[FAIL\]/);
assertLogged('error', /such an error/);
resetLogs();
c.Error('such an error');
assertLogged(t, 'error', /\[FAIL\]/);
assertLogged(t, 'error', /such an error/);

resetLogs();
c.raw = true;
c.log('a key', null, 'a log message');
assertLogged('log', /^a log message$/);
c.raw = false;
resetLogs();
c.raw = true;
c.log('a key', null, 'a log message');
assertLogged(t, 'log', /^a log message$/);
c.raw = false;

assert.lengthOf(c.trim('a very long string this is!', 5), 6);
t.equal(c.trim('a very long string this is!', 5).length, 6);

t.end();
});

function makeLogger(collector) {
return function() {
Expand All @@ -56,12 +60,12 @@ function resetLogs() {
logs.error.splice(0, logs.error.length);
}

function assertLogged(logName, pattern) {
function assertLogged(t, logName, pattern) {
var actual = logs[logName][logs[logName].length - 1];

Object.keys(logs).forEach(function (log) {
assert.lengthOf(logs[log], logName === log ? 1 : 0);
t.equal(logs[log].length, logName === log ? 1 : 0);
});

assert.match(actual, pattern);
t.match(actual, pattern);
}

0 comments on commit 5f6f708

Please sign in to comment.