Skip to content

Commit

Permalink
Handle cases when vipAddress may not be present (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhamann authored and awolden committed Jan 13, 2017
1 parent 987d28f commit 8932a47
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/EurekaClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(',');
}

Expand Down
9 changes: 9 additions & 0 deletions test/EurekaClient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ describe('Eureka client', () => {
let instance1;
let instance2;
let instance3;
let instance4;
let downInstance;
let theVip;
let multiVip;
Expand All @@ -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: {} };
Expand All @@ -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);
Expand Down

0 comments on commit 8932a47

Please sign in to comment.