-
Notifications
You must be signed in to change notification settings - Fork 72
Add flag var lazyConnect to ds config #185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -906,6 +906,62 @@ describe('executor', function() { | |
| }); | ||
| }); | ||
|
|
||
| describe('when booting with lazy connect', function() { | ||
| var SAMPLE_INSTRUCTION = someInstructions({ | ||
| dataSources: { | ||
| lazyConnector: { | ||
| connector: 'testLazyConnect', | ||
| name: 'lazyConnector', | ||
| }, | ||
| }, | ||
| }); | ||
| var connectTriggered = true; | ||
|
|
||
| beforeEach(function() { | ||
| app.connector('testLazyConnect', { | ||
| initialize: function(dataSource, callback) { | ||
| if (dataSource.settings.lazyConnect) { | ||
| connectTriggered = false; | ||
| } else { | ||
| connectTriggered = true; | ||
| } | ||
| }, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this configuration is same for both tests, please refactor it into a shared variable, e.g. |
||
| }); | ||
| }); | ||
|
|
||
| it('should trigger connect with ENV undefined', function(done) { | ||
| delete process.env.LB_LAZYCONNECT_DATASOURCES; | ||
| boot.execute(app, SAMPLE_INSTRUCTION, function() { | ||
| expect(connectTriggered).to.equal(true); | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it('should not trigger connect with ENV true', function(done) { | ||
| process.env.LB_LAZYCONNECT_DATASOURCES = 'true'; | ||
| boot.execute(app, SAMPLE_INSTRUCTION, function() { | ||
| expect(connectTriggered).to.equal(false); | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it('should trigger connect with ENV false', function(done) { | ||
| process.env.LB_LAZYCONNECT_DATASOURCES = 'false'; | ||
| boot.execute(app, SAMPLE_INSTRUCTION, function() { | ||
| expect(connectTriggered).to.equal(true); | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it('should trigger connect with ENV 0', function(done) { | ||
| process.env.LB_LAZYCONNECT_DATASOURCES = '0'; | ||
| boot.execute(app, SAMPLE_INSTRUCTION, function() { | ||
| expect(connectTriggered).to.equal(true); | ||
| done(); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add unit-tests for the following cases too - notice the value is always a string!
|
||
| describe('dynamic configuration for datasources.json', function() { | ||
| beforeEach(function() { | ||
| delete process.env.DYNAMIC_HOST; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: the value is always reset in
beforeEachhook below, there is no need to assign a value here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bajtos actually the variable will not reset lol. it's defined outside the hook, and stay the same value as previous test without reset.
But i think a more reasonable logic is
then there is no need to reset it at the beginning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do reset it at the beginning. If it happens that the code in your custom connector does not get called by some weird error that is swallowed, or perhaps because the connector API changed and our mocked connector is no longer valid, then test will see the result of the previous call, which is not right.
IMO, the most correct solution is to:
beforeEachhook toundefinedornulllazyConnect, as you shown in the code snippet aboveThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, will fix it with a reset