Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50675 views
1
/*
2
* attach-test.js: Tests 'router.attach' functionality.
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 assertData(uri) {
19
return macros.assertGet(
20
9091,
21
uri,
22
JSON.stringify([1,2,3])
23
);
24
}
25
26
vows.describe('director/http/attach').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.respondWithData
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.attach(function () {
41
this.data = [1,2,3];
42
});
43
44
helpers.createServer(router)
45
.listen(9091, this.callback);
46
},
47
"a request to hello": assertData('hello'),
48
}
49
}
50
}
51
}).export(module);
52
53