Permalink
Browse files

Pass along errors to the CB when creating an ES client. Before those …

…were clobbered. Better API.

Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
  • Loading branch information...
1 parent 1739160 commit bad3215e3f01ea3877cd4b23146fb2e8057eb556 @ncb000gt committed Mar 10, 2011
Showing with 14 additions and 15 deletions.
  1. +1 −1 lib/elasticsearch.js
  2. +8 −10 lib/index.js
  3. +1 −1 tests/suites/test-iface.js
  4. +4 −3 tests/utils.js
View
2 lib/elasticsearch.js
@@ -17,7 +17,7 @@ function ElasticSearch(args) {
var self = this;
this.index.create(function(err, res) {
if (cb) {
- cb(self);
+ cb(err, self);
}
});
} else {
View
18 lib/index.js
@@ -1,13 +1,12 @@
-var utils = require('./utils');
+var utils = require('./utils'),
+ util = require('sys');
function Index(opts) {
if (!opts) {
throw new Error('Must specify config options.');
}
- if (!(opts.deleting)) {
- if (!(opts.name)) {
- throw new Error('Must specify an index name.');
- }
+ if (!(opts.name)) {
+ throw new Error('Must specify an index name.');
}
this.name = opts.name;
@@ -43,21 +42,20 @@ Index.prototype.refresh = function(opts, cb) {
}
Index.prototype.create = function(opts, config, cb) {
- if (opts && !(config || cb) && typeof(opts) == 'function') {
+ if (opts && !(config && cb) && typeof(opts) == 'function') {
cb = opts;
- config = {}
+ config = {settings: {index: {number_of_shards: 5, number_of_replicas: 1}}};
opts = {};
} else if (config && !cb && typeof(config) == 'function') {
cb = config;
- config = {}
+ config = {settings: {index: {number_of_shards: 5, number_of_replicas: 1}}};
}
- config = utils.mapConfig({settings: {number_of_shards: 5, number_of_replicas: 1}}, config);
var req_opts = {
method: ((config.mappings)?'POST':'PUT'),
path: '/'+this.name+'/'
};
- utils.request(utils.mapConfig(utils.default_config, req_opts, opts), config, cb);
+ utils.request(utils.mapConfig(utils.default_config, req_opts, opts), utils.mapConfig(config, this.idx_config), cb);
}
Index.prototype.delete = function(cb) {
View
2 tests/suites/test-iface.js
@@ -8,7 +8,7 @@ module.exports = {
'check init index': function(assert) {
assert.expect(2);
var idx_name = 'test'+(new Date()).getTime();
- var index = new Index({name: idx_name});
+ var index = new Index({name: idx_name});
assert.equal(index.name, idx_name);
assert.deepEqual(index.idx_config, {});
assert.done();
View
7 tests/utils.js
@@ -8,7 +8,10 @@ function clientTestCase(suite) {
suite.setUp = function(done) {
var self = this,
idx_name = 'test'+(new Date()).getTime();
- lib.createClient({index: idx_name}, function(client) {
+ lib.createClient({index: idx_name}, function(err, client) {
+ if (err) {
+ self.fail(err);
+ }
self.client = client;
done();
});
@@ -21,7 +24,6 @@ function clientTestCase(suite) {
return clientTestCase.super_.call(this, suite);
}
-
util.inherits(clientTestCase, nodeunit.testCase);
exports.clientTestCase = clientTestCase;
@@ -43,6 +45,5 @@ function indexTestCase(suite) {
return indexTestCase.super_.call(this, suite);
}
-
util.inherits(indexTestCase, nodeunit.testCase);
exports.indexTestCase = indexTestCase;

0 comments on commit bad3215

Please sign in to comment.