Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50675 views
1
/*
2
* http-test.js: Tests for basic HTTP server(s).
3
*
4
* (C) 2011, Nodejitsu Inc.
5
* MIT LICENSE
6
*
7
*/
8
9
var assert = require('assert'),
10
http = require('http'),
11
vows = require('vows'),
12
request = require('request'),
13
director = require('../../../lib/director'),
14
helpers = require('../helpers'),
15
handlers = helpers.handlers,
16
macros = helpers.macros;
17
18
function assertBark(uri) {
19
return macros.assertGet(
20
9090,
21
uri,
22
'hello from (bark)'
23
);
24
}
25
26
vows.describe('director/http').addBatch({
27
"An instance of director.http.Router": {
28
"instantiated with a Routing table": {
29
topic: new director.http.Router({
30
'/hello': {
31
get: handlers.respondWithId
32
}
33
}),
34
"should have the correct routes defined": function (router) {
35
assert.isObject(router.routes.hello);
36
assert.isFunction(router.routes.hello.get);
37
},
38
"when passed to an http.Server instance": {
39
topic: function (router) {
40
router.get(/foo\/bar\/(\w+)/, handlers.respondWithId);
41
router.get(/foo\/update\/(\w+)/, handlers.respondWithId);
42
router.path(/bar\/bazz\//, function () {
43
this.get(/(\w+)/, handlers.respondWithId);
44
});
45
46
helpers.createServer(router)
47
.listen(9090, this.callback);
48
},
49
"a request to foo/bar/bark": assertBark('foo/bar/bark'),
50
"a request to foo/update/bark": assertBark('foo/update/bark'),
51
"a request to bar/bazz/bark": assertBark('bar/bazz/bark'),
52
"a request to foo/bar/bark?test=test": assertBark('foo/bar/bark?test=test')
53
}
54
}
55
}
56
}).export(module);
57