Skip to content

Commit

Permalink
Merge pull request #1397 from nylen/tests-improve-pipe-from-file
Browse files Browse the repository at this point in the history
Improve pipe-from-file tests
  • Loading branch information
nylen committed Feb 5, 2015
2 parents f0acc0b + 68f9976 commit 25ee80f
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions tests/test-pipes.js
Expand Up @@ -132,16 +132,37 @@ tape('piping from a request object', function(t) {
}
})

tape('piping from a file', function(t) {
s.once('/pushjs', function(req, res) {
if (req.method === 'PUT') {
t.equal(req.headers['content-type'], 'application/javascript')
t.end()
res.end()
var fileContents = fs.readFileSync(__filename).toString()
function testPipeFromFile(testName, hasContentLength) {
tape(testName, function(t) {
s.once('/pushjs', function(req, res) {
if (req.method === 'PUT') {
t.equal(req.headers['content-type'], 'application/javascript')
t.equal(
req.headers['content-length'],
(hasContentLength ? '' + fileContents.length : undefined))
var body = ''
req.on('data', function(data) {
body += data
})
req.on('end', function() {
t.equal(body, fileContents)
t.end()
})
res.end()
}
})
var r = request.put(s.url + '/pushjs')
fs.createReadStream(__filename).pipe(r)
if (hasContentLength) {
r.setHeader('content-length', fileContents.length)
}
})
fs.createReadStream(__filename).pipe(request.put(s.url + '/pushjs'))
})
}

// TODO Piping from a file does not send content-length header
testPipeFromFile('piping from a file', false)
testPipeFromFile('piping from a file with content-length', true)

tape('piping to and from same URL', function(t) {
s.once('catDone', function(req, res, body) {
Expand Down

0 comments on commit 25ee80f

Please sign in to comment.