Skip to content

Commit

Permalink
review: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Feb 19, 2024
1 parent 0a06a89 commit 22efa8b
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 2 deletions.
86 changes: 86 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package config

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestIsGoGreaterThanOrEqual(t *testing.T) {
testCases := []struct {
desc string
current string
limit string
assert assert.BoolAssertionFunc
}{
{
desc: "current (with minor.major) lower than limit",
current: "go1.21",
limit: "1.22",
assert: assert.False,
},
{
desc: "current (with 0 patch) lower than limit",
current: "go1.21.0",
limit: "1.22",
assert: assert.False,
},
{
desc: "current (current with multiple patches) lower than limit",
current: "go1.21.6",
limit: "1.22",
assert: assert.False,
},
{
desc: "current lower than limit (with minor.major)",
current: "go1.22",
limit: "1.22",
assert: assert.True,
},
{
desc: "current lower than limit (with 0 patch)",
current: "go1.22.0",
limit: "1.22",
assert: assert.True,
},
{
desc: "current lower than limit (current with multiple patches)",
current: "go1.22.6",
limit: "1.22",
assert: assert.True,
},
{
desc: "current greater than limit",
current: "go1.23.0",
limit: "1.22",
assert: assert.True,
},
{
desc: "current with no prefix",
current: "1.22",
limit: "1.22",
assert: assert.True,
},
{
desc: "invalid current value",
current: "go",
limit: "1.22",
assert: assert.False,
},
{
desc: "invalid limit value",
current: "go1.22",
limit: "go",
assert: assert.False,
},
}

for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

test.assert(t, IsGoGreaterThanOrEqual(test.current, test.limit))
})
}
}
4 changes: 2 additions & 2 deletions pkg/lint/linter/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type Noop struct {
reason string
}

func NewNoop(l Linter, reason string) *Noop {
return &Noop{
func NewNoop(l Linter, reason string) Noop {
return Noop{
name: l.Name(),
desc: l.Desc(),
reason: reason,
Expand Down

0 comments on commit 22efa8b

Please sign in to comment.