From 6f7b2ac68a3f65e1a1f2fac98cd2610874bab312 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Thu, 10 Mar 2016 20:03:06 -0500 Subject: [PATCH 1/2] Pass esclient config to elasticsearch module This fixes a regression in #423 that breaks our configuration in dev and production. --- src/backend.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend.js b/src/backend.js index 3d2bc993..c983dbba 100644 --- a/src/backend.js +++ b/src/backend.js @@ -1,6 +1,6 @@ - +var config = require( 'pelias-config' ).generate().esclient; var Backend = require('geopipes-elasticsearch-backend'), - client = require('elasticsearch').Client(), + client = require('elasticsearch').Client(config), backends = {}; function getBackend( index, type ){ From b4fb62f2c9d546da669f83e81f517b021439300a Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Fri, 11 Mar 2016 15:13:41 -0500 Subject: [PATCH 2/2] Test that src/backend passes correct config to elasticsearch --- test/unit/run.js | 1 + test/unit/src/backend.js | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 test/unit/src/backend.js diff --git a/test/unit/run.js b/test/unit/run.js index de13bbe0..ccb3c790 100644 --- a/test/unit/run.js +++ b/test/unit/run.js @@ -45,6 +45,7 @@ var tests = [ require('./sanitiser/_sources'), require('./sanitiser/_sources_and_layers'), require('./sanitiser/_text'), + require('./src/backend'), require('./sanitiser/autocomplete'), require('./sanitiser/place'), require('./sanitiser/reverse'), diff --git a/test/unit/src/backend.js b/test/unit/src/backend.js new file mode 100644 index 00000000..1b750396 --- /dev/null +++ b/test/unit/src/backend.js @@ -0,0 +1,40 @@ +var proxyquire = require('proxyquire'); + +var stubConfig = { + generate: function generate() { + return { + esclient: { + hosts: [ + 'http://notLocalhost:9200', + 'http://anotherHost:9200' + ] + } + }; + } +}; + + +module.exports.tests = {}; + +module.exports.tests.config_properly_passed = function(test, common) { + test('Elasticsearch config is properly passed to elasticsearch module', function(t) { + var stubElasticsearchClient = { + Client: function(config) { + t.deepEquals(config.hosts, [ 'http://notLocalhost:9200', 'http://anotherHost:9200' ], 'hosts set correctly' ); + t.end(); + } + }; + + proxyquire('../../../src/backend', { 'pelias-config': stubConfig, 'elasticsearch': stubElasticsearchClient } ); + }); +}; + +module.exports.all = function (tape, common) { + function test(name, testFunction) { + return tape('SANTIZE src/backend ' + name, testFunction); + } + + for( var testCase in module.exports.tests ){ + module.exports.tests[testCase](test, common); + } +};