Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion api/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:<namespace>" and not "namespace:<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
Expand Down
4 changes: 3 additions & 1 deletion context/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -62,7 +64,7 @@ func (p *fooPlugin) Info() api.PluginInfo {
}
}

func (p *fooPlugin) Defaults() yaml.Unmarshaler {
func (p *fooPlugin) Defaults() api.DefaultsHandler {
return &fooDefaults{}
}

Expand Down
4 changes: 3 additions & 1 deletion internal/testutil/plugin/bar/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -98,7 +100,7 @@ func (p *Plugin) Info() api.PluginInfo {
}
}

func (p *Plugin) Defaults() yaml.Unmarshaler {
func (p *Plugin) Defaults() api.DefaultsHandler {
return &Defaults{}
}

Expand Down
4 changes: 3 additions & 1 deletion internal/testutil/plugin/failer/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -129,7 +131,7 @@ func (p *Plugin) Info() api.PluginInfo {
}
}

func (p *Plugin) Defaults() yaml.Unmarshaler {
func (p *Plugin) Defaults() api.DefaultsHandler {
return &Defaults{}
}

Expand Down
4 changes: 3 additions & 1 deletion internal/testutil/plugin/foo/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -136,7 +138,7 @@ func (p *Plugin) Info() api.PluginInfo {
}
}

func (p *Plugin) Defaults() yaml.Unmarshaler {
func (p *Plugin) Defaults() api.DefaultsHandler {
return &Defaults{}
}

Expand Down
4 changes: 3 additions & 1 deletion internal/testutil/plugin/priorrun/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -116,7 +118,7 @@ func (p *Plugin) Info() api.PluginInfo {
}
}

func (p *Plugin) Defaults() yaml.Unmarshaler {
func (p *Plugin) Defaults() api.DefaultsHandler {
return &Defaults{}
}

Expand Down
7 changes: 7 additions & 0 deletions plugin/exec/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:<namespace>" and not "namespace:<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)
Expand Down
4 changes: 1 addition & 3 deletions plugin/exec/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
package exec

import (
"gopkg.in/yaml.v3"

"github.com/gdt-dev/core/api"
gdtplugin "github.com/gdt-dev/core/plugin"
)
Expand Down Expand Up @@ -44,7 +42,7 @@ func (p *plugin) Info() api.PluginInfo {
}
}

func (p *plugin) Defaults() yaml.Unmarshaler {
func (p *plugin) Defaults() api.DefaultsHandler {
return &Defaults{}
}

Expand Down
4 changes: 3 additions & 1 deletion plugin/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -59,7 +61,7 @@ func (p *fooPlugin) Info() api.PluginInfo {
}
}

func (p *fooPlugin) Defaults() yaml.Unmarshaler {
func (p *fooPlugin) Defaults() api.DefaultsHandler {
return &fooDefaults{}
}

Expand Down
4 changes: 4 additions & 0 deletions scenario/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading