Skip to content

Commit 0b62feb

Browse files
authored
dev: add tests for the new ginkgolinter's configuration (#3970)
1 parent d58342f commit 0b62feb

11 files changed

+201
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
ginkgolinter:
3+
suppress-focus-container: true

test/testdata/ginkgolinter/ginkgolinter.go

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"time"
77

8+
. "github.com/onsi/ginkgo/v2"
89
. "github.com/onsi/gomega"
910
)
1011

@@ -76,3 +77,11 @@ func WrongEventuallyWithFunction() {
7677
Eventually(slowInt).Should(Equal(42)) // valid
7778
Eventually(slowInt()).Should(Equal(42)) // want "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\\(slowInt\\)\\.Should\\(Equal\\(42\\)\\). instead"
7879
}
80+
81+
var _ = Describe("Should warn for focused containers", func() {
82+
FContext("should not allow FContext", func() { // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"Context\""
83+
FWhen("should not allow FWhen", func() { // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"When\""
84+
FIt("should not allow FIt", func() {}) // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"It\""
85+
})
86+
})
87+
})

test/testdata/ginkgolinter/ginkgolinter_havelen0.go

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"time"
88

9+
. "github.com/onsi/ginkgo/v2"
910
. "github.com/onsi/gomega"
1011
)
1112

@@ -77,3 +78,11 @@ func WrongEventuallyWithFunction_havelen0() {
7778
Eventually(slowInt_havelen0).Should(Equal(42)) // valid
7879
Eventually(slowInt_havelen0()).Should(Equal(42)) // want "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\\(slowInt_havelen0\\)\\.Should\\(Equal\\(42\\)\\). instead"
7980
}
81+
82+
var _ = Describe("Should warn for focused containers", func() {
83+
FContext("should not allow FContext", func() { // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"Context\""
84+
FWhen("should not allow FWhen", func() { // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"When\""
85+
FIt("should not allow FIt", func() {}) // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"It\""
86+
})
87+
})
88+
})

test/testdata/ginkgolinter/ginkgolinter_suppress_async.go

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"time"
88

9+
. "github.com/onsi/ginkgo/v2"
910
. "github.com/onsi/gomega"
1011
)
1112

@@ -78,3 +79,11 @@ func WrongEventuallyWithFunction_async() {
7879
Eventually(slowInt_async).Should(Equal(42)) // valid
7980
Eventually(slowInt_async()).Should(Equal(42)) // suppressed
8081
}
82+
83+
var _ = Describe("Should warn for focused containers", func() {
84+
FContext("should not allow FContext", func() { // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"Context\""
85+
FWhen("should not allow FWhen", func() { // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"When\""
86+
FIt("should not allow FIt", func() {}) // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"It\""
87+
})
88+
})
89+
})

test/testdata/ginkgolinter/ginkgolinter_suppress_compare.go

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"time"
88

9+
. "github.com/onsi/ginkgo/v2"
910
. "github.com/onsi/gomega"
1011
)
1112

@@ -78,3 +79,11 @@ func WrongEventuallyWithFunction_compare() {
7879
Eventually(slowInt_compare).Should(Equal(42)) // valid
7980
Eventually(slowInt_compare()).Should(Equal(42)) // want "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\\(slowInt_compare\\)\\.Should\\(Equal\\(42\\)\\). instead"
8081
}
82+
83+
var _ = Describe("Should warn for focused containers", func() {
84+
FContext("should not allow FContext", func() { // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"Context\""
85+
FWhen("should not allow FWhen", func() { // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"When\""
86+
FIt("should not allow FIt", func() {}) // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"It\""
87+
})
88+
})
89+
})

test/testdata/ginkgolinter/ginkgolinter_suppress_err.go

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"time"
88

9+
. "github.com/onsi/ginkgo/v2"
910
. "github.com/onsi/gomega"
1011
)
1112

