Skip to content

Commit

Permalink
Adding test for onelineproxy.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeal committed Apr 22, 2013
1 parent 62f3b92 commit 74c6b2e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/test-onelineproxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var http = require('http')
, assert = require('assert')
, request = require('../index')
;

var server = http.createServer(function (req, resp) {
resp.statusCode = 200
if (req.url === '/get') {
assert.equal(req.method, 'GET')
resp.write('content')
resp.end()
return
}
if (req.url === '/put') {
var x = ''
assert.equal(req.method, 'PUT')
req.on('data', function (chunk) {
x += chunk
})
req.on('end', function () {
assert.equal(x, 'content')
resp.write('success')
resp.end()
})
return
}
if (req.url === '/test') {
return request('http://localhost:8080/get').pipe(request.put('http://localhost:8080/put')).pipe(resp)
}
throw new Error('Unknown url', req.url)
}).listen(8080, function () {
request('http://localhost:8080/test', function (e, resp, body) {
if (e) throw e
if (resp.statusCode !== 200) throw new Error('statusCode not 200 ' + resp.statusCode)
assert.equal(body, 'success')
server.close()
})
})



0 comments on commit 74c6b2e

Please sign in to comment.