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

Tests #12

Merged
merged 1 commit into from
Sep 8, 2014
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions test/README.md
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.
1 change: 1 addition & 0 deletions test/package/README.md
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.
14 changes: 14 additions & 0 deletions test/package/package.json
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 &"
}
}
19 changes: 19 additions & 0 deletions test/package/server.js
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)
26 changes: 26 additions & 0 deletions test/package/test.js
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])
119 changes: 119 additions & 0 deletions test/test
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