Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ElasticSearch Nodejs Express Automated Testing

How to implement automated test for ElasticSearch using Node testing framework?

I want to implement ElasticSearch into my nodejs Project for efficient searching abilities, which is using Express framework , frisby, Socket.io etc. ElasticSearch nodejs implementation is easily available on google but not it's automation testing. Need Suggestions.

like image 586
Atif Hussain Avatar asked May 04 '15 07:05

Atif Hussain


1 Answers

You can use Jasmine or Mocha as testing frameworks for Node.js. Within the test suites you can use another library: superagent.

Superagent allows you to perform HTTP requests to a specified url.

On the other hand you have an elasticsearch that receives HTTP requests.

You can have a library of data sets in the form of http requests to issue towards elasticsearch. Each data set will be suitable to feed elasticsearch to check wether or not a test passes or fails.

Here is an example of how superagent can be used to issue a request to an elasticsearch server:

var request = require('superagent');
var should = require('should.js');

describe('Your test suite', function () {
    it('Should test elasticsearch search', function (done) {
      request.get('http://localhost:9002/index/type/_search')
        .end(function (err, res) {
          should.not.exist(err);
          should.exist(res);
        });
    });
});
like image 109
javierfdezg Avatar answered Oct 18 '22 19:10

javierfdezg