@@ -78,3 +79,11 @@ func WrongEventuallyWithFunction_err() {
7879
Eventually(slowInt_err).Should(Equal(42)) // valid
7980
Eventually(slowInt_err()).Should(Equal(42)) // want "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\\(slowInt_err\\)\\.Should\\(Equal\\(42\\)\\). instead"
8081
}
82+
83+
var _ = Describe("Should warn for focused containers", func() {
84+
FContext("should not allow FContext", func() { // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"Context\""
85+
FWhen("should not allow FWhen", func() { // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"When\""
86+
FIt("should not allow FIt", func() {}) // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"It\""
87+
})
88+
})
89+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//golangcitest:args --disable-all -Eginkgolinter
2+
//golangcitest:config_path configs/ginkgolinter_suppress_focused_containers.yml
3+
package ginkgolinter
4+
5+
import (
6+
"errors"
7+
"time"
8+
9+
. "github.com/onsi/ginkgo/v2"
10+
. "github.com/onsi/gomega"
11+
)
12+
13+
func LenUsecase_focus() {
14+
var fakeVarUnderTest []int
15+
Expect(fakeVarUnderTest).Should(BeEmpty()) // valid
16+
Expect(fakeVarUnderTest).ShouldNot(HaveLen(5)) // valid
17+
18+
Expect(len(fakeVarUnderTest)).Should(Equal(0)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.Should\\(BeEmpty\\(\\)\\). instead"
19+
Expect(len(fakeVarUnderTest)).ShouldNot(Equal(2)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.ShouldNot\\(HaveLen\\(2\\)\\). instead"
20+
Expect(len(fakeVarUnderTest)).To(BeNumerically("==", 0)) // // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.To\\(BeEmpty\\(\\)\\). instead"
21+
22+
fakeVarUnderTest = append(fakeVarUnderTest, 3)
23+
Expect(len(fakeVarUnderTest)).ShouldNot(Equal(0)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.ShouldNot\\(BeEmpty\\(\\)\\). instead"
24+
Expect(len(fakeVarUnderTest)).Should(Equal(1)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.Should\\(HaveLen\\(1\\)\\). instead"
25+
Expect(len(fakeVarUnderTest)).To(BeNumerically(">", 0)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.ToNot\\(BeEmpty\\(\\)\\). instead"
26+
Expect(len(fakeVarUnderTest)).To(BeNumerically(">=", 1)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.ToNot\\(BeEmpty\\(\\)\\). instead"
27+
Expect(len(fakeVarUnderTest)).To(BeNumerically("!=", 0)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.ToNot\\(BeEmpty\\(\\)\\). instead"
28+
}
29+
30+
func NilUsecase_focus() {
31+
y := 5
32+
x := &y
33+
Expect(x == nil).To(Equal(true)) // want "ginkgo-linter: wrong nil assertion; consider using .Expect\\(x\\)\\.To\\(BeNil\\(\\)\\). instead"
34+
Expect(nil == x).To(Equal(true)) // want "ginkgo-linter: wrong nil assertion; consider using .Expect\\(x\\)\\.To\\(BeNil\\(\\)\\). instead"
35+
Expect(x != nil).To(Equal(true)) // want "ginkgo-linter: wrong nil assertion; consider using .Expect\\(x\\)\\.ToNot\\(BeNil\\(\\)\\). instead"
36+
Expect(x == nil).To(BeTrue()) // want "ginkgo-linter: wrong nil assertion; consider using .Expect\\(x\\)\\.To\\(BeNil\\(\\)\\). instead"
37+
Expect(x == nil).To(BeFalse()) // want "ginkgo-linter: wrong nil assertion; consider using .Expect\\(x\\)\\.ToNot\\(BeNil\\(\\)\\). instead"
38+
}
39+
func BooleanUsecase_focus() {
40+
x := true
41+
Expect(x).To(Equal(true)) // want "ginkgo-linter: wrong boolean assertion; consider using .Expect\\(x\\)\\.To\\(BeTrue\\(\\)\\). instead"
42+
x = false
43+
Expect(x).To(Equal(false)) // want "ginkgo-linter: wrong boolean assertion; consider using .Expect\\(x\\)\\.To\\(BeFalse\\(\\)\\). instead"
44+
}
45+
46+
func ErrorUsecase_focus() {
47+
err := errors.New("fake error")
48+
funcReturnsErr := func() error { return err }
49+
50+
Expect(err).To(BeNil()) // want "ginkgo-linter: wrong error assertion; consider using .Expect\\(err\\)\\.ToNot\\(HaveOccurred\\(\\)\\). instead"
51+
Expect(err == nil).To(Equal(true)) // want "ginkgo-linter: wrong error assertion; consider using .Expect\\(err\\)\\.ToNot\\(HaveOccurred\\(\\)\\). instead"
52+
Expect(err == nil).To(BeFalse()) // want "ginkgo-linter: wrong error assertion; consider using .Expect\\(err\\)\\.To\\(HaveOccurred\\(\\)\\). instead"
53+
Expect(err != nil).To(BeTrue()) // want "ginkgo-linter: wrong error assertion; consider using .Expect\\(err\\)\\.To\\(HaveOccurred\\(\\)\\). instead"
54+
Expect(funcReturnsErr()).To(BeNil()) // want "ginkgo-linter: wrong error assertion; consider using .Expect\\(funcReturnsErr\\(\\)\\)\\.To\\(Succeed\\(\\)\\). instead"
55+
}
56+
57+
func HaveLen0Usecase_focus() {
58+
x := make([]string, 0)
59+
Expect(x).To(HaveLen(0)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(x\\)\\.To\\(BeEmpty\\(\\)\\). instead"
60+
}
61+
62+
func WrongComparisonUsecase_focus() {
63+
x := 8
64+
Expect(x == 8).To(BeTrue()) // want "ginkgo-linter: wrong comparison assertion; consider using .Expect\\(x\\)\\.To\\(Equal\\(8\\)\\). instead"
65+
Expect(x < 9).To(BeTrue()) // want "ginkgo-linter: wrong comparison assertion; consider using .Expect\\(x\\)\\.To\\(BeNumerically\\(\"<\", 9\\)\\). instead"
66+
Expect(x < 7).To(Equal(false)) // want "ginkgo-linter: wrong comparison assertion; consider using .Expect\\(x\\)\\.ToNot\\(BeNumerically\\(\"<\", 7\\)\\). instead"
67+
68+
p1, p2 := &x, &x
69+
Expect(p1 == p2).To(Equal(true)) // want "ginkgo-linter: wrong comparison assertion; consider using .Expect\\(p1\\).To\\(BeIdenticalTo\\(p2\\)\\). instead"
70+
}
71+
72+
func slowInt_focus() int {
73+
time.Sleep(time.Second)
74+
return 42
75+
}
76+
77+
func WrongEventuallyWithFunction_focus() {
78+
Eventually(slowInt_focus).Should(Equal(42)) // valid
79+
Eventually(slowInt_focus()).Should(Equal(42)) // want "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\\(slowInt_focus\\)\\.Should\\(Equal\\(42\\)\\). instead"
80+
}
81+
82+
var _ = FDescribe("Should warn for focused containers", func() {
83+
FContext("should not allow FContext", func() {
84+
FWhen("should not allow FWhen", func() {
85+
FIt("should not allow FIt", func() {
86+
87+
})
88+
})
89+
})
90+
})

test/testdata/ginkgolinter/ginkgolinter_suppress_len.go

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"time"
88

9+
. "github.com/onsi/ginkgo/v2"
910
. "github.com/onsi/gomega"
1011
)
1112

@@ -78,3 +79,11 @@ func WrongEventuallyWithFunction_len() {
7879
Eventually(slowInt_len).Should(Equal(42)) // valid
7980
Eventually(slowInt_len()).Should(Equal(42)) // want "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\\(slowInt_len\\)\\.Should\\(Equal\\(42\\)\\). instead"
8081
}
82+
83+
var _ = Describe("Should warn for focused containers", func() {
84+
FContext("should not allow FContext", func() { // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"Context\""
85+
FWhen("should not allow FWhen", func() { // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"When\""
86+
FIt("should not allow FIt", func() {}) // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"It\""
87+
})
88+
})
89+
})

test/testdata/ginkgolinter/ginkgolinter_suppress_nil.go

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"time"
88

9+
. "github.com/onsi/ginkgo/v2"
910
. "github.com/onsi/gomega"
1011
)
1112

@@ -78,3 +79,11 @@ func WrongEventuallyWithFunction_nil() {
7879
Eventually(slowInt_nil).Should(Equal(42)) // valid
7980
Eventually(slowInt_nil()).Should(Equal(42)) // want "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\\(slowInt_nil\\)\\.Should\\(Equal\\(42\\)\\). instead"
8081
}
82+
83+
var _ = Describe("Should warn for focused containers", func() {
84+
FContext("should not allow FContext", func() { // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"Context\""
85+
FWhen("should not allow FWhen", func() { // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"When\""
86+
FIt("should not allow FIt", func() {}) // want "ginkgo-linter: Focus container found. This is used only for local debug and should not be part of the actual source code, consider to replace with \"It\""
87+
})
88+
})
89+
})

test/testdata/ginkgolinter/go.mod

+11-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@ module ginkgolinter
22

33
go 1.19
44

5-
require github.com/onsi/gomega v1.27.4
5+
require (
6+
github.com/onsi/ginkgo/v2 v2.11.0
7+
github.com/onsi/gomega v1.27.8
8+
)
69

710
require (
11+
github.com/go-logr/logr v1.2.4 // indirect
12+
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
813
github.com/google/go-cmp v0.5.9 // indirect
9-
golang.org/x/net v0.8.0 // indirect
10-
golang.org/x/text v0.8.0 // indirect
14+
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
15+
golang.org/x/net v0.10.0 // indirect
16+
golang.org/x/sys v0.9.0 // indirect
17+
golang.org/x/text v0.9.0 // indirect
18+
golang.org/x/tools v0.9.3 // indirect
1119
gopkg.in/yaml.v3 v3.0.1 // indirect
1220
)

test/testdata/ginkgolinter/go.sum

+34-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)