This repository was archived by the owner on Dec 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 414
/
Copy pathcollector-test.js
84 lines (73 loc) · 2.41 KB
/
collector-test.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
78
79
80
81
82
83
84
var vows = require("vows"),
assert = require("assert"),
cube = require("../"),
test = require("./helpers");
var suite = vows.describe("collector");
var server = cube.server(test.config),
port = test.config["http-port"];
console.log('collector port %s', port);
server.register = cube.collector.register;
server.start();
suite.addBatch(test.batch({
"POST /event/put with invalid JSON": {
topic: test.request({method: "POST", port: port, path: "/1.0/event/put"}, "This ain't JSON.\n"),
"responds with status 400": function(response) {
assert.equal(response.statusCode, 400);
assert.deepEqual(JSON.parse(response.body), {error: "SyntaxError: Unexpected token T"});
}
}
}));
suite.addBatch(test.batch({
"POST /event/put with a JSON object": {
topic: test.request({method: "POST", port: port, path: "/1.0/event/put"}, JSON.stringify({
type: "test",
time: new Date(),
data: {
foo: "bar"
}
})),
"responds with status 400": function(response) {
assert.equal(response.statusCode, 400);
assert.deepEqual(JSON.parse(response.body), {error: "TypeError: Object #<Object> has no method 'forEach'"});
}
}
}));
suite.addBatch(test.batch({
"POST /event/put with a JSON array": {
topic: test.request({method: "POST", port: port, path: "/1.0/event/put"}, JSON.stringify([{
type: "test",
time: new Date(),
data: {
foo: "bar"
}
}])),
"responds with status 200": function(response) {
assert.equal(response.statusCode, 200);
assert.deepEqual(JSON.parse(response.body), {});
}
}
}));
suite.addBatch(test.batch({
"POST /event/put with a JSON number": {
topic: test.request({method: "POST", port: port, path: "/1.0/event/put"}, JSON.stringify(42)),
"responds with status 400": function(response) {
assert.equal(response.statusCode, 400);
assert.deepEqual(JSON.parse(response.body), {error: "TypeError: Object 42 has no method 'forEach'"});
}
}
}));
suite.addBatch(test.batch({
"POST /event/put without an associated time": {
topic: test.request({method: "POST", port: port, path: "/1.0/event/put"}, JSON.stringify([{
type: "test",
data: {
foo: "bar"
}
}])),
"responds with status 200": function(response) {
assert.equal(response.statusCode, 200);
assert.deepEqual(JSON.parse(response.body), {});
}
}
}));
suite.export(module);