From d334425ada2b073907b4a3b641bc31c3bd3f4b66 Mon Sep 17 00:00:00 2001 From: juehou Date: Thu, 14 Apr 2016 16:38:11 -0400 Subject: [PATCH] Add flag var lazyConnect to ds config --- lib/executor.js | 5 ++++ test/executor.test.js | 56 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/lib/executor.js b/lib/executor.js index 16430d8..c22e32e 100644 --- a/lib/executor.js +++ b/lib/executor.js @@ -175,6 +175,11 @@ function setupDataSources(app, instructions) { useEnvVars: true, }; obj = getUpdatedConfigObject(app, obj, opts); + var lazyConnect = process.env.LB_LAZYCONNECT_DATASOURCES; + if (lazyConnect) { + obj.lazyConnect = + lazyConnect === 'false' || lazyConnect === '0' ? false : true; + } app.dataSource(key, obj); }); } diff --git a/test/executor.test.js b/test/executor.test.js index c61d8be..1851395 100644 --- a/test/executor.test.js +++ b/test/executor.test.js @@ -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; + } + }, + }); + }); + + 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(); + }); + }); + }); + describe('dynamic configuration for datasources.json', function() { beforeEach(function() { delete process.env.DYNAMIC_HOST;