Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Some updates based around testing.

Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
  • Loading branch information...
commit 106a6480945109df66b37859ad1afbcf0350d0fe 1 parent f036158
Nick Campbell authored
11 lib/elasticsearch.js
View
@@ -36,16 +36,7 @@ function ElasticSearch(args) {
module.exports = ElasticSearch;
ElasticSearch.prototype.status = function(opts, cb) {
- if (opts && !cb && typeof(opts) == 'function') {
- cb = opts;
- opts = {};
- }
- var def = {
- method: 'GET',
- path: '/'+((this.index)?this.index+'/':'')+'_status'
- };
-
- utils.request(utils.mapConfig(def, utils.default_config, opts), {}, cb);
+ this.index.status(opts, cb);
}
ElasticSearch.prototype.add = function(opts, doc, cb) {
18 lib/index.js
View
@@ -2,7 +2,10 @@ var utils = require('./utils'),
sys = require('sys');
function Index(opts) {
- if (!(opts._deleting)) {
+ if (!opts) {
+ throw new Error('Must specify config options.');
+ }
+ if (!(opts.deleting)) {
if (!(opts.name)) {
throw new Error('Must specify an index name.');
}
@@ -14,6 +17,19 @@ function Index(opts) {
module.exports = Index;
+Index.prototype.status = function(opts, cb) {
+ if (opts && !cb && typeof(opts) == 'function') {
+ cb = opts;
+ opts = {};
+ }
+ var def = {
+ method: 'GET',
+ path: '/'+this.name+'/_status'
+ };
+
+ utils.request(utils.mapConfig(def, utils.default_config, opts), null, cb);
+}
+
Index.prototype.create = function(opts, config, cb) {
if (opts && !(config || cb) && typeof(opts) == 'function') {
cb = opts;
2  tests/suites/test-client.js
View
@@ -1,6 +1,6 @@
var lib = require('../../index'),
sys = require('sys'),
- testCase = require('../utils').testCase;
+ testCase = require('../utils').clientTestCase;
module.exports = testCase({
'test client connection': function(assert) {
28 tests/suites/test-iface.js
View
@@ -0,0 +1,28 @@
+var sys = require('sys'),
+ Index = require('../../lib/index'),
+ ES = require('../../lib/elasticsearch'),
+ lib = require('../../index');
+
+/* Must have some magic in here where the indexes are cleaned out of the system... Not exactly magic, but we have to assume that index deletion works in some sense just like we assume creation works on the other test suites.
+ */
+module.exports = {
+ 'check init index': function(assert) {
+ assert.expect(2);
+ var idx_name = 'test'+(new Date()).getTime();
+ var index = new Index({name: idx_name});
+ assert.equal(index.name, idx_name);
+ assert.deepEqual(index.idx_config, {});
+ assert.done();
+ },
+ 'check init index invalid': function(assert) {
+ assert.expect(1);
+ assert.throws(function() {new Index()});
+ assert.done();
+ },
+ 'check init index invalid - no name': function(assert) {
+ assert.expect(1);
+ assert.throws(function() {new Index({})});
+ assert.done();
+ }
+};
+
13 tests/suites/test-index.js
View
@@ -0,0 +1,13 @@
+var sys = require('sys'),
+ testCase = require('../utils').indexTestCase;
+
+module.exports = testCase({
+ 'check index status': function(assert) {
+ assert.expect(2);
+ this.index.status(function(err, status) {
+ assert.ifError(err);
+ assert.ok(status.ok);
+ assert.done();
+ });
+ }
+});
18 tests/suites/test-query.js
View
@@ -1,18 +0,0 @@
-var es = require('../index'),
- assert = require('assert');
-
-module.exports = {
- 'add field': function() {
- var field = {query: 'text'}, name = 'test';
- var def = {query: {field: {'test': field}}};
-
- assert.deepEqual((new es.query()).addField(name, field).query, def);
- },
- 'add fields chained': function() {
- var field1 = {query: 'text'}, name = 'test1',field2 = {query: 'text'}, name2 = 'test2';
- var def = {query: {field: {'test1': field1, 'test2': field2}}};
-
- var new_query = (new es.query()).addField(name, field1).addField(name2, field2);
- assert.deepEqual(new_query.query, def);
- }
-};
32 tests/utils.js
View
@@ -1,9 +1,10 @@
var nodeunit = require('nodeunit'),
sys = require('sys'),
- lib = require('../index'),
+ lib = require('../index'), //library index (more for noding this piece)
+ Index = require('../lib/index'), //search index
exports = module.exports;
-function testCase(suite) {
+function clientTestCase(suite) {
suite.setUp = function(done) {
var self = this,
idx_name = 'test'+(new Date()).getTime();
@@ -18,8 +19,29 @@ function testCase(suite) {
});
}
- return testCase.super_.call(this, suite);
+ return clientTestCase.super_.call(this, suite);
}
-sys.inherits(testCase, nodeunit.testCase);
-exports.testCase = testCase;
+sys.inherits(clientTestCase, nodeunit.testCase);
+exports.clientTestCase = clientTestCase;
+
+function indexTestCase(suite) {
+ suite.setUp = function(done) {
+ var self = this,
+ idx_name = 'test'+(new Date()).getTime();
+ this.index = new Index({name: idx_name});
+ this.index.create(function(err, res) {
+ done();
+ });
+ }
+ suite.tearDown = function(done) {
+ this.index.delete(function() {
+ done();
+ });
+ }
+
+ return indexTestCase.super_.call(this, suite);
+}
+
+sys.inherits(indexTestCase, nodeunit.testCase);
+exports.indexTestCase = indexTestCase;
Please sign in to comment.
Something went wrong with that request. Please try again.