From 8932a472ceba8c08f4a42b8dedcb280274beda3f Mon Sep 17 00:00:00 2001 From: Matt Hamann Date: Thu, 12 Jan 2017 22:39:34 -0500 Subject: [PATCH] Handle cases when vipAddress may not be present (#102) --- src/EurekaClient.js | 4 ++++ test/EurekaClient.test.js | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/EurekaClient.js b/src/EurekaClient.js index c5dfbe0..b589282 100644 --- a/src/EurekaClient.js +++ b/src/EurekaClient.js @@ -401,6 +401,10 @@ export default class Eureka extends EventEmitter { Returns an array of vipAddresses from string vipAddress given by eureka */ splitVipAddress(vipAddress) { // eslint-disable-line + if (typeof vipAddress !== 'string') { + return []; + } + return vipAddress.split(','); } diff --git a/test/EurekaClient.test.js b/test/EurekaClient.test.js index 0cab708..fb4712a 100644 --- a/test/EurekaClient.test.js +++ b/test/EurekaClient.test.js @@ -747,6 +747,7 @@ describe('Eureka client', () => { let instance1; let instance2; let instance3; + let instance4; let downInstance; let theVip; let multiVip; @@ -761,6 +762,7 @@ describe('Eureka client', () => { instance1 = { host: '127.0.0.1', port: 1000, vipAddress: theVip, status: 'UP' }; instance2 = { host: '127.0.0.2', port: 2000, vipAddress: theVip, status: 'UP' }; instance3 = { host: '127.0.0.2', port: 2000, vipAddress: multiVip, status: 'UP' }; + instance4 = { host: '127.0.0.2', port: 2000, vipAddress: void 0, status: 'UP' }; downInstance = { host: '127.0.0.2', port: 2000, vipAddress: theVip, status: 'DOWN' }; app = { name: 'theapp' }; cache = { app: {}, vip: {} }; @@ -781,6 +783,13 @@ describe('Eureka client', () => { expect(cache.vip[multiVip.split(',')[1]].length).to.equal(1); }); + it('should transform an app with one instance that has no vipAddress', () => { + app.instance = instance4; + client.transformApp(app, cache); + expect(cache.app[app.name.toUpperCase()].length).to.equal(1); + expect(Object.keys(cache.vip).length).to.equal(0); + }); + it('should transform an app with two or more instances', () => { app.instance = [instance1, instance2, instance3]; client.transformApp(app, cache);