Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reworking Riak-JS tests to be mocha based

  • Loading branch information...
commit 4f51da87501d525e95b34aade7fb586f12000dd5 1 parent 10a7b51
@kenperkins kenperkins authored
View
13 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
View
2  lib/utils.js
@@ -24,7 +24,7 @@ module.exports = {
* @api public
*/
test: function(s) {
- console.log(' - ' + s);
+ //console.log(' - ' + s);
}
}
View
5 package.json
@@ -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"
View
89 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();
+ });
+ });
});
View
200 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();
+// });
+//});
View
215 test/http-client-search-test.js
@@ -1,101 +1,118 @@
var HttpClient = require('../lib/http-client'),
- seq = require('seq'),
- assert = require('assert'),
- test = require('../lib/utils').test;
-
-var db = new HttpClient({ port: 8098 }),
- bucket = 'users';
-
-seq()
-
- .seq(function() {
- test('Save the properties of a bucket');
- db.saveBucket(bucket, { search: true }, this);
- })
-
- .seq(function() {
- test('Get the properties of a bucket');
- db.getBucket(bucket, this);
- })
- .seq(function(props) {
- assert.equal(props.search, true);
- this.ok();
- })
- .seq(function() {
- test('Save');
- db.save('users', 'test-search@gmail.com', { email: 'test-search@gmail.com', name: 'Testy Test for Riak Search' }, function(err, data, meta) {
- assert.equal(meta.statusCode, 204);
- assert.ok(!data);
- assert.equal(meta.key, 'test-search@gmail.com');
- this.ok();
- }.bind(this));
- })
- .seq(function() {
- test('Map/Reduce with search');
- db.mapreduce.search('users', 'email:test-search@gmail.com').map('Riak.mapValuesJson').run(this);
- })
- .seq(function(data) {
- assert.equal(data[0].email, "test-search@gmail.com");
- this.ok();
- })
- .seq(function() {
- test('Searching via Solr interface');
- db.search.find('users', 'email:test-search@gmail.com', function(err, data) {
- this.ok(data);
- }.bind(this));
- })
- .seq(function(data) {
- test('Finds one result');
- assert.equal(data.numFound, 1);
- assert.equal(data.docs[0].id, "test-search@gmail.com");
- this.ok(data)
- })
- .seq(function(data) {
- test('Includes the document');
- assert.equal(data.docs[0].fields.email, "test-search@gmail.com");
- this.ok();
- })
- .seq(function() {
- test('Add a document');
- db.search.add('users', {id: "test-add-search@gmail.com", name: "Sean Cribbs"}, function(err) {
- assert.equal(err, null);
- this.ok();
- }.bind(this));
- })
- .seq(function() {
- test('Find added document');
- db.search.find('users', 'name:"Sean Cribbs"', function(err, data) {
- this.ok(data);
- }.bind(this));
- })
- .seq(function(data) {
- test('Includes the added document');
- assert.equal(data.docs[0].fields.name, "Sean Cribbs");
- this.ok();
- })
- .seq(function() {
- test('Remove the added document');
- db.search.remove('users', {id: 'test-add-search@gmail.com'}, function(err) {
- assert.equal(err, null);
- this.ok();
- }.bind(this));
- })
- .seq(function() {
- test('Should have removed the added document');
- db.search.find('users', 'name:"Sean Cribbs"', function(err, data) {
- this.ok(data);
- }.bind(this));
- })
- .seq(function(data) {
- assert.equal(data.numFound, 0);
- this.ok();
- })
- .seq(function() {
- test('Remove document');
- db.remove('users', 'test-search@gmail.com', this);
- this.ok();
- })
- .catch(function(err) {
- console.log(err.stack);
- process.exit(1);
+ should = require('should');
+
+var db, events = [], listener, bucket;
+
+describe('http-client-search-tests', function() {
+ before(function(done) {
+ db = new HttpClient({ port: 8098 });
+
+ // Ensure unit tests don't collide with pre-existing buckets
+ bucket = 'users-riak-js-tests';
+
+ done();
+ });
+
+ it('Save the properties of a bucket', function(done) {
+ db.saveBucket(bucket, { search: true }, function(err) {
+ should.not.exist(err);
+
+ done();
+ });
+ });
+
+ it('Get the properties of a bucket', function(done) {
+ db.getBucket(bucket, function(err, props) {
+ should.not.exist(err);
+ should.exist(props);
+ props.search.should.equal(true);
+
+ done();
+ });
+ });
+
+ it('Save a document to a search enabled bucket', function(done) {
+ db.save(bucket, 'test-search@gmail.com',
+ {
+ email: 'test-search@gmail.com',
+ name: 'Testy Test for Riak Search'
+ },
+ function(err, data, meta) {
+ should.not.exist(err);
+ should.not.exist(data);
+ should.exist(meta);
+ meta.key.should.equal('test-search@gmail.com');
+ meta.statusCode.should.equal(204);
+
+ done();
+ });
+ });
+
+ it('Map/Reduce with saerch', function(done) {
+ db.mapreduce.search(bucket, 'email:test-search@gmail.com')
+ .map('Riak.mapValuesJson')
+ .run(function(err, data) {
+ should.not.exist(err);
+ should.exist(data);
+ data.length.should.equal(1);
+ data[0].email.should.equal('test-search@gmail.com');
+
+ done();
+ });
+ });
+
+ it('Searching via Solr interface', function(done) {
+ db.search.find(bucket, 'email:test-search@gmail.com', function(err, data) {
+ should.not.exist(err);
+ should.exist(data);
+ data.numFound.should.equal(1);
+ data.docs[0].id.should.equal('test-search@gmail.com');
+ data.docs[0].fields.email.should.equal('test-search@gmail.com');
+
+ done();
+ });
+ });
+
+ it('Add a document', function(done) {
+ db.search.add(bucket, {id: 'test-add-search@gmail.com', name: 'Sean Cribbs'},
+ function(err) {
+ should.not.exist(err);
+
+ done();
+ });
+ });
+
+ it('Find added document', function(done) {
+ db.search.find(bucket, 'name:"Sean Cribbs"', function(err, data) {
+ should.not.exist(err);
+ should.exist(data);
+ data.numFound.should.equal(1);
+ data.docs[0].id.should.equal('test-add-search@gmail.com');
+ data.docs[0].fields.name.should.equal('Sean Cribbs');
+
+ done();
+ });
+ });
+
+ it('Remove the added document', function(done) {
+ db.search.remove(bucket, {id: 'test-add-search@gmail.com'}, function(err) {
+ should.not.exist(err);
+
+ // try and find the removed document
+ db.search.find(bucket, 'name:"Sean Cribbs"', function(err, data) {
+ should.not.exist(err);
+ should.exist(data);
+ data.numFound.should.equal(0);
+
+ done();
+ });
+ });
+ });
+
+ after(function(done) {
+ db.remove(bucket, 'test-search@gmail.com');
+ db.remove(bucket, 'test-add-search@gmail.com');
+
+ done();
});
+});
View
87 test/http-client-siblings-test.js
@@ -1,39 +1,50 @@
-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, accept: 'multipart/mixed,application/json;q=0.7, */*;q=0.5'}),
- bucket = 'siblings';
-
-seq()
- .seq(function() {
- test('Enable siblings');
- db.saveBucket(bucket, {allow_mult: true}, this);
- })
- .seq(function() {
- test('Delete existing objects');
- db.remove(bucket, 'haensel', function() {
- this.ok();
- }.bind(this));
- })
- .seq(function() {
- test('Create first sibling');
- db.save(bucket, 'haensel', {eats: 'lebkuchen'}, function() {
- this.ok();
- }.bind(this));
- })
- .seq(function() {
- test('Create second sibling');
- db.save(bucket, 'haensel', {likes: 'lebkuchen'}, function() {
- this.ok()
- }.bind(this));
- })
- .seq(function() {
- db.get(bucket, 'haensel', function(err, data, meta) {
- assert.equal(data.length, 2)
- this.ok();
- }.bind(this));
+var HttpClient = require('../lib/http-client'),
+ HttpMeta = require('../lib/http-meta'),
+ should = require('should'),
+ util = require('util');
+
+var db, bucket;
+
+describe('http-client-siblings-tests', function() {
+ before(function(done) {
+ db = new HttpClient({
+ port: 8098,
+ accept: 'multipart/mixed,application/json;q=0.7, */*;q=0.5'
+ });
+
+ // Ensure unit tests don't collide with pre-existing buckets
+ bucket = 'siblings-riak-js-tests';
+
+ done();
+ });
+
+ it('Enable siblings', function(done) {
+ db.saveBucket(bucket, {allow_mult: true}, function(err) {
+ should.not.exist(err);
+ done();
+ });
+ });
+
+ it('Create and get siblings', function(done) {
+ db.save(bucket, 'haensel', {eats: 'lebkuchen'}, function(err) {
+ should.not.exist(err);
+ db.save(bucket, 'haensel', {likes: 'lebkuchen'}, function(err) {
+ should.not.exist(err);
+ db.get(bucket, 'haensel', function(err, data, meta) {
+ should.not.exist(err);
+ should.exist(data);
+ data.length.should.equal(2);
+
+ done();
+ });
+ });
+ });
+ });
+
+ after(function(done) {
+ db.remove(bucket, 'haensel', function(err) {
+ should.not.exist(err);
+ done();
+ });
});
+});
View
666 test/http-client-test.js
@@ -1,308 +1,384 @@
var HttpClient = require('../lib/http-client'),
HttpMeta = require('../lib/http-meta'),
- seq = require('seq'),
+ async = require('async'),
util = require('util'),
- assert = require('assert'),
- test = require('../lib/utils').test;
+ should = require('should');
-var db = new HttpClient({ port: 8098 }),
- db2 = new HttpClient({ port: 64208 }),
- many = [];
-for (var i = 0; i < 600; i++) many.push(String(i));
+var db, db2, many = [], bucket;
/* Tests */
-seq()
-
- .seq(function() {
- test('Save with returnbody');
- db.save('users', 'test-returnbody@gmail.com', { email: 'test@gmail.com', name: 'Testy Test', a: [1,2], returnbody: 'yes please' }, { returnbody: true }, function(err, data, meta) {
- assert.equal(meta.statusCode, 200);
- assert.ok(data);
- assert.deepEqual(data.a, [1,2]);
- assert.equal(meta.key, 'test-returnbody@gmail.com');
- this.ok();
- }.bind(this));
- })
-
- .seq(function() {
- test('Save');
- db.save('users', 'test@gmail.com', "Some text", function(err, data, meta) {
- assert.equal(meta.statusCode, 204);
- assert.ok(!data);
- assert.equal(meta.key, 'test@gmail.com');
- this.ok();
- }.bind(this));
- })
-
- .seq(function() {
- test('Get with no options or callback');
- db.get('users', 'test@gmail.com', this);
- })
- .seq(function(doc2) {
- assert.equal(doc2, "Some text");
- this.ok();
- })
-
- .seq(function() {
- test('Store plain text with unicode in it');
- db.save('users', 'text-user', 'tét', function() {
- db.get('users', 'text-user', this);
- }.bind(this));
- })
- .seq(function(text) {
- assert.equal(new Buffer(text).length, 4);
- assert.equal(text, 'tét');
- this.ok();
- })
- .seq(function() {
- test("Get all");
- db.getAll('users', this);
- })
-
- .seq(function(users) {
- assert.ok(Array.isArray(users));
- assert.ok(users.some(function(u) { return u == "Some text" }));
- this.ok();
- })
-
- .seq(function() {
- test('Head request');
- db.head('users', 'test@gmail.com', function(err, data, meta) {
- assert.ok(!err && !data);
- assert.ok(meta.statusCode === 200);
- this.ok();
- }.bind(this));
- })
-
- .seq(function() {
- test('Storing document with links');
- db.save('users', 'other@gmail.com', {name: "Other Dude"}, {links: [{bucket: 'users', key: 'test@gmail.com'}]}, function(erro, data, meta) {
- assert.ok(meta.statusCode === 204);
- this.ok();
- }.bind(this));
- })
- .seq(function() {
- test('Fetching a document with links');
- db.get('users', 'other@gmail.com', function(err, data, meta) {
- this.ok(meta);
- }.bind(this));
- })
- .seq(function(meta) {
- test('Includes links in the meta object');
- assert.equal(meta.links.length, 1);
- this.ok(meta);
- })
- .seq(function(meta) {
- test("Doesn't store undefined for empty tags");
- assert.equal(meta.links[0].tag, '_');
- this.ok();
- })
- .seq(function(){
- test("Fetch via Linkwalk");
- db.walk('users', 'other@gmail.com', [{bucket: 'users'}], function(err, data, meta){
- assert.equal(data.length, 1);
- assert.equal(data[0].length, 1);
- assert.ok(data[0][0].meta);
- assert.ok(data[0][0].data);
- this.ok();
- }.bind(this));
- })
- .seq(function() {
- test("Vector clock not overwritten on link walk");
- db.walk('users', 'other@gmail.com', [{bucket: 'users'}], function(err, data, meta) {
- assert.ok(data[0][0].meta.vclock);
- this.ok();
- }.bind(this));
- })
- .seq(function() {
- test('Reusing meta object');
- db.get('users', 'test@gmail.com', function(err, data, meta) {
- this.ok(data, meta);
- }.bind(this));
- })
- .seq(function(user, meta) {
- db.save('users', 'test@gmail.com', user, meta, function(err, data, meta) {
- this.ok(meta);
- }.bind(this));
- })
- .seq(function(meta) {
- assert.equal(meta.statusCode, 204);
- this.ok();
- })
- .seq(function() {
- test('Remove document');
- db.remove('users', 'test@gmail.com', function(err, data, meta) {
- assert.equal(meta.statusCode, 204);
- this.ok();
- }.bind(this));
- })
-
- .seq(function() {
- test('Document exists');
- db.exists('users', 'test@gmail.com', function(err, does, meta) {
- assert.equal(meta.statusCode, 404);
- assert.equal(does, false);
- this.ok();
- }.bind(this));
- })
-
- .seq(function() {
- test('Get non-existent document');
- db.get('users', 'test@gmail.com', function(err, does, meta) {
- assert.equal(err.message, 'not found');
- assert.equal(meta.statusCode, 404);
- this.ok();
- }.bind(this));
- })
-
- .seq(function() {
- test('Get non-existent document, ignoring the not found error');
- db.get('users', 'test@gmail.com', { noError404: true }, this);
- // no error should be returned
- })
-
-
- .seq(function() {
- test('Ensure a second riak-js instance does not inherit settings from the first one');
-
- // we're expecting this instance to be down (listening on port 64208)
- db2.on('error', function(err) {
- assert.ok(err);
- this.ok();
- }.bind(this));
-
- db2.get('users', 'test@gmail.com');
- })
-
- .seq(function() {
- test('Ensure riak-js gracefully handles a down riak connection');
- db2.get('users', 'test@gmail.com', function(err, user, meta) {
- assert.ok(err);
+describe('http-client-tests', function() {
+ before(function(done) {
+ db = new HttpClient({ port: 8098 });
+ db2 = new HttpClient({ port: 64208 });
+ for (var i = 0; i < 600; i++) {
+ many.push(String(i));
+ }
+ // Ensure unit tests don't collide with pre-existing buckets
+ bucket = 'users-riak-js-tests';
+
+ done();
+ });
+
+ it('Save with returnbody', function(done) {
+ db.save(bucket, 'test-returnbody@gmail.com',
+ { email: 'test@gmail.com',
+ name: 'Testy Test',
+ a: [1, 2],
+ returnbody: 'yes please' },
+ { returnbody: true },
+ function(err, data, meta) {
+ should.not.exist(err);
+ meta.statusCode.should.equal(200);
+ should.exist(data);
+ data.a.should.eql([1, 2]);
+ meta.key.should.equal('test-returnbody@gmail.com');
+
+ done();
+ });
+ });
+
+ it('Save', function(done) {
+ db.save(bucket, 'test@gmail.com', 'Some text', function(err, data, meta) {
+ should.not.exist(err);
+ should.not.exist(data);
+ meta.key.should.equal('test@gmail.com');
+
+ done();
+ });
+ });
+
+ it('Get with no options', function(done) {
+ db.get(bucket, 'test@gmail.com', function(err, document) {
+ should.not.exist(err);
+ should.exist(document);
+ document.should.equal('Some text');
+
+ done();
+ });
+ });
+
+ it('Store plain text with unicode in it', function(done) {
+ db.save(bucket, 'text-with-unicode', 'tét', function(err) {
+ should.not.exist(err);
+
+ db.get(bucket, 'text-with-unicode', function(err, document) {
+ should.not.exist(err);
+ should.exist(document);
+ new Buffer(document).length.should.equal(4);
+ document.should.equal('tét');
+
+ done();
+ });
+ });
+ });
+
+ it('Get all', function(done) {
+ db.getAll(bucket, function(err, documents) {
+ should.not.exist(err);
+ should.exist(documents);
+ documents.should.be.an.instanceof(Array);
+ // TODO get this to properly match expected contents
+ //documents.should.includeEql('some text');
+
+ done();
+ });
+ });
+
+ it('Head Request', function(done) {
+ db.head(bucket, 'test@gmail.com', function(err, data, meta) {
+ should.not.exist(err);
+ should.not.exist(data);
+ should.exist(meta);
+ meta.statusCode.should.equal(200);
+
+ done();
+ });
+ });
+
+ it('Storing document with links', function(done) {
+ db.save(bucket, 'other@gmail.com',
+ { name: 'Other Dude' },
+ { links: [
+ { bucket: bucket, key: 'test@gmail.com' }
+ ]}, function(err, data, meta) {
+ should.not.exist(err);
+ should.not.exist(data);
+ should.exist(meta);
+ meta.statusCode.should.equal(204);
+
+ done();
+ });
+ });
+
+ it('Fetching a document with links', function(done) {
+ db.get(bucket, 'other@gmail.com', function(err, data, meta) {
+ should.not.exist(err);
+ should.exist(data);
+ should.exist(meta);
+ meta.links.length.should.equal(1);
+ meta.links[0].tag.should.equal('_');
+
+ done();
+ });
+ });
+
+ it('Fetch via Linkwalk', function(done) {
+ db.walk(bucket, 'other@gmail.com', [
+ {bucket: bucket}
+ ],
+ function(err, data, meta) {
+ should.not.exist(err);
+ should.exist(data);
+ data.length.should.equal(1);
+ data[0].length.should.equal(1);
+ should.exist(data[0][0].meta);
+ should.exist(data[0][0].data);
+
+ done();
+ });
+ });
+
+ it('Vector clock not overwritten on link walk', function(done) {
+ db.walk(bucket, 'other@gmail.com', [
+ {bucket: bucket}
+ ],
+ function(err, data, meta) {
+ should.not.exist(err);
+ should.exist(data);
+ data.length.should.equal(1);
+ data[0].length.should.equal(1);
+ should.exist(data[0][0].meta);
+ should.exist(data[0][0].data);
+ should.exist(data[0][0].meta.vclock);
+
+ done();
+ });
+ });
+
+ it('Reusing meta object', function(done) {
+ db.get(bucket, 'test@gmail.com', function(err, data, meta) {
+ should.not.exist(err);
+ should.exist(data);
+ should.exist(meta);
+
+ db.save(bucket, 'test@gmail.com', data, meta, function(err, data, meta) {
+ should.not.exist(err);
+ should.exist(meta);
+ meta.statusCode.should.equal(204);
+
+ done();
+ });
+ });
+ });
+
+ it('Remove document', function(done) {
+ db.remove(bucket, 'test@gmail.com', function(err, data, meta) {
+ should.not.exist(err);
+ should.exist(meta);
+ meta.statusCode.should.equal(204);
+
+ done();
});
- })
-
- .seq(function() {
- test('Save with returnbody=true actually returns the body');
- db.save('users', 'test2@gmail.com', { user: 'test2@gmail.com' }, { returnbody: true }, this);
- })
- .seq(function(doc) {
- assert.ok(doc);
- assert.equal(doc.user, 'test2@gmail.com');
- setTimeout(this.ok, 3000); // wait for damn dead horse riak; see https://issues.basho.com/show_bug.cgi?id=1269
- })
-
- .set(many)
- .flatten()
- .parEach(20, function(key) {
- db.save('test', key, key, this);
- })
-
- .seq(function() {
- test("Stream keys");
- var buf = [],
- keys = function(keys) { buf = buf.concat(keys) },
- end = function() {
- // keys come in random order, need to sort both arrays by string in order to compare
- buf = buf.sort(); many = many.sort();
- assert.deepEqual(many, buf);
- this.ok();
- }.bind(this);
-
- db
- .keys('test')
- .on('keys', keys)
- .on('end', end)
- .start();
- })
-
- .seq(function() {
- test("Count keys");
- db.count('test', this);
- })
- .seq(function(total) {
- assert.equal(total, many.length);
- this.ok();
- })
- .seq(function() {
- test("Secondary indices");
- db.save('users', 'fran@gmail.com', { age: 28 }, { index: { age: 28, alias: 'fran' } }, this);
- })
- .seq(function() {
- db.query('users', { age: [20,30] }, this);
- })
- .seq(function(keys) {
- assert.equal(keys[0], 'fran@gmail.com');
- this.ok();
- })
- .seq(function() {
- db.query('users', { alias: 'fran' }, this);
- })
- .seq(function(keys) {
- assert.equal(keys[0], 'fran@gmail.com');
- this.ok();
- })
-
- .seq(function() {
- test('Buckets is an Array');
- db.buckets(this);
- })
- .seq(function(buckets) {
- assert.ok(Array.isArray(buckets));
- this.ok(buckets);
- })
-
- .seq(function(buckets) {
- test('Get the properties of a bucket');
- var bucket = buckets[0];
- db.getBucket(bucket, this);
- })
- .seq(function(props) {
- assert.ok(props && props.r);
- this.ok()
- })
-
- .seq(function() {
- test("List resources");
- db.resources(this);
- })
- .seq(function(resources) {
- assert.ok(resources && resources.riak_kv_wm_buckets);
- this.ok();
- })
-
- .seq(function() {
- test('Ping');
- db.ping(this);
- })
- .seq(function(pong) {
- assert.ok(pong);
- this.ok()
- })
-
- .seq(function() {
- test('Stats');
- db.stats(this);
- })
- .seq(function(stats) {
- assert.ok(stats.riak_core_version);
- this.ok();
- })
-
- .seq(function() {
- test('Custom Meta');
+ });
+
+ it('Document exists', function(done) {
+ db.exists(bucket, 'test@gmail.com', function(err, data, meta) {
+ should.not.exist(err);
+ data.should.equal(false);
+ should.exist(meta);
+ meta.statusCode.should.equal(404);
+
+ done();
+ });
+ });
+
+ it('Get non-existent document', function(done) {
+ db.get(bucket, 'test@gmail.com', function(err, data, meta) {
+ should.exist(err);
+ should.exist(data);
+ data.notFound.should.equal(true);
+ should.exist(meta);
+ meta.statusCode.should.equal(404);
+
+ done();
+ });
+ });
+
+ it('Get non-existent document, ignoring not found error', function(done) {
+ db.get(bucket, 'test@gmail.com', { noError404: true },
+ function(err, data, meta) {
+ should.not.exist(err);
+ should.exist(data);
+ data.statusCode.should.equal(404);
+ should.exist(meta);
+ meta.statusCode.should.equal(404);
+
+ done();
+ });
+ });
+
+ it('Ensure a second riak-js instance does not inherit settings from the first one', function(done) {
+ db2.get(bucket, 'test@gmail.com', function(err, data, meta) {
+ should.exist(err);
+ should.not.exist(data);
+ should.not.exist(meta);
+
+ done();
+ });
+ });
+
+ it('Save with returnbody=true actually returns the body', function(done) {
+ db.save(bucket, 'test2@gmail.com',
+ { user: 'test2@gmail.com' },
+ { returnbody: true },
+ function(err, data, meta) {
+ should.not.exist(err);
+ should.exist(data);
+ data.should.eql({ user: 'test2@gmail.com' });
+
+ done();
+ });
+ });
+
+ it('Stream Keys', function(done) {
+ async.forEachLimit(many, 10, function(key, next) {
+ db.save(bucket + '-keys', key, key, function(err) {
+ should.not.exist(err);
+ next();
+ });
+ }, function() {
+ var buf = [],
+ keys = function(keys) {
+ buf = buf.concat(keys)
+ },
+ end = function() {
+ // keys come in random order, need to sort
+ // both arrays by string in order to compare
+ buf = buf.sort();
+ many = many.sort();
+ many.should.eql(buf);
+ done();
+ };
+
+ db.keys(bucket + '-keys')
+ .on('keys', keys)
+ .on('end', end)
+ .start();
+ });
+ });
+
+ it('Count Keys', function(done) {
+ db.count(bucket + '-keys', function(err, total) {
+ should.not.exist(err);
+ should.exist(total);
+ total.should.equal(many.length);
+
+ done();
+ });
+ });
+
+ it('Secondary Indices', function(done) {
+ db.save(bucket, 'fran@gmail.com',
+ { age: 28 },
+ { index: { age: 28, alias: 'fran' } },
+ function(err, data, meta) {
+ should.not.exist(err);
+ async.parallel([
+ function(callback) {
+ db.query(bucket, { age: [20, 30] }, function(err, results) {
+ should.not.exist(err);
+ should.exist(results);
+ results.length.should.equal(1);
+ results[0].should.equal('fran@gmail.com');
+
+ callback();
+ });
+ }, function(callback) {
+ db.query(bucket, { alias: 'fran' }, function(err, results) {
+ should.not.exist(err);
+ should.exist(results);
+ results.length.should.equal(1);
+ results[0].should.equal('fran@gmail.com');
+
+ callback();
+ });
+ }], function() {
+ done();
+ });
+ });
+ });
+
+ it('Buckets is an Array', function(done) {
+ db.buckets(function(err, buckets) {
+ should.not.exist(err);
+ should.exist(buckets);
+ buckets.should.be.an.instanceof(Array);
+
+ done();
+ });
+ });
+
+ it('Get the properties of a bucket', function(done) {
+ db.buckets(function(err, buckets) {
+ should.not.exist(err);
+ should.exist(buckets);
+ buckets.should.be.an.instanceof(Array);
+
+ var bucket = buckets[0];
+
+ db.getBucket(bucket, function(err, data) {
+ should.not.exist(err);
+ should.exist(data);
+ should.exist(data.r);
+
+ done();
+ });
+ });
+ });
+
+ it('List Resources', function(done) {
+ db.resources(function(err, resources) {
+ should.not.exist(err);
+ should.exist(resources);
+ should.exist(resources.riak_kv_wm_buckets);
+
+ done();
+ });
+ });
+
+ it('Ping', function(done) {
+ db.ping(function(err, pong) {
+ should.not.exist(err);
+ should.exist(pong);
+
+ done();
+ });
+ });
+
+ it('Stats', function(done) {
+ db.stats(function(err, stats) {
+ should.not.exist(err);
+ should.exist(stats);
+ should.exist(stats.riak_core_version);
+
+ done();
+ });
+ });
+
+ it('Custom Meta', function(done) {
var meta = new CustomMeta();
- db.get('users', 'test2@gmail.com', meta, this);
- })
- .seq(function(user) {
- assert.equal(user.intercepted, true);
- this.ok();
- })
- .catch(function(err) {
- console.log(err.stack);
- process.exit(1);
+ db.get(bucket, 'test2@gmail.com', meta, function(err, document) {
+ should.not.exist(err);
+ should.exist(document);
+ document.intercepted.should.equal(true);
+
+ done();
+ });
});
-
+});
+
/* Custom Meta */
var CustomMeta = function() {
View
36 test/http-connection-test.js
@@ -1,17 +1,27 @@
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;
+ should = require('should');
-var db = new HttpClient({ port: 64208 });
+var db, bucket;
-seq().
- seq(function() {
- test("Connection to an unavailable port shouldn't fail the process");
- db.get('users', 'test', function(err) {
- assert.ok(err);
- this.ok();
- }.bind(this));
+/* Tests */
+
+describe('http-connection-tests', function() {
+ before(function(done) {
+ db = new HttpClient({ port: 64208 });
+
+ // Ensure unit tests don't collide with pre-existing buckets
+ bucket = 'users-riak-js-tests';
+
+ done();
+ });
+
+ it('Connection to an unavailable port shouldn\'t fail the process', function(done) {
+ db.get(bucket, 'test@gmail.com', function(err, data, meta) {
+ should.exist(err);
+ should.not.exist(data);
+ should.not.exist(meta);
+
+ done();
+ });
});
+});
View
202 test/http-mapreduce-client-test.js
@@ -1,99 +1,121 @@
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;
+ should = require('should');
-var db = new HttpClient({ port: 8098 });
+var db, bucket;
/* Tests */
-seq()
-
- .seq(function() {
- test('Clear database');
- db.remove('map-users', 'test@gmail.com', function() {
- db.remove('map-users', 'other@gmail.com', function() {
- this.ok()
- }.bind(this));
- }.bind(this));
- })
- .seq(function() {
- test('Create object');
- db.save('map-users', 'test@gmail.com', {name: "Sean Cribbs"}, function(err, data, meta) {
- db.save('map-users', 'other@gmail.com', {name: "Mathias Meyer"}, function(err, data, meta) {
- this.ok();
- }.bind(this));
- }.bind(this));
- })
- .seq(function() {
- test('Map');
- db.mapreduce.add('map-users').map('Riak.mapValuesJson').run(this);
- })
- .seq(function(data) {
- test('Successful response');
- assert.ok(data);
- this.ok(data);
- })
- .seq(function(data) {
- test('Returns and evaluates array of JSON objects');
- assert.equal(data.length, 2);
- assert.notEqual(data[0].name, null);
- this.ok();
- })
- .seq(function() {
- test('Custom Map JavaScript functions');
- db.mapreduce.add('map-users').map(function(value, keyData, args) {
+describe('http-mapreduce-client-tests', function() {
+ before(function(done) {
+ db = new HttpClient({ port: 8098 });
+
+ // Ensure unit tests don't collide with pre-existing buckets
+ bucket = 'map-users-riak-js-tests';
+
+ db.save(bucket, 'test@gmail.com', {name: "Sean Cribbs"}, function(err, data, meta) {
+ should.not.exist(err);
+ db.save(bucket, 'other@gmail.com', {name: "Mathias Meyer"}, function(err, data, meta) {
+ should.not.exist(err);
+ done();
+ });
+ });
+ });
+
+ it('Map to an array of JSON objects', function(done) {
+ db.mapreduce.add(bucket).map('Riak.mapValuesJson').run(function(err, data) {
+ should.not.exist(err);
+ should.exist(data);
+ data.length.should.equal(2);
+
+ for (var i = 0; i < data.length; i++) {
+ should.exist(data[i].name);
+ }
+
+ done();
+ });
+ });
+
+ it('Map to a custom function', function(done) {
+ db.mapreduce.add(bucket).map(function(value, keyData, args){
return ['custom'];
- }).run(this);
- })
- .seq(function(data) {
- test('Custom Map function response');
- assert.equal(data[0], 'custom');
- this.ok();
- })
- .seq(function() {
- test('Map with arguments');
- db.mapreduce.add('map-users').map('Riak.mapByFields', {name: 'Sean Cribbs'}).run(this);
- })
- .seq(function(data) {
- test('Successful response');
- assert.equal(data[0].name, 'Sean Cribbs');
- this.ok();
- })
- .seq(function() {
- test('Reduce');
- db.mapreduce.add('map-users').map('Riak.mapByFields', {name: 'Sean Cribbs'}).reduce('Riak.reduceLimit', 2).run(this);
- })
- .seq(function(data) {
- test('Reduce response');
- assert.equal(data.length, 1);
- this.ok();
- })
- .seq(function() {
- test('Map Erlang functions');
- db.mapreduce.add('map-users').map({language: 'erlang', module: 'riak_kv_mapreduce', function: 'map_object_value'}).run(this);
- })
- .seq(function(data) {
- test('Erlang response');
- assert.equal(data.length, 2);
- this.ok();
- })
- .seq(function() {
- test('Chain phases with bucket inputs');
- db.mapreduce.add([['map-users', 'test@gmail.com']]).map(function(value) {
- return [['map-users', 'other@gmail.com']];
- }).map('Riak.mapValuesJson').run(this);
- })
- .seq(function(data) {
- assert.equal(data[0].name, "Mathias Meyer");
- this.ok();
- })
- .catch(function(err) {
- console.log(err)
- console.log(err.stack);
- process.exit(1);
- })
-
+ }).run(function(err, data) {
+ should.not.exist(err);
+ should.exist(data);
+ data.length.should.equal(2);
+
+ for (var i = 0; i < data.length; i++) {
+ data[i].should.equal('custom');
+ }
+
+ done();
+ });
+ });
+
+ it('Map with arguments', function(done) {
+ db.mapreduce.add(bucket).map('Riak.mapByFields', {
+ name: 'Sean Cribbs'
+ }).run(function(err, data) {
+ should.not.exist(err);
+ should.exist(data);
+ data.length.should.equal(1);
+ data[0].name.should.equal('Sean Cribbs');
+ done();
+ });
+ });
+
+ // TODO not sure this has the correct prerequisites
+ it('Map/Reduce', function(done) {
+ db.mapreduce.add(bucket).map('Riak.mapByFields', {
+ name: 'Sean Cribbs'
+ }).reduce('Riak.reduceLimit', 2)
+ .run(function(err, data) {
+ should.not.exist(err);
+ should.exist(data);
+ data.length.should.equal(1);
+ done();
+ });
+ });
+
+ it('Map Erlang functions', function(done) {
+ db.mapreduce.add(bucket).map({
+ language: 'erlang',
+ module: 'riak_kv_mapreduce',
+ function: 'map_object_value'})
+ .run(function(err, data) {
+ should.not.exist(err);
+ should.exist(data);
+ data.length.should.equal(2);
+ done();
+ });
+ });
+
+ // TODO figure out why this isn't passing. It seems like straight port from
+ // the previous tests
+ it('Chain phases with bucket inputs', function(done) {
+ db.mapreduce.add([
+ [bucket, 'test@gmail.com']
+ ]).map(function(value) {
+ return [
+ [bucket, 'other@gmail.com']
+ ];
+ })
+ .map('Riak.mapValuesJson')
+ .run(function(err, data) {
+ console.dir(err.message);
+ should.not.exist(err);
+ should.exist(data);
+ data[0].name.should.equal('Mathias Meyer');
+ done();
+ });
+ });
+ after(function(done) {
+ db.remove(bucket, 'test@gmail.com', function() {
+ db.remove(bucket, 'other@gmail.com', function() {
+ done();
+ });
+ });
+ });
+});
View
399 test/http-meta-test.js
@@ -1,168 +1,241 @@
var Meta = require('../lib/http-meta'),
- assert = require('assert'),
- test = require('../lib/utils').test,
+ should = require('should'),
fs = require('fs');
-test('Sets its attributes');
-
-var meta = new Meta({ bucket: 'bucket', key: 'key', contentType: 'png', data: 'd32n92390XMIW0' });
-
-assert.equal(meta.bucket, 'bucket');
-assert.equal(meta.key, 'key');
-assert.equal(meta.vclock, null);
-assert.equal(meta.contentType, 'image/png');
-assert.equal(meta.data, 'd32n92390XMIW0');
-
-test('Gives back its HTTP path');
-
-meta = new Meta({ bucket: 'bucket', key: 'key' });
-assert.equal("/riak/bucket/key", meta.path);
-
-meta.resource = 'luwak';
-meta.bucket = '';
-assert.equal("/luwak/key", meta.path);
-
-test('Parses headers when loaded with a Riak HTTP response');
-
-var riakResponse = {
- httpVersion: '1.1',
- headers: {
- vary: 'Accept-Encoding',
- server: 'MochiWeb/1.1 WebMachine/1.7.1 (participate in the frantic)',
- 'x-riak-vclock': 'a85hYGBgzGDKBVIsbLvm1WYwJTLmsTLcjeE5ypcFAA==',
- 'x-riak-meta-acl': 'users:r,administrators:f',
- link: '</riak/test>; rel="up", </riak/test/doc%252%24%40>; riaktag="next"',
- 'last-modified': 'Wed, 10 Mar 2010 18:11:41 GMT',
- etag: '6dQBm9oYA1mxRSH0e96l5W',
- date: 'Wed, 10 Mar 2010 18:11:52 GMT',
- 'content-type': 'text/rtf',
- 'content-length': '2946'
- },
- statusCode: 200
-}
-
-meta = new Meta({ bucket: 'bucket', key: 'key' });
-meta.loadResponse(riakResponse);
-
-// assert.deepEqual(meta.usermeta, { acl: 'users:r,administrators:f' }); -- usermeta is not supported
-assert.equal(meta.statusCode, 200);
-assert.equal(new Date(meta.date).getTime(), 1268244712000);
-assert.equal(new Date(meta.lastMod).getTime(), 1268244701000);
-// assert.deepEqual(meta.links, [{ bucket: 'test', key: 'doc%2$@', tag: 'next' }]); -- not yet implemented
-assert.equal(meta.contentType, 'text/rtf');
-assert.equal(meta.path, '/riak/bucket/key');
-
-test('Custom headers are correctly included and override');
-
-meta = new Meta({
- links: [{ bucket: 'test', key: 'doc%2$@', tag: 'next' }],
- headers: { Authorization: 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', 'X-Riak-Meta-fire': 'yes' }
+describe('http-meta-tests', function() {
+ it('Set Meta Attributes', function(done) {
+ var meta = new Meta({ bucket: 'bucket', key: 'key', contentType: 'png', data: 'd32n92390XMIW0' });
+ meta.bucket.should.equal('bucket');
+ meta.key.should.equal('key');
+ should.not.exist(meta.vclock);
+ meta.contentType.should.equal('image/png');
+ meta.data.toString().should.equal('d32n92390XMIW0');
+
+ done();
+ });
+
+ it('Gives back its HTTP path', function(done) {
+ var meta = new Meta({ bucket: 'bucket', key: 'key' });
+ meta.path.should.equal('/riak/bucket/key');
+ meta.resource = 'luwak';
+ meta.bucket = '';
+ meta.path.should.equal('/luwak/key');
+
+ done();
+ });
+
+ it('Parses headers when loaded with a Riak HTTP response', function(done) {
+ var riakResponse = {
+ httpVersion: '1.1',
+ headers: {
+ vary: 'Accept-Encoding',
+ server: 'MochiWeb/1.1 WebMachine/1.7.1 (participate in the frantic)',
+ 'x-riak-vclock': 'a85hYGBgzGDKBVIsbLvm1WYwJTLmsTLcjeE5ypcFAA==',
+ 'x-riak-meta-acl': 'users:r,administrators:f',
+ link: '</riak/test>; rel="up", </riak/test/doc%252%24%40>; riaktag="next"',
+ 'last-modified': 'Wed, 10 Mar 2010 18:11:41 GMT',
+ etag: '6dQBm9oYA1mxRSH0e96l5W',
+ date: 'Wed, 10 Mar 2010 18:11:52 GMT',
+ 'content-type': 'text/rtf',
+ 'content-length': '2946'
+ },
+ statusCode: 200
+ }
+
+ var meta = new Meta({ bucket: 'bucket', key: 'key' });
+ meta.loadResponse(riakResponse);
+
+ // assert.deepEqual(meta.usermeta, { acl: 'users:r,administrators:f' }); -- usermeta is not supported
+ meta.statusCode.should.equal(200);
+ new Date(meta.date).getTime().should.equal(1268244712000);
+ new Date(meta.lastMod).getTime().should.equal(1268244701000);
+ meta.contentType.should.equal('text/rtf');
+ meta.path.should.equal('/riak/bucket/key');
+
+ done();
+ });
+
+ it('Custom headers are correctly included and override', function(done) {
+
+ var meta = new Meta({
+ links: [
+ { bucket: 'test', key: 'doc%2$@', tag: 'next' }
+ ],
+ headers: { Authorization: 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', 'X-Riak-Meta-fire': 'yes' }
+ });
+
+ should.not.exist(meta.headers.statusCode);
+ meta.headers['X-Riak-Meta-fire'].should.equal('yes');
+ // meta.headers['Link'].should.equal('</riak/test/doc%252%24%40>; riaktag="next"'); -- not yet implemented
+ meta.headers['Authorization'].should.equal('Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==');
+ done();
+
+ });
+
+ it('It returns its location from a POST request', function(done) {
+ var riakResponse = {
+ headers: {
+ location: '/riak/test/bzPygTesROPtGGVUKfyvp2RR49'
+ },
+ statusCode: 201
+ };
+
+ var meta = new Meta();
+ meta.loadResponse(riakResponse);
+
+ meta.key.should.equal('bzPygTesROPtGGVUKfyvp2RR49');
+ meta.statusCode.should.equal(201);
+ done();
+ });
+
+ it('It guesses its content type', function(done) {
+ var headers = new Meta({ data: { test: true } }).headers;
+
+ headers['content-type'].should.equal('application/json');
+ should.not.exist(headers['link']);
+
+ done();
+ });
+
+ it('Does not send clientId if there is no vclock', function(done) {
+ var headers = new Meta().headers;
+
+ should.not.exist(headers['x-riak-clientId']);
+
+ done();
+ });
+
+ it('It returns its full path including query properties', function(done) {
+ var meta = new Meta({
+ bucket: 'bucket',
+ key: 'key',
+ r: 1,
+ w: 2,
+ dw: 2,
+ rw: 2,
+ keys: true,
+ props: false,
+ vtag: 'asweetvtag',
+ returnbody: true,
+ chunked: true
+ });
+
+ meta.path.should.equal('/riak/bucket/key?r=1&w=2&dw=2&rw=2&keys=true&props=false&vtag=asweetvtag&returnbody=true&chunked=true');
+
+ done();
+ });
+
+ it('Returns an URI-encoded path if used with encodeUri option', function(done) {
+ var meta = new Meta({
+ bucket: 'spåce bucket',
+ key: 'çøµπléx–key',
+ encodeUri: true
+ });
+
+ meta.path.should.equal('/riak/sp%C3%A5ce%20bucket/%C3%A7%C3%B8%C2%B5%CF%80l%C3%A9x%E2%80%93key');
+
+ done();
+ });
+
+ it('Sets a boundary when response is multipart', function(done) {
+ var meta = new Meta({
+ });
+
+ var multipartResponse = {
+ httpVersion: '1.1',
+ headers: {
+ vary: 'Accept-Encoding',
+ server: 'MochiWeb/1.1 WebMachine/1.7.1 (participate in the frantic)',
+ 'x-riak-vclock': 'a85hYGBgzGDKBVIsbLvm1WYwJTLmsTLcjeE5ypcFAA==',
+ 'x-riak-meta-acl': 'users:r,administrators:f',
+ link: '</riak/test>; rel="up", </riak/test/doc%252%24%40>; riaktag="next"',
+ 'last-modified': 'Wed, 10 Mar 2010 18:11:41 GMT',
+ etag: '6dQBm9oYA1mxRSH0e96l5W',
+ date: 'Wed, 10 Mar 2010 18:11:52 GMT',
+ 'content-type': 'multipart/mixed; boundary=59RSLp9FHlsTnSGjjlVsrs0Aud',
+ 'content-length': '2946'
+ },
+ statusCode: 200
+ };
+
+ meta.loadResponse(multipartResponse);
+ meta.boundary.should.equal('59RSLp9FHlsTnSGjjlVsrs0Aud');
+
+ done();
+ });
+
+ it('Parsing the multipart body', function(done) {
+
+ var meta = new Meta({
+ });
+
+ var multipartResponse = {
+ httpVersion: '1.1',
+ headers: {
+ vary: 'Accept-Encoding',
+ server: 'MochiWeb/1.1 WebMachine/1.7.1 (participate in the frantic)',
+ 'x-riak-vclock': 'a85hYGBgzGDKBVIsbLvm1WYwJTLmsTLcjeE5ypcFAA==',
+ 'x-riak-meta-acl': 'users:r,administrators:f',
+ link: '</riak/test>; rel="up", </riak/test/doc%252%24%40>; riaktag="next"',
+ 'last-modified': 'Wed, 10 Mar 2010 18:11:41 GMT',
+ etag: '6dQBm9oYA1mxRSH0e96l5W',
+ date: 'Wed, 10 Mar 2010 18:11:52 GMT',
+ 'content-type': 'multipart/mixed; boundary=59RSLp9FHlsTnSGjjlVsrs0Aud',
+ 'content-length': '2946'
+ },
+ statusCode: 200
+ };
+
+ meta.loadResponse(multipartResponse);
+ meta.boundary.should.equal('59RSLp9FHlsTnSGjjlVsrs0Aud');
+
+ var multipartMessage = fs.readFileSync(__dirname + '/fixtures/multipart');
+ var parts = meta._parseMultipartMixed(multipartMessage);
+
+ parts.length.should.equal(2);
+ parts[0].body.should.equal('{"likes":"lebkuchen"}');
+ parts[1].body.should.equal('{"eats":"lebkuchen"}');
+
+ parts[0].headers['content-type'].should.equal('application/json');
+ parts[1].headers['content-type'].should.equal('application/json');
+
+ parts[0].headers['etag'].should.equal('4w0Pmt0N1yXnR1ecZiFxPi');
+ parts[1].headers['etag'].should.equal('p8gYGbYxc78iCllp9PqkK');
+
+ done();
+ });
+
+ it('Parsing more than 2 siblings', function(done) {
+
+ var meta = new Meta({
+ });
+
+ var multipartResponse = {
+ httpVersion: '1.1',
+ headers: {
+ vary: 'Accept-Encoding',
+ server: 'MochiWeb/1.1 WebMachine/1.7.1 (participate in the frantic)',
+ 'x-riak-vclock': 'a85hYGBgzGDKBVIsbLvm1WYwJTLmsTLcjeE5ypcFAA==',
+ 'x-riak-meta-acl': 'users:r,administrators:f',
+ link: '</riak/test>; rel="up", </riak/test/doc%252%24%40>; riaktag="next"',
+ 'last-modified': 'Wed, 10 Mar 2010 18:11:41 GMT',
+ etag: '6dQBm9oYA1mxRSH0e96l5W',
+ date: 'Wed, 10 Mar 2010 18:11:52 GMT',
+ 'content-type': 'multipart/mixed; boundary=59RSLp9FHlsTnSGjjlVsrs0Aud',
+ 'content-length': '2946'
+ },
+ statusCode: 200
+ };
+
+ meta.loadResponse(multipartResponse);
+ meta.boundary.should.equal('59RSLp9FHlsTnSGjjlVsrs0Aud');
+
+ var multipartMessage = fs.readFileSync(__dirname + '/fixtures/big_multipart');
+ var parts = meta._parseMultipartMixed(multipartMessage);
+
+ parts.length.should.equal(8);
+
+ done();
+ });
});
-headers = meta.headers;
-
-assert.equal(headers.statusCode, undefined);
-assert.equal(headers['X-Riak-Meta-fire'], 'yes');
-// assert.equal(headers['Link'], '</riak/test/doc%252%24%40>; riaktag="next"'); -- not yet implemented
-assert.equal(headers['Authorization'], 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==');
-
-test('It returns its location from a POST request');
-
-riakResponse = {
- headers: {
- location: '/riak/test/bzPygTesROPtGGVUKfyvp2RR49'
- },
- statusCode: 201
-}
-
-meta = new Meta();
-meta.loadResponse(riakResponse);
-
-assert.equal(meta.bucket, 'test');
-assert.equal(meta.key, 'bzPygTesROPtGGVUKfyvp2RR49');
-assert.equal(meta.statusCode, 201);
-
-test('It guesses its content type');
-
-headers = new Meta({ data: { test: true } }).headers;
-
-assert.equal(headers['content-type'], 'application/json');
-assert.equal(headers['link'], undefined);
-
-test('Does not send clientId if there is no vclock');
-
-headers = new Meta().headers;
-assert.equal(headers['x-riak-clientId'], undefined);
-
-test('It returns its full path including query properties');
-
-meta = new Meta({
- bucket: 'bucket',
- key: 'key',
- r: 1,
- w: 2,
- dw: 2,
- rw: 2,
- keys: true,
- props: false,
- vtag: 'asweetvtag',
- returnbody: true,
- chunked: true
-});
-
-assert.equal("/riak/bucket/key?r=1&w=2&dw=2&rw=2&keys=true&props=false&vtag=asweetvtag&returnbody=true&chunked=true", meta.path);
-
-test('Returns an URI-encoded path if used with encodeUri option');
-
-meta = new Meta({
- bucket: 'spåce bucket',
- key: 'çøµπléx–key',
- encodeUri: true
-});
-
-assert.equal("/riak/sp%C3%A5ce%20bucket/%C3%A7%C3%B8%C2%B5%CF%80l%C3%A9x%E2%80%93key", meta.path);
-
-meta = new Meta({
-});
-
-var multipartResponse = {
- httpVersion: '1.1',
- headers: {
- vary: 'Accept-Encoding',
- server: 'MochiWeb/1.1 WebMachine/1.7.1 (participate in the frantic)',
- 'x-riak-vclock': 'a85hYGBgzGDKBVIsbLvm1WYwJTLmsTLcjeE5ypcFAA==',
- 'x-riak-meta-acl': 'users:r,administrators:f',
- link: '</riak/test>; rel="up", </riak/test/doc%252%24%40>; riaktag="next"',
- 'last-modified': 'Wed, 10 Mar 2010 18:11:41 GMT',
- etag: '6dQBm9oYA1mxRSH0e96l5W',
- date: 'Wed, 10 Mar 2010 18:11:52 GMT',
- 'content-type': 'multipart/mixed; boundary=59RSLp9FHlsTnSGjjlVsrs0Aud',
- 'content-length': '2946'
- },
- statusCode: 200
-}
-
-test("Sets a boundary when response is multipart");
-meta.loadResponse(multipartResponse);
-assert.equal('59RSLp9FHlsTnSGjjlVsrs0Aud', meta.boundary)
-
-test("Parsing the multipart body");
-var multipartMessage = fs.readFileSync(__dirname + '/fixtures/multipart');
-var parts = meta._parseMultipartMixed(multipartMessage);
-
-assert.equal(2, parts.length);
-assert.equal(parts[0].body, '{"likes":"lebkuchen"}');
-assert.equal(parts[1].body, '{"eats":"lebkuchen"}');
-
-test("Set content-type header for each sibling");
-assert.equal(parts[0].headers['content-type'], 'application/json');
-assert.equal(parts[1].headers['content-type'], 'application/json');
-
-test("Set an etag for each sibling");
-assert.equal(parts[0].headers['etag'], '4w0Pmt0N1yXnR1ecZiFxPi');
-assert.equal(parts[1].headers['etag'], 'p8gYGbYxc78iCllp9PqkK');
-
-test("Parses more than two siblings");
-multipartMessage = fs.readFileSync(__dirname + '/fixtures/big_multipart');
-parts = meta._parseMultipartMixed(multipartMessage);
-assert.equal(8, parts.length);
View
45 test/mapper-test.js
@@ -1,27 +1,34 @@
-var assert = require('assert'),
- test = require('../lib/utils').test,
+var should = require('should'),
Mapper = require('../lib/mapper');
-test('Does not have any phases when initialized');
+describe('mapper-tests', function() {
+ it('Does not have any phases when initialized', function(done) {
+ var mapper = new Mapper('airlines');
-var mapper = new Mapper('airlines');
+ mapper.phases.should.be.eql([]);
+ mapper.inputs.should.equal('airlines');
-assert.deepEqual(mapper.phases, []);
-assert.equal(mapper.inputs, 'airlines');
+ done();
+ });
-test('Phases are added correctly');
+ it('Phases are added correctly', function(done) {
-var job = mapper
- .map('Riak.mapValuesJson', 'abc')
- .link({ bucket: 'flights', keep: false, language: 'english' })
- .reduce(function() { return 1 + 1 });
-
-assert.equal(job.phases.length, 3);
-assert.deepEqual(job.phases[0].map, { name: 'Riak.mapValuesJson', arg: 'abc', language: 'javascript' });
-assert.deepEqual(job.phases[1].link, { bucket: 'flights', keep: false, language: 'english' });
-assert.equal(job.phases[2].reduce.source, "function () { return 1 + 1 }");
-assert.equal(job.phases[2].reduce.language, 'javascript');
+ var mapper = new Mapper('airlines');
-// the `run` function depends on a client, so will be tested there instead
+ var job = mapper
+ .map('Riak.mapValuesJson', 'abc')
+ .link({ bucket: 'flights', keep: false, language: 'english' })
+ .reduce(function() { return 1 + 1 });
-assert.equal(mapper.client, undefined);
+ job.phases.length.should.equal(3);
+ job.phases[0].map.should.eql({ name: 'Riak.mapValuesJson', arg: 'abc', language: 'javascript' });
+ job.phases[1].link.should.eql({ bucket: 'flights', keep: false, language: 'english' });
+ job.phases[2].reduce.source.should.equal('function () { return 1 + 1 }');
+ job.phases[2].reduce.language.should.equal('javascript');
+
+ // the `run` function depends on a client, so will be tested there instead
+ should.not.exist(mapper.client);
+
+ done();
+ });
+});
View
156 test/meta-test.js
@@ -1,56 +1,108 @@
var Meta = require('../lib/meta'),
- assert = require('assert'),
- test = require('../lib/utils').test;
-
-test('Sets its attributes');
-
-var meta = new Meta({ bucket: 'bucket', key: 'key', contentType: 'png', data: 'd32n92390XMIW0', host: '192.168.1.2', myown: 'field' });
-
-assert.equal(meta.bucket, 'bucket');
-assert.equal(meta.key, 'key');
-assert.equal(meta.vclock, null);
-assert.equal(meta.contentType, 'image/png');
-assert.equal(meta.data, 'd32n92390XMIW0');
-
-test('Properly falls back to defaults');
-
-assert.deepEqual(meta.links, Meta.defaults.links);
-assert.equal(meta.resource, Meta.defaults.resource);
-assert.equal(meta.clientId, Meta.defaults.clientId);
-assert.equal(meta.host, '192.168.1.2');
-
-test('Unrecognized properties are ignored');
-
-assert.equal(meta.myown, null);
-
-test('Is able to detect the content type');
-
-meta = new Meta({ data: { a: 1 } });
-assert.equal(meta.contentType, 'application/json');
-
-meta = new Meta({ contentType: 'xml', data: '<a>b</a>' })
-assert.equal(meta.contentType, 'text/xml');
-
-test("Manual content type setting has priority over detection");
-
-meta.loadData('some text');
-assert.notEqual(meta.contentType, 'text/plain');
-
-test("Can be passed multiple option objects, and it mixes in correctly");
-
-meta = new Meta({ bucket: '?', stream: true, key: 'key' }, { bucket: '_', callback: function() { console.log('test') }}, { bucket: 'bucket' });
-
-assert.equal(meta.bucket, 'bucket');
-assert.equal(meta.key, 'key');
-assert.ok(meta.stream);
-assert.equal(meta.callback, 'function () { console.log(\'test\') }')
-
-test("A Meta fed with another Meta results in identity");
-
-var meta = new Meta({ bucket: 'bucket', key: 'key' }),
- meta2 = new Meta(meta);
-
-assert.deepEqual(meta, meta2);
+ should = require('should');
+
+describe('meta-tests', function() {
+ it('Sets its attributes', function(done) {
+ var meta = new Meta({
+ bucket: 'bucket',
+ key: 'key',
+ contentType: 'png',
+ data: 'd32n92390XMIW0',
+ host: '192.168.1.2',
+ myown: 'field' });
+
+ meta.bucket.should.equal('bucket');
+ meta.key.should.equal('key');
+ should.not.exist(meta.vclock);
+ meta.contentType.should.equal('image/png');
+ meta.data.toString().should.equal('d32n92390XMIW0');
+
+ done();
+ });
+
+ it('Properly falls back to defaults', function(done) {
+
+ var meta = new Meta({
+ bucket: 'bucket',
+ key: 'key',
+ contentType: 'png',
+ data: 'd32n92390XMIW0',
+ host: '192.168.1.2',
+ myown: 'field' });
+
+ meta.links.should.eql(Meta.defaults.links);
+ meta.resource.should.equal(Meta.defaults.resource);
+ meta.clientId.should.equal(Meta.defaults.clientId);
+ meta.host.should.equal('192.168.1.2');
+ done();
+ });
+
+ it('Properly falls back to defaults', function(done) {
+
+ var meta = new Meta({
+ bucket: 'bucket',
+ key: 'key',
+ contentType: 'png',
+ data: 'd32n92390XMIW0',
+ host: '192.168.1.2',
+ myown: 'field' });
+
+ should.not.exist(meta.myown);
+
+ done();
+ });
+
+ it('Is able to detect the content type', function(done) {
+ var meta = new Meta({ data: { a: 1 } });
+ meta.contentType.should.equal('application/json');
+
+ done();
+ });
+
+ it('Is able to detect the content type (XML)', function(done) {
+ var meta = new Meta({ contentType: 'xml', data: '<a>b</a>' });
+ meta.contentType.should.equal('text/xml');
+
+ done();
+ });
+
+ it('Manual content type setting has priority over detection', function(done) {
+ var meta = new Meta();
+
+ meta.loadData('some text');
+ meta.contentType.should.equal('text/plain');
+
+ done();
+ });
+
+ it('Can be passed multiple option objects, and it mixes in correctly', function(done) {
+ var meta = new Meta({
+ bucket: '?',
+ stream: true,
+ key: 'key' },
+ { bucket: '_',
+ callback: function() { console.log('test') }
+ }, { bucket: 'bucket' });
+
+ meta.bucket.should.equal('bucket');
+ meta.key.should.equal('key');
+ should.exist(meta.stream);
+ meta.callback.toString().should.equal('function () { console.log(\'test\') }');
+
+ done();
+ });
+
+ it('A Meta fed with another Meta results in identity', function(done) {
+ var meta = new Meta({ bucket: 'bucket', key: 'key' }),
+ meta2 = new Meta(meta);
+
+ meta.should.eql(meta2);
+ done();
+ });
+
+});
+
+// TODO What are these?
// keyless.addLink { bucket: 'bucket', key: 'test' }
// keyless.addLink { bucket: 'bucket', key: 'test2', tag: '_' }
View
12 test/runner.js
@@ -3,7 +3,7 @@ var seq = require('seq'),
util = require('util'),
spawn = require('child_process').spawn,
files = fs.readdirSync(__dirname);
-
+
files = files
.map(function(f) {
return __dirname + '/' + f;
@@ -19,22 +19,18 @@ seq(files)
exec(file, this);
})
.seq(function() {
- console.log('[\033[32m' + 'SUCCESS' + '\033[39m]');
+ //console.log('[\033[32m' + 'SUCCESS' + '\033[39m]');
});
-
-
function exec(test, callback) {
-
- var child = spawn('node', [test]);
+var child = spawn('node', [test]);
child.stdout.pipe(process.stdout, { end: false });
child.stderr.pipe(process.stderr, { end: false });
-
+
child.on('exit', function(code) {
console.log();
if (code == 0) return callback(null);
console.error('[\033[31m' + 'FAILURE' + '\033[39m] ' + test + " returned with code " + code);
process.exit(code);
});
-
}
View
22 test/utils-test.js
@@ -1,11 +1,13 @@
-var assert = require('assert'),
- utils = require('../lib/utils'),
- test = utils.test;
-
-test('Utils mixin');
+var should = require('should'),
+ utils = require('../lib/utils');
- var o1 = { a: 1, b: 2, g: 8 },
- o2 = { b: 3, c: 4 },
- o3 = { b: 5, d: 6 };
-
- assert.deepEqual(utils.mixin(o1, o2, o3), { a: 1, b: 5, c: 4, d: 6, g: 8 })
+describe('Utils-tests', function() {
+ it('Should mixin correctly', function(done) {
+ var o1 = { a: 1, b: 2, g: 8 },
+ o2 = { b: 3, c: 4 },
+ o3 = { b: 5, d: 6 };
+
+ utils.mixin(o1, o2, o3).should.eql({ a: 1, b: 5, c: 4, d: 6, g: 8 });
+ done();
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.