Skip to content

Commit

Permalink
Reworking Riak-JS tests to be mocha based
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Perkins committed Dec 5, 2012
1 parent 10a7b51 commit 4f51da8
Show file tree
Hide file tree
Showing 15 changed files with 1,210 additions and 939 deletions.
13 changes: 11 additions & 2 deletions Makefile
@@ -1,4 +1,13 @@
test:
node test/runner.js
MOCHA_OPTS=-t 20000 test/*-test.js
REPORTER = spec

check: test

test: test-unit

test-unit:
@NODE_ENV=test ./node_modules/.bin/mocha \
--reporter $(REPORTER) \
$(MOCHA_OPTS)

.PHONY: test
2 changes: 1 addition & 1 deletion lib/utils.js
Expand Up @@ -24,7 +24,7 @@ module.exports = {
* @api public
*/
test: function(s) {
console.log(' - ' + s);
//console.log(' - ' + s);
}

}
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -51,7 +51,10 @@
"xml": "0.0.7"
},
"devDependencies": {
"seq": "0.3.5"
"seq": "0.3.5",
"mocha": "1.7.3",
"should": "*",
"async": "*"
},
"engines": {
"node": ">=0.4.0"
Expand Down
89 changes: 42 additions & 47 deletions test/http-client-instrumentation-test.js
@@ -1,51 +1,46 @@
var HttpClient = require('../lib/http-client'),
HttpMeta = require('../lib/http-meta'),
seq = require('seq'),
util = require('util'),
assert = require('assert'),
test = require('../lib/utils').test;

var db = new HttpClient({ port: 8098 });
var events = []

var listener = {
"riak.request.start": function(event) {
events.push(event)
},
"riak.request.response": function(event) {
events.push(event)
},
"riak.request.finish": function(event) {
events.push(event)
},
"riak.request.end": function(event) {
events.push(event)
}
}

seq()
.seq(function() {
test('Register event listeners');
db.registerListener(listener);
this.ok();
})
.seq(function() {
test('Creates an object');
db.save('users', 'someone@gmail.com', {name: 'Someone Else'}, function() {
this.ok(events[0]);
}.bind(this));
})
.seq(function(event) {
test('Assigns a unique ID to a request');
assert.notEqual(event.uuid, undefined);
this.ok();
})
.seq(function() {
test('Creates four unique events');
assert.equal(events.length, 4);
for (var i in events) {
assert.notEqual(events[i], undefined);
}
this.ok();
should = require('should'),
util = require('util');

var db, events = [], listener, bucket;

describe('http-client-instrumentation-tests', function() {
before(function(done) {
db = new HttpClient({ port: 8098 });

listener = {
"riak.request.start": function(event) {
events.push(event)
},
"riak.request.response": function(event) {
events.push(event)
},
"riak.request.finish": function(event) {
events.push(event)
},
"riak.request.end": function(event) {
events.push(event)
}
};

// Ensure unit tests don't collide with pre-existing buckets
bucket = 'users-riak-js-tests';

db.registerListener(listener);

done();
});

it('Create an object', function(done) {
db.save(bucket, 'someone@gmail.com',
{name: 'Someone Else'}, function(err, doc, meta) {
events.length.should.equal(4);
for (var i = 0; i < events.length; i++) {
should.exist(events[i].uuid);
}
done();
});
});
});

200 changes: 99 additions & 101 deletions test/http-client-luwak-test.js
@@ -1,108 +1,106 @@
var HttpClient = require('../lib/http-client'),
seq = require('seq'),
fs = require('fs'),
assert = require('assert'),
test = require('../lib/utils').test;
should = require('should');

var db = new HttpClient({ port: 8098 }),
var db, events = [], listener,
filename = __dirname + '/fixtures/cat.jpg',
filename2 = __dirname + '/fixtures/cat2.jpg',
filename3 = __dirname + '/fixtures/cat3.jpg',
image = fs.readFileSync(filename);
image;

// seq()
//
// .seq(function() {
// test('Save a file from a buffer');
//
// db.saveFile('cat2', image, { contentType: 'image/jpeg' }, function(err, data, meta) {
// assert.ok(meta.statusCode, 204);
// assert.ok(!data);
// assert.equal(meta.key, 'cat2');
//
// // race condition - wait for riak
// setTimeout(this.ok, 500);
// }.bind(this));
// })
//
// .seq(function() {
// test('Get the file');
// db.getFile('cat2', this);
// })
// .seq(function(data) {
// assert.ok(data instanceof Buffer);
// assert.deepEqual(data, image);
// fs.writeFileSync(filename2, data);
// this.ok();
// })
//
// .seq(function() {
// test('Remove the file');
// db.removeFile('cat2', this);
// })
// .seq(function(data) {
// // TODO assert something
// this.ok();
// })
//
// .seq(function() {
// test('Save a file from a stream');
// db.saveFile('cat3', fs.createReadStream(filename), { contentType: 'image/jpeg' }, function(err, data, meta) {
// assert.equal(meta.statusCode, 204);
// assert.ok(!data);
// assert.equal(meta.key, 'cat3');
//
// // race condition - wait for riak
// setTimeout(this.ok, 500);
// }.bind(this));
// })
//
// // TODO test luwak with returnbody=true
//
// .seq(function() {
// test('Get the file stream');
// db.getFile('cat3', { stream: true }, this);
// })
// .seq(function(stream) {
//
// assert.ok(stream);
//
// var out = fs.createWriteStream(filename3);
// stream.pipe(out);
//
// out.on('close', function() {
// this.ok();
// }.bind(this));
//
// })
//
// .seq(function() {
// test('Remove the file');
// db.removeFile('cat3', this);
// })
// .seq(function(data) {
// this.ok()
// // TODO assert something
// })
//
// .seq(function() {
// test('Buffers are equal');
//
// var buf2 = fs.readFileSync(filename2),
// buf3 = fs.readFileSync(filename3);
//
// // assert.deepEqual(buf2, buf3);
// assert.equal(buf3.length, image.length);
//
// // cleanup
// fs.unlinkSync(filename2);
// fs.unlinkSync(filename3);
//
// this.ok();
//
// })
//
// .catch(function(err) {
// console.log(err.stack);
// process.exit(1);
// });
//describe('http-client-luwak-tests', function() {
// before(function(done) {
// db = new HttpClient({ port: 8098 });
//
// image = fs.readFileSync(filename);
//
// // Ensure unit tests don't collide with pre-existing buckets
// bucketName = 'users-riak-js-tests';
//
// done();
// });
//
// it('Save a file from a buffer', function(done) {
// db.saveFile('cat2', image,
// { contentType: 'image/jpeg' },
// function(err, data, meta) {
// should.not.exist(err);
// should.not.exist(data);
// should.exist(meta);
// meta.key.should.equal('cat2');
// meta.statusCode.should.equal(204);
//
// // race condition - wait for riak
// setTimeout(function() {
// db.getFile('cat2', function(data) {
// data.should.be.an.instanceof(Buffer);
//
// // TODO compare data to image
// fs.writeFileSync(filename2, data);
//
// done();
// });
// }, 500);
// });
// });
//
// it('Remove a file', function(done) {
// db.removeFile('cat2', function(data) {
// // TODO what are we supposed to be checking here?
// done();
// });
// });
//
// it('Save a file from a stream', function(done) {
// db.saveFile('cat3',
// fs.createReadStream(filename),
// { contentType: 'image/jpeg' },
// function(err, data, meta) {
// should.not.exist(err);
// should.not.exist(data);
// should.exist(meta);
// meta.statusCode.should.equal(204);
//
// // race condition - wait for riak
// setTimeout(function() {
// db.getFile('cat3', { stream: true }, function(stream) {
//
// should.exist(stream);
// var out = fs.createWriteStream(filename3);
// stream.pipe(out);
//
// out.on('close', function() {
// done();
// });
// });
// }, 500);
// });
// });
//
// // TODO test luwak with returnbody=true
//
// it('Remove the file stream', function(done) {
// db.removeFile('cat3', function(data) {
// // TODO what are we supposed to be checking here?
// done();
// });
// });
//
// it('Buffers are equal', function(done) {
// var buf2 = fs.readFileSync(filename2),
// buf3 = fs.readFileSync(filename3);
//
// should.exist(buf2);
// should.exist(buf3);
//
// buf2.length.should.equal(buf3.length);
//
// // TODO should there be a better comparison here?
//
// // cleanup
// fs.unlinkSync(filename2);
// fs.unlinkSync(filename3);
//
// done();
// });
//});

0 comments on commit 4f51da8

Please sign in to comment.