Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add basic tests

  • Loading branch information...
commit af4d0c6583be69b3afb111eba3c9ba47bcf4bcf6 1 parent f192562
@dchester dchester authored
View
23 tests/client.js
@@ -0,0 +1,23 @@
+var lilbro = require('../lib/lilbro');
+var fixtures = require('./data/fixtures');
+
+exports.clientjs = function(test) {
+
+
+ var req = { url: '/lilbro.js', method: 'GET' };
+
+ var res = {
+ write: function() {},
+ end: function(data) {
+ test.equal(data.substring(0,6), 'LilBro', 'we get reasonable content back for client js');
+ test.done();
+ },
+ writeHead: function(status, headers) {
+ test.equal(status, 200, 'client js response has 200');
+ test.equal(headers['Content-Type'], 'application/javascript', 'client js request has good content type headers')
+ }
+ };
+
+ lilbro.initialize(fixtures.defaults);
+ lilbro.listener(req, res);
+};
View
20 tests/data/fixtures.js
@@ -0,0 +1,20 @@
+module.exports = {
+
+ encodedRequestURL: '/%01default%011345738072767%010%011649295%0189c659cf3c9c7588e9b459923d048f17%01%01%011905%01386%01%01%01%01%01%01%01%01%01%01%01%01%01%01Chrome%0112%01Linux%01/rickshaw/.png?f07a745a',
+
+ jsonData: '{"version":"default","timestamp":"1345738072767","event_type":"0","visitor_id":"1649295","visit_id":"89c659cf3c9c7588e9b459923d048f17","mouse_x":"","mouse_y":"","viewport_width":"1905","viewport_height":"386","scroll_x":"","scroll_y":"","element_id":"","element_id_from":"","element_class":"","element_class_from":"","element_name":"","element_tag":"","element_type":"","element_checked":"","element_value":"","element_x":"","element_y":"","browser":"Chrome","browser_version":"12","operating_system":"Linux","request_path":"/rickshaw/"}',
+
+ defaults: {
+ 'png-bug': './data/b.png',
+ 'https-port': false,
+ 'https-key': './data/test-cert/privatekey.pem',
+ 'https-cert': './data/test-cert/certificate.pem',
+ 'http-port': 8000,
+ 'devent-host': 'prod-deventforwarder01.nyc01',
+ 'devent-port': 7664,
+ 'devent-topic': 'lilbro',
+ 'client-js-path': './client/src/',
+ writer: 'devent-forwarder',
+ 'output-file': false
+ }
+};
View
68 tests/deventForwarderWriter.js
@@ -0,0 +1,68 @@
+var http = require('http');
+
+var lilbro = require('../lib/lilbro');
+var fixtures = require('./data/fixtures');
+
+exports.event = function(test) {
+
+ var options = clone(fixtures.defaults);
+
+ options.writer = 'devent-forwarder';
+ options['devent-host'] = 'localhost';
+ options['devent-port'] = 11991;
+
+ lilbro.initialize(options);
+
+ var req = { url: fixtures.encodedRequestURL, method: 'GET' };
+
+ var res = {
+ write: function() {},
+ end: function() {},
+ writeHead: function() {}
+ };
+
+ var devent_listener = function(req, res) {
+
+ var chunks = [];
+ var body_len = 0;
+
+ req.on('data', function(chunk) {
+ body_len += chunk.length;
+ chunks.push(chunk);
+ });
+
+ req.on('end', function() {
+
+ var body = new Buffer(body_len);
+ var cur_len = 0;
+
+ for (var i = 0; i < chunks.length; i++) {
+ chunks[i].copy(body, cur_len);
+ cur_len += chunks[i].length;
+ }
+
+ // test content type, method
+ test.equal(req.method, 'POST', 'devent forwarder is a POST');
+ test.equal(req.headers['content-type'], 'application/json', 'devent forwarder gets application/json content type');
+
+ var data = decodeURIComponent(body.toString());
+
+ test.deepEqual( JSON.parse(data), JSON.parse(fixtures.jsonData), 'event data makes it to devent-forwarder' );
+ test.done();
+
+ server.close();
+ res.end();
+ });
+
+ };
+
+ var server = http.createServer(devent_listener);
+ server.listen(options['devent-port']);
+
+ lilbro.listener(req, res);
+
+};
+
+var clone = function(object) {
+ return JSON.parse(JSON.stringify(object));
+}
View
46 tests/deventZMQWriter.js
@@ -0,0 +1,46 @@
+var http = require('http');
+var zmq = require('zmq');
+
+var lilbro = require('../lib/lilbro');
+var fixtures = require('./data/fixtures');
+
+exports.event = function(test) {
+
+ var options = clone(fixtures.defaults);
+
+ options.writer = 'devent-zmq';
+ options['devent-host'] = '127.0.0.1';
+ options['devent-port'] = 11991;
+
+ lilbro.initialize(options);
+
+ var req = { url: fixtures.encodedRequestURL, method: 'GET' };
+
+ var res = {
+ write: function() {},
+ end: function() {},
+ writeHead: function() {}
+ };
+
+ var uri = 'tcp://' + [options['devent-host'], options['devent-port']].join(':');
+
+ var puller = zmq.socket('pull');
+ puller.connect(uri);
+
+ puller.on('message', function(topic, data) {
+
+ test.equal( topic, 'lilbro', 'devent zmq topic is lilbro' );
+
+ test.deepEqual( JSON.parse(data), JSON.parse(fixtures.jsonData), 'event data makes it to devent-zmq' );
+ test.done();
+
+ puller.close();
+ lilbro.close();
+ });
+
+ lilbro.listener(req, res);
+};
+
+var clone = function(object) {
+ return JSON.parse(JSON.stringify(object));
+}
View
45 tests/fileWriter.js
@@ -0,0 +1,45 @@
+var http = require('http');
+var fs = require('fs');
+
+var lilbro = require('../lib/lilbro');
+var fixtures = require('./data/fixtures');
+
+exports.missingOutputFile = function(test) {
+
+ var options = clone(fixtures.defaults);
+ options.writer = 'file';
+
+ test.throws(function() { lilbro.initialize(options) }, Error, 'throws an error for no output file');
+ test.done();
+};
+
+exports.event = function(test) {
+
+ var outputFile = '/tmp/lilbro' + process.pid;
+
+ var options = clone(fixtures.defaults);
+ options.writer = 'file';
+ options['output-file'] = outputFile;
+
+ lilbro.initialize(options);
+
+ var req = { url: fixtures.encodedRequestURL, method: 'GET' };
+
+ var res = {
+ write: function() {},
+ end: function() {},
+ writeHead: function() {}
+ };
+
+ lilbro.listener(req, res);
+
+ setTimeout( function() {
+ var fileData = fs.readFileSync(outputFile, 'utf8');
+ test.deepEqual( JSON.parse(fileData), JSON.parse(fixtures.jsonData), 'event data makes it to file' );
+ test.done();
+ }, 500);
+};
+
+var clone = function(object) {
+ return JSON.parse(JSON.stringify(object));
+}
View
15 tests/initialize.js
@@ -0,0 +1,15 @@
+var lilbro = require('../lib/lilbro');
+var fixtures = require('./data/fixtures');
+
+exports.class = function(test) {
+
+ test.ok(typeof lilbro === 'object', 'we have a lilbro');
+ test.done();
+};
+
+exports.initialize = function(test) {
+
+ lilbro.initialize(fixtures.defaults);
+ test.ok(typeof lilbro === 'object', 'we have a lilbro');
+ test.done();
+};
Please sign in to comment.
Something went wrong with that request. Please try again.