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

🏃 Cleanup the readability of some gomega error checking #1497

Merged
merged 1 commit into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Copy link
Member

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

Copy link
Member Author

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

Copy link
Member

Choose a reason for hiding this comment

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

sgtm

Copy link
Contributor

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.


// apply generated manifests
applyManifests(kindCluster, &manifestFile)
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/kind/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ func (c *Cluster) run(cmd *exec.Cmd) {
go captureOutput(&wg, outPipe, "stdout")
}

gomega.Expect(cmd.Start()).NotTo(gomega.HaveOccurred())
gomega.Expect(cmd.Start()).To(gomega.Succeed())
wg.Wait()
gomega.Expect(cmd.Wait()).NotTo(gomega.HaveOccurred())
gomega.Expect(cmd.Wait()).To(gomega.Succeed())
}

func captureOutput(wg *sync.WaitGroup, r io.Reader, label string) {
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/scheme/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

func SetupScheme() *runtime.Scheme {
scheme := runtime.NewScheme()
gomega.Expect(clientgoscheme.AddToScheme(scheme)).NotTo(gomega.HaveOccurred())
gomega.Expect(clusterv1.AddToScheme(scheme)).NotTo(gomega.HaveOccurred())
gomega.Expect(clientgoscheme.AddToScheme(scheme)).To(gomega.Succeed())
gomega.Expect(clusterv1.AddToScheme(scheme)).To(gomega.Succeed())
return scheme
}