Skip to content

Conversation

mayuka-c
Copy link
Contributor

@mayuka-c mayuka-c commented Sep 3, 2025

Updates: #4925

  • Improve the coverage by adding UTs for cli alpha generate.go.
  • This is the continuation of my other UT PRs to improve coverage :)

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

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 3, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mayuka-c
Once this PR has been reviewed and has the lgtm label, please assign varshaprasad96 for approval. For more information see the Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 3, 2025
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Sep 3, 2025
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@mayuka-c mayuka-c changed the title Add unit tests for cli alpha generate.go 🌱 (CLI) Add unit tests for cli alpha generate.go Sep 3, 2025
@mayuka-c mayuka-c force-pushed the ut-alpha-generate branch 4 times, most recently from c6961d7 to 0ec9db7 Compare September 3, 2025 05:56
@mayuka-c mayuka-c changed the title 🌱 (CLI) Add unit tests for cli alpha generate.go 🌱 (CLI) Add unit tests for cli alpha generate.go Sep 4, 2025
@mayuka-c
Copy link
Contributor Author

mayuka-c commented Sep 8, 2025

Hi @camilamacedo86 Could you please review the PR whenever you have some time. Thanks :)
Also could you please run /ok-to-test if the changes are good

oldPath string
err error
)
BeforeEach(func() {
Copy link
Contributor

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?

Copy link
Contributor Author

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 :)

Copy link
Contributor Author

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!

Copy link
Contributor Author

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

@mayuka-c mayuka-c force-pushed the ut-alpha-generate branch 2 times, most recently from dac18fe to 7f381b0 Compare September 15, 2025 15:00
Copy link
Contributor

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.

Copy link
Contributor Author

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 :)

Copy link
Contributor Author

@mayuka-c mayuka-c Sep 16, 2025

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 :)

Copy link
Contributor

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.

Copy link
Contributor Author

@mayuka-c mayuka-c Sep 17, 2025

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

Comment on lines 286 to 293
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() {
Copy link
Contributor

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?

Copy link
Contributor Author

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

Comment on lines 426 to 441
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,
Copy link
Contributor

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.

Copy link
Contributor Author

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
@mayuka-c
Copy link
Contributor Author

/hold
Waiting for the dependency PR to be merged: #5102

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants