Skip to content

test(client): wrap cmd.SetArgs to fix bugs for cmd.SetArgs#18876

Merged
tac0turtle merged 5 commits into
cosmos:mainfrom
levisyin:refactor/cmd-setargs
Dec 26, 2023
Merged

test(client): wrap cmd.SetArgs to fix bugs for cmd.SetArgs#18876
tac0turtle merged 5 commits into
cosmos:mainfrom
levisyin:refactor/cmd-setargs

Conversation

@levisyin
Copy link
Copy Markdown
Contributor

@levisyin levisyin commented Dec 23, 2023

Description

This pr is aim to provide a simple way testutil.SetArgs to replace cmd.SetArgs in test as there is bug for cmd.SetArgs, see spf13/cobra/issues/2079 for more detail info about the bug.


Reason

Refer to pr #18557 added test, it's fussy to explicitly set all args that has changed before in writing unit test. We should concentrate on the new test case, no need to care about what this case's args will take effects to other test cases.


Test

I have replaced cmd.SetArgs to testutil.SetArgs in keys show test, it works well. If this pr LGTY, I will draft a new pr to check if there are test cases that depend on the bug behavior of SetArgs, and replace cmd.SetArgs to testutil.SetArgs for all test file.

@levisyin levisyin requested a review from a team December 23, 2023 04:34
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 23, 2023

Walkthrough

The codebase underwent a refactor where the SetArgs function was moved from a test file in the client/keys directory to a utility file in the testutil package. This move was intended to resolve issues with resetting flag values during testing. The runShowCmd function's tests were updated to use the new testutil.SetArgs method. Additionally, two new tests were added to demonstrate the differences between the original cobra.Command.SetArgs method and the new wrapped method.

Changes

Files Change Summary
client/keys/show_test.go
testutil/cmd.go
testutil/cmd_test.go
Moved SetArgs to cmd.go and added new tests for argument setting methods.
Replaced cmd.SetArgs with testutil.SetArgs in test functions.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

Note: Auto-reply has been disabled for this repository by the repository owner. The CodeRabbit bot will not respond to your comments unless it is explicitly tagged.

  • You can tag CodeRabbit on specific lines of code or entire files in the PR by tagging @coderabbitai in a comment. Examples:
  • You can tag @coderabbitai in a PR comment and ask questions about the PR and the codebase. Use quoted replies to pass the context for follow-up questions. Examples:
    • @coderabbitai render interesting statistics about this repository as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai generate unit tests for the src/utils.ts file.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@github-actions github-actions Bot added C:CLI C:Keys Keybase, KMS and HSMs labels Dec 23, 2023
Comment thread testutil/cmd.go
Comment thread testutil/cmd_test.go
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Comment thread testutil/cmd.go
// SetArgs sets arguments for the command. It is desired to replace the cmd.SetArgs in all test case, as cmd.SetArgs doesn't reset flag value as expected.
//
// see https://github.com/spf13/cobra/issues/2079#issuecomment-1867991505 for more detail info
func SetArgs(cmd *cobra.Command, args []string) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should be mindful of new public api we add. Can we maybe have this in an internal package?

Concerning using it everywhere in the sdk, we should really really watch out that we don't increase the reliance on the sdk for already extracted modules.

Copy link
Copy Markdown
Contributor Author

@levisyin levisyin Dec 23, 2023

Choose a reason for hiding this comment

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

@julienrbrt Hi sir, I have moved it to internal/testutil

@julienrbrt julienrbrt changed the title refactor(tests): wrap cmd.SerArgs to fix bugs for cmd.SetArgs test(client) wrap cmd.SetArgs to fix bugs for cmd.SetArgs Dec 23, 2023
Comment thread internal/testutil/cmd.go
Comment thread internal/testutil/cmd_test.go
Comment thread internal/testutil/cmd_test.go
@levisyin levisyin changed the title test(client) wrap cmd.SetArgs to fix bugs for cmd.SetArgs test(client): wrap cmd.SetArgs to fix bugs for cmd.SetArgs Dec 23, 2023
Copy link
Copy Markdown
Contributor

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

lgtm, ty!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C:CLI C:Keys Keybase, KMS and HSMs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants