Skip to content

Commit 22efa8b

Browse files
committed
review: unit tests
1 parent 0a06a89 commit 22efa8b

File tree

2 files changed

+88
-2
lines changed

2 files changed

+88
-2
lines changed

pkg/config/config_test.go

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package config
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestIsGoGreaterThanOrEqual(t *testing.T) {
10+
testCases := []struct {
11+
desc string
12+
current string
13+
limit string
14+
assert assert.BoolAssertionFunc
15+
}{
16+
{
17+
desc: "current (with minor.major) lower than limit",
18+
current: "go1.21",
19+
limit: "1.22",
20+
assert: assert.False,
21+
},
22+
{
23+
desc: "current (with 0 patch) lower than limit",
24+
current: "go1.21.0",
25+
limit: "1.22",
26+
assert: assert.False,
27+
},
28+
{
29+
desc: "current (current with multiple patches) lower than limit",
30+
current: "go1.21.6",
31+
limit: "1.22",
32+
assert: assert.False,
33+
},
34+
{
35+
desc: "current lower than limit (with minor.major)",
36+
current: "go1.22",
37+
limit: "1.22",
38+
assert: assert.True,
39+
},
40+
{
41+
desc: "current lower than limit (with 0 patch)",
42+
current: "go1.22.0",
43+
limit: "1.22",
44+
assert: assert.True,
45+
},
46+
{
47+
desc: "current lower than limit (current with multiple patches)",
48+
current: "go1.22.6",
49+
limit: "1.22",
50+
assert: assert.True,
51+
},
52+
{
53+
desc: "current greater than limit",
54+
current: "go1.23.0",
55+
limit: "1.22",
56+
assert: assert.True,
57+
},
58+
{
59+
desc: "current with no prefix",
60+
current: "1.22",
61+
limit: "1.22",
62+
assert: assert.True,
63+
},
64+
{
65+
desc: "invalid current value",
66+
current: "go",
67+
limit: "1.22",
68+
assert: assert.False,
69+
},
70+
{
71+
desc: "invalid limit value",
72+
current: "go1.22",
73+
limit: "go",
74+
assert: assert.False,
75+
},
76+
}
77+
78+
for _, test := range testCases {
79+
test := test
80+
t.Run(test.desc, func(t *testing.T) {
81+
t.Parallel()
82+
83+
test.assert(t, IsGoGreaterThanOrEqual(test.current, test.limit))
84+
})
85+
}
86+
}

pkg/lint/linter/linter.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ type Noop struct {
1818
reason string
1919
}
2020

21-
func NewNoop(l Linter, reason string) *Noop {
22-
return &Noop{
21+
func NewNoop(l Linter, reason string) Noop {
22+
return Noop{
2323
name: l.Name(),
2424
desc: l.Desc(),
2525
reason: reason,

0 commit comments

Comments
 (0)