-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Improve Ginkgo/Gomega Test Practices in Scaffolded and e2e Tests #4424
Comments
/assign |
In #4135, I originally made a suggestion of replacing the following type of tests:
with the more concise (but functionally equivalent)
The one line above
Should we reconsider this? The one line is (to me) more maintainable, although it relies Gomega implicitly testing that From #4135:
Maybe we should provide a document that describes the desired test idioms for the scaffolded tests and for the internal tests? Because, as mentioned, kubebuilder will often be introducing both Ginkgo and Gomega to its users; we should probably spend time explaining some of those test idioms in the scaffolded tests. e.g. adding a comment as denoted by /**/ below:
This way we would be "teaching" the API (in this case the utils.Run(), and then how to use Ginkgo to make assertions against that. |
Hi @mogsie, We really appreciate the amazing contributions you’ve been making to the tests—it’s fantastic work! kubebuilder/testdata/project-v4/test/e2e/e2e_test.go Lines 70 to 71 in e25aec4
I believe we discussed this previously and even reverted a similar change in the past—right? Why this is important: It makes clear what is returned from Most importantly, this approach allows us to check for errors encountered during the tests. Remember that we checked that? |
So, to close this one, IHMO it is only missing: Replace the Then, we can close this one. |
Yes, but I think it happened on slack, so it is hard to find. This is why I think maybe these decisions should live in a document in the repo, for contributors to get guidance.
kubebuilder/testdata/project-v4/test/e2e/e2e_test.go Lines 154 to 159 in e25aec4
The comment is mainly to explain why two styles of assertions are used in the same function body. I would personally prefer to only do the second style, removing the need for a comment. The implicit checking of errors of Gomega is indeed "hidden", but not embracing it results in a lot of extra noise and typing. Just in that e2e_test.go file, there are ~20 such "expect err not to have occurred" lines, and additional noise introduced by temporary variables that are often only used once By not showing this way of writing tests, the scaffolded code encourages IMHO bad habits.
I'm not quite sure I understand this comment. The errors are automatically checked for nil-ness, unless you expect an error. If you're talking about making assertions on the error itself, then yes, you can still do this: Lines 116 to 118 in e25aec4
|
What do you want to happen?
Kubebuilder creates/scaffolds a lot of test code. This test code uses Ginkgo and Gomega. Some of the tests as written don't take full advantage of Gomega's testing framework. Since Kubebuilder is likely to introduce many developers to Gomega, it is important that the scaffolded code provides the best possible examples.
We should see that the tests scaffolded for end-users have this issue fixed already: testdata/project-v4/test.
What we need to do here is ensure that ALL our e2e tests are also following the same patterns as the end-user scaffolds. Therefore, the necessary changes must be implemented in: test/e2e.
Context
The context for this issue and similar discussions can be found here: kubernetes-sigs/kubebuilder#4135.
Tasks
testdata/project-v4/test
to ensure best practices in Ginkgo/Gomega are being followed.test/e2e
to align with these patterns and provide the best examples for developers.Extra Labels
/kind cleanup
The text was updated successfully, but these errors were encountered: