nunnatsa / ginkgolinter

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

[BUG] `Eventually(gexec-session).Should(....)` musst not error #88

Closed danail-branekov closed 1 year ago

danail-branekov commented 1 year ago

Describe the bug According to gexec.Session docs

In addition, Session satisfies the gbytes.BufferProvider interface and provides the stdout *gbytes.Buffer.  This allows you to replace the first line, above, with:

    Expect(session).Should(gbytes.Say("foo-out"))

However, ginkgolinter reports an error when using a function returning a session as an Eventually argument:

Example:

package my_test

import (
    "os"
    "os/exec"

    . "github.com/onsi/ginkgo/v2"
    . "github.com/onsi/gomega"
    . "github.com/onsi/gomega/gexec"
)

var _ = FDescribe("Foo", func() {
    createSession := func() *Session {
        s, err := Start(exec.Command(os.Args[0]), GinkgoWriter, GinkgoWriter)
        Expect(err).NotTo(HaveOccurred())
        return s
    }

    It("foos", func() {
        Eventually(createSession()).Should(Exit())
    })
})

Produces the following error:

foo_test.go:20:3: ginkgo-linter: use a function call in Eventually. This actually checks nothing, because Eventually receives the function returned value, instead of function itself, and this value is never changed; consider using `Eventually(createSession).Should(Exit())` instead

To Reproduce Steps to reproduce the behavior:

  1. Run ginkgo linter on the sample above

Expected behavior The linter should not produce an error

Environment:

nunnatsa commented 1 year ago

Thanks for the report, @danail-branekov

Addressed in #89

nunnatsa commented 1 year ago

@danail-branekov, fyi, golangci-lint v1.53.3 just released with a fix to this issue.