-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
🌱 Added the test-coverage for completion.go and version.go inside cli pkg #3233
🌱 Added the test-coverage for completion.go and version.go inside cli pkg #3233
Conversation
Hi @yashsingh74. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
cc: @camilamacedo86 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one needs to add the tests.
Also, should I change the runE?
The idea of #3211 would not ensure that we cover all (100%) with the unit test but ensure that we increase the tests by covering the methods/func that can easily be covered with unit tests. The commands do not seem a good fit for this one.
Also, in this case, the emoji is 🌱 because it does not change anything for end users, and we should not add those changes in the release notes, which are generated automatically based on the emojis.
Understand. I will add the test case for the files. |
cc: @varshaprasad96 |
@@ -0,0 +1,74 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The header needs to be fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Hi @yashsingh74, It is failing in the tests, could you please:
and the push again for we check out its latest state? |
pkg/cli/completion_test.go
Outdated
Expect(cmd.Short).To(ContainSubstring("Load bash completions")) | ||
Expect(cmd.Example).NotTo(Equal("")) | ||
Expect(cmd.Example).To(ContainSubstring("# To load completion for this session")) | ||
Expect(cmd.Execute()).Error() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to assert here and in the following tests?:
Expect(cmd.Execute()).Error() | |
Expect(cmd.Execute()).Error().ShouldNot(HaveOccured()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran this Execute locally, which returns the error because it returns the multiple possible values. So, checking whether the Execute runs as expected will be good.
• [FAILED] [0.001 seconds]
Version newVersionCmd [It] Test the version
/Users/syash/Desktop/Sample/examples/version/version_test.go:18
[FAILED] Expected an error-type. Got:
<*cobra.Command | 0x140000e2000>: {
Use: "version",
Aliases: nil,
SuggestFor: nil,
Short: "Print the version",
GroupID: "",
Long: "Print the version",
Example: " version",
ValidArgs: nil,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work:
err := cmd.Execute()
Expect(err).To(BeNil())
Expect(cmd.Execute()).Error()
does not assert anything if I'm not wrong. If there is no error, we should assert that error did not occur.
If we expect an output of type *cobra.Command
, we should assert exactly the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran the following workaround with Expect(err).To(BeNil())
• [FAILED] [0.001 seconds]
Version newVersionCmd [It] Test the version
/Users/syash/go/src/k8s.io/kubebuilder/pkg/cli/version_test.go:34
[FAILED] Expected
<*errors.errorString | 0x1400061d390>: {
s: "unknown flag: --test.timeout",
}
to be nil
In [It] at: /Users/syash/go/src/k8s.io/kubebuilder/pkg/cli/version_test.go:47 @ 03/20/23 21:48:32.276
and with Expect(err).NotTo(BeNil())
the test are passing.
I am confused that the Execute command should return nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that the command does return an error, with an unknown flag: --test.timeout
. Could you check where it is coming from? It seems to be a flag being passed by ginkgo tests. If that's an inevitable case, I'd say to remove this check.
a59746c
to
7322709
Compare
@camilamacedo86 I rebased the branch with master but still the test are failing.
|
pkg/cli/completion_test.go
Outdated
Expect(cmd.Short).To(ContainSubstring("Load bash completions")) | ||
Expect(cmd.Example).NotTo(Equal("")) | ||
Expect(cmd.Example).To(ContainSubstring("# To load completion for this session")) | ||
Expect(cmd.Execute()).Error() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that the command does return an error, with an unknown flag: --test.timeout
. Could you check where it is coming from? It seems to be a flag being passed by ginkgo tests. If that's an inevitable case, I'd say to remove this check.
@camilamacedo86 @varshaprasad96 can you review and help to mark this completed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/ok-to-test
/hold cancel
Could you please squash the commits so we can get this one merged now that the suggestion in the review are addressed? |
3fc4358
to
9ed16e7
Compare
9ed16e7
to
3811dd7
Compare
@camilamacedo86 I have squashed the commit. Please provide your approval. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: camilamacedo86, yashsingh74 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
All your requests shows addressed so I am moving forward with this one
This PR introduces the files changes in
completion.go
andversion.go
that will enhance the test coverage.Fixes: #3211
Result -