Plugins: Update plugin fakes package name (#112503)
update plugin fakes package name
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/config"
|
||||
"github.com/grafana/grafana/pkg/plugins/log"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/fakes"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/pluginfakes"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/sources"
|
||||
"github.com/grafana/grafana/pkg/plugins/repo"
|
||||
"github.com/grafana/grafana/pkg/plugins/storage"
|
||||
@@ -40,7 +40,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
FileHeader: zip.FileHeader{Name: zipNameV1},
|
||||
}}}}
|
||||
|
||||
loader := &fakes.FakeLoader{
|
||||
loader := &pluginfakes.FakeLoader{
|
||||
LoadFunc: func(ctx context.Context, src plugins.PluginSource) ([]*plugins.Plugin, error) {
|
||||
return []*plugins.Plugin{pluginV1}, nil
|
||||
},
|
||||
@@ -49,7 +49,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
pluginRepo := &fakes.FakePluginRepo{
|
||||
pluginRepo := &pluginfakes.FakePluginRepo{
|
||||
GetPluginArchiveFunc: func(_ context.Context, id, version string, _ repo.CompatOpts) (*repo.PluginArchive, error) {
|
||||
require.Equal(t, pluginID, id)
|
||||
require.Equal(t, v1, version)
|
||||
@@ -59,7 +59,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
fs := &fakes.FakePluginStorage{
|
||||
fs := &pluginfakes.FakePluginStorage{
|
||||
ExtractFunc: func(_ context.Context, id string, _ storage.DirNameGeneratorFunc, z *zip.ReadCloser) (*storage.ExtractedPluginArchive, error) {
|
||||
require.Equal(t, pluginID, id)
|
||||
require.Equal(t, mockZipV1, z)
|
||||
@@ -71,12 +71,12 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
inst := New(&config.PluginManagementCfg{}, fakes.NewFakePluginRegistry(), loader, pluginRepo, fs, storage.SimpleDirNameGeneratorFunc, &fakes.FakeAuthService{})
|
||||
inst := New(&config.PluginManagementCfg{}, pluginfakes.NewFakePluginRegistry(), loader, pluginRepo, fs, storage.SimpleDirNameGeneratorFunc, &pluginfakes.FakeAuthService{})
|
||||
err := inst.Add(context.Background(), pluginID, v1, testCompatOpts())
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("Won't add if already exists", func(t *testing.T) {
|
||||
inst.pluginRegistry = &fakes.FakePluginRegistry{
|
||||
inst.pluginRegistry = &pluginfakes.FakePluginRegistry{
|
||||
Store: map[string]*plugins.Plugin{
|
||||
pluginID: pluginV1,
|
||||
},
|
||||
@@ -90,7 +90,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
|
||||
t.Run("Add from URL", func(t *testing.T) {
|
||||
url := "https://grafanaplugins.com"
|
||||
pluginRepo := &fakes.FakePluginRepo{
|
||||
pluginRepo := &pluginfakes.FakePluginRepo{
|
||||
GetPluginArchiveByURLFunc: func(_ context.Context, archiveURL string, _ repo.CompatOpts) (*repo.PluginArchive, error) {
|
||||
require.Equal(t, pluginID, pluginID)
|
||||
require.Equal(t, url, archiveURL)
|
||||
@@ -99,7 +99,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
}, nil
|
||||
},
|
||||
}
|
||||
inst := New(&config.PluginManagementCfg{}, fakes.NewFakePluginRegistry(), loader, pluginRepo, fs, storage.SimpleDirNameGeneratorFunc, &fakes.FakeAuthService{})
|
||||
inst := New(&config.PluginManagementCfg{}, pluginfakes.NewFakePluginRegistry(), loader, pluginRepo, fs, storage.SimpleDirNameGeneratorFunc, &pluginfakes.FakeAuthService{})
|
||||
err := inst.Add(context.Background(), pluginID, v1, plugins.NewAddOpts(v1, runtime.GOOS, runtime.GOARCH, url))
|
||||
require.NoError(t, err)
|
||||
})
|
||||
@@ -183,14 +183,14 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Removing an existing plugin", func(t *testing.T) {
|
||||
inst.pluginRegistry = &fakes.FakePluginRegistry{
|
||||
inst.pluginRegistry = &pluginfakes.FakePluginRegistry{
|
||||
Store: map[string]*plugins.Plugin{
|
||||
pluginID: pluginV1,
|
||||
},
|
||||
}
|
||||
|
||||
var unloadedPlugins []string
|
||||
inst.pluginLoader = &fakes.FakeLoader{
|
||||
inst.pluginLoader = &pluginfakes.FakeLoader{
|
||||
UnloadFunc: func(_ context.Context, p *plugins.Plugin) (*plugins.Plugin, error) {
|
||||
unloadedPlugins = append(unloadedPlugins, p.ID)
|
||||
return p, nil
|
||||
@@ -203,7 +203,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
require.Equal(t, []string{pluginID}, unloadedPlugins)
|
||||
|
||||
t.Run("Won't remove if not exists", func(t *testing.T) {
|
||||
inst.pluginRegistry = fakes.NewFakePluginRegistry()
|
||||
inst.pluginRegistry = pluginfakes.NewFakePluginRegistry()
|
||||
|
||||
err = inst.Remove(context.Background(), pluginID, v2)
|
||||
require.Equal(t, plugins.ErrPluginNotInstalled, err)
|
||||
@@ -216,13 +216,13 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
plugin.Info.Version = "1.0.0"
|
||||
})
|
||||
|
||||
reg := &fakes.FakePluginRegistry{
|
||||
reg := &pluginfakes.FakePluginRegistry{
|
||||
Store: map[string]*plugins.Plugin{
|
||||
testPluginID: p,
|
||||
},
|
||||
}
|
||||
|
||||
pm := New(&config.PluginManagementCfg{}, reg, &fakes.FakeLoader{}, &fakes.FakePluginRepo{}, &fakes.FakePluginStorage{}, storage.SimpleDirNameGeneratorFunc, &fakes.FakeAuthService{})
|
||||
pm := New(&config.PluginManagementCfg{}, reg, &pluginfakes.FakeLoader{}, &pluginfakes.FakePluginRepo{}, &pluginfakes.FakePluginStorage{}, storage.SimpleDirNameGeneratorFunc, &pluginfakes.FakeAuthService{})
|
||||
err := pm.Add(context.Background(), p.ID, "3.2.0", testCompatOpts())
|
||||
require.ErrorIs(t, err, plugins.ErrInstallCorePlugin)
|
||||
|
||||
@@ -243,7 +243,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
)
|
||||
|
||||
var loadedPaths []string
|
||||
loader := &fakes.FakeLoader{
|
||||
loader := &pluginfakes.FakeLoader{
|
||||
LoadFunc: func(ctx context.Context, src plugins.PluginSource) ([]*plugins.Plugin, error) {
|
||||
// Check if this is a LocalSource and get its paths
|
||||
if localSrc, ok := src.(*sources.LocalSource); ok {
|
||||
@@ -253,7 +253,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
pluginRepo := &fakes.FakePluginRepo{
|
||||
pluginRepo := &pluginfakes.FakePluginRepo{
|
||||
GetPluginArchiveFunc: func(_ context.Context, id, version string, _ repo.CompatOpts) (*repo.PluginArchive, error) {
|
||||
return &repo.PluginArchive{File: &zip.ReadCloser{Reader: zip.Reader{File: []*zip.File{{
|
||||
FileHeader: zip.FileHeader{Name: fmt.Sprintf("%s.zip", id)},
|
||||
@@ -261,7 +261,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
fs := &fakes.FakePluginStorage{
|
||||
fs := &pluginfakes.FakePluginStorage{
|
||||
ExtractFunc: func(_ context.Context, id string, _ storage.DirNameGeneratorFunc, z *zip.ReadCloser) (*storage.ExtractedPluginArchive, error) {
|
||||
switch id {
|
||||
case p1:
|
||||
@@ -287,7 +287,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
inst := New(&config.PluginManagementCfg{}, fakes.NewFakePluginRegistry(), loader, pluginRepo, fs, storage.SimpleDirNameGeneratorFunc, &fakes.FakeAuthService{})
|
||||
inst := New(&config.PluginManagementCfg{}, pluginfakes.NewFakePluginRegistry(), loader, pluginRepo, fs, storage.SimpleDirNameGeneratorFunc, &pluginfakes.FakeAuthService{})
|
||||
err := inst.Add(context.Background(), p3, "", testCompatOpts())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []string{p1Zip, p2Zip, p3Zip}, loadedPaths)
|
||||
@@ -300,7 +300,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
)
|
||||
|
||||
var loadedPaths []string
|
||||
loader := &fakes.FakeLoader{
|
||||
loader := &pluginfakes.FakeLoader{
|
||||
LoadFunc: func(ctx context.Context, src plugins.PluginSource) ([]*plugins.Plugin, error) {
|
||||
// Check if this is a LocalSource and get its paths
|
||||
if localSrc, ok := src.(*sources.LocalSource); ok {
|
||||
@@ -310,7 +310,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
pluginRepo := &fakes.FakePluginRepo{
|
||||
pluginRepo := &pluginfakes.FakePluginRepo{
|
||||
GetPluginArchiveFunc: func(_ context.Context, id, version string, _ repo.CompatOpts) (*repo.PluginArchive, error) {
|
||||
return &repo.PluginArchive{File: &zip.ReadCloser{Reader: zip.Reader{File: []*zip.File{{
|
||||
FileHeader: zip.FileHeader{Name: fmt.Sprintf("%s.zip", id)},
|
||||
@@ -318,7 +318,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
fs := &fakes.FakePluginStorage{
|
||||
fs := &pluginfakes.FakePluginStorage{
|
||||
ExtractFunc: func(_ context.Context, id string, _ storage.DirNameGeneratorFunc, z *zip.ReadCloser) (*storage.ExtractedPluginArchive, error) {
|
||||
switch id {
|
||||
case p1:
|
||||
@@ -339,7 +339,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
inst := New(&config.PluginManagementCfg{}, fakes.NewFakePluginRegistry(), loader, pluginRepo, fs, storage.SimpleDirNameGeneratorFunc, &fakes.FakeAuthService{})
|
||||
inst := New(&config.PluginManagementCfg{}, pluginfakes.NewFakePluginRegistry(), loader, pluginRepo, fs, storage.SimpleDirNameGeneratorFunc, &pluginfakes.FakeAuthService{})
|
||||
err := inst.Add(context.Background(), p1, "", testCompatOpts())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []string{p2Zip, p1Zip}, loadedPaths)
|
||||
@@ -347,14 +347,14 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
|
||||
t.Run("Plugin can successfully install even if dependency plugin is already installed", func(t *testing.T) {
|
||||
const pluginDependencyID = "test-plugin-dependency"
|
||||
reg := &fakes.FakePluginRegistry{
|
||||
reg := &pluginfakes.FakePluginRegistry{
|
||||
Store: map[string]*plugins.Plugin{
|
||||
pluginDependencyID: createPlugin(t, pluginDependencyID, plugins.ClassExternal, false, false),
|
||||
},
|
||||
}
|
||||
|
||||
var loadedPaths []string
|
||||
loader := &fakes.FakeLoader{
|
||||
loader := &pluginfakes.FakeLoader{
|
||||
LoadFunc: func(ctx context.Context, src plugins.PluginSource) ([]*plugins.Plugin, error) {
|
||||
// Check if this is a LocalSource and get its paths
|
||||
if localSrc, ok := src.(*sources.LocalSource); ok {
|
||||
@@ -364,7 +364,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
pluginRepo := &fakes.FakePluginRepo{
|
||||
pluginRepo := &pluginfakes.FakePluginRepo{
|
||||
GetPluginArchiveFunc: func(_ context.Context, id, version string, _ repo.CompatOpts) (*repo.PluginArchive, error) {
|
||||
return &repo.PluginArchive{File: &zip.ReadCloser{Reader: zip.Reader{File: []*zip.File{{
|
||||
FileHeader: zip.FileHeader{Name: fmt.Sprintf("%s.zip", id)},
|
||||
@@ -372,7 +372,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
fs := &fakes.FakePluginStorage{
|
||||
fs := &pluginfakes.FakePluginStorage{
|
||||
ExtractFunc: func(_ context.Context, id string, _ storage.DirNameGeneratorFunc, z *zip.ReadCloser) (*storage.ExtractedPluginArchive, error) {
|
||||
switch id {
|
||||
case testPluginID:
|
||||
@@ -387,7 +387,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
inst := New(&config.PluginManagementCfg{}, reg, loader, pluginRepo, fs, storage.SimpleDirNameGeneratorFunc, &fakes.FakeAuthService{})
|
||||
inst := New(&config.PluginManagementCfg{}, reg, loader, pluginRepo, fs, storage.SimpleDirNameGeneratorFunc, &pluginfakes.FakeAuthService{})
|
||||
err := inst.Add(context.Background(), testPluginID, "", testCompatOpts())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []string{"test-plugin.zip"}, loadedPaths)
|
||||
@@ -401,7 +401,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
)
|
||||
|
||||
var loadedPaths []string
|
||||
loader := &fakes.FakeLoader{
|
||||
loader := &pluginfakes.FakeLoader{
|
||||
LoadFunc: func(ctx context.Context, src plugins.PluginSource) ([]*plugins.Plugin, error) {
|
||||
// Check if this is a LocalSource and get its paths
|
||||
if localSrc, ok := src.(*sources.LocalSource); ok {
|
||||
@@ -415,7 +415,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
urlMethodCalled := false
|
||||
catalogMethodCalled := false
|
||||
|
||||
pluginRepo := &fakes.FakePluginRepo{
|
||||
pluginRepo := &pluginfakes.FakePluginRepo{
|
||||
GetPluginArchiveByURLFunc: func(_ context.Context, url string, _ repo.CompatOpts) (*repo.PluginArchive, error) {
|
||||
urlMethodCalled = true
|
||||
require.Equal(t, parentURL, url, "URL method should only be called for parent plugin")
|
||||
@@ -432,7 +432,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
fs := &fakes.FakePluginStorage{
|
||||
fs := &pluginfakes.FakePluginStorage{
|
||||
ExtractFunc: func(_ context.Context, id string, _ storage.DirNameGeneratorFunc, z *zip.ReadCloser) (*storage.ExtractedPluginArchive, error) {
|
||||
switch id {
|
||||
case parentPluginID:
|
||||
@@ -452,7 +452,7 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
inst := New(&config.PluginManagementCfg{}, fakes.NewFakePluginRegistry(), loader, pluginRepo, fs, storage.SimpleDirNameGeneratorFunc, &fakes.FakeAuthService{})
|
||||
inst := New(&config.PluginManagementCfg{}, pluginfakes.NewFakePluginRegistry(), loader, pluginRepo, fs, storage.SimpleDirNameGeneratorFunc, &pluginfakes.FakeAuthService{})
|
||||
err := inst.Add(context.Background(), parentPluginID, "", plugins.NewAddOpts("10.0.0", runtime.GOOS, runtime.GOARCH, parentURL))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []string{"dependency-plugin.zip", "parent-plugin.zip"}, loadedPaths)
|
||||
@@ -474,7 +474,7 @@ func createPlugin(t *testing.T, pluginID string, class plugins.Class, managed, b
|
||||
}
|
||||
p.SetLogger(log.NewTestLogger())
|
||||
if p.Backend {
|
||||
p.RegisterClient(&fakes.FakePluginClient{
|
||||
p.RegisterClient(&pluginfakes.FakePluginClient{
|
||||
ID: pluginID,
|
||||
Managed: managed,
|
||||
Log: p.Logger(),
|
||||
@@ -517,13 +517,13 @@ func TestPluginInstaller_Removal(t *testing.T) {
|
||||
plugin.FS = localFS
|
||||
})
|
||||
|
||||
registry := &fakes.FakePluginRegistry{
|
||||
registry := &pluginfakes.FakePluginRegistry{
|
||||
Store: map[string]*plugins.Plugin{
|
||||
"localfs-plugin": pluginV1,
|
||||
},
|
||||
}
|
||||
|
||||
loader := &fakes.FakeLoader{
|
||||
loader := &pluginfakes.FakeLoader{
|
||||
UnloadFunc: func(_ context.Context, p *plugins.Plugin) (*plugins.Plugin, error) {
|
||||
return p, nil
|
||||
},
|
||||
@@ -532,7 +532,7 @@ func TestPluginInstaller_Removal(t *testing.T) {
|
||||
_, err = os.Stat(pluginDir)
|
||||
require.NoError(t, err)
|
||||
|
||||
inst := New(&config.PluginManagementCfg{}, registry, loader, &fakes.FakePluginRepo{}, &fakes.FakePluginStorage{}, storage.SimpleDirNameGeneratorFunc, &fakes.FakeAuthService{})
|
||||
inst := New(&config.PluginManagementCfg{}, registry, loader, &pluginfakes.FakePluginRepo{}, &pluginfakes.FakePluginStorage{}, storage.SimpleDirNameGeneratorFunc, &pluginfakes.FakeAuthService{})
|
||||
err = inst.Remove(context.Background(), "localfs-plugin", "1.0.0")
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -565,13 +565,13 @@ func TestPluginInstaller_Removal(t *testing.T) {
|
||||
plugin.FS = staticFS
|
||||
})
|
||||
|
||||
registry := &fakes.FakePluginRegistry{
|
||||
registry := &pluginfakes.FakePluginRegistry{
|
||||
Store: map[string]*plugins.Plugin{
|
||||
"staticfs-plugin": pluginV1,
|
||||
},
|
||||
}
|
||||
|
||||
loader := &fakes.FakeLoader{
|
||||
loader := &pluginfakes.FakeLoader{
|
||||
UnloadFunc: func(_ context.Context, p *plugins.Plugin) (*plugins.Plugin, error) {
|
||||
return p, nil
|
||||
},
|
||||
@@ -580,7 +580,7 @@ func TestPluginInstaller_Removal(t *testing.T) {
|
||||
_, err = os.Stat(pluginDir)
|
||||
require.NoError(t, err)
|
||||
|
||||
inst := New(&config.PluginManagementCfg{}, registry, loader, &fakes.FakePluginRepo{}, &fakes.FakePluginStorage{}, storage.SimpleDirNameGeneratorFunc, &fakes.FakeAuthService{})
|
||||
inst := New(&config.PluginManagementCfg{}, registry, loader, &pluginfakes.FakePluginRepo{}, &pluginfakes.FakePluginStorage{}, storage.SimpleDirNameGeneratorFunc, &pluginfakes.FakeAuthService{})
|
||||
err = inst.Remove(context.Background(), "staticfs-plugin", "1.0.0")
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user