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..5b041a2f 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,21 @@ 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 +736,19 @@ 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);