diff --git a/api/plugin.go b/api/plugin.go index b0b3e21..97f0a35 100644 --- a/api/plugin.go +++ b/api/plugin.go @@ -23,13 +23,23 @@ type PluginInfo struct { Retry *Retry } +type DefaultsHandler interface { + yaml.Unmarshaler + // Merge merges the supplies map of key/value combinations with the set of + // handled defaults for the plugin. The supplied key/value map will NOT be + // unpacked from its top-most plugin named element. So, for example, the + // kube plugin should expect to get a map that looks like + // "kube:namespace:" and not "namespace:". + Merge(map[string]any) +} + // Plugin is the driver interface for different types of gdt tests. type Plugin interface { // Info returns a struct that describes what the plugin does Info() PluginInfo // Defaults returns a YAML Unmarshaler types that the plugin knows how // to parse its defaults configuration with. - Defaults() yaml.Unmarshaler + Defaults() DefaultsHandler // Specs returns a list of YAML Unmarshaler types that the plugin knows // how to parse. Specs() []Evaluable diff --git a/context/context_test.go b/context/context_test.go index 5d41973..2b2ed3d 100644 --- a/context/context_test.go +++ b/context/context_test.go @@ -21,6 +21,8 @@ type fooDefaults struct { Foo string `yaml:"foo"` } +func (d *fooDefaults) Merge(map[string]any) {} + func (d *fooDefaults) UnmarshalYAML(node *yaml.Node) error { return nil } @@ -62,7 +64,7 @@ func (p *fooPlugin) Info() api.PluginInfo { } } -func (p *fooPlugin) Defaults() yaml.Unmarshaler { +func (p *fooPlugin) Defaults() api.DefaultsHandler { return &fooDefaults{} } diff --git a/internal/testutil/plugin/bar/plugin.go b/internal/testutil/plugin/bar/plugin.go index 4f2774b..2dda4a0 100644 --- a/internal/testutil/plugin/bar/plugin.go +++ b/internal/testutil/plugin/bar/plugin.go @@ -28,6 +28,8 @@ type Defaults struct { Foo string `yaml:"bar"` } +func (d *Defaults) Merge(map[string]any) {} + func (d *Defaults) UnmarshalYAML(node *yaml.Node) error { return nil } @@ -98,7 +100,7 @@ func (p *Plugin) Info() api.PluginInfo { } } -func (p *Plugin) Defaults() yaml.Unmarshaler { +func (p *Plugin) Defaults() api.DefaultsHandler { return &Defaults{} } diff --git a/internal/testutil/plugin/failer/plugin.go b/internal/testutil/plugin/failer/plugin.go index 043e651..913ecee 100644 --- a/internal/testutil/plugin/failer/plugin.go +++ b/internal/testutil/plugin/failer/plugin.go @@ -28,6 +28,8 @@ type Defaults struct { InnerDefaults } +func (d *Defaults) Merge(map[string]any) {} + func (d *Defaults) UnmarshalYAML(node *yaml.Node) error { if node.Kind != yaml.MappingNode { return parse.ExpectedMapAt(node) @@ -129,7 +131,7 @@ func (p *Plugin) Info() api.PluginInfo { } } -func (p *Plugin) Defaults() yaml.Unmarshaler { +func (p *Plugin) Defaults() api.DefaultsHandler { return &Defaults{} } diff --git a/internal/testutil/plugin/foo/plugin.go b/internal/testutil/plugin/foo/plugin.go index d8eb5e9..9b640a3 100644 --- a/internal/testutil/plugin/foo/plugin.go +++ b/internal/testutil/plugin/foo/plugin.go @@ -33,6 +33,8 @@ type Defaults struct { InnerDefaults `yaml:",inline"` } +func (d *Defaults) Merge(map[string]any) {} + func (d *Defaults) UnmarshalYAML(node *yaml.Node) error { if node.Kind != yaml.MappingNode { return parse.ExpectedMapAt(node) @@ -136,7 +138,7 @@ func (p *Plugin) Info() api.PluginInfo { } } -func (p *Plugin) Defaults() yaml.Unmarshaler { +func (p *Plugin) Defaults() api.DefaultsHandler { return &Defaults{} } diff --git a/internal/testutil/plugin/priorrun/plugin.go b/internal/testutil/plugin/priorrun/plugin.go index 58c279a..dd2a070 100644 --- a/internal/testutil/plugin/priorrun/plugin.go +++ b/internal/testutil/plugin/priorrun/plugin.go @@ -24,6 +24,8 @@ const PriorRunDataKey = "priorrun" type Defaults struct{} +func (d *Defaults) Merge(map[string]any) {} + func (d *Defaults) UnmarshalYAML(node *yaml.Node) error { return nil } @@ -116,7 +118,7 @@ func (p *Plugin) Info() api.PluginInfo { } } -func (p *Plugin) Defaults() yaml.Unmarshaler { +func (p *Plugin) Defaults() api.DefaultsHandler { return &Defaults{} } diff --git a/plugin/exec/defaults.go b/plugin/exec/defaults.go index 6355a0b..d96ee1a 100644 --- a/plugin/exec/defaults.go +++ b/plugin/exec/defaults.go @@ -16,6 +16,13 @@ type Defaults struct { execDefaults } +// Merge merges the supplies map of key/value combinations with the set of +// handled defaults for the plugin. The supplied key/value map will NOT be +// unpacked from its top-most plugin named element. So, for example, the +// kube plugin should expect to get a map that looks like +// "kube:namespace:" and not "namespace:". +func (d *Defaults) Merge(map[string]any) {} + func (d *Defaults) UnmarshalYAML(node *yaml.Node) error { if node.Kind != yaml.MappingNode { return parse.ExpectedMapAt(node) diff --git a/plugin/exec/plugin.go b/plugin/exec/plugin.go index ac1ac14..0a06230 100644 --- a/plugin/exec/plugin.go +++ b/plugin/exec/plugin.go @@ -5,8 +5,6 @@ package exec import ( - "gopkg.in/yaml.v3" - "github.com/gdt-dev/core/api" gdtplugin "github.com/gdt-dev/core/plugin" ) @@ -44,7 +42,7 @@ func (p *plugin) Info() api.PluginInfo { } } -func (p *plugin) Defaults() yaml.Unmarshaler { +func (p *plugin) Defaults() api.DefaultsHandler { return &Defaults{} } diff --git a/plugin/registry_test.go b/plugin/registry_test.go index f03d6a3..9c2f35f 100644 --- a/plugin/registry_test.go +++ b/plugin/registry_test.go @@ -18,6 +18,8 @@ type fooDefaults struct { Foo string `yaml:"foo"` } +func (d *fooDefaults) Merge(map[string]any) {} + func (d *fooDefaults) UnmarshalYAML(node *yaml.Node) error { return nil } @@ -59,7 +61,7 @@ func (p *fooPlugin) Info() api.PluginInfo { } } -func (p *fooPlugin) Defaults() yaml.Unmarshaler { +func (p *fooPlugin) Defaults() api.DefaultsHandler { return &fooDefaults{} } diff --git a/scenario/parse.go b/scenario/parse.go index 1c9e52d..8f4e220 100644 --- a/scenario/parse.go +++ b/scenario/parse.go @@ -81,6 +81,10 @@ func (s *Scenario) UnmarshalYAML(node *yaml.Node) error { if err := valNode.Decode(plugDefaults); err != nil { return err } + // The user may have used scenario.WithDefaults() so we need to + // merge anything we got from WithDefaults with anything we + // parsed from the plugins. + plugDefaults.Merge(s.Defaults) defaults[p.Info().Name] = plugDefaults } // The scenario may have its own defaults as well, so we stash