Skip to content

fix: CLI option count type deprecation warning #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2021
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
1 change: 1 addition & 0 deletions logs/googleLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class GoogleLogs {
count: {
usage: 'Amount of requested logs',
shortcut: 'c',
type: 'string',
},
},
},
Expand Down
4 changes: 4 additions & 0 deletions logs/googleLogs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ describe('GoogleLogs', () => {
expect(googleLogs.commands.logs.options.count).not.toEqual(undefined);
});

it('should have the option "count" with type "string"', () => {
expect(googleLogs.commands.logs.options.count.type).toEqual('string');
});

describe('hooks', () => {
let validateStub;
let setDefaultsStub;
Expand Down
2 changes: 1 addition & 1 deletion logs/lib/retrieveLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
getLogs() {
const project = this.serverless.service.provider.project;
let func = this.options.function;
const pageSize = this.options.count || 10;
const pageSize = parseInt(this.options.count, 10) || 10;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it worked previously correctly without casting to int, but I think it doesn't hurt here 👍


func = getGoogleCloudFunctionName(this.serverless.service.functions, func);

Expand Down
16 changes: 16 additions & 0 deletions logs/lib/retrieveLogs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ describe('RetrieveLogs', () => {
});
});

it('should parse the "count" option as an integer', () => {
googleLogs.options.function = 'func1';
googleLogs.options.count = '100';

return googleLogs.getLogs().then(() => {
expect(
requestStub.calledWithExactly('logging', 'entries', 'list', {
filter: 'resource.labels.function_name="full-function-name" AND NOT textPayload=""',
orderBy: 'timestamp desc',
resourceNames: ['projects/my-project'],
pageSize: parseInt(googleLogs.options.count, 10),
})
).toEqual(true);
});
});

it('should throw an error if the function could not be found in the service', () => {
googleLogs.options.function = 'missingFunc';

Expand Down