Skip to content

Commit

Permalink
added test to fix coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Meiler committed Jan 2, 2025
1 parent 5dde23f commit 40e03b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions lambda/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ module.exports.extractDurationFromJSON = (log, durationType) => {
lines = JSON.parse(log);
}
} catch (e) {
// in case the log is not pretty printed, the string needs to be transformed first
console.log('Json Log not pretty printed');
lines = log.split('\n').filter((line) => line.includes('platform.report')).map((line) => {
return JSON.parse(line);
Expand Down
20 changes: 20 additions & 0 deletions test/unit/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1433,5 +1433,25 @@ describe('Lambda Utils', () => {
}`;
expect(() => utils.extractDurationFromJSON(logWithNoPlatformReport, utils.DURATIONS.durationMs)).to.throwError();
});
it('should handle logs with no platform.report', () => {
const logWithoutDurationMS = `
{
"cold_start": true,
"function_arn": "arn:aws:lambda:eu-west-1:123456789012:function:TestFunction",
"function_memory_size": "128",
"function_name": "TestFunction",
"function_request_id": "test-id",
"level": "INFO",
"message": "Lambda invocation event",
"timestamp": "2024-12-12T17:00:03.173Z",
"type": "platform.report",
"record": {
"metrics": {
"initDurationMs": 200.0
}
}
}`;
expect(() => utils.extractDurationFromJSON(logWithoutDurationMS, utils.DURATIONS.durationMs)).to.throwError();
});
});
});

0 comments on commit 40e03b3

Please sign in to comment.