Add ability to get plugin with a particular instance

This commit is contained in:
sophia 2022-02-24 14:00:19 -06:00 committed by Paul Hinze
parent 06cfbb79bf
commit df0fb642b0
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
3 changed files with 24 additions and 4 deletions

View File

@ -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)

View File

@ -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
}
}

View File

@ -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
}
}