Plugins: Add /meta and /metas APIs to plugins app (#113775)
* add /meta and /metas APIs * wrapped storage route * format file * fix switch statement lint issue * fix plugininstaller test --------- Co-authored-by: Todd Treece <todd.treece@grafana.com>
This commit is contained in:
co-authored by
Todd Treece
parent
335111e783
commit
f1dbbcbe00
@@ -238,6 +238,7 @@ type ReleaseState string
|
||||
|
||||
const (
|
||||
ReleaseStateAlpha ReleaseState = "alpha"
|
||||
ReleaseStateBeta ReleaseState = "beta"
|
||||
)
|
||||
|
||||
type SignatureType string
|
||||
|
||||
@@ -33,7 +33,7 @@ import (
|
||||
func ProvideAppInstallers(
|
||||
features featuremgmt.FeatureToggles,
|
||||
playlistAppInstaller *playlist.PlaylistAppInstaller,
|
||||
pluginsApplInstaller *plugins.PluginsAppInstaller,
|
||||
pluginsApplInstaller *plugins.AppInstaller,
|
||||
shorturlAppInstaller *shorturl.ShortURLAppInstaller,
|
||||
rulesAppInstaller *rules.AlertingRulesAppInstaller,
|
||||
correlationsAppInstaller *correlations.AppInstaller,
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
|
||||
func TestProvideAppInstallers_Table(t *testing.T) {
|
||||
playlistInstaller := &playlist.PlaylistAppInstaller{}
|
||||
pluginsInstaller := &plugins.PluginsAppInstaller{}
|
||||
pluginsInstaller := &plugins.AppInstaller{}
|
||||
rulesInstaller := &rules.AlertingRulesAppInstaller{}
|
||||
correlationsAppInstaller := &correlations.AppInstaller{}
|
||||
notificationsAppInstaller := ¬ifications.AlertingNotificationsAppInstaller{}
|
||||
|
||||
@@ -1,34 +1,59 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/grafana/grafana-app-sdk/k8s"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apiserver/pkg/authorization/authorizer"
|
||||
"k8s.io/apiserver/pkg/registry/generic"
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
|
||||
"github.com/grafana/grafana-app-sdk/app"
|
||||
appsdkapiserver "github.com/grafana/grafana-app-sdk/k8s/apiserver"
|
||||
"github.com/grafana/grafana-app-sdk/simple"
|
||||
|
||||
pluginsappapis "github.com/grafana/grafana/apps/plugins/pkg/apis"
|
||||
pluginsv0alpha1 "github.com/grafana/grafana/apps/plugins/pkg/apis/plugins/v0alpha1"
|
||||
pluginsapp "github.com/grafana/grafana/apps/plugins/pkg/app"
|
||||
"github.com/grafana/grafana/apps/plugins/pkg/app/meta"
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/services/apiserver"
|
||||
"github.com/grafana/grafana/pkg/services/apiserver/appinstaller"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/services/apiserver/endpoints/request"
|
||||
)
|
||||
|
||||
var (
|
||||
_ appsdkapiserver.AppInstaller = (*PluginsAppInstaller)(nil)
|
||||
_ appinstaller.AuthorizerProvider = (*PluginsAppInstaller)(nil)
|
||||
_ appsdkapiserver.AppInstaller = (*AppInstaller)(nil)
|
||||
_ appinstaller.AuthorizerProvider = (*AppInstaller)(nil)
|
||||
)
|
||||
|
||||
type PluginsAppInstaller struct {
|
||||
type AppInstaller struct {
|
||||
metaManager *meta.ProviderManager
|
||||
cfgProvider configprovider.ConfigProvider
|
||||
restConfigProvider apiserver.RestConfigProvider
|
||||
|
||||
appsdkapiserver.AppInstaller
|
||||
}
|
||||
|
||||
func RegisterAppInstaller(
|
||||
cfg *setting.Cfg,
|
||||
features featuremgmt.FeatureToggles,
|
||||
) (*PluginsAppInstaller, error) {
|
||||
installer := &PluginsAppInstaller{}
|
||||
specificConfig := any(nil)
|
||||
cfgProvider configprovider.ConfigProvider,
|
||||
restConfigProvider apiserver.RestConfigProvider,
|
||||
) (*AppInstaller, error) {
|
||||
grafanaComAPIURL := os.Getenv("GRAFANA_COM_API_URL")
|
||||
if grafanaComAPIURL == "" {
|
||||
grafanaComAPIURL = "https://grafana.com/api/plugins"
|
||||
}
|
||||
|
||||
coreProvider := meta.NewCoreProvider()
|
||||
cloudProvider := meta.NewCloudProvider(grafanaComAPIURL)
|
||||
metaProviderManager := meta.NewProviderManager(coreProvider, cloudProvider)
|
||||
specificConfig := &pluginsapp.PluginAppConfig{
|
||||
MetaProviderManager: metaProviderManager,
|
||||
}
|
||||
provider := simple.NewAppProvider(pluginsappapis.LocalManifest(), specificConfig, pluginsapp.New)
|
||||
appConfig := app.Config{
|
||||
KubeConfig: restclient.Config{}, // this will be overridden by the installer's InitializeApp method
|
||||
@@ -39,11 +64,54 @@ func RegisterAppInstaller(
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
installer.AppInstaller = i
|
||||
return installer, nil
|
||||
|
||||
return &AppInstaller{
|
||||
metaManager: metaProviderManager,
|
||||
cfgProvider: cfgProvider,
|
||||
restConfigProvider: restConfigProvider,
|
||||
AppInstaller: i,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *AppInstaller) InstallAPIs(
|
||||
server appsdkapiserver.GenericAPIServer,
|
||||
restOptsGetter generic.RESTOptionsGetter,
|
||||
) error {
|
||||
ctx := context.Background()
|
||||
cfg, err := p.cfgProvider.Get(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create a client factory function that will be called lazily when the client is needed.
|
||||
// This avoids deadlock issues since the restConfigProvider/API server will not be ready during API installation.
|
||||
clientFactory := func(ctx context.Context) (*pluginsv0alpha1.PluginClient, error) {
|
||||
kubeConfig, err := p.restConfigProvider.GetRestConfig(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get rest config: %w", err)
|
||||
}
|
||||
|
||||
clientGenerator := k8s.NewClientRegistry(*kubeConfig, k8s.DefaultClientConfig())
|
||||
client, err := pluginsv0alpha1.NewPluginClientFromGenerator(clientGenerator)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create plugin client: %w", err)
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
pluginMetaGVR := pluginsv0alpha1.PluginMetaKind().GroupVersionResource()
|
||||
replacedStorage := map[schema.GroupVersionResource]rest.Storage{
|
||||
pluginMetaGVR: pluginsapp.NewPluginMetaStorage(p.metaManager, clientFactory, request.GetNamespaceMapper(cfg)),
|
||||
}
|
||||
wrappedServer := &customStorageWrapper{
|
||||
wrapped: server,
|
||||
replace: replacedStorage,
|
||||
}
|
||||
return p.AppInstaller.InstallAPIs(wrappedServer, restOptsGetter)
|
||||
}
|
||||
|
||||
// GetAuthorizer returns the authorizer for the plugins app.
|
||||
func (p *PluginsAppInstaller) GetAuthorizer() authorizer.Authorizer {
|
||||
func (p *AppInstaller) GetAuthorizer() authorizer.Authorizer {
|
||||
return pluginsapp.GetAuthorizer()
|
||||
}
|
||||
|
||||
Generated
+6
-6
@@ -786,7 +786,7 @@ func Initialize(ctx context.Context, cfg *setting.Cfg, opts Options, apiOpts api
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pluginsAppInstaller, err := plugins.RegisterAppInstaller(cfg, featureToggles)
|
||||
appInstaller, err := plugins.RegisterAppInstaller(configProvider, eventualRestConfigProvider)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -798,7 +798,7 @@ func Initialize(ctx context.Context, cfg *setting.Cfg, opts Options, apiOpts api
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
appInstaller, err := correlations2.RegisterAppInstaller(cfg, featureToggles, correlationsService)
|
||||
correlationsAppInstaller, err := correlations2.RegisterAppInstaller(cfg, featureToggles, correlationsService)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -823,7 +823,7 @@ func Initialize(ctx context.Context, cfg *setting.Cfg, opts Options, apiOpts api
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v2 := appregistry.ProvideAppInstallers(featureToggles, playlistAppInstaller, pluginsAppInstaller, shortURLAppInstaller, alertingRulesAppInstaller, appInstaller, alertingNotificationsAppInstaller, logsDrilldownAppInstaller, annotationAppInstaller, exampleAppInstaller, advisorAppInstaller)
|
||||
v2 := appregistry.ProvideAppInstallers(featureToggles, playlistAppInstaller, appInstaller, shortURLAppInstaller, alertingRulesAppInstaller, correlationsAppInstaller, alertingNotificationsAppInstaller, logsDrilldownAppInstaller, annotationAppInstaller, exampleAppInstaller, advisorAppInstaller)
|
||||
builderMetrics := builder.ProvideBuilderMetrics(registerer)
|
||||
apiserverService, err := apiserver.ProvideService(cfg, featureToggles, routeRegisterImpl, tracingService, serverLockService, sqlStore, kvStore, middlewareHandler, scopedPluginDatasourceProvider, plugincontextProvider, pluginstoreService, dualwriteService, resourceClient, inlineSecureValueSupport, eventualRestConfigProvider, v, eventualRestConfigProvider, registerer, aggregatorRunner, v2, builderMetrics)
|
||||
if err != nil {
|
||||
@@ -1435,7 +1435,7 @@ func InitializeForTest(ctx context.Context, t sqlutil.ITestDB, testingT interfac
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pluginsAppInstaller, err := plugins.RegisterAppInstaller(cfg, featureToggles)
|
||||
appInstaller, err := plugins.RegisterAppInstaller(configProvider, eventualRestConfigProvider)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1447,7 +1447,7 @@ func InitializeForTest(ctx context.Context, t sqlutil.ITestDB, testingT interfac
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
appInstaller, err := correlations2.RegisterAppInstaller(cfg, featureToggles, correlationsService)
|
||||
correlationsAppInstaller, err := correlations2.RegisterAppInstaller(cfg, featureToggles, correlationsService)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1472,7 +1472,7 @@ func InitializeForTest(ctx context.Context, t sqlutil.ITestDB, testingT interfac
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v2 := appregistry.ProvideAppInstallers(featureToggles, playlistAppInstaller, pluginsAppInstaller, shortURLAppInstaller, alertingRulesAppInstaller, appInstaller, alertingNotificationsAppInstaller, logsDrilldownAppInstaller, annotationAppInstaller, exampleAppInstaller, advisorAppInstaller)
|
||||
v2 := appregistry.ProvideAppInstallers(featureToggles, playlistAppInstaller, appInstaller, shortURLAppInstaller, alertingRulesAppInstaller, correlationsAppInstaller, alertingNotificationsAppInstaller, logsDrilldownAppInstaller, annotationAppInstaller, exampleAppInstaller, advisorAppInstaller)
|
||||
builderMetrics := builder.ProvideBuilderMetrics(registerer)
|
||||
apiserverService, err := apiserver.ProvideService(cfg, featureToggles, routeRegisterImpl, tracingService, serverLockService, sqlStore, kvStore, middlewareHandler, scopedPluginDatasourceProvider, plugincontextProvider, pluginstoreService, dualwriteService, resourceClient, inlineSecureValueSupport, eventualRestConfigProvider, v, eventualRestConfigProvider, registerer, aggregatorRunner, v2, builderMetrics)
|
||||
if err != nil {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/pluginfakes"
|
||||
@@ -208,7 +209,9 @@ func TestService_Run(t *testing.T) {
|
||||
|
||||
t.Cleanup(func() {
|
||||
s.StopAsync()
|
||||
err := s.AwaitTerminated(context.Background())
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
err := s.AwaitTerminated(ctx)
|
||||
if tt.shouldThrowError {
|
||||
require.ErrorContains(t, err, "Failed to install plugin")
|
||||
return
|
||||
@@ -225,6 +228,8 @@ func TestService_Run(t *testing.T) {
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
<-s.installComplete
|
||||
|
||||
if tt.shouldInstall {
|
||||
expectedInstalled := 0
|
||||
expectedInstalledFromURL := 0
|
||||
@@ -246,7 +251,6 @@ func TestService_Run(t *testing.T) {
|
||||
expectedInstalled++
|
||||
}
|
||||
}
|
||||
<-s.installComplete
|
||||
require.Equal(t, expectedInstalled, installed)
|
||||
require.Equal(t, expectedInstalledFromURL, installedFromURL)
|
||||
}
|
||||
|
||||
@@ -19,6 +19,35 @@ func TestIntegrationPluginsIntegrationDiscovery(t *testing.T) {
|
||||
"version": "v0alpha1",
|
||||
"freshness": "Current",
|
||||
"resources": [
|
||||
{
|
||||
"resource": "pluginmetas",
|
||||
"responseKind": {
|
||||
"group": "",
|
||||
"kind": "PluginMeta",
|
||||
"version": ""
|
||||
},
|
||||
"scope": "Namespaced",
|
||||
"singularResource": "pluginmeta",
|
||||
"subresources": [
|
||||
{
|
||||
"responseKind": {
|
||||
"group": "",
|
||||
"kind": "PluginMeta",
|
||||
"version": ""
|
||||
},
|
||||
"subresource": "status",
|
||||
"verbs": [
|
||||
"get",
|
||||
"patch",
|
||||
"update"
|
||||
]
|
||||
}
|
||||
],
|
||||
"verbs": [
|
||||
"get",
|
||||
"list"
|
||||
]
|
||||
},
|
||||
{
|
||||
"resource": "plugins",
|
||||
"responseKind": {
|
||||
@@ -29,17 +58,6 @@ func TestIntegrationPluginsIntegrationDiscovery(t *testing.T) {
|
||||
"scope": "Namespaced",
|
||||
"singularResource": "plugins",
|
||||
"subresources": [
|
||||
{
|
||||
"responseKind": {
|
||||
"group": "",
|
||||
"kind": "ResourceCallOptions",
|
||||
"version": ""
|
||||
},
|
||||
"subresource": "meta",
|
||||
"verbs": [
|
||||
"get"
|
||||
]
|
||||
},
|
||||
{
|
||||
"responseKind": {
|
||||
"group": "",
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
pluginsv0alpha1 "github.com/grafana/grafana/apps/plugins/pkg/apis/plugins/v0alpha1"
|
||||
"github.com/grafana/grafana/pkg/tests/apis"
|
||||
"github.com/grafana/grafana/pkg/util/testutil"
|
||||
)
|
||||
|
||||
func TestIntegrationPluginMeta(t *testing.T) {
|
||||
testutil.SkipIntegrationTestInShortMode(t)
|
||||
|
||||
t.Run("get plugin meta", func(t *testing.T) {
|
||||
helper := setupHelper(t)
|
||||
ctx := context.Background()
|
||||
client := helper.GetResourceClient(apis.ResourceClientArgs{
|
||||
User: helper.Org1.Admin,
|
||||
GVR: gvrPlugins,
|
||||
})
|
||||
|
||||
pluginName := "test-plugin-meta"
|
||||
plugin := helper.LoadYAMLOrJSON(fmt.Sprintf(`{
|
||||
"apiVersion": "plugins.grafana.app/v0alpha1",
|
||||
"kind": "Plugin",
|
||||
"metadata": {"name": "%s"},
|
||||
"spec": {"id": "grafana-piechart-panel", "version": "1.0.0"}
|
||||
}`, pluginName))
|
||||
_, err := client.Resource.Create(ctx, plugin, metav1.CreateOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
namespace := helper.Org1.Admin.Identity.GetNamespace()
|
||||
path := fmt.Sprintf("/apis/plugins.grafana.app/v0alpha1/namespaces/%s/pluginmetas/%s", namespace, pluginName)
|
||||
response := apis.DoRequest(helper, apis.RequestParams{
|
||||
User: helper.Org1.Admin,
|
||||
Method: "GET",
|
||||
Path: path,
|
||||
}, &pluginsv0alpha1.PluginMeta{})
|
||||
|
||||
require.NotNil(t, response.Result)
|
||||
require.NotNil(t, response.Result.Spec.PluginJSON)
|
||||
require.Equal(t, "grafana-piechart-panel", response.Result.Spec.PluginJSON.Id)
|
||||
require.NotEmpty(t, response.Result.Spec.PluginJSON.Name)
|
||||
require.NotEmpty(t, response.Result.Spec.PluginJSON.Type)
|
||||
})
|
||||
|
||||
t.Run("get plugin meta for non-existent plugin", func(t *testing.T) {
|
||||
helper := setupHelper(t)
|
||||
namespace := helper.Org1.Admin.Identity.GetNamespace()
|
||||
path := fmt.Sprintf("/apis/plugins.grafana.app/v0alpha1/namespaces/%s/pluginmetas/non-existent-plugin", namespace)
|
||||
response := apis.DoRequest(helper, apis.RequestParams{
|
||||
User: helper.Org1.Admin,
|
||||
Method: "GET",
|
||||
Path: path,
|
||||
}, &pluginsv0alpha1.PluginMeta{})
|
||||
|
||||
require.NotNil(t, response.Status)
|
||||
require.Equal(t, int32(404), response.Status.Code)
|
||||
})
|
||||
|
||||
t.Run("get plugin meta for plugin with non-existent metadata", func(t *testing.T) {
|
||||
helper := setupHelper(t)
|
||||
ctx := context.Background()
|
||||
client := helper.GetResourceClient(apis.ResourceClientArgs{
|
||||
User: helper.Org1.Admin,
|
||||
GVR: gvrPlugins,
|
||||
})
|
||||
|
||||
pluginName := "test-plugin-meta-not-found"
|
||||
plugin := helper.LoadYAMLOrJSON(fmt.Sprintf(`{
|
||||
"apiVersion": "plugins.grafana.app/v0alpha1",
|
||||
"kind": "Plugin",
|
||||
"metadata": {"name": "%s"},
|
||||
"spec": {"id": "non-existent-plugin-id", "version": "1.0.0"}
|
||||
}`, pluginName))
|
||||
_, err := client.Resource.Create(ctx, plugin, metav1.CreateOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
namespace := helper.Org1.Admin.Identity.GetNamespace()
|
||||
path := fmt.Sprintf("/apis/plugins.grafana.app/v0alpha1/namespaces/%s/pluginmetas/%s", namespace, pluginName)
|
||||
response := apis.DoRequest(helper, apis.RequestParams{
|
||||
User: helper.Org1.Admin,
|
||||
Method: "GET",
|
||||
Path: path,
|
||||
}, &pluginsv0alpha1.PluginMeta{})
|
||||
|
||||
require.NotNil(t, response.Status)
|
||||
require.Equal(t, int32(404), response.Status.Code)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
pluginsv0alpha1 "github.com/grafana/grafana/apps/plugins/pkg/apis/plugins/v0alpha1"
|
||||
"github.com/grafana/grafana/pkg/tests/apis"
|
||||
"github.com/grafana/grafana/pkg/util/testutil"
|
||||
)
|
||||
|
||||
func TestIntegrationPluginMetas(t *testing.T) {
|
||||
testutil.SkipIntegrationTestInShortMode(t)
|
||||
|
||||
t.Run("list plugin metas", func(t *testing.T) {
|
||||
helper := setupHelper(t)
|
||||
ctx := context.Background()
|
||||
client := helper.GetResourceClient(apis.ResourceClientArgs{
|
||||
User: helper.Org1.Admin,
|
||||
GVR: gvrPlugins,
|
||||
})
|
||||
|
||||
plugin1Name := "test-plugin-metas-1"
|
||||
plugin1 := helper.LoadYAMLOrJSON(fmt.Sprintf(`{
|
||||
"apiVersion": "plugins.grafana.app/v0alpha1",
|
||||
"kind": "Plugin",
|
||||
"metadata": {"name": "%s"},
|
||||
"spec": {"id": "grafana-piechart-panel", "version": "1.0.0"}
|
||||
}`, plugin1Name))
|
||||
_, err := client.Resource.Create(ctx, plugin1, metav1.CreateOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
plugin2Name := "test-plugin-metas-2"
|
||||
plugin2 := helper.LoadYAMLOrJSON(fmt.Sprintf(`{
|
||||
"apiVersion": "plugins.grafana.app/v0alpha1",
|
||||
"kind": "Plugin",
|
||||
"metadata": {"name": "%s"},
|
||||
"spec": {"id": "grafana-clock-panel", "version": "1.0.0"}
|
||||
}`, plugin2Name))
|
||||
_, err = client.Resource.Create(ctx, plugin2, metav1.CreateOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
namespace := helper.Namespacer(helper.Org1.Admin.Identity.GetOrgID())
|
||||
path := fmt.Sprintf("/apis/plugins.grafana.app/v0alpha1/namespaces/%s/pluginmetas", namespace)
|
||||
response := apis.DoRequest(helper, apis.RequestParams{
|
||||
User: helper.Org1.Admin,
|
||||
Method: "GET",
|
||||
Path: path,
|
||||
}, &pluginsv0alpha1.PluginMetaList{})
|
||||
|
||||
require.NotNil(t, response.Result)
|
||||
require.NotNil(t, response.Result.Items)
|
||||
require.GreaterOrEqual(t, len(response.Result.Items), 2)
|
||||
|
||||
foundIDs := make(map[string]bool)
|
||||
for _, item := range response.Result.Items {
|
||||
require.NotNil(t, item.Spec.PluginJSON)
|
||||
foundIDs[item.Spec.PluginJSON.Id] = true
|
||||
require.NotEmpty(t, item.Spec.PluginJSON.Id)
|
||||
require.NotEmpty(t, item.Spec.PluginJSON.Type)
|
||||
require.NotEmpty(t, item.Spec.PluginJSON.Name)
|
||||
}
|
||||
require.True(t, foundIDs["grafana-piechart-panel"])
|
||||
require.True(t, foundIDs["grafana-clock-panel"])
|
||||
})
|
||||
|
||||
t.Run("list plugin metas with no plugins", func(t *testing.T) {
|
||||
helper := setupHelper(t)
|
||||
namespace := helper.Namespacer(helper.Org1.Admin.Identity.GetOrgID())
|
||||
path := fmt.Sprintf("/apis/plugins.grafana.app/v0alpha1/namespaces/%s/pluginmetas", namespace)
|
||||
response := apis.DoRequest(helper, apis.RequestParams{
|
||||
User: helper.Org1.Admin,
|
||||
Method: "GET",
|
||||
Path: path,
|
||||
}, &pluginsv0alpha1.PluginMetaList{})
|
||||
|
||||
require.NotNil(t, response.Result)
|
||||
require.NotNil(t, response.Result.Items)
|
||||
require.GreaterOrEqual(t, len(response.Result.Items), 0)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user