-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from nodesource/test
Tests
- Loading branch information
Showing
6 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
**test** is deployed to <https://deb.nodesource.com/test> | ||
|
||
It can be executed with: | ||
|
||
```text | ||
$ curl -sL https://deb.nodesource.com/test | sudo bash - | ||
``` | ||
|
||
The test script will clean up after itself and report a `0` or `1` exit code on success or failure respectively. The output is verbose and should show any problems along the way. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is the package embedded in the test script, changes made here should be copied back into test.sh manually. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "test", | ||
"version": "1.0.0", | ||
"main": "server.js", | ||
"dependencies": { | ||
"bl": "~0.9.1", | ||
"buffertools": "~2.1.2", | ||
"hyperquest": "~0.3.0" | ||
}, | ||
"scripts": { | ||
"test": "npm start; node test.js", | ||
"start": "node server.js &" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const http = require('http') | ||
, bl = require('bl') | ||
, bt = require('buffertools') | ||
|
||
http.createServer(function (req, res) { | ||
req.pipe(bl(function (err, data) { | ||
res.setHeader('content-type', 'text/plain') | ||
if (err) { | ||
res.statusCode = 500 | ||
res.end(err.stack) | ||
} else { | ||
res.statusCode = 200 | ||
res.end(bt.reverse(data.slice())) | ||
} | ||
setTimeout(function () { | ||
process.exit(0) | ||
}, 200) | ||
})) | ||
}).listen(3456) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const hyperquest = require('hyperquest') | ||
, crypto = require('crypto') | ||
, bl = require('bl') | ||
, assert = require('assert') | ||
, rnd = [ crypto.randomBytes(32), crypto.randomBytes(32) ] | ||
|
||
var req = hyperquest.post('http://localhost:3456') | ||
|
||
req.pipe(bl(function (err, data) { | ||
assert.ifError(err) | ||
|
||
var rev = data.toString('hex') | ||
, orig = Buffer.concat(rnd) | ||
, i = orig.length - 1 | ||
, origRev = new Buffer(orig.length) | ||
|
||
for (; i >= 0; i--) | ||
origRev[orig.length - i - 1] = orig[i] | ||
|
||
assert.equal(rev, origRev.toString('hex')) | ||
|
||
console.log('SUCCESS') | ||
})) | ||
|
||
req.write(rnd[0]) | ||
req.end(rnd[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#!/bin/bash | ||
|
||
NPM_CACHE=".npm-test-cache" | ||
TEST_DIR="_test-node-install" | ||
OWD=$(pwd) | ||
|
||
print_status() { | ||
echo | ||
echo "## $1" | ||
echo | ||
} | ||
|
||
cleanup() { | ||
print_status "Cleaning up ..." | ||
cd $OWD | ||
exec_cmd "rm -rf ${TEST_DIR}" | ||
} | ||
|
||
bail() { | ||
echo 'Error executing command' | ||
cleanup | ||
exit 1 | ||
} | ||
|
||
exec_cmd_nobail() { | ||
echo "+ $1" | ||
bash -c "$1" | ||
} | ||
|
||
exec_cmd() { | ||
exec_cmd_nobail "$1" || bail | ||
} | ||
|
||
print_status "Testing Node.js and npm installation ..." | ||
|
||
exec_cmd "mkdir ${TEST_DIR} && cd ${TEST_DIR}" | ||
|
||
# because the previous cd was in a subshell and only for show | ||
cd $TEST_DIR | ||
|
||
print_status "Creating test package ..." | ||
|
||
cat > server.js << EOF | ||
const http = require('http') | ||
, bl = require('bl') | ||
, bt = require('buffertools') | ||
http.createServer(function (req, res) { | ||
req.pipe(bl(function (err, data) { | ||
res.setHeader('content-type', 'text/plain') | ||
if (err) { | ||
res.statusCode = 500 | ||
res.end(err.stack) | ||
} else { | ||
res.statusCode = 200 | ||
res.end(bt.reverse(data.slice())) | ||
} | ||
setTimeout(function () { | ||
process.exit(0) | ||
}, 200) | ||
})) | ||
}).listen(3456) | ||
EOF | ||
|
||
cat > test.js << EOF | ||
const hyperquest = require('hyperquest') | ||
, crypto = require('crypto') | ||
, bl = require('bl') | ||
, assert = require('assert') | ||
, rnd = [ crypto.randomBytes(32), crypto.randomBytes(32) ] | ||
var req = hyperquest.post('http://localhost:3456') | ||
req.pipe(bl(function (err, data) { | ||
assert.ifError(err) | ||
var rev = data.toString('hex') | ||
, orig = Buffer.concat(rnd) | ||
, i = orig.length - 1 | ||
, origRev = new Buffer(orig.length) | ||
for (; i >= 0; i--) | ||
origRev[orig.length - i - 1] = orig[i] | ||
assert.equal(rev, origRev.toString('hex')) | ||
console.log('SUCCESS') | ||
})) | ||
req.write(rnd[0]) | ||
req.end(rnd[1]) | ||
EOF | ||
|
||
cat > package.json << EOF | ||
{ | ||
"name": "test", | ||
"version": "1.0.0", | ||
"main": "server.js", | ||
"dependencies": { | ||
"bl": "~0.9.1", | ||
"buffertools": "~2.1.2", | ||
"hyperquest": "~0.3.0" | ||
}, | ||
"scripts": { | ||
"test": "npm start; node test.js", | ||
"start": "node server.js &" | ||
} | ||
} | ||
EOF | ||
|
||
print_status "Installing dependencies ..." | ||
|
||
exec_cmd "npm install --spin=false --loglevel=info --cache=${NPM_CACHE}" | ||
|
||
print_status "Running test ..." | ||
|
||
exec_cmd "npm test" | ||
|
||
cleanup |