nunnatsa / ginkgolinter

golang linter for ginkgo and gomega
MIT License
24 stars 6 forks source link

Add new rule: function call in async assertions #74

Closed nunnatsa closed 1 year ago

nunnatsa commented 1 year ago

Description

The linter now warns about using Eventually or Consistently with a function call. This is because when doing that, Eventually checks the same returned value again and again, instead of polling by calling the function.

For example:

func slowInt() int {
    time.Sleep(time.Second)
    return 42
}

...

It("should test that slowInt returns 42, eventually", func() {
    Eventually(slowInt()).WithPolling(time.Millisecond * 100).WithTimeout(time.Second * 2).Equal(42)
})

In the above code, Eventually receives 42 as its argument. Then it polls this value to check if it equal

  1. What we really wanted here is:
It("should test that slowInt returns 42, eventually", func() {
    Eventually(slowInt).WithPolling(time.Millisecond * 100).WithTimeout(time.Second * 2).Equal(42)
})

Now, Eventually calls the function until it returns the required value.

To suppress this warning entirely, add the --suppress-async-assertion=true command line flag, or the ginkgo-linter:ignore-async-assert-warning comment.

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

Checklist:

coveralls commented 1 year ago

Pull Request Test Coverage Report for Build 4469374789


Changes Missing Coverage Covered Lines Changed/Added Lines %
types/config.go 2 3 66.67%
ginkgo_linter.go 67 69 97.1%
<!-- Total: 69 72 95.83% -->
Files with Coverage Reduction New Missed Lines %
types/config.go 1 33.33%
ginkgo_linter.go 4 89.34%
<!-- Total: 5 -->
Totals Coverage Status
Change from base Build 4468477451: 0.8%
Covered Lines: 754
Relevant Lines: 898

💛 - Coveralls