Skip to content

Commit

Permalink
edited test cases
Browse files Browse the repository at this point in the history
updated test cases for logs to match the enhancement
  • Loading branch information
Roy Hui committed Jan 5, 2018
1 parent f230c79 commit 22000b3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
12 changes: 7 additions & 5 deletions lib/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ module.exports = {
throw new this.serverless.classes
.Error('No existing streams for the function alias');
}
return _.map(
const logStreamNames = _.map(
_.filter(reply.logStreams, stream => _.includes(stream.logStreamName, `[${version}]`)),
stream => stream.logStreamName);

if (_.isEmpty(logStreamNames)) {
return BbPromise.reject(new this.serverless.classes
.Error('No existing streams for the latest version of function alias. If you want to view logs of a specific function version, please use --version to specify'));
}
return logStreamNames
});
});

Expand Down Expand Up @@ -125,10 +131,6 @@ module.exports = {
},

functionLogsShowLogs(logStreamNames) {
if (_.isEmpty(logStreamNames)) {
return BbPromise.reject(new this.serverless.classes
.Error('No existing streams for the latest version of function alias. If you want to view logs of a specific function version, please use --version to specify'));
}
const formatLambdaLogEvent = event => {
const msgParam = event.message;
let msg = msgParam;
Expand Down
13 changes: 4 additions & 9 deletions test/logs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('logs', () => {
let sandbox;
let providerRequestStub;
let logStub;
let aliasGetAliasFunctionVersionsStub;
let aliasGetAliasLatestFunctionVersionByFunctionNameStub;
let aliasStacksDescribeResourceStub;

before(() => {
Expand All @@ -45,7 +45,7 @@ describe('logs', () => {
awsAlias = new AWSAlias(serverless, options);
providerRequestStub = sandbox.stub(awsAlias._provider, 'request');
logStub = sandbox.stub(serverless.cli, 'log');
aliasGetAliasFunctionVersionsStub = sandbox.stub(awsAlias, 'aliasGetAliasFunctionVersions');
aliasGetAliasLatestFunctionVersionByFunctionNameStub = sandbox.stub(awsAlias, 'aliasGetAliasLatestFunctionVersionByFunctionName');
aliasStacksDescribeResourceStub = sandbox.stub(awsAlias, 'aliasStacksDescribeResource');

logStub.returns();
Expand Down Expand Up @@ -206,12 +206,7 @@ describe('logs', () => {
],
};
providerRequestStub.resolves(streamReply);
aliasGetAliasFunctionVersionsStub.returns(BbPromise.resolve([
{
functionName: 'func1',
functionVersion: '20'
}
]));
aliasGetAliasLatestFunctionVersionByFunctionNameStub.returns(BbPromise.resolve('20'));
awsAlias._lambdaName = 'func1';

return expect(awsAlias.logsGetLogStreams()).to.be.fulfilled
Expand Down Expand Up @@ -239,7 +234,7 @@ describe('logs', () => {

it('should throw error if no log streams found', () => {
providerRequestStub.resolves();
aliasGetAliasFunctionVersionsStub.returns(BbPromise.resolve([]));
aliasGetAliasLatestFunctionVersionByFunctionNameStub.returns(BbPromise.resolve(null));

return expect(awsAlias.logsGetLogStreams()).to.be.rejectedWith("");
});
Expand Down

0 comments on commit 22000b3

Please sign in to comment.