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
17 changes: 7 additions & 10 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,14 @@ Lambda.prototype._params = function (program, buffer) {
};

Lambda.prototype._eventSourceList = function (program) {
var eventSourceList = []
if (program.eventSourceFile) {
try {
eventSourceList = fs.readJsonSync(program.eventSourceFile);
} catch(err) {
eventSourceList = [];
throw err;
}
if (!program.eventSourceFile) {
return [];
}
try {
return fs.readJsonSync(program.eventSourceFile);
} catch(err) {
throw err;
}

return eventSourceList;
};

/**
Expand Down
31 changes: 30 additions & 1 deletion test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var originalProgram = {
deadLetterConfigTargetArn: '',
region: 'us-east-1,us-west-2,eu-west-1',
eventFile: 'event.json',
eventSourceFile: '',
contextFile: 'context.json',
prebuiltDirectory: '',
};
Expand Down Expand Up @@ -473,10 +474,11 @@ describe('node-lambda', function () {
'event_sources.json'
];

afterEach(function () {
after(function () {
targetFiles.forEach(function(file) {
fs.unlinkSync(file);
});
program.eventSourceFile = '';
});

it('should create sample files', function () {
Expand All @@ -493,6 +495,33 @@ describe('node-lambda', function () {
);
});
});

describe('_eventSourceList', function () {
it('program.eventSourceFile is empty value', function () {
program.eventSourceFile = '';
assert.deepEqual(lambda._eventSourceList(program), []);
});

it('program.eventSourceFile is valid value', function () {
program.eventSourceFile = 'event_sources.json';
const expected = [{
BatchSize: 100,
Enabled: true,
EventSourceArn: 'your event source arn',
StartingPosition: 'LATEST',
}];
assert.deepEqual(lambda._eventSourceList(program), expected);
});

it('program.eventSourceFile is invalid value', function () {
program.eventSourceFile = '/hoge/fuga';
assert.throws(
() => { lambda._eventSourceList(program); },
Error,
"ENOENT: no such file or directory, open '/hoge/fuga'"
);
});
});
});

describe('check env vars before create sample files', function () {
Expand Down