grafana/pkg/api/fakes.go
Will Browne 4a707e2a88
Plugins: Split plugin manager into smaller components (#54384)
* split out plugin manager

* remove whitespace

* fix tests

* split up tests

* updating naming conventions

* simplify manager

* tidy

* add more fakes

* testing time

* add query verif to int test

* renaming

* add process tests

* tidy up manager tests

* add extra case to int test

* add more coverage to store and process tests

* remove comment

* fix capatilization

* init on provide

* remove addfromsource from API
2022-08-30 17:30:43 +02:00

75 lines
1.4 KiB
Go

package api
import (
"context"
"github.com/grafana/grafana/pkg/plugins"
)
type fakePluginManager struct {
plugins.Manager
plugins map[string]fakePlugin
}
type fakePlugin struct {
pluginID string
version string
}
func (pm *fakePluginManager) Add(_ context.Context, pluginID, version string, _ plugins.CompatOpts) error {
pm.plugins[pluginID] = fakePlugin{
pluginID: pluginID,
version: version,
}
return nil
}
func (pm *fakePluginManager) Remove(_ context.Context, pluginID string) error {
delete(pm.plugins, pluginID)
return nil
}
type fakePluginStore struct {
plugins.Store
plugins map[string]plugins.PluginDTO
}
func (pr fakePluginStore) Plugin(_ context.Context, pluginID string) (plugins.PluginDTO, bool) {
p, exists := pr.plugins[pluginID]
return p, exists
}
func (pr fakePluginStore) Plugins(_ context.Context, pluginTypes ...plugins.Type) []plugins.PluginDTO {
var result []plugins.PluginDTO
for _, v := range pr.plugins {
for _, t := range pluginTypes {
if v.Type == t {
result = append(result, v)
}
}
}
return result
}
type fakeRendererManager struct {
plugins.RendererManager
}
func (ps *fakeRendererManager) Renderer() *plugins.Plugin {
return nil
}
type fakePluginStaticRouteResolver struct {
plugins.StaticRouteResolver
routes []*plugins.StaticRoute
}
func (psrr *fakePluginStaticRouteResolver) Routes() []*plugins.StaticRoute {
return psrr.routes
}