grafana/pkg/plugins/pluginscdn/pluginscdn_test.go
Will Browne 5edd96ae77
Plugins: Refactor plugin config into separate env var and request scoped services (#83261)
* seperate services for env + req

* merge with main

* fix tests

* undo changes to golden file

* fix linter

* remove unused fields

* split out new config struct

* provide config

* undo go mod changes

* more renaming

* fix tests

* undo bra.toml changes

* update go.work.sum

* undo changes

* trigger

* apply PR feedback
2024-02-27 12:38:02 +01:00

50 lines
1.2 KiB
Go

package pluginscdn
import (
"testing"
"github.com/grafana/grafana/pkg/plugins/config"
"github.com/stretchr/testify/require"
)
func TestService(t *testing.T) {
svc := ProvideService(&config.PluginManagementCfg{
PluginsCDNURLTemplate: "https://cdn.example.com",
PluginSettings: map[string]map[string]string{
"one": {"cdn": "true"},
"two": {},
},
})
t.Run("IsCDNPlugin", func(t *testing.T) {
require.True(t, svc.PluginSupported("one"))
require.False(t, svc.PluginSupported("two"))
require.False(t, svc.PluginSupported("unknown"))
})
t.Run("CDNBaseURL", func(t *testing.T) {
for _, c := range []struct {
name string
cfgURL string
expBaseURL string
}{
{
name: "valid",
cfgURL: "https://grafana-assets.grafana.net/plugin-cdn-test/plugin-cdn",
expBaseURL: "https://grafana-assets.grafana.net/plugin-cdn-test/plugin-cdn",
},
{
name: "empty",
cfgURL: "",
expBaseURL: "",
},
} {
t.Run(c.name, func(t *testing.T) {
u, err := ProvideService(&config.PluginManagementCfg{PluginsCDNURLTemplate: c.cfgURL}).BaseURL()
require.NoError(t, err)
require.Equal(t, c.expBaseURL, u)
})
}
})
}