-
Notifications
You must be signed in to change notification settings - Fork 8
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
The linter raises false positives for the correct usage of MatchError
on Eventually
statements with a SpecContext
argument:
It("should work", func(ctx SpecContext) {
Eventually(ctx, func() error {
return fmt.Errorf("foo")
}).Should(MatchError("foo"))
}, SpecTimeout(time.Second))
ginkgo-linter: the MatchError matcher used to assert a non error type (ctx)
This pattern is the recommended way for implementing interruptible specs when using Eventually
(docs).
To Reproduce
package main_test
import (
"fmt"
"testing"
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
func TestE2E(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "demo")
}
var _ = Describe("the MatchError matcher used to assert a non error type", func() {
It("should work", func(ctx SpecContext) {
Eventually(func() error {
return fmt.Errorf("foo")
}).WithContext(ctx).Should(MatchError("foo"))
}, SpecTimeout(time.Second))
})
Expected behavior
No linter error
Environment:
- OS: macOS
- Version: v0.19.0
Additional context
Note that passing the context as the first Eventually
arg is convenience over passing it to WithContext
.
I.e., this is semantically equivalent but does not raise a false positive:
It("should work", func(ctx SpecContext) {
Eventually(func() error {
return fmt.Errorf("foo")
}).WithContext(ctx).Should(MatchError("foo"))
}, SpecTimeout(time.Second))
nunnatsa
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working