update node-reading logic to match elasticsearch-py

This commit is contained in:
spalger
2017-02-08 16:58:27 -07:00
parent 684fbd77c8
commit 6309425951
10 changed files with 204 additions and 87 deletions

View File

@ -2,61 +2,108 @@ describe('Nodes to host callback', function () {
var callback = require('../../../src/lib/nodes_to_host');
var expect = require('expect.js');
// example node list that would come back from "GET _cluster/nodes"
var nodes = require('../../fixtures/short_node_list.json');
var nodes90 = require('../../fixtures/short_node_list.0.90.json');
var nodes10 = require('../../fixtures/short_node_list.1.0.json');
var nodes20 = require('../../fixtures/short_node_list.2.0.json');
var nodes50 = require('../../fixtures/short_node_list.5.0.json');
context('pre 2.0 nodes style', function () {
context('0.x style', function () {
it('properly creates host objects', function () {
var hosts = callback(nodes);
expect(hosts.length).to.be(2);
expect(hosts[0]).to.eql({
host: '10.10.10.100',
port: 9205,
_meta: {
id: 'id1',
name: 'Headknocker',
hostname: 'Spencers-MacBook-Pro.local',
version: '0.90.5'
expect(callback(nodes90)).to.eql([
{
host: '192.168.1.1',
port: 9400,
_meta: {
id: 'id1',
name: 'name1',
version: '0.90.14-SNAPSHOT'
}
},
{
host: 'localhost',
port: 9440,
_meta: {
id: 'id2',
name: 'name2',
version: '0.90.14-SNAPSHOT'
}
}
});
expect(hosts[1]).to.eql({
host: '10.10.10.101',
port: 9205,
_meta: {
id: 'id2',
name: 'Buttknocker',
hostname: 'Johns-MacBook-Pro.local',
version: '0.90.5'
]);
});
});
context('1.0 nodes style', function () {
it('properly creates host objects', function () {
expect(callback(nodes10)).to.eql([
{
host: '10.10.10.100',
port: 9205,
_meta: {
id: 'id1',
name: 'name1',
version: '1.0.4-SNAPSHOT'
}
},
{
host: 'published.hostname',
port: 9205,
_meta: {
id: 'id2',
name: 'name2',
version: '1.0.4-SNAPSHOT'
}
}
});
]);
});
});
context('2.0 nodes style', function () {
it('properly creates host objects', function () {
var hosts = callback(nodes20);
expect(hosts.length).to.be(2);
expect(hosts[0]).to.eql({
host: '10.10.10.100',
port: 9205,
_meta: {
id: 'id1',
name: 'Headknocker',
hostname: 'Spencers-MacBook-Pro.local',
version: '0.90.5'
expect(callback(nodes20)).to.eql([
{
host: '127.0.0.1',
port: 9400,
_meta: {
id: 'id1',
name: 'name1',
version: '2.0.3-SNAPSHOT'
}
},
{
host: 'published.hostname',
port: 9400,
_meta: {
id: 'id2',
name: 'name2',
version: '2.0.3-SNAPSHOT'
}
}
});
expect(hosts[1]).to.eql({
host: 'published.hostname',
port: 9205,
_meta: {
id: 'id2',
name: 'Buttknocker',
hostname: 'Johns-MacBook-Pro.local',
version: '0.90.5'
]);
});
});
context('5.0 nodes style', function () {
it('properly creates host objects', function () {
expect(callback(nodes50)).to.eql([
{
host: '127.0.0.1',
port: 9400,
_meta: {
id: 'id1',
name: 'name1',
version: '5.0.3'
}
},
{
host: 'published.hostname',
port: 9440,
_meta: {
id: 'id2',
name: 'name2',
version: '5.0.3'
}
}
});
]);
});
});
@ -75,10 +122,12 @@ describe('Nodes to host callback', function () {
expect(function () {
callback({
node_id: {
http_address: 'not actually an http host'
http: {
publish_address: 'not actually an http host'
}
}
});
}).to.throwException(/^Malformed http_address/);
}).to.throwException(/^Malformed http.publish_address/);
});
});

View File

@ -5,7 +5,7 @@ var errors = require('../../../src/lib/errors');
var sinon = require('sinon');
var expect = require('expect.js');
var _ = require('lodash');
var nodeList = require('../../fixtures/short_node_list.json');
var nodeList = require('../../fixtures/short_node_list.5.0.json');
var stub = require('../../utils/auto_release_stub').make();
/**
@ -371,12 +371,12 @@ describe('Transport Class', function () {
expect(hosts).to.have.length(2);
expect(hosts[0]).to.be.a(Host);
expect(hosts[0].host).to.eql('10.10.10.100');
expect(hosts[0].port).to.eql(9205);
expect(hosts[0].host).to.eql('127.0.0.1');
expect(hosts[0].port).to.eql(9400);
expect(hosts[0]).to.be.a(Host);
expect(hosts[1].host).to.eql('10.10.10.101');
expect(hosts[1].port).to.eql(9205);
expect(hosts[1].host).to.eql('published.hostname');
expect(hosts[1].port).to.eql(9440);
done();
});
});

View File

@ -8,7 +8,6 @@ var sinon = require('sinon');
var nock = require('../../mocks/server.js');
var through2 = require('through2');
var _ = require('lodash');
var nodeList = require('../../fixtures/short_node_list.json');
var stub = require('../../utils/auto_release_stub').make();
/**