From eda443b5b61b1fb4e8188f1f6d0a42f28e0f7e35 Mon Sep 17 00:00:00 2001 From: spalger Date: Mon, 16 Nov 2015 15:12:05 -0600 Subject: [PATCH] [transport] maintain support for 1.x nodes formatted urls --- src/lib/nodes_to_host.js | 2 +- test/.jshintrc | 1 + test/fixtures/short_node_list.2.0.json | 16 +++++ test/unit/specs/nodes_to_host_callback.js | 78 ++++++++++++++++------- 4 files changed, 73 insertions(+), 24 deletions(-) create mode 100644 test/fixtures/short_node_list.2.0.json diff --git a/src/lib/nodes_to_host.js b/src/lib/nodes_to_host.js index abcb48e79..eba61081a 100644 --- a/src/lib/nodes_to_host.js +++ b/src/lib/nodes_to_host.js @@ -1,5 +1,5 @@ var _ = require('./utils'); -var extractHostPartsRE = /^([\.:0-9a-f]*):([0-9]+)?$/; +var extractHostPartsRE = /(?:^([\.:0-9a-f]*):([0-9]+)?$|\[\/*([^:]+):(\d+)\])/; function makeNodeParser(hostProp) { return function (nodes) { diff --git a/test/.jshintrc b/test/.jshintrc index ef050dd78..6c7ea6e67 100644 --- a/test/.jshintrc +++ b/test/.jshintrc @@ -32,6 +32,7 @@ "globals": { "describe": true, + "context": true, "before": true, "after": true, "it": true, diff --git a/test/fixtures/short_node_list.2.0.json b/test/fixtures/short_node_list.2.0.json new file mode 100644 index 000000000..8d8248136 --- /dev/null +++ b/test/fixtures/short_node_list.2.0.json @@ -0,0 +1,16 @@ +{ + "id1": { + "name": "Headknocker", + "transport_address": "10.10.10.100:9300", + "hostname": "Spencers-MacBook-Pro.local", + "version": "0.90.5", + "http_address": "10.10.10.100:9205" + }, + "id2": { + "name": "Buttknocker", + "transport_address": "10.10.10.101:9300", + "hostname": "Johns-MacBook-Pro.local", + "version": "0.90.5", + "http_address": "10.10.10.101:9205" + } +} diff --git a/test/unit/specs/nodes_to_host_callback.js b/test/unit/specs/nodes_to_host_callback.js index 282150c54..4102fb0bf 100644 --- a/test/unit/specs/nodes_to_host_callback.js +++ b/test/unit/specs/nodes_to_host_callback.js @@ -4,32 +4,64 @@ describe('Nodes to host callback', function () { // example node list that would come back from "GET _cluster/nodes" var nodes = require('../../fixtures/short_node_list.json'); + var nodes20 = require('../../fixtures/short_node_list.2.0.json'); - 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(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('pre 2.0 nodes 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(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('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(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' + } + }); + }); + }); + + + it('ignores hosts that don\'t have an http_host property', function () { var hosts = callback({ node_id: { @@ -50,4 +82,4 @@ describe('Nodes to host callback', function () { }).to.throwException(/does not match the expected pattern/); }); -}); \ No newline at end of file +});