mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 21:19:28 -06:00
0b511aaace
* add backend check for roles * tidy * fix tests * incorporate rbac * fix linter * apply PR feedback * add tests * fix logic * add comment * apply PR feedback
45 lines
780 B
Go
45 lines
780 B
Go
package pluginstore
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana/pkg/plugins"
|
|
)
|
|
|
|
type FakePluginStore struct {
|
|
PluginList []Plugin
|
|
}
|
|
|
|
func NewFakePluginStore(ps ...Plugin) *FakePluginStore {
|
|
return &FakePluginStore{
|
|
PluginList: ps,
|
|
}
|
|
}
|
|
|
|
func (pr *FakePluginStore) Plugin(_ context.Context, pluginID string) (Plugin, bool) {
|
|
for _, v := range pr.PluginList {
|
|
if v.ID == pluginID {
|
|
return v, true
|
|
}
|
|
}
|
|
|
|
return Plugin{}, false
|
|
}
|
|
|
|
func (pr *FakePluginStore) Plugins(_ context.Context, pluginTypes ...plugins.Type) []Plugin {
|
|
var result []Plugin
|
|
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
|
|
}
|