-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
🏃 Cleanup the readability of some gomega error checking #1497
Conversation
@@ -134,7 +134,7 @@ func deployCAPIComponents(kindCluster kind.Cluster) { | |||
|
|||
// write out the manifests | |||
manifestFile := path.Join(suiteTmpDir, "cluster-api-components.yaml") | |||
gomega.Expect(ioutil.WriteFile(manifestFile, capiManifests, 0644)).NotTo(gomega.HaveOccurred()) | |||
gomega.Expect(ioutil.WriteFile(manifestFile, capiManifests, 0644)).To(gomega.Succeed()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For errors we usually use .NotTo(HaveOccurred())
, in line with Solly's suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are testing the error separately, I agree. If we are testing the result of a method that returns a single error value, .NotTo(HaveOccurred()
reads as if you intend for the call to not have occurred, vs testing for success.
Gomega docs recommend using Succeed in this case as well: https://onsi.github.io/gomega/#handling-errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have been meaning to file an issue about this. Expect(SomeCallThatReturnsAnError()).NotTo(HaveOccurred()) is super confusing to read.
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: detiber, vincepri 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 |
What this PR does / why we need it:
Cleans up the readability of some of the gomega error checking in the test helpers.