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

refactor gomega assertions #15

Open
mayankshah1607 opened this issue Jul 27, 2020 · 0 comments
Open

refactor gomega assertions #15

mayankshah1607 opened this issue Jul 27, 2020 · 0 comments

Comments

@mayankshah1607
Copy link
Contributor

mayankshah1607 commented Jul 27, 2020

Problem

Currently, we're making use of Gomega as a matcher library with Ginkgo, for making assertions in the tests. An example of such an assertion would be:

func testSomething() {
    err := doSomething()
    gomega.Expect(err).Should(gomega.BeNil(), fmt.Sprint("failed to do something: %s", err.Error()))
}

The problem with using these directly in the tests would be that contributors now have to deal with learning the Gomega syntax for assertions, and also having too many of these look ugly and make the code less readable.

Solution

We could create reusable helper functions that essentially act as wrappers around these assertions. For example

func ExpectNil(item interface{}. annotation string) {
    gomega.Expect(err).Should(gomega.BeNil(), message)
}

func testSomething() {
    err := doSomething()
    utils.ExpectNil(err, fmt.Sprintf("failed to do something: %s", err.Error()))
}
@mayankshah1607 mayankshah1607 changed the title reafactor gomega assertions refactor gomega assertions Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant