-
Notifications
You must be signed in to change notification settings - Fork 1.6k
🌱 (CLI) Add unit tests for cli alpha generate.go #5074
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
base: master
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mayuka-c The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Hi @mayuka-c. 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-sigs/prow repository. |
c6961d7
to
0ec9db7
Compare
Hi @camilamacedo86 Could you please review the PR whenever you have some time. Thanks :) |
oldPath string | ||
err error | ||
) | ||
BeforeEach(func() { |
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.
Hi @mayuka-c I see there are some BeforeEach
blocks that are identifical. Could we extract them to a helper function and then call that instead? I think this would reduce the code by dozens of lines and make the setup for each test group much cleaner and easier to read. WDYT?
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.
Sure @vitorfloriano, will refactor things to a separate function. It does make sense to simplify and have cleaner test cases. Will be doing it, Thanks :)
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.
Have done the refactoring, PTAL. Thanks!
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.
After doing the rebase, had to make few updates. Please find the change done in description
dac18fe
to
7f381b0
Compare
pkg/cli/alpha/internal/generate.go
Outdated
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.
@mayuka-c Perhaps we should open a PR to address the issue you encountered in this file, with the motivation for the changes. That helps keep each PR within their own scope. This also helps in case we need to revert the changes in the PR.
You could then mark this PR (#5074) as blocked by the new PR.
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.
Sounds good, I was thinking the same. But then as it is mainly done for mocking for helping with UT, decided to keep in the same PR. Will be raising a seperate PR for it. Thanks :)
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.
Here's the seperate PR: #5102.
Have currently set this PR on hold till the above PR is merged and then will be rebasing the changes here so that the test cases will not fail. PTAL, Thanks :)
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.
Now that we have the other PR we can revert the changes in this file.
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 didnt want to revert it here as I didnt want the test cases to fail in this PR. Once my other PR is merged, will be rebasing the changes so that those changes dont appear here. I have made the current PR on hold till my other PR is merged. Hope this is fine
It("should return correct args for plugins, domain, repo", func() { | ||
cfg := &fakeConfig{pluginChain: []string{"go.kubebuilder.io/v3"}, domain: "foo.com", repo: "bar"} | ||
store := &fakeStore{cfg: cfg} | ||
args := getInitArgs(store) | ||
Expect(args).To(ContainElements("--plugins", ContainSubstring("go.kubebuilder.io/v4"), | ||
"--domain", "foo.com", "--repo", "bar")) | ||
}) | ||
It("should return correct args for plugins, domain, repo", func() { |
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.
@mayuka-c These two tests have the same description. Could we improve that to make it more distinguishable?
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.
Nice catch :). Have made the change to include a When
block. PTAL
Context("Without External flag set", func() { | ||
It("runs kubebuilder create api successfully for a resource", func() { | ||
res := resource.Resource{ | ||
GVK: resource.GVK{Group: "example.com", Version: "v1", Kind: "Example", Domain: "external"}, | ||
Plural: "examples", | ||
API: &resource.API{Namespaced: true}, | ||
Controller: true, | ||
External: true, |
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.
@mayuka-c This seems a bit confusing. The context says "Without External flag set"
, but we are setting External
to true.
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.
Looks like a typo from my end. Have updated the description. PTAL
lint fix Modify Tests Minor-1 Minor fix Minor fix 1 Minor fix 2 Minor fix 3 Minor fix 4 Fix - 4 Comments - 1
7f381b0
to
63071ff
Compare
/hold |
Updates: #4925
Also had to make slight modification (after rebasing with main branch) to use dependency injection for mocking executable because of this recent change: #5081
Have raised a seperate PR to address the above issue: #5102