Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Fix issue found to re-generate the scaffolds with the new alpha command and adding e2e tests #3461

Merged
merged 1 commit into from
Jul 5, 2023

Conversation

yyy1000
Copy link
Member

@yyy1000 yyy1000 commented Jun 19, 2023

Description:

Add e2e tests for kubebuilder alpha generate command.

Motivation:

Validate the functionality and the behavior of the new alpha command that has been merged.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 19, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @yyy1000. 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/test-infra repository.

@camilamacedo86
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 20, 2023
@camilamacedo86
Copy link
Member

@yyy1000,

PLease squash the commits and rebase it with master so that we can move forward with this one

// Run e2e tests using the Ginkgo runner.
func TestE2E(t *testing.T) {
RegisterFailHandler(Fail)
fmt.Fprintf(GinkgoWriter, "Starting kubebuilder alpha generate suite\n")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fmt.Fprintf(GinkgoWriter, "Starting kubebuilder alpha generate suite\n")
fmt.Fprintf(GinkgoWriter, "Starting kubebuilder suite test for the alpha command generate\n")

kbc.Destroy()
})

It("should generate a runnable project with alpha generate", func() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
It("should generate a runnable project with alpha generate", func() {
It("should regenerate the project with success", func() {

We are not testing that the result is runnable so I think we need to change the test description

@yyy1000
Copy link
Member Author

yyy1000 commented Jun 20, 2023

I seems that the e2e tests in CI indicate other error not related to the change in this PR.

@yyy1000
Copy link
Member Author

yyy1000 commented Jun 20, 2023

/retest

)
ExpectWithOffset(1, err).NotTo(HaveOccurred())

fileContainsExpr, err := pluginutil.HasFileContentWith(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fileContainsExpr, err := pluginutil.HasFileContentWith(
By("checking if the project file was generated with the expected content")
fileContainsExpr, err := pluginutil.HasFileContentWith(

Copy link
Member

Choose a reason for hiding this comment

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

Let's add a description so we have further info when fails to know where it failed

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good idea.

- go.kubebuilder.io/v4
projectName: testdir
repo: my.domain/hello
version: "3"`)
Copy link
Member

Choose a reason for hiding this comment

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

I think it is easier to keep maintained if we create a const could we use a const instead?
See the other places for example.
It might be failing due missing spaces and etc.

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

I added so comments but you are doing great !!!

)
ExpectWithOffset(1, err).NotTo(HaveOccurred())

fileContainsExpr, err := pluginutil.HasFileContentWith(
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a description so we have further info when fails to know where it failed

layout:
- go.kubebuilder.io/v4
projectName: testdir
repo: my.domain/hello
Copy link
Member

Choose a reason for hiding this comment

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

The repo, domain will not be this one since when we use the testContext and generate the project we create a domain and etc for the test. Therefore, see that

  • The domain will be kbc.Domain so you can use format string to pass the const with %s and replace the domain with the expected value
  • I would suggest you remove the repo: my.domain/hello

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry for this problem. I set domain to this because I tested in local, and whatever the old PROJECT file is. The domain of the new PROJECT file is always 'my.domain'. Maybe there's some problem with my implementation of 'alpha generate'.

@yyy1000 yyy1000 force-pushed the e2e branch 3 times, most recently from b45192b to c81f978 Compare June 25, 2023 05:08
@camilamacedo86 camilamacedo86 changed the title 馃尡 Add e2e tests for alpha generate command 馃悰 Fix issue found to re-generate the scaffolds with the new alpha command and adding e2e tests Jun 25, 2023
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

I just change the title but it seems great for me 馃
Good work !!

It has my approval,

Lets see if @varshaprasad96 and @Kavinjsir has none any extra considerations and if we have their lgtm as well.

Thank you

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86, yyy1000

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 25, 2023
Copy link
Member

@varshaprasad96 varshaprasad96 left a comment

Choose a reason for hiding this comment

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

Great work @yyy1000. Just a few nit questions.

Comment on lines +114 to +115
args = append(args, "--plugins")
args = append(args, plugins...)
Copy link
Member

Choose a reason for hiding this comment

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

could we do all the appends together?

Suggested change
args = append(args, "--plugins")
args = append(args, plugins...)
args = append(args, "--plugins", plugins...)

Copy link
Member Author

Choose a reason for hiding this comment

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

No, I tried this and it will not compile:

too many arguments in call to append
        have ([]string, string, []string)
        want ([]string, ...string)
make: *** [Makefile:57: build] Error 1

Comment on lines 119 to 120
args = append(args, "--domain")
args = append(args, domain)
Copy link
Member

Choose a reason for hiding this comment

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

Similarly, does this work?

Suggested change
args = append(args, "--domain")
args = append(args, domain)
args = append(args, "--domain", domain)

Copy link
Member Author

Choose a reason for hiding this comment

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

This works! I think it's because when using append method, you either append multiple single element or a slice of elements. But can't mix them. :)

Comment on lines 29 to 30
//nolint:golint
//nolint:revive
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to disable the linters here? Looks like we don't in other places and it works (https://github.com/kubernetes-sigs/kubebuilder/blob/47e6cab305336e1a7a5d577dc3c1500a445a70d1/pkg/cli/version_test.go#L20C1-L21)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I just copy the code from other e2e tests code. I removed them, ran 'make lint' command and it was OK. I think I can also remove other unnecessary linters in another PR. :)

feat: add test data

fix: add test in setup

fix: change the file to PROJECT

fix: test file update

fix: doc nit and test data

feat: Add By to check and project file

feat: separate fields

feat: use domain when scafflod

feat: add plugin arg when re-scaffold

fix: function name

feat: refactor plugins

fix: remove lint

fix: domain append
@camilamacedo86 camilamacedo86 dismissed varshaprasad96鈥檚 stale review July 3, 2023 12:55

All seems most addressed so moving forward here for @yyy1000 does not get blocked.

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 3, 2023
@camilamacedo86
Copy link
Member

/pull-kubebuilder-e2e-k8s-1-27-1
/pull-kubebuilder-e2e-k8s-1-25-3

@yyy1000
Copy link
Member Author

yyy1000 commented Jul 4, 2023

/retest

@camilamacedo86
Copy link
Member

/test pull-kubebuilder-e2e-k8s-1-27-1
/test pull-kubebuilder-e2e-k8s-1-25-3

@k8s-ci-robot k8s-ci-robot merged commit a632400 into kubernetes-sigs:master Jul 5, 2023
17 checks passed
@yyy1000 yyy1000 deleted the e2e branch July 5, 2023 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants