mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 12:52:15 +08:00
Plugins: Factory for instantiating core plugin (#85047)
This commit is contained in:

committed by
GitHub

parent
6137c4e0a6
commit
8f12fb94f9
63
pkg/plugins/backendplugin/coreplugin/registry_test.go
Normal file
63
pkg/plugins/backendplugin/coreplugin/registry_test.go
Normal file
@ -0,0 +1,63 @@
|
||||
package coreplugin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNewPlugin(t *testing.T) {
|
||||
tcs := []struct {
|
||||
ID string
|
||||
ExpectedID string
|
||||
ExpectedAlias string
|
||||
ExpectedNotFoundErr bool
|
||||
}{
|
||||
{ID: AzureMonitor},
|
||||
{ID: CloudMonitoring},
|
||||
{ID: CloudWatch},
|
||||
{ID: Elasticsearch},
|
||||
{ID: Grafana, ExpectedNotFoundErr: true},
|
||||
{ID: Graphite},
|
||||
{ID: InfluxDB},
|
||||
{ID: Loki},
|
||||
{ID: MSSQL},
|
||||
{ID: MySQL},
|
||||
{ID: OpenTSDB},
|
||||
{ID: Parca},
|
||||
{ID: PostgreSQL},
|
||||
{ID: Prometheus},
|
||||
{ID: Pyroscope},
|
||||
{ID: Tempo},
|
||||
{ID: TestData, ExpectedAlias: TestDataAlias},
|
||||
{ID: TestDataAlias, ExpectedID: TestData, ExpectedAlias: TestDataAlias},
|
||||
}
|
||||
|
||||
for _, tc := range tcs {
|
||||
t.Run(tc.ID, func(t *testing.T) {
|
||||
if tc.ExpectedID == "" {
|
||||
tc.ExpectedID = tc.ID
|
||||
}
|
||||
|
||||
p, err := NewPlugin(tc.ID, setting.NewCfg(), httpclient.NewProvider(), tracing.InitializeTracerForTest(), featuremgmt.WithFeatures())
|
||||
if tc.ExpectedNotFoundErr {
|
||||
require.ErrorIs(t, err, ErrCorePluginNotFound)
|
||||
require.Nil(t, p)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, p)
|
||||
require.Equal(t, tc.ExpectedID, p.ID)
|
||||
if tc.ExpectedAlias != "" {
|
||||
require.Equal(t, tc.ExpectedAlias, p.AliasIDs[0])
|
||||
}
|
||||
c, exists := p.Client()
|
||||
require.True(t, exists)
|
||||
require.NotNil(t, c)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user