add tests for get plugins

This commit is contained in:
2022-11-02 16:48:33 +01:00
parent a5859107f1
commit ebc2d7aa8f
3 changed files with 112 additions and 5 deletions

View File

@@ -24,14 +24,27 @@ func ParseFile(ctx context.Context, path string) (*CharSchema, error) {
return nil, fmt.Errorf("could not read file: %w", err)
}
return Parse(file)
}
func Parse(content []byte) (*CharSchema, error) {
var schema CharSchema
if err = yaml.Unmarshal(file, &schema); err != nil {
return nil, fmt.Errorf("could not deserialize yaml file into CharSchema: %w", err)
if err := yaml.Unmarshal(content, &schema); err != nil {
return nil, fmt.Errorf("could not deserialize yaml into CharSchema: %w", err)
}
return &schema, nil
}
func (cs *CharSchema) GetPlugins(ctx context.Context) (*PluginOps, error) {
return nil, nil
func (cs *CharSchema) GetPlugins(ctx context.Context) (CharSchemaPlugins, error) {
plugins := make(map[CharSchemaPluginName]*CharSchemaPlugin, len(cs.Plugins))
for n, plugin := range cs.Plugins {
po, err := n.Get()
if err != nil {
return nil, err
}
plugin.Opts = po
plugins[n] = plugin
}
return plugins, nil
}