Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Use supported elasticsearch client #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var suite = new elastictest.Suite();

var doc = {
index: suite.props.index,
type: 'mytype',
id: '1',
body: {
foo: 'bar'
Expand All @@ -29,7 +28,6 @@ suite.action( function( done ){
suite.assert( function( done ){
suite.client.count({
index: doc.index,
type: doc.type
}, function( err, res ){
t.equal( res.count, 1, 'record count' );
done();
Expand Down Expand Up @@ -71,7 +69,6 @@ You **must** call `done()` when your async operations are complete. You may add
suite.assert( function( done ){
suite.client.count({
index: doc.index,
type: doc.type
}, function( err, res ){
t.equal( res.count, 1, 'record count' );
done();
Expand Down
4 changes: 2 additions & 2 deletions lib/Suite.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

const _ = require('lodash');
const randomstring = require('randomstring');
const elasticsearch = require('elasticsearch');
const elasticsearch = require('@elastic/elasticsearch');
const async = require('async');

function Suite( clientOpts, props ){
this.actions = [];
this.asserts = [];
this.client = null;
this.clientOpts = clientOpts && clone( clientOpts ) || {
host: 'localhost:9200',
node: 'http://localhost:9200',
keepAlive: true
};
this.props = props || {};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"dependencies": {
"async": "^3.1.0",
"elasticsearch": "^16.5.0",
"@elastic/elasticsearch": "^7.17.0",
"lodash": "^4.17.15",
"randomstring": "^1.1.5"
}
Expand Down
11 changes: 5 additions & 6 deletions test/custom_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports.tests = {};

var custom_schema = {
settings: { index: { refresh_interval: '-1' } },
mappings: { _doc: { properties: { name: { type: 'long' } } } }
mappings: { properties: { name: { type: 'long' } } }
};

// test creating index with custom schema
Expand All @@ -19,9 +19,8 @@ module.exports.tests.custom_schema = function(test, common) {
suite.assert( function( done ){
suite.client.indices.getMapping({
index: suite.props.index,
type: '_doc'
}, function( err, res ){
t.deepEqual( res[suite.props.index].mappings, custom_schema.mappings, 'mappings set' );
t.deepEqual( res.body[suite.props.index].mappings, custom_schema.mappings, 'mappings set' );
done();
});
});
Expand All @@ -39,7 +38,7 @@ module.exports.tests.custom_schema = function(test, common) {
suite.client.indices.getSettings({
index: suite.props.index
}, function( err, res ){
t.deepEqual( res[suite.props.index].settings.index_concurrency, custom_schema.settings.index_concurrency, 'settings set' );
t.deepEqual( res.body[suite.props.index].settings.index_concurrency, custom_schema.settings.index_concurrency, 'settings set' );
done();
});
});
Expand All @@ -63,7 +62,7 @@ module.exports.tests.default_schema = function(test, common) {
}, function( err, res ){
var expected = {};
expected[suite.props.index] = { mappings: {} };
t.deepEqual( res, expected, 'default mappings' );
t.deepEqual( res.body, expected, 'default mappings' );
done();
});
});
Expand All @@ -81,7 +80,7 @@ module.exports.tests.default_schema = function(test, common) {
suite.client.indices.getSettings({
index: suite.props.index
}, function( err, res ){
t.deepEqual( res[suite.props.index].settings.index_concurrency, undefined, 'default settings' );
t.deepEqual( res.body[suite.props.index].settings.index_concurrency, undefined, 'default settings' );
done();
});
});
Expand Down
17 changes: 7 additions & 10 deletions test/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module.exports.tests.example = function(test, common) {

var doc = {
index: suite.props.index,
type: '_doc',
id: '1',
body: {
foo: 'bar'
Expand All @@ -25,25 +24,23 @@ module.exports.tests.example = function(test, common) {
suite.assert( function( done ){
suite.client.count({
index: doc.index,
type: doc.type
}, function( err, res ){
t.equal( res.count, 1, 'record count' );
t.equal( res.body.count, 1, 'record count' );
done();
});
});

suite.assert( function( done ){
suite.client.get({
index: doc.index,
type: doc.type,
id: doc.id
}, function( err, res ){
t.equal( res.found, true );
t.equal( res._id, doc.id );
t.equal( res._index, doc.index );
t.equal( res._type, doc.type );
t.deepEqual( res._source, doc.body );
t.equal( res._version, 1 );
const body = res.body;
t.equal( body.found, true );
t.equal( body._id, doc.id );
t.equal( body._index, doc.index );
t.deepEqual( res.body._source, doc.body );
t.equal( body._version, 1 );
done();
});
});
Expand Down