Permalink
Browse files

Merge branch 'collector-missing-require'

  • Loading branch information...
2 parents a8e16a5 + 73c15be commit 333c32b0454b68895cfac0af86465cf8996cb6a9 @mbostock mbostock committed Sep 16, 2011
Showing with 84 additions and 46 deletions.
  1. +1 −1 lib/cube/index.js
  2. +2 −1 lib/cube/server/collector.js
  3. +1 −1 package.json
  4. +29 −0 test/collector-test.js
  5. +23 −42 test/endpoint-test.js
  6. +28 −1 test/test.js
View
@@ -1,4 +1,4 @@
-exports.version = "0.0.2";
+exports.version = "0.0.3";
exports.emitter = require("./server/emitter");
exports.server = require("./server/server");
exports.collector = require("./server/collector");
@@ -1,4 +1,5 @@
-var endpoint = require("./endpoint");
+var endpoint = require("./endpoint"),
+ util = require("util");
exports.register = function(db, endpoints) {
var putter = require("./event").putter(db);
View
@@ -1,6 +1,6 @@
{
"name": "cube",
- "version": "0.0.2",
+ "version": "0.0.3",
"description": "A system for time series visualization using MongoDB, Node and D3.",
"keywords": ["time series", "visualization"],
"homepage": "http://square.github.com/cube/",
View
@@ -0,0 +1,29 @@
+var vows = require("vows"),
+ assert = require("assert"),
+ cube = require("../"),
+ test = require("./test");
+
+var suite = vows.describe("collector");
+
+var port = ++test.port, server = cube.server({
+ "mongo-host": "localhost",
+ "mongo-port": 27017,
+ "mongo-database": "cube_test",
+ "http-port": 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), {status: 400});
+ }
+ }
+}));
+
+suite.export(module);
View
@@ -1,51 +1,58 @@
var vows = require("vows"),
assert = require("assert"),
+ http = require("http"),
+ test = require("./test"),
endpoint = require("../lib/cube/server/endpoint");
var suite = vows.describe("endpoint");
+var port = ++test.port,
+ server = http.createServer(endpoint.file("../client/semicolon.js", "../client/semicolon.js"));
+
+server.listen(port, "127.0.0.1");
+
suite.addBatch({
"file": {
"GET": {
- topic: testFile("GET", {}),
+ topic: test.request({method: "GET", port: port}),
"the status should be 200": function(response) {
- assert.equal(response.status, 200);
+ assert.equal(response.statusCode, 200);
},
"the expected headers should be set": function(response) {
- assert.equal(response.headers["Content-Type"], "text/javascript;charset=utf-8");
- assert.equal(response.headers["Content-Length"], 2);
- assert.ok(new Date(response.headers["Date"]) > Date.UTC(2011, 0, 1));
- assert.ok(new Date(response.headers["Last-Modified"]) > Date.UTC(2011, 0, 1));
+ assert.equal(response.headers["content-type"], "text/javascript;charset=utf-8");
+ assert.equal(response.headers["content-length"], 2);
+ assert.ok(new Date(response.headers["date"]) > Date.UTC(2011, 0, 1));
+ assert.ok(new Date(response.headers["last-modified"]) > Date.UTC(2011, 0, 1));
},
"the expected content should be returned": function(response) {
assert.equal(response.body, ";;");
}
},
"GET If-Modified-Since": {
- topic: testFile("GET", {"if-modified-since": new Date(2101, 0, 1).toUTCString()}),
+ topic: test.request({method: "GET", port: port, headers: {"if-modified-since": new Date(2101, 0, 1).toUTCString()}}),
"the status should be 304": function(response) {
- assert.equal(response.status, 304);
+ assert.equal(response.statusCode, 304);
},
"the expected headers should be set": function(response) {
- assert.equal(response.headers["Content-Type"], "text/javascript;charset=utf-8");
+ assert.equal(response.headers["content-type"], "text/javascript;charset=utf-8");
assert.ok(!("Content-Length" in response.headers));
- assert.ok(new Date(response.headers["Date"]) > Date.UTC(2011, 0, 1));
- assert.ok(new Date(response.headers["Last-Modified"]) > Date.UTC(2011, 0, 1));
+ assert.ok(new Date(response.headers["date"]) > Date.UTC(2011, 0, 1));
+ assert.ok(new Date(response.headers["last-modified"]) > Date.UTC(2011, 0, 1));
},
"no content should be returned": function(response) {
assert.equal(response.body, "");
}
},
"HEAD": {
- topic: testFile("HEAD", {"if-modified-since": new Date(2001, 0, 1).toUTCString()}),
+ topic: test.request({method: "HEAD", port: port, headers: {"if-modified-since": new Date(2001, 0, 1).toUTCString()}}),
"the status should be 200": function(response) {
- assert.equal(response.status, 200);
+ assert.equal(response.statusCode, 200);
},
"the expected headers should be set": function(response) {
- assert.equal(response.headers["Content-Type"], "text/javascript;charset=utf-8");
+ assert.equal(response.headers["content-type"], "text/javascript;charset=utf-8");
assert.ok(!("Content-Length" in response.headers));
- assert.ok(new Date(response.headers["Date"]) > Date.UTC(2011, 0, 1));
- assert.ok(new Date(response.headers["Last-Modified"]) > Date.UTC(2011, 0, 1));
+ assert.ok(new Date(response.headers["date"]) > Date.UTC(2011, 0, 1));
+ assert.ok(new Date(response.headers["last-modified"]) > Date.UTC(2011, 0, 1));
},
"no content should be returned": function(response) {
assert.equal(response.body, "");
@@ -54,30 +61,4 @@ suite.addBatch({
}
});
-function testFile(method, headers) {
- return function() {
- var file = endpoint.file("../client/semicolon.js", "../client/semicolon.js"),
- request = {headers: headers, method: method},
- response = {writeHead: head, write: write, end: end},
- status,
- body = "",
- cb = this.callback;
-
- function head(s, h) {
- status = s;
- headers = h;
- }
-
- function write(data) {
- body += data;
- }
-
- function end() {
- cb(null, {status: status, headers: headers, body: body});
- }
-
- file(request, response);
- };
-}
-
suite.export(module);
View
@@ -1,5 +1,9 @@
var mongodb = require("mongodb"),
- assert = require("assert");
+ assert = require("assert"),
+ util = require("util"),
+ http = require("http");
+
+exports.port = 1083;
exports.batch = function(batch) {
return {
@@ -47,3 +51,26 @@ exports.batch = function(batch) {
}
};
};
+
+exports.request = function(options, data) {
+ return function() {
+ var cb = this.callback;
+
+ options.host = "localhost";
+
+ var request = http.request(options, function(response) {
+ response.body = "";
+ response.setEncoding("utf8");
+ response.on("data", function(chunk) { response.body += chunk; });
+ response.on("end", function() { cb(null, response); });
+ });
+
+ request.on("error", function(e) { cb(e, null); });
+
+ if (arguments.length > 1) request.write(data);
+ request.end();
+ };
+};
+
+// Disable logging for tests.
+util.log = function() {};

0 comments on commit 333c32b

Please sign in to comment.