-
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.
Added support for a "query" option value that is a hash of querystrin…
…g values that is merged (taking precedence over) with the querystring passed in the uri string.
- Loading branch information
Chris Sainty
committed
Feb 18, 2012
1 parent
12f4997
commit 2f34fd1
Showing
4 changed files
with
62 additions
and
7 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
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
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
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,52 @@ | ||
var request = request = require('../main.js') | ||
, assert = require('assert') | ||
, url = require('url') | ||
, qs = require('querystring') | ||
, server = require('./server') | ||
, s = server.createServer() | ||
; | ||
|
||
s.listen(s.port, function () { | ||
var serverUri = 'http://localhost:' + s.port | ||
, numTests = 0 | ||
, numOutstandingTests = 0 | ||
|
||
function createTest(requestObj, query, serverAssertFn) { | ||
var testNumber = numTests; | ||
numTests += 1; | ||
numOutstandingTests += 1; | ||
s.on('/' + testNumber, function (req, res) { | ||
serverAssertFn(req, res); | ||
res.writeHead(200); | ||
res.end(); | ||
}); | ||
requestObj.url = serverUri + '/' + testNumber + query | ||
request(requestObj, function (err, res, body) { | ||
assert.ok(!err) | ||
assert.equal(res.statusCode, 200) | ||
numOutstandingTests -= 1 | ||
if (numOutstandingTests === 0) { | ||
console.log(numTests + ' tests passed.') | ||
s.close() | ||
} | ||
}) | ||
} | ||
|
||
// Test adding a querystring | ||
createTest({ query: { q : 'search' } }, '', function (req, res) { | ||
var result = qs.parse(url.parse(req.url).query) | ||
assert.deepEqual({ q : 'search' }, result) | ||
}) | ||
|
||
// Test replacing a querystring value | ||
createTest({ query: { q : 'search' } }, '?q=abc', function (req, res) { | ||
var result = qs.parse(url.parse(req.url).query) | ||
assert.deepEqual({ q : 'search' }, result) | ||
}) | ||
|
||
// Test appending a querystring value to the ones present in the uri | ||
createTest({ query: { q : 'search' } }, '?x=y', function (req, res) { | ||
var result = qs.parse(url.parse(req.url).query) | ||
assert.deepEqual({ q : 'search', x : 'y' }, result) | ||
}) | ||
}) |