Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworking Riak-JS tests to be mocha based
- Loading branch information
Ken Perkins
committed
Dec 5, 2012
1 parent
10a7b51
commit 4f51da8
Showing
15 changed files
with
1,210 additions
and
939 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ module.exports = { | |
* @api public | ||
*/ | ||
test: function(s) { | ||
console.log(' - ' + s); | ||
//console.log(' - ' + s); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
// }); | ||
//}); |
Oops, something went wrong.