Add ability to get plugin with a particular instance
This commit is contained in:
parent
06cfbb79bf
commit
df0fb642b0
@ -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)
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user