a6c5b3ab2303ae41f3bc307f1c776114ec665986.svn-base
2.34 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
var server = require('./server')
, assert = require('assert')
, request = require('../main.js')
;
var s = server.createServer();
var tests =
{ testGet :
{ resp : server.createGetResponse("TESTING!")
, expectBody: "TESTING!"
}
, testGetChunkBreak :
{ resp : server.createChunkResponse(
[ new Buffer([239])
, new Buffer([163])
, new Buffer([191])
, new Buffer([206])
, new Buffer([169])
, new Buffer([226])
, new Buffer([152])
, new Buffer([131])
])
, expectBody: "Ω☃"
}
, testGetBuffer :
{ resp : server.createGetResponse(new Buffer("TESTING!"))
, encoding: null
, expectBody: new Buffer("TESTING!")
}
, testGetJSON :
{ resp : server.createGetResponse('{"test":true}', 'application/json')
, json : true
, expectBody: {"test":true}
}
, testPutString :
{ resp : server.createPostValidator("PUTTINGDATA")
, method : "PUT"
, body : "PUTTINGDATA"
}
, testPutBuffer :
{ resp : server.createPostValidator("PUTTINGDATA")
, method : "PUT"
, body : new Buffer("PUTTINGDATA")
}
, testPutJSON :
{ resp : server.createPostValidator(JSON.stringify({foo: 'bar'}))
, method: "PUT"
, json: {foo: 'bar'}
}
, testPutMultipart :
{ resp: server.createPostValidator(
'--frontier\r\n' +
'content-type: text/html\r\n' +
'\r\n' +
'<html><body>Oh hi.</body></html>' +
'\r\n--frontier\r\n\r\n' +
'Oh hi.' +
'\r\n--frontier--'
)
, method: "PUT"
, multipart:
[ {'content-type': 'text/html', 'body': '<html><body>Oh hi.</body></html>'}
, {'body': 'Oh hi.'}
]
}
}
s.listen(s.port, function () {
var counter = 0
for (i in tests) {
(function () {
var test = tests[i]
s.on('/'+i, test.resp)
//test.uri = s.url + '/' + i
request(s.url + '/' + i, test, function (err, resp, body) {
if (err) throw err
if (test.expectBody) {
assert.deepEqual(test.expectBody, body)
}
counter = counter - 1;
if (counter === 0) {
console.log(Object.keys(tests).length+" tests passed.")
s.close()
}
})
counter++
})()
}
})