mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 07:12:13 +08:00
Plugins: Make it possible to support multiple plugin versions (#82116)
* first pass * use version in more places * add comment * update installer * fix wire * fix tests * tidy * simplify changes * fix in mem * remove unused step * fix step dupe logic for child plugins + add tests
This commit is contained in:
@ -1,12 +1,14 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/config"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/registry"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
@ -82,3 +84,98 @@ func TestAsExternal(t *testing.T) {
|
||||
require.Equal(t, filtered[0].Primary.JSONData.ID, "plugin2")
|
||||
})
|
||||
}
|
||||
|
||||
func TestDuplicatePluginIDValidation(t *testing.T) {
|
||||
tcs := []struct {
|
||||
name string
|
||||
registeredPlugins []string
|
||||
in []*plugins.FoundBundle
|
||||
out []*plugins.FoundBundle
|
||||
}{
|
||||
{
|
||||
name: "should filter out a plugin if it already exists in the plugin registry",
|
||||
registeredPlugins: []string{"foobar-datasource"},
|
||||
in: []*plugins.FoundBundle{
|
||||
{
|
||||
Primary: plugins.FoundPlugin{
|
||||
JSONData: plugins.JSONData{
|
||||
ID: "foobar-datasource",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
out: []*plugins.FoundBundle{},
|
||||
},
|
||||
{
|
||||
name: "should not filter out a plugin if it doesn't exist in the plugin registry",
|
||||
registeredPlugins: []string{"foobar-datasource"},
|
||||
in: []*plugins.FoundBundle{
|
||||
{
|
||||
Primary: plugins.FoundPlugin{
|
||||
JSONData: plugins.JSONData{
|
||||
ID: "test-datasource",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
out: []*plugins.FoundBundle{
|
||||
{
|
||||
Primary: plugins.FoundPlugin{
|
||||
JSONData: plugins.JSONData{
|
||||
ID: "test-datasource",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "should filter out child plugins if they are already registered",
|
||||
registeredPlugins: []string{"foobar-datasource"},
|
||||
in: []*plugins.FoundBundle{
|
||||
{
|
||||
Primary: plugins.FoundPlugin{
|
||||
JSONData: plugins.JSONData{
|
||||
ID: "test-datasource",
|
||||
},
|
||||
},
|
||||
Children: []*plugins.FoundPlugin{
|
||||
{
|
||||
JSONData: plugins.JSONData{
|
||||
ID: "foobar-datasource",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
out: []*plugins.FoundBundle{
|
||||
{
|
||||
Primary: plugins.FoundPlugin{
|
||||
JSONData: plugins.JSONData{
|
||||
ID: "test-datasource",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tc := range tcs {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
r := registry.NewInMemory()
|
||||
s := NewDuplicatePluginIDFilterStep(r)
|
||||
|
||||
ctx := context.Background()
|
||||
for _, pluginID := range tc.registeredPlugins {
|
||||
err := r.Add(ctx, &plugins.Plugin{
|
||||
JSONData: plugins.JSONData{
|
||||
ID: pluginID,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
res, err := s.Filter(ctx, tc.in)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tc.out, res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user