Skip to content

Commit 22000b3

Browse files
author
Roy Hui
committed
edited test cases
updated test cases for logs to match the enhancement
1 parent f230c79 commit 22000b3

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

lib/logs.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,15 @@ module.exports = {
7777
throw new this.serverless.classes
7878
.Error('No existing streams for the function alias');
7979
}
80-
return _.map(
80+
const logStreamNames = _.map(
8181
_.filter(reply.logStreams, stream => _.includes(stream.logStreamName, `[${version}]`)),
8282
stream => stream.logStreamName);
83+
84+
if (_.isEmpty(logStreamNames)) {
85+
return BbPromise.reject(new this.serverless.classes
86+
.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'));
87+
}
88+
return logStreamNames
8389
});
8490
});
8591

@@ -125,10 +131,6 @@ module.exports = {
125131
},
126132

127133
functionLogsShowLogs(logStreamNames) {
128-
if (_.isEmpty(logStreamNames)) {
129-
return BbPromise.reject(new this.serverless.classes
130-
.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'));
131-
}
132134
const formatLambdaLogEvent = event => {
133135
const msgParam = event.message;
134136
let msg = msgParam;

test/logs.test.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('logs', () => {
2323
let sandbox;
2424
let providerRequestStub;
2525
let logStub;
26-
let aliasGetAliasFunctionVersionsStub;
26+
let aliasGetAliasLatestFunctionVersionByFunctionNameStub;
2727
let aliasStacksDescribeResourceStub;
2828

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

5151
logStub.returns();
@@ -206,12 +206,7 @@ describe('logs', () => {
206206
],
207207
};
208208
providerRequestStub.resolves(streamReply);
209-
aliasGetAliasFunctionVersionsStub.returns(BbPromise.resolve([
210-
{
211-
functionName: 'func1',
212-
functionVersion: '20'
213-
}
214-
]));
209+
aliasGetAliasLatestFunctionVersionByFunctionNameStub.returns(BbPromise.resolve('20'));
215210
awsAlias._lambdaName = 'func1';
216211

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

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

244239
return expect(awsAlias.logsGetLogStreams()).to.be.rejectedWith("");
245240
});

0 commit comments

Comments
 (0)