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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance webhook_test template #4148

Closed
camilamacedo86 opened this issue Sep 9, 2024 · 2 comments · Fixed by #4151
Closed

Enhance webhook_test template #4148

camilamacedo86 opened this issue Sep 9, 2024 · 2 comments · Fixed by #4151
Assignees
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug. release-blocker

Comments

@camilamacedo86
Copy link
Member

What broke? What's expected?

We need to address this in the scaffold. See: webhook_test_template.go.

More information can be found in the comments raised in this PR.

Reproducing this issue

Odd Indentation:

// It("Should apply defaults when a required field is empty", func() {
		//     By("simulating a scenario where defaults should be applied")
		// 	   obj.SomeFieldWithDefault = ""

Improvements to gomega usage:

  • Replace : Expect(err).NotTo(HaveOccurred())

  • With: Expect(obj.Default(ctx)).To(Succeed())

  • Replace: warnings, err := obj.ValidateCreate(ctx)

  • With: Expect(obj.ValidateCreate(ctx)).Error().To(HaveOccurred())

See that we will need to either change the contents that we find/replace to generate the docs samples under the hack/docs.

KubeBuilder (CLI) Version

master

PROJECT version

No response

Plugin versions

No response

Other versions

No response

Extra Labels

No response

@camilamacedo86 camilamacedo86 added the kind/bug Categorizes issue or PR as related to a bug. label Sep 9, 2024
@camilamacedo86
Copy link
Member Author

c/c @mogsie

@camilamacedo86 camilamacedo86 added release-blocker help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. labels Sep 9, 2024
@mogsie
Copy link
Contributor

mogsie commented Sep 9, 2024

/assign

mogsie added a commit to mogsie/kubebuilder that referenced this issue Sep 9, 2024
Fixes kubernetes-sigs#4148

- Indentation
- simplify gomega assertions
mogsie added a commit to mogsie/kubebuilder that referenced this issue Sep 9, 2024
The webhook scaffold had some oddly indented regions, resulting in the
generated source code having a mix of tabs and spaces, and was generally
looking quite ugly.

The gomega asserions are too chatty; errors, and return values are
checked after first being assigned as variables in scope. This is not
needed, and Gomega checks all of this for us:

Expect(someFunc()).Error().To(HaveOccurred()) checks both the error, but also that the other return values are zero or nil.
Expect(someFunc()).To(ContainSubstring("X")) checks both the return value and verifies that the error is nil.

Fixes kubernetes-sigs#4148

- Indentation
- simplify gomega assertions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug. release-blocker
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants