-
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
🐛 (go/v4): Refactor e2e-tests for clearer error handling and readable logs #4158
🐛 (go/v4): Refactor e2e-tests for clearer error handling and readable logs #4158
Conversation
c/c @mogsie |
/test pull-kubebuilder-e2e-k8s-1-31-0 |
I added a commit 05da7bc that has a different approach to fixing this. It replaces the []byte with a string in the utils.Run() signature. |
Hi @mogsie I do not think that we should have |
I understand. It may be more a matter of style; maybe we should discuss that (style) over in #4135 before I continue making suggestions to changes to these assertions 😊 |
Hi @mogsie
All contributions that you are doing a terrific great !!! Are you ok with we get this one merged? |
docs/book/src/cronjob-tutorial/testdata/project/test/e2e/e2e_test.go
Outdated
Show resolved
Hide resolved
docs/book/src/cronjob-tutorial/testdata/project/test/e2e/e2e_test.go
Outdated
Show resolved
Hide resolved
Refactors all test cases that use g.Expect(utils.Run(cmd)) to improve both the readability of logs and the clarity of the code. Changes: - Replaced occurrences of g.Expect(utils.Run(cmd)) with: ```go output, err := utils.Run(cmd) g.Expect(err).NotTo(HaveOccurred()) g.Expect(string(output)).To(<condition>) ``` OR ```go _, err := utils.Run(cmd) g.Expect(err).NotTo(HaveOccurred()) ``` **Motivation** - **Human-readable logs:** Output is now converted to a string, providing more understandable logs by displaying actual kubectl command results instead of raw byte arrays. - **Improved code clarity:** The previous `g.Expect(utils.Run(cmd))` usage did not make it clear that the function returns both output and error. By explicitly handling the output and err variables, the code is more transparent and easier to maintain. **Example of problematic scenario** Otherwise, we are unable to check the output when errors are faced. For example Before the changes: ```sh [FAILED] Timed out after 120.001s. The function passed to Eventually failed at /home/runner/work/kubebuilder/kubebuilder/testdata/project-v4-multigroup/test/e2e/e2e_test.go:145 with: Metrics endpoint is not ready Expected <[]uint8 | len:151, cap:1024>: [78, 65, 77, 69, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 69, 78, 68, 80, 79, 73, 78, 84, 83, 32, 32, 32, 65, 71, 69, 10, 112, 114, 111, 106, 101, 99, 116, 45, 118, 52, 45, 109, 117, 108, 116, 105, 103, 114, 111, 117, 112, 45, 99, 111, 110, 116, 114, 111, 108, 108, 101, 114, 45, 109, 97, 110, 97, 103, 101, 114, 45, 109, 101, 116, 114, 105, 99, 115, 45, 115, 101, 114, 118, 105, 99, 101, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 50, 109, 51, 115, 10] to contain substring <string>: 8443 ``` And then, after the changes: ```sh [FAILED] Timed out after 120.001s. The function passed to Eventually failed at /home/runner/work/kubebuilder/kubebuilder/testdata/project-v4-multigroup/test/e2e/e2e_test.go:145 with: Metrics endpoint is not ready Expected <string>: NAME ENDPOINTS AGE project-v4-multigroup-controller-manager-metrics-service 2m3s to contain substring <string>: 8443 In [It] at: /home/runner/work/kubebuilder/kubebuilder/testdata/project-v4-multigroup/test/e2e/e2e_test.go:147 @ 09/11/ ```
77a240f
to
bb94cdd
Compare
Hi @mogsie Thank you for your review ! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: camilamacedo86, mogsie 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 |
…d readable logs BeforeAll func was missing the changes done in the PR: kubernetes-sigs#4158
…d readable logs BeforeAll func was missing the changes done in the PR: kubernetes-sigs#4158
…d readable logs BeforeAll func was missing the changes done in the PR: kubernetes-sigs#4158
Refactors all test cases that use g.Expect(utils.Run(cmd)) to improve both the readability of logs and the clarity of the code.
Changes:
OR
Motivation
g.Expect(utils.Run(cmd))
usage did not make it clear that the function returns both output and error. By explicitly handling the output and err variables, the code is more transparent and easier to maintain.Example of problematic scenario
Otherwise, we are unable to check the output when errors are faced. For example
Before the changes:
Example: https://github.com/kubernetes-sigs/kubebuilder/actions/runs/10807585375/job/29978696165
And then, after the changes:
Example: https://github.com/kubernetes-sigs/kubebuilder/actions/runs/10808334463/job/29981083176?pr=4154