Browse files

Basic test-suite per #10.

It cheats by re-implementing the ephemeral socket to one that simply
stores messages in an array.
  • Loading branch information...
1 parent 61e4fb2 commit a0d6ab4b31501c25dcd8920ecee70314f78dbfb6 @msiebuhr committed Jun 19, 2012
Showing with 66 additions and 0 deletions.
  1. +55 −0 test/StatsDClient-test.js
  2. +11 −0 test/fakeEphemeralSocket.js
View
55 test/StatsDClient-test.js
@@ -0,0 +1,55 @@
+var vows = require('vows'),
+ assert = require('assert'),
+ FakeEphemeralSocket = require('./fakeEphemeralSocket'),
+ StatsDClient = require('../lib/statsd-client');
+
+function assertGotMessage(message) {
+ return function (client) {
+ assert(client._ephemeralSocket.sent_messages.indexOf(message) !== -1);
+ }
+}
+
+vows.describe('StatsDClient Basics').addBatch({
+ 'StatsDClient()': {
+ topic: function () {
+ return new StatsDClient({
+ _ephemeralSocket: new FakeEphemeralSocket()
+ });
+ },
+ '.increment(foo)': {
+ topic: function (client) {
+ client.increment('foo');
+ return client;
+ },
+ 'foo:1|c': assertGotMessage('foo:1|c'),
+ },
+ '.increment(foo, 10)': {
+ topic: function (c) {
+ c.increment('foo', 10);
+ return c;
+ },
+ 'foo:10|c': assertGotMessage('foo:10|c')
+ },
+ '.decrement(foo, -10)': {
+ topic: function (c) {
+ c.decrement('foo', -10);
+ return c;
+ },
+ 'foo:-10|c': assertGotMessage('foo:-10|c')
+ },
+ '.decrement(foo, 11)': {
+ topic: function (c) {
+ c.decrement('foo', 11);
+ return c;
+ },
+ 'foo:-11|c': assertGotMessage('foo:-11|c')
+ },
+ '.gauge(foo, 10)': {
+ topic: function (c) {
+ c.gauge('foo', 10);
+ return c;
+ },
+ 'foo:10|g': assertGotMessage('foo:10|g')
+ }
+ }
+})['export'](module);
View
11 test/fakeEphemeralSocket.js
@@ -0,0 +1,11 @@
+function FakeEphemeralSocket(options) {
+ this.sent_messages = [];
+}
+
+FakeEphemeralSocket.prototype.close = function () { };
+
+FakeEphemeralSocket.prototype.send = function (data) {
+ this.sent_messages.push(data);
+};
+
+module.exports = FakeEphemeralSocket;

0 comments on commit a0d6ab4

Please sign in to comment.