Plugins: Add Plugin FS abstraction (#63734)

* unexport pluginDir from dto

* first pass

* tidy

* naming + add mutex

* add dupe checking

* fix func typo

* interface + move logic from renderer

* remote finder

* remote signing

* fix tests

* tidy up

* tidy markdown logic

* split changes

* fix tests

* slim interface down

* fix status code

* tidy exec path func

* fixup

* undo changes

* remove unused func

* remove unused func

* fix goimports

* fetch remotely

* simultaneous support

* fix linter

* use var

* add exception for gosec warning

* fixup

* fix tests

* tidy

* rework cfg pattern

* simplify

* PR feedback

* fix dupe field

* remove g304 nolint

* apply PR feedback

* remove unnecessary gosec nolint

* fix finder loop and update comment

* fix map alloc

* fix test

* remove commented code
This commit is contained in:
Will Browne
2023-03-07 15:47:02 +00:00
committed by GitHub
parent 380138f57b
commit 68df83c86d
22 changed files with 1344 additions and 870 deletions

View File

@ -22,13 +22,11 @@ func TestPluginManager_Add_Remove(t *testing.T) {
const (
pluginID, v1 = "test-panel", "1.0.0"
zipNameV1 = "test-panel-1.0.0.zip"
pluginDirV1 = "/data/plugin/test-panel-1.0.0"
)
// mock a plugin to be returned automatically by the plugin loader
pluginV1 := createPlugin(t, pluginID, plugins.External, true, true, func(plugin *plugins.Plugin) {
plugin.Info.Version = v1
plugin.PluginDir = pluginDirV1
})
mockZipV1 := &zip.ReadCloser{Reader: zip.Reader{File: []*zip.File{{
FileHeader: zip.FileHeader{Name: zipNameV1},
@ -63,7 +61,6 @@ func TestPluginManager_Add_Remove(t *testing.T) {
},
RegisterFunc: func(_ context.Context, pluginID, pluginDir string) error {
require.Equal(t, pluginV1.ID, pluginID)
require.Equal(t, pluginV1.PluginDir, pluginDir)
return nil
},
Store: map[string]struct{}{},
@ -88,14 +85,12 @@ func TestPluginManager_Add_Remove(t *testing.T) {
t.Run("Update plugin to different version", func(t *testing.T) {
const (
v2 = "2.0.0"
zipNameV2 = "test-panel-2.0.0.zip"
pluginDirV2 = "/data/plugin/test-panel-2.0.0"
v2 = "2.0.0"
zipNameV2 = "test-panel-2.0.0.zip"
)
// mock a plugin to be returned automatically by the plugin loader
pluginV2 := createPlugin(t, pluginID, plugins.External, true, true, func(plugin *plugins.Plugin) {
plugin.Info.Version = v2
plugin.PluginDir = pluginDirV2
})
mockZipV2 := &zip.ReadCloser{Reader: zip.Reader{File: []*zip.File{{
@ -126,7 +121,6 @@ func TestPluginManager_Add_Remove(t *testing.T) {
}
fs.RegisterFunc = func(_ context.Context, pluginID, pluginDir string) error {
require.Equal(t, pluginV2.ID, pluginID)
require.Equal(t, pluginV2.PluginDir, pluginDir)
return nil
}