add tests for get plugins
This commit is contained in:
93
pkg/schema/schema_test.go
Normal file
93
pkg/schema/schema_test.go
Normal file
@@ -0,0 +1,93 @@
|
||||
package schema_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"git.front.kjuulh.io/kjuulh/char/pkg/schema"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSchemaParse(t *testing.T) {
|
||||
t.Parallel()
|
||||
tt := []struct {
|
||||
name string
|
||||
input string
|
||||
expected *schema.CharSchema
|
||||
}{
|
||||
{
|
||||
name: "with plugins",
|
||||
input: `
|
||||
registry: git.front.kjuulh.io
|
||||
plugins:
|
||||
"kjuulh/char#plugins/gocli": {}
|
||||
"kjuulh/char#plugins/rust": {}
|
||||
`,
|
||||
expected: &schema.CharSchema{
|
||||
Registry: "git.front.kjuulh.io",
|
||||
Plugins: map[schema.CharSchemaPluginName]*schema.CharSchemaPlugin{
|
||||
"kjuulh/char#plugins/gocli": {},
|
||||
"kjuulh/char#plugins/rust": {},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tt {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
s, err := schema.Parse([]byte(tc.input))
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tc.expected, s)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetPlugins(t *testing.T) {
|
||||
t.Parallel()
|
||||
tt := []struct {
|
||||
name string
|
||||
input string
|
||||
expected schema.CharSchemaPlugins
|
||||
}{
|
||||
{
|
||||
name: "with plugins",
|
||||
input: `
|
||||
registry: git.front.kjuulh.io
|
||||
plugins:
|
||||
"kjuulh/char#plugins/gocli": {}
|
||||
"kjuulh/char#plugins/rust": {}
|
||||
`,
|
||||
expected: map[schema.CharSchemaPluginName]*schema.CharSchemaPlugin{
|
||||
"kjuulh/char#plugins/gocli": {
|
||||
Opts: &schema.PluginOps{
|
||||
Org: "kjuulh",
|
||||
RepositoryName: "char",
|
||||
Path: "plugins/gocli",
|
||||
Version: "",
|
||||
},
|
||||
},
|
||||
"kjuulh/char#plugins/rust": {
|
||||
Opts: &schema.PluginOps{
|
||||
Org: "kjuulh",
|
||||
RepositoryName: "char",
|
||||
Path: "plugins/rust",
|
||||
Version: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tt {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
s, err := schema.Parse([]byte(tc.input))
|
||||
require.NoError(t, err)
|
||||
|
||||
plugins, err := s.GetPlugins(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, tc.expected, plugins)
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user