Plugins: Migrate PluginStore mock to pre-existing fakes package (#71664)
* migrate to existing fakes package * fix imports
This commit is contained in:
@@ -6,9 +6,11 @@ import (
|
||||
"testing"
|
||||
"testing/fstest"
|
||||
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/fakes"
|
||||
)
|
||||
|
||||
func TestDashboardFileStore(t *testing.T) {
|
||||
@@ -219,7 +221,7 @@ func setupPluginDashboardsForTest(t *testing.T) *FileStoreManager {
|
||||
}
|
||||
|
||||
return &FileStoreManager{
|
||||
pluginStore: &plugins.FakePluginStore{
|
||||
pluginStore: &fakes.FakePluginStore{
|
||||
PluginList: []plugins.PluginDTO{p1.ToDTO(), p2.ToDTO()},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -432,3 +432,34 @@ type FakeOauthService struct {
|
||||
func (f *FakeOauthService) RegisterExternalService(ctx context.Context, name string, svc *plugindef.ExternalServiceRegistration) (*oauth.ExternalService, error) {
|
||||
return f.Result, nil
|
||||
}
|
||||
|
||||
type FakePluginStore struct {
|
||||
PluginList []plugins.PluginDTO
|
||||
}
|
||||
|
||||
func (pr *FakePluginStore) Plugin(_ context.Context, pluginID string) (plugins.PluginDTO, bool) {
|
||||
for _, v := range pr.PluginList {
|
||||
if v.ID == pluginID {
|
||||
return v, true
|
||||
}
|
||||
}
|
||||
|
||||
return plugins.PluginDTO{}, false
|
||||
}
|
||||
|
||||
func (pr *FakePluginStore) Plugins(_ context.Context, pluginTypes ...plugins.Type) []plugins.PluginDTO {
|
||||
var result []plugins.PluginDTO
|
||||
if len(pluginTypes) == 0 {
|
||||
pluginTypes = plugins.PluginTypes
|
||||
}
|
||||
|
||||
for _, v := range pr.PluginList {
|
||||
for _, t := range pluginTypes {
|
||||
if v.Type == t {
|
||||
result = append(result, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user