Permalink
Browse files

write test for hostname-based scripts

  • Loading branch information...
1 parent adb8d1f commit fc006babd9109cba25acaf218cb1b5afcca33433 @mhansen committed Jul 10, 2010
Showing with 31 additions and 4 deletions.
  1. +7 −4 tests/common.js
  2. +6 −0 tests/fixtures/scripthost.js
  3. +18 −0 tests/test-scripthost.js
View
@@ -16,6 +16,9 @@ exports.settings = {
"hosts" : {
"examplevirtualhost.com" : {
"root" : path.join(fixturesDir,"examplevirtualhost.com")
+ },
+ "scripthost.com" : {
+ "script" : path.join(fixturesDir,"scripthost.js")
}
},
"default_host" : {
@@ -27,16 +30,16 @@ exports.settings = {
/* Testing helper functions */
-/** Make an HTTP req (given parameters in req), and test the response
+/** Fires an HTTP request, and test that the response is what we expect
+ *
* test: The nodeunit test object
*
* req.method: HTTP request method
* req.headers: HTTP request headers
* req.pathname: HTTP Request resource
*
- * expected_res represents the expected HTTP Response.
- * expected_res.statusCode
- * expected_res.body
+ * expected_res.statusCode: The expected response code
+ * expected_res.body: The expected HTTP response body
* Leave any of these values undefined, and they won't be tested
*/
exports.test_http = function(test, req, expected_res, callback) {
@@ -0,0 +1,6 @@
+var sys = require('sys');
+
+exports.handle = function (req, res) {
+ res.writeHead(200, { 'Content-Type': 'text/plain' });
+ res.end('hello world');
+}
View
@@ -0,0 +1,18 @@
+require('./common');
+
+exports['Request to host with a script handler'] = function (test) {
+ antinode.start(settings, function() {
+ test_http(test, {
+ 'method':'GET',
+ 'pathname':'/',
+ 'headers': { 'host' : 'scripthost.com' }
+ }, {
+ 'statusCode':200,
+ 'body':'hello world'
+ },
+ function () {
+ antinode.stop();
+ test.done();
+ });
+ });
+};

0 comments on commit fc006ba

Please sign in to comment.