Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 });
Expand Down
30 changes: 29 additions & 1 deletion test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ describe('node-lambda', function () {
program.eventSourceFile = '';
assert.deepEqual(
lambda._eventSourceList(program),
{ EventSourceMappings: [], ScheduleEvents: [] }
{ EventSourceMappings: null, ScheduleEvents: null }
);
});

Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -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);
Expand Down