From df0fb642b06c70f52488cff436638e9075cfcf4b Mon Sep 17 00:00:00 2001 From: sophia Date: Thu, 24 Feb 2022 14:00:19 -0600 Subject: [PATCH] Add ability to get plugin with a particular instance --- internal/core/machine_test.go | 4 ++-- internal/plugin/testing_factory.go | 7 +++++++ internal/plugin/testing_plugin.go | 17 +++++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/internal/core/machine_test.go b/internal/core/machine_test.go index ff8d12ef1..15464c8bc 100644 --- a/internal/core/machine_test.go +++ b/internal/core/machine_test.go @@ -97,7 +97,7 @@ func TestMachineConfigedGuest(t *testing.T) { pluginManager := plugin.TestManager(t, plugin.TestPlugin(t, plugin.WithPluginName("myguest"), - plugin.WithPluginComponents(component.GuestType, guestMock)), + plugin.WithPluginMinimalComponents(component.GuestType, guestMock)), ) tp := TestProject(t, WithPluginManager(pluginManager)) @@ -125,7 +125,7 @@ func TestMachineNoConfigGuest(t *testing.T) { guestMock.On("Detect", mock.AnythingOfType("*core.Machine")).Return(true, nil) detectingPlugin := plugin.TestPlugin(t, plugin.WithPluginName("myguest"), - plugin.WithPluginComponents(component.GuestType, guestMock)) + plugin.WithPluginMinimalComponents(component.GuestType, guestMock)) notGuestMock := seededGuestMock() notGuestMock.On("Detect", mock.AnythingOfType("*core.Machine")).Return(false, nil) diff --git a/internal/plugin/testing_factory.go b/internal/plugin/testing_factory.go index 04cc8de94..a35b01d89 100644 --- a/internal/plugin/testing_factory.go +++ b/internal/plugin/testing_factory.go @@ -44,3 +44,10 @@ func WithPluginInstanceComponent(c interface{}) PluginInstanceProperty { return } } + +func WithPluginInstanceParent(p *Instance) PluginInstanceProperty { + return func(i *Instance) (err error) { + i.Parent = i + return + } +} diff --git a/internal/plugin/testing_plugin.go b/internal/plugin/testing_plugin.go index 7404574be..b8f3ffc29 100644 --- a/internal/plugin/testing_plugin.go +++ b/internal/plugin/testing_plugin.go @@ -36,16 +36,29 @@ func WithPluginName(name string) PluginProperty { } } -func WithPluginComponents(t component.Type, i interface{}) PluginProperty { +func WithPluginMinimalComponents(t component.Type, i interface{}) PluginProperty { return func(p *Plugin) (err error) { instance := &Instance{ Name: p.Name, Type: t, Component: i, } - p.components = make(map[component.Type]*Instance) + if p.components == nil { + p.components = make(map[component.Type]*Instance) + } p.components[t] = instance p.Types = append(p.Types, t) return } } + +func WithPluginInstance(i *Instance) PluginProperty { + return func(p *Plugin) (err error) { + if p.components == nil { + p.components = make(map[component.Type]*Instance) + } + p.components[i.Type] = i + p.Types = append(p.Types, i.Type) + return + } +}