vaguerent/internal/plugin/testing_plugin.go
2022-04-25 16:12:38 -07:00

37 lines
809 B
Go

package plugin
import (
"github.com/hashicorp/go-hclog"
"github.com/mitchellh/go-testing-interface"
)
func TestMinimalPlugin(t testing.T) *Plugin {
plugin := &Plugin{
Location: "test",
logger: hclog.New(&hclog.LoggerOptions{}),
}
return plugin
}
// TestPlugin returns a fully in-memory and side-effect free Plugin that
// can be used for testing. Additional options can be given to provide your own
// factories, configuration, etc.
func TestPlugin(t testing.T, opts ...PluginProperty) (plugin *Plugin) {
plugin = TestMinimalPlugin(t)
for _, opt := range opts {
if err := opt(plugin); err != nil {
t.Error(err)
}
}
return
}
type PluginProperty func(*Plugin) error
func WithPluginName(name string) PluginProperty {
return func(p *Plugin) (err error) {
p.Name = name
return
}
}