T001

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

README

T001

T001 checks that Gomega's Eventually and Consistently blocks use a local Gomega instance for asserts instead of a global one.

It is a common pattern to make multiple assertions on a single object in an Eventually or Consistently block:

func ExpectCondition(name string, expectedStatus string, expectedReason string) {
    Eventually(func(g Gomega) {
		conditions := getter.GetConditions(name)
		g.Expect(conditions).NotTo(BeNil())
		g.Expect(actualCondition.Status).To(Equal(expectedStatus))
        // This can fail silently
		Expect(actualCondition.Reason).To(Equal(expectedReason))
	}, timeout, interval).Should(Succeed())
}

However if the code calls the global Expect function from the gomega module instead of using the locally passed in g Gomega variable then such Except call can fail silently without properly stopping and cleaning up the test. This is documented in the gomega doc but nothing is enforcing this rule in gomega.

Documentation

Index

Constants

View Source
const (
	Name = "L001"
	Doc  = "Checks Eventually and Consistently Gomega blocks to alway use a local Gomega variable for asserts"
)
View Source
const (
	GomegaPkg  = "\"github.com/onsi/gomega\""
	GomegaType = "Gomega"
)

Variables

This section is empty.

Functions

func NewAnalyzer

func NewAnalyzer() *analysis.Analyzer

Types

type Linter

type Linter struct {
	*b.BaseLinter
}

func (*Linter) LintFile

func (l *Linter) LintFile(file *ast.File) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL