mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-28 22:28:43 -04:00
feat: new custom linters system (#4437)
This commit is contained in:
parent
f0fdea006f
commit
167204c1fd
31 changed files with 1339 additions and 110 deletions
127
pkg/commands/internal/configuration_test.go
Normal file
127
pkg/commands/internal/configuration_test.go
Normal file
|
@ -0,0 +1,127 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestConfiguration_Validate(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
cfg *Configuration
|
||||
}{
|
||||
{
|
||||
desc: "version",
|
||||
cfg: &Configuration{
|
||||
Version: "v1.57.0",
|
||||
Plugins: []*Plugin{
|
||||
{
|
||||
Module: "example.org/foo/bar",
|
||||
Import: "example.org/foo/bar/test",
|
||||
Version: "v1.2.3",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "path",
|
||||
cfg: &Configuration{
|
||||
Version: "v1.57.0",
|
||||
Plugins: []*Plugin{
|
||||
{
|
||||
Module: "example.org/foo/bar",
|
||||
Import: "example.org/foo/bar/test",
|
||||
Path: "/my/path",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
err := test.cfg.Validate()
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfiguration_Validate_error(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
cfg *Configuration
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
desc: "missing version",
|
||||
cfg: &Configuration{},
|
||||
expected: "root field 'version' is required",
|
||||
},
|
||||
{
|
||||
desc: "no plugins",
|
||||
cfg: &Configuration{
|
||||
Version: "v1.57.0",
|
||||
},
|
||||
expected: "no plugins defined",
|
||||
},
|
||||
{
|
||||
desc: "missing module",
|
||||
cfg: &Configuration{
|
||||
Version: "v1.57.0",
|
||||
Plugins: []*Plugin{
|
||||
{
|
||||
Module: "",
|
||||
Import: "example.org/foo/bar/test",
|
||||
Version: "v1.2.3",
|
||||
Path: "/my/path",
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: "field 'module' is required",
|
||||
},
|
||||
{
|
||||
desc: "module version and path",
|
||||
cfg: &Configuration{
|
||||
Version: "v1.57.0",
|
||||
Plugins: []*Plugin{
|
||||
{
|
||||
Module: "example.org/foo/bar",
|
||||
Import: "example.org/foo/bar/test",
|
||||
Version: "v1.2.3",
|
||||
Path: "/my/path",
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: "invalid configuration: 'version' and 'path' should not be provided at the same time",
|
||||
},
|
||||
{
|
||||
desc: "no module version and path",
|
||||
cfg: &Configuration{
|
||||
Version: "v1.57.0",
|
||||
Plugins: []*Plugin{
|
||||
{
|
||||
Module: "example.org/foo/bar",
|
||||
Import: "example.org/foo/bar/test",
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: "missing information: 'version' or 'path' should be provided",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
err := test.cfg.Validate()
|
||||
|
||||
assert.EqualError(t, err, test.expected)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue