From 43ce0d71f4dba5ff0ec0202ae446f83e80634ed8 Mon Sep 17 00:00:00 2001 From: abetomo Date: Tue, 2 May 2017 15:36:13 +0900 Subject: [PATCH 1/2] Fix not doing anything if `event_sources.json` is not specified --- lib/main.js | 10 ++++++++-- test/main.js | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index f012a6ca..c3e21885 100644 --- a/lib/main.js +++ b/lib/main.js @@ -149,8 +149,8 @@ Lambda.prototype._params = function (program, buffer) { Lambda.prototype._eventSourceList = function (program) { if (!program.eventSourceFile) { return { - EventSourceMappings: [], - ScheduleEvents: [] + EventSourceMappings: null, + ScheduleEvents: null }; } const list = (function() { @@ -523,6 +523,9 @@ Lambda.prototype._listEventSourceMappings = function (lambda, params, cb) { }; Lambda.prototype._updateEventSources = function (lambda, functionName, existingEventSourceList, eventSourceList, cb) { + if (eventSourceList == null) { + return cb(null, []); + } var updateEventSourceList = []; // Checking new and update event sources for (var i in eventSourceList) { @@ -600,6 +603,9 @@ Lambda.prototype._updateEventSources = function (lambda, functionName, existingE }; Lambda.prototype._updateScheduleEvents = function (scheduleEvents, functionArn, scheduleList, cb) { + if (scheduleList == null) { + return cb(null, []); + } return async.series(scheduleList.map(function(schedule) { return function(_cb) { const params = Object.assign(schedule, { FunctionArn: functionArn }); diff --git a/test/main.js b/test/main.js index ff9b2014..2881798b 100644 --- a/test/main.js +++ b/test/main.js @@ -588,7 +588,7 @@ describe('node-lambda', function () { program.eventSourceFile = ''; assert.deepEqual( lambda._eventSourceList(program), - { EventSourceMappings: [], ScheduleEvents: [] } + { EventSourceMappings: null, ScheduleEvents: null } ); }); @@ -683,6 +683,24 @@ describe('node-lambda', function () { }); }); + describe('_updateEventSources', function () { + it('program.eventSourceFile is empty value', function () { + program.eventSourceFile = ''; + const eventSourceList = lambda._eventSourceList(program); + return new Promise(function (resolve) { + lambda._updateEventSources(lambda, '', [], eventSourceList.EventSourceMappings, function(err, results) { + resolve({ err: err, results: results }); + }); + }).then(function (actual) { + const expected = { + err: null, + results: [] + }; + assert.deepEqual(actual, expected); + }); + }); + }); + describe('_updateScheduleEvents', function () { const aws = require('aws-sdk-mock'); const ScheduleEvents = require(path.join('..', 'lib', 'schedule_events')); @@ -721,6 +739,22 @@ describe('node-lambda', function () { aws.restore('Lambda'); }); + it('program.eventSourceFile is empty value', function () { + program.eventSourceFile = ''; + const eventSourceList = lambda._eventSourceList(program); + return new Promise(function (resolve) { + lambda._updateScheduleEvents(schedule, '', eventSourceList.ScheduleEvents, function(err, results) { + resolve({ err: err, results: results }); + }); + }).then(function (actual) { + const expected = { + err: null, + results: [] + }; + assert.deepEqual(actual, expected); + }); + }); + it('simple test with mock', function () { program.eventSourceFile = 'event_sources.json'; const eventSourceList = lambda._eventSourceList(program); From 1631683b973909a079e430683383c97a3ed358b9 Mon Sep 17 00:00:00 2001 From: abetomo Date: Tue, 2 May 2017 15:50:36 +0900 Subject: [PATCH 2/2] Remove unnecessary line feeds --- test/main.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/test/main.js b/test/main.js index 2881798b..5b041a2f 100644 --- a/test/main.js +++ b/test/main.js @@ -692,10 +692,7 @@ describe('node-lambda', function () { resolve({ err: err, results: results }); }); }).then(function (actual) { - const expected = { - err: null, - results: [] - }; + const expected = { err: null, results: [] }; assert.deepEqual(actual, expected); }); }); @@ -747,10 +744,7 @@ describe('node-lambda', function () { resolve({ err: err, results: results }); }); }).then(function (actual) { - const expected = { - err: null, - results: [] - }; + const expected = { err: null, results: [] }; assert.deepEqual(actual, expected); }); });