-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-restify.js
77 lines (64 loc) · 1.95 KB
/
test-restify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var restify = require('restify')
, tape = require('tape')
, common = require('./common.js')
, agnostic = require('../')
, bodyParserOptions = { maxBodySize: 100 }
;
// Restify options
// https://gist.github.com/LeCoupa/0664e885fd74152d1f90
tape.test('restify as route, no parser', function(t)
{
var server = restify.createServer();
// plug-in request handlers
Object.keys(common.requests).forEach(function(id)
{
var endpoint = [common.server.endpoint, id].join('/')
, handler = agnostic(common.requests[id].requestHandler)
;
server.get(endpoint, handler);
server.head(endpoint, handler);
server.post(endpoint, handler);
});
// start the server
server.listen(common.server.port, function()
{
common.sendAllRequests.call(t, 'restify', function(error, responded)
{
t.error(error);
t.equal(Object.keys(responded).length, Object.keys(common.requests).length, 'expect same number of responses as requests');
server.close(function()
{
t.end();
});
});
});
});
tape.test('restify as route, with bodyParser middleware', function(t)
{
var server = restify.createServer();
// made it parse input from start
server.use(restify.bodyParser(bodyParserOptions));
// plug-in request handlers
Object.keys(common.requests).forEach(function(id)
{
var endpoint = [common.server.endpoint, id].join('/')
, handler = agnostic(common.requests[id].requestHandler)
;
server.get(endpoint, handler);
server.head(endpoint, handler);
server.post(endpoint, handler);
});
// start the server
server.listen(common.server.port, function()
{
common.sendAllRequests.call(t, 'restify', function(error, responded)
{
t.error(error);
t.equal(Object.keys(responded).length, Object.keys(common.requests).length, 'expect same number of responses as requests');
server.close(function()
{
t.end();
});
});
});
});