Plugins: Include decommissioned plugins when ignoring plugins during re-loading (#46958)

This commit is contained in:
Will Browne 2022-03-30 15:05:12 +02:00 committed by GitHub
parent 23dde457ef
commit 56e9c24f08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 11 deletions

View File

@ -37,7 +37,7 @@ func TestPluginManager_Init(t *testing.T) {
func TestPluginManager_loadPlugins(t *testing.T) {
t.Run("Managed backend plugin", func(t *testing.T) {
p, pc := createPlugin(testPluginID, "", plugins.External, true, true)
p, pc := createPlugin(t, testPluginID, "", plugins.External, true, true)
loader := &fakeLoader{
mockedLoadedPlugins: []*plugins.Plugin{p},
@ -63,7 +63,7 @@ func TestPluginManager_loadPlugins(t *testing.T) {
})
t.Run("Unmanaged backend plugin", func(t *testing.T) {
p, pc := createPlugin(testPluginID, "", plugins.External, false, true)
p, pc := createPlugin(t, testPluginID, "", plugins.External, false, true)
loader := &fakeLoader{
mockedLoadedPlugins: []*plugins.Plugin{p},
@ -89,7 +89,7 @@ func TestPluginManager_loadPlugins(t *testing.T) {
})
t.Run("Managed non-backend plugin", func(t *testing.T) {
p, pc := createPlugin(testPluginID, "", plugins.External, false, true)
p, pc := createPlugin(t, testPluginID, "", plugins.External, false, true)
loader := &fakeLoader{
mockedLoadedPlugins: []*plugins.Plugin{p},
@ -115,7 +115,7 @@ func TestPluginManager_loadPlugins(t *testing.T) {
})
t.Run("Unmanaged non-backend plugin", func(t *testing.T) {
p, pc := createPlugin(testPluginID, "", plugins.External, false, false)
p, pc := createPlugin(t, testPluginID, "", plugins.External, false, false)
loader := &fakeLoader{
mockedLoadedPlugins: []*plugins.Plugin{p},
@ -143,7 +143,7 @@ func TestPluginManager_loadPlugins(t *testing.T) {
func TestPluginManager_Installer(t *testing.T) {
t.Run("Install", func(t *testing.T) {
p, pc := createPlugin(testPluginID, "1.0.0", plugins.External, true, true)
p, pc := createPlugin(t, testPluginID, "1.0.0", plugins.External, true, true)
l := &fakeLoader{
mockedLoadedPlugins: []*plugins.Plugin{p},
@ -186,7 +186,7 @@ func TestPluginManager_Installer(t *testing.T) {
})
t.Run("Update", func(t *testing.T) {
p, pc := createPlugin(testPluginID, "1.2.0", plugins.External, true, true)
p, pc := createPlugin(t, testPluginID, "1.2.0", plugins.External, true, true)
l := &fakeLoader{
mockedLoadedPlugins: []*plugins.Plugin{p},
@ -230,7 +230,7 @@ func TestPluginManager_Installer(t *testing.T) {
})
t.Run("Can't update core plugin", func(t *testing.T) {
p, pc := createPlugin(testPluginID, "", plugins.Core, true, true)
p, pc := createPlugin(t, testPluginID, "", plugins.Core, true, true)
loader := &fakeLoader{
mockedLoadedPlugins: []*plugins.Plugin{p},
@ -264,7 +264,7 @@ func TestPluginManager_Installer(t *testing.T) {
})
t.Run("Can't update bundled plugin", func(t *testing.T) {
p, pc := createPlugin(testPluginID, "", plugins.Bundled, true, true)
p, pc := createPlugin(t, testPluginID, "", plugins.Bundled, true, true)
loader := &fakeLoader{
mockedLoadedPlugins: []*plugins.Plugin{p},
@ -298,6 +298,30 @@ func TestPluginManager_Installer(t *testing.T) {
})
}
func TestPluginManager_registeredPlugins(t *testing.T) {
t.Run("Decommissioned plugins are included in registeredPlugins", func(t *testing.T) {
pm := New(&plugins.Cfg{}, []PluginSource{}, &fakeLoader{})
decommissionedPlugin, _ := createPlugin(t, testPluginID, "", plugins.Core, false, true,
func(plugin *plugins.Plugin) {
err := plugin.Decommission()
require.NoError(t, err)
},
)
require.True(t, decommissionedPlugin.IsDecommissioned())
pm.store = map[string]*plugins.Plugin{
testPluginID: decommissionedPlugin,
"test-app": {},
}
rps := pm.registeredPlugins()
require.Equal(t, 2, len(rps))
require.NotNil(t, rps[testPluginID])
require.NotNil(t, rps["test-app"])
})
}
func TestPluginManager_lifecycle_managed(t *testing.T) {
newScenario(t, true, func(t *testing.T, ctx *managerScenarioCtx) {
t.Run("Managed plugin scenario", func(t *testing.T) {
@ -504,7 +528,9 @@ func createManager(t *testing.T, cbs ...func(*PluginManager)) *PluginManager {
return pm
}
func createPlugin(pluginID, version string, class plugins.Class, managed, backend bool) (*plugins.Plugin, *fakePluginClient) {
func createPlugin(t *testing.T, pluginID, version string, class plugins.Class, managed, backend bool, cbs ...func(*plugins.Plugin)) (*plugins.Plugin, *fakePluginClient) {
t.Helper()
p := &plugins.Plugin{
Class: class,
JSONData: plugins.JSONData{
@ -529,6 +555,10 @@ func createPlugin(pluginID, version string, class plugins.Class, managed, backen
p.RegisterClient(pc)
for _, cb := range cbs {
cb(p)
}
return p, pc
}
@ -555,7 +585,7 @@ func newScenario(t *testing.T, managed bool, fn func(t *testing.T, ctx *managerS
manager: manager,
}
ctx.plugin, ctx.pluginClient = createPlugin(testPluginID, "", plugins.External, managed, true)
ctx.plugin, ctx.pluginClient = createPlugin(t, testPluginID, "", plugins.External, managed, true)
fn(t, ctx)
}

View File

@ -75,7 +75,7 @@ func (m *PluginManager) isRegistered(pluginID string) bool {
func (m *PluginManager) registeredPlugins() map[string]struct{} {
pluginsByID := make(map[string]struct{})
for _, p := range m.plugins() {
for _, p := range m.store {
pluginsByID[p.ID] = struct{}{}
}