feat: new custom linters system (#4437)

This commit is contained in:
Ludovic Fernandez 2024-03-11 17:40:26 +01:00 committed by GitHub
parent f0fdea006f
commit 167204c1fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 1339 additions and 110 deletions

View 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)
})
}
}