grafana/pkg/plugins/pluginscdn/pluginscdn_test.go
Giuseppe Guerra 966bcd3545
Plugins: Fix plugins CDN not working when plugins are not in domain's root path (#63202)
* Plugins CDN: Add support for different CDN root path

* Plugins CDN: Make frontendsettings return the correct CDN base path

* Update comments

* Fix version detection

* Undo frontend changes

* Fix system.js asset path construction

* fix(plugins): translate all plugin css asset paths loaded via cdn

* refactor(plugins): rename extractPluginNameVersionFromUrl and add comments

* Fix typo in comment

Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>

* Hardcode CDN URL structure

/{id}/{version}/public/plugins/{id}/{assetPath} is not required anymore in the cdn url template config

---------

Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>
2023-02-24 14:28:13 +01:00

50 lines
1.1 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.Cfg{
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.Cfg{PluginsCDNURLTemplate: c.cfgURL}).BaseURL()
require.NoError(t, err)
require.Equal(t, c.expBaseURL, u)
})
}
})
}