Skip to content
Browse files

Convert to utest

  • Loading branch information...
1 parent fde3421 commit 8ceae16b03f7b3bf5aaf34cb31f7f5fb87e70733 @felixge committed Nov 15, 2011
Showing with 44 additions and 41 deletions.
  1. +2 −1 package.json
  2. +42 −40 test/unit/test-client.js
View
3 package.json
@@ -16,6 +16,7 @@
"request": "2.1.1"
},
"devDependencies": {
- "urun": "0.0.3"
+ "urun": "0.0.3",
+ "utest": "0.0.2"
}
}
View
82 test/unit/test-client.js
@@ -1,3 +1,4 @@
+var test = require('utest');
var common = require('../common');
var assert = require('assert');
var CarbonClient = require(common.dir.lib + '/carbon_client');
@@ -10,53 +11,54 @@ SocketDummy.prototype.write = function() {
this._writes.push(arguments);
};
-(function testSingleWrite() {
- var client = new CarbonClient(new SocketDummy());
+var client;
+test('write', {
+ before: function() {
+ client = new CarbonClient(new SocketDummy());
+ },
- client.write('foo.bar', 25);
- assert.equal(client.socket._writes.length, 1);
+ 'single write': function() {
+ client.write('foo.bar', 25);
+ assert.equal(client.socket._writes.length, 1);
- var args = client.socket._writes.shift();
- assert.ok(/^foo\.bar 25 [\d]+\n/.test(args[0]), args[0]);
- assert.equal(args[1], 'utf8');
- assert.equal(args[2], undefined);
-})();
+ var args = client.socket._writes.shift();
+ assert.ok(/^foo\.bar 25 [\d]+\n/.test(args[0]), args[0]);
+ assert.equal(args[1], 'utf8');
+ assert.equal(args[2], undefined);
+ },
-(function testSingleWriteWithCallback() {
- var client = new CarbonClient(new SocketDummy());
- var cb = function() {};
+ 'single write with callback': function() {
+ var cb = function() {};
- client.write('foo.bar', 25, cb);
- assert.equal(client.socket._writes.length, 1);
+ client.write('foo.bar', 25, cb);
+ assert.equal(client.socket._writes.length, 1);
- var args = client.socket._writes.shift();
- assert.ok(/^foo\.bar 25 [\d]+\n/.test(args[0]), args[0]);
- assert.equal(args[2], cb);
-})();
+ var args = client.socket._writes.shift();
+ assert.ok(/^foo\.bar 25 [\d]+\n/.test(args[0]), args[0]);
+ assert.equal(args[2], cb);
+ },
-(function testSingleWriteWithTimestamp() {
- var client = new CarbonClient(new SocketDummy());
- var cb = function() {};
+ 'test single write with timestamp': function() {
+ var cb = function() {};
- client.write('foo.bar', 25, 2001, cb);
- assert.equal(client.socket._writes.length, 1);
+ client.write('foo.bar', 25, 2001, cb);
+ assert.equal(client.socket._writes.length, 1);
- var args = client.socket._writes.shift();
- assert.ok(/^foo\.bar 25 2\n/.test(args[0]), args[0]);
- assert.equal(args[2], cb);
-})();
+ var args = client.socket._writes.shift();
+ assert.ok(/^foo\.bar 25 2\n/.test(args[0]), args[0]);
+ assert.equal(args[2], cb);
+ },
+ 'batch write': function() {
+ var cb = function() {};
-(function testBatchWrite() {
- var client = new CarbonClient(new SocketDummy());
- var cb = function() {};
+ client.write([
+ {path: 'one', value: 30, timestamp: 9000},
+ {path: 'two', value: 33, timestamp: 8000},
+ ], cb);
+ assert.equal(client.socket._writes.length, 1);
- client.write([
- {path: 'one', value: 30, timestamp: 9000},
- {path: 'two', value: 33, timestamp: 8000},
- ], cb);
- assert.equal(client.socket._writes.length, 1);
-
- var args = client.socket._writes.shift();
- assert.ok(/^one 30 9\ntwo 33 8\n/.test(args[0]), args[0]);
- assert.equal(args[2], cb);
-})();
+ var args = client.socket._writes.shift();
+ assert.ok(/^one 30 9\ntwo 33 8\n/.test(args[0]), args[0]);
+ assert.equal(args[2], cb);
+ }
+});

0 comments on commit 8ceae16

Please sign in to comment.
Something went wrong with that request. Please try again.