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
This commit is contained in:
@@ -7,12 +7,12 @@ import (
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
pluginDashboardsManager "github.com/grafana/grafana/pkg/plugins/manager/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/plugindashboards"
|
||||
)
|
||||
|
||||
func ProvideService(pluginDashboardStore plugins.DashboardFileStore, dashboardPluginService dashboards.PluginService) *Service {
|
||||
func ProvideService(pluginDashboardStore pluginDashboardsManager.FileStore, dashboardPluginService dashboards.PluginService) *Service {
|
||||
return &Service{
|
||||
pluginDashboardStore: pluginDashboardStore,
|
||||
dashboardPluginService: dashboardPluginService,
|
||||
@@ -21,7 +21,7 @@ func ProvideService(pluginDashboardStore plugins.DashboardFileStore, dashboardPl
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
pluginDashboardStore plugins.DashboardFileStore
|
||||
pluginDashboardStore pluginDashboardsManager.FileStore
|
||||
dashboardPluginService dashboards.PluginService
|
||||
logger log.Logger
|
||||
}
|
||||
@@ -31,7 +31,7 @@ func (s Service) ListPluginDashboards(ctx context.Context, req *plugindashboards
|
||||
return nil, fmt.Errorf("req cannot be nil")
|
||||
}
|
||||
|
||||
listArgs := &plugins.ListPluginDashboardFilesArgs{
|
||||
listArgs := &pluginDashboardsManager.ListPluginDashboardFilesArgs{
|
||||
PluginID: req.PluginID,
|
||||
}
|
||||
listResp, err := s.pluginDashboardStore.ListPluginDashboardFiles(ctx, listArgs)
|
||||
@@ -106,7 +106,7 @@ func (s Service) LoadPluginDashboard(ctx context.Context, req *plugindashboards.
|
||||
return nil, fmt.Errorf("req cannot be nil")
|
||||
}
|
||||
|
||||
args := &plugins.GetPluginDashboardFileContentsArgs{
|
||||
args := &pluginDashboardsManager.GetPluginDashboardFileContentsArgs{
|
||||
PluginID: req.PluginID,
|
||||
FileReference: req.Reference,
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/plugindashboards"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -169,7 +170,7 @@ type pluginDashboardStoreMock struct {
|
||||
pluginDashboardFiles map[string]map[string][]byte
|
||||
}
|
||||
|
||||
func (m pluginDashboardStoreMock) ListPluginDashboardFiles(ctx context.Context, args *plugins.ListPluginDashboardFilesArgs) (*plugins.ListPluginDashboardFilesResult, error) {
|
||||
func (m pluginDashboardStoreMock) ListPluginDashboardFiles(ctx context.Context, args *dashboards.ListPluginDashboardFilesArgs) (*dashboards.ListPluginDashboardFilesResult, error) {
|
||||
if dashboardFiles, exists := m.pluginDashboardFiles[args.PluginID]; exists {
|
||||
references := []string{}
|
||||
|
||||
@@ -179,7 +180,7 @@ func (m pluginDashboardStoreMock) ListPluginDashboardFiles(ctx context.Context,
|
||||
|
||||
sort.Strings(references)
|
||||
|
||||
return &plugins.ListPluginDashboardFilesResult{
|
||||
return &dashboards.ListPluginDashboardFilesResult{
|
||||
FileReferences: references,
|
||||
}, nil
|
||||
}
|
||||
@@ -187,11 +188,11 @@ func (m pluginDashboardStoreMock) ListPluginDashboardFiles(ctx context.Context,
|
||||
return nil, plugins.NotFoundError{PluginID: args.PluginID}
|
||||
}
|
||||
|
||||
func (m pluginDashboardStoreMock) GetPluginDashboardFileContents(ctx context.Context, args *plugins.GetPluginDashboardFileContentsArgs) (*plugins.GetPluginDashboardFileContentsResult, error) {
|
||||
func (m pluginDashboardStoreMock) GetPluginDashboardFileContents(ctx context.Context, args *dashboards.GetPluginDashboardFileContentsArgs) (*dashboards.GetPluginDashboardFileContentsResult, error) {
|
||||
if dashboardFiles, exists := m.pluginDashboardFiles[args.PluginID]; exists {
|
||||
if content, exists := dashboardFiles[args.FileReference]; exists {
|
||||
r := bytes.NewReader(content)
|
||||
return &plugins.GetPluginDashboardFileContentsResult{
|
||||
return &dashboards.GetPluginDashboardFileContentsResult{
|
||||
Content: io.NopCloser(r),
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user