Skip to content

Commit

Permalink
FABN-1128 Discovery options not merged correctly
Browse files Browse the repository at this point in the history
Fix to correctly merge the options structure passed into
the Gateway connect() method

Change-Id: Ifbdf604246c9cfcbfc893fab8f5284ef9b4faa19
Signed-off-by: andrew-coleman <[email protected]>
  • Loading branch information
andrew-coleman committed Feb 13, 2019
1 parent 28b8989 commit 57b683e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fabric-network/lib/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Gateway {

static _mergeOptions(defaultOptions, suppliedOptions) {
for (const prop in suppliedOptions) {
if (suppliedOptions[prop] instanceof Object && prop.endsWith('Options')) {
if (typeof suppliedOptions[prop] === 'object' && suppliedOptions[prop] !== null) {
if (defaultOptions[prop] === undefined) {
defaultOptions[prop] = suppliedOptions[prop];
} else {
Expand Down
71 changes: 71 additions & 0 deletions fabric-network/test/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,77 @@ describe('Gateway', () => {
defaultOptions.should.deep.equal(expectedOptions);
});

it('should merge option structures - even ones that don\t end in Option', () => {
const strategy = () => {
return null;
};
defaultOptions = {
commitTimeout: 300 * 1000,
identity: 'user',
eventHandlerOptions: {
commitTimeout: 300, // 5 minutes
strategy: strategy
},
discovery: {
enabled: true,
asLocalhost: true
}
};
const overrideOptions = {
identity: 'admin',
discovery: {
asLocalhost: false
}
};
const expectedOptions = {
commitTimeout: 300 * 1000,
identity: 'admin',
eventHandlerOptions: {
commitTimeout: 300, // 5 minutes
strategy: strategy
},
discovery: {
enabled: true,
asLocalhost: false
}
};
Gateway._mergeOptions(defaultOptions, overrideOptions);
defaultOptions.should.deep.equal(expectedOptions);
});

it('should merge null option structures', () => {
const strategy = () => {
return null;
};
defaultOptions = {
commitTimeout: 300 * 1000,
identity: 'user',
eventHandlerOptions: {
commitTimeout: 300, // 5 minutes
strategy: strategy
},
discovery: {
enabled: true,
asLocalhost: true
}
};
const overrideOptions = {
identity: 'admin',
discovery: null
};
const expectedOptions = {
commitTimeout: 300 * 1000,
identity: 'admin',
eventHandlerOptions: {
commitTimeout: 300, // 5 minutes
strategy: strategy
},
discovery: null
};
Gateway._mergeOptions(defaultOptions, overrideOptions);
defaultOptions.should.deep.equal(expectedOptions);
});

});

describe('#constructor', () => {
Expand Down

0 comments on commit 57b683e

Please sign in to comment.