Browse files

Adding test for pipeing file to disc.

  • Loading branch information...
1 parent 2f0cf6b commit 6e3ecb106c3a32101d80ac0f87968fddd3ac5e2c @mikeal mikeal committed Jul 20, 2011
Showing with 19 additions and 1 deletion.
  1. BIN tests/googledoodle.png
  2. +19 −1 tests/test-pipes.js
View
BIN tests/googledoodle.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
20 tests/test-pipes.js
@@ -4,6 +4,7 @@ var server = require('./server')
, assert = require('assert')
, fs = require('fs')
, request = require('../main.js')
+ , path = require('path')
;
var s = server.createServer(3453);
@@ -17,7 +18,7 @@ var check = function () {
process.exit();
}, 500)
}
- if (passes > 5) throw new Error('Need to update for more failures')
+ if (passes > 6) throw new Error('Need to update for more failures')
}
// Test pipeing to a request object
@@ -85,6 +86,10 @@ s.on('/pushjs', function (req, resp) {
s.on('/catresp', function (req, resp) {
request.get('http://localhost:3453/cat').pipe(resp)
})
+s.on('/doodle', function (req, resp) {
+ resp.writeHead('200', {'content-type':'image/png'})
+ fs.createReadStream(path.join(__dirname, 'googledoodle.png')).pipe(resp)
+})
fs.createReadStream(__filename).pipe(request.put('http://localhost:3453/pushjs'))
@@ -95,4 +100,17 @@ request.get('http://localhost:3453/catresp', function (e, resp, body) {
assert.ok(resp.headers['content-length'] == 4)
passes += 1
check();
+})
+
+var doodleWrite = fs.createWriteStream(path.join(__dirname, 'test.png'))
+
+request.get('http://localhost:3453/doodle').pipe(doodleWrite)
+
+doodleWrite.on('close', function () {
+ assert.deepEqual(fs.readFileSync(path.join(__dirname, 'googledoodle.png')), fs.readFileSync(path.join(__dirname, 'test.png')))
+ check()
+})
+
+process.on('exit', function () {
+ fs.unlinkSync(path.join(__dirname, 'test.png'))
})

0 comments on commit 6e3ecb1

Please sign in to comment.