mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 03:34:15 -06:00
78596a6756
Fixes #30144 Co-authored-by: dsotirakis <sotirakis.dim@gmail.com> Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com> Co-authored-by: Ida Furjesova <ida.furjesova@grafana.com> Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com> Co-authored-by: Will Browne <wbrowne@users.noreply.github.com> Co-authored-by: Leon Sorokin <leeoniya@gmail.com> Co-authored-by: Andrej Ocenas <mr.ocenas@gmail.com> Co-authored-by: spinillos <selenepinillos@gmail.com> Co-authored-by: Karl Persson <kalle.persson@grafana.com> Co-authored-by: Leonard Gram <leo@xlson.com>
61 lines
1.9 KiB
Go
61 lines
1.9 KiB
Go
package rendering
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGetUrl(t *testing.T) {
|
|
path := "render/d-solo/5SdHCadmz/panel-tests-graph?orgId=1&from=1587390211965&to=1587393811965&panelId=5&width=1000&height=500&tz=Europe%2FStockholm"
|
|
cfg := setting.NewCfg()
|
|
rs := &RenderingService{
|
|
Cfg: cfg,
|
|
}
|
|
|
|
t.Run("When renderer and callback url configured should return callback url plus path", func(t *testing.T) {
|
|
rs.Cfg.RendererUrl = "http://localhost:8081/render"
|
|
rs.Cfg.RendererCallbackUrl = "http://public-grafana.com/"
|
|
url := rs.getURL(path)
|
|
require.Equal(t, rs.Cfg.RendererCallbackUrl+path+"&render=1", url)
|
|
})
|
|
|
|
t.Run("When renderer url not configured", func(t *testing.T) {
|
|
rs.Cfg.RendererUrl = ""
|
|
rs.domain = "localhost"
|
|
rs.Cfg.HTTPPort = "3000"
|
|
|
|
t.Run("And protocol HTTP configured should return expected path", func(t *testing.T) {
|
|
rs.Cfg.ServeFromSubPath = false
|
|
rs.Cfg.AppSubURL = ""
|
|
rs.Cfg.Protocol = setting.HTTPScheme
|
|
url := rs.getURL(path)
|
|
require.Equal(t, "http://localhost:3000/"+path+"&render=1", url)
|
|
|
|
t.Run("And serve from sub path should return expected path", func(t *testing.T) {
|
|
rs.Cfg.ServeFromSubPath = true
|
|
rs.Cfg.AppSubURL = "/grafana"
|
|
url := rs.getURL(path)
|
|
require.Equal(t, "http://localhost:3000/grafana/"+path+"&render=1", url)
|
|
})
|
|
})
|
|
|
|
t.Run("And protocol HTTPS configured should return expected path", func(t *testing.T) {
|
|
rs.Cfg.ServeFromSubPath = false
|
|
rs.Cfg.AppSubURL = ""
|
|
rs.Cfg.Protocol = setting.HTTPSScheme
|
|
url := rs.getURL(path)
|
|
require.Equal(t, "https://localhost:3000/"+path+"&render=1", url)
|
|
})
|
|
|
|
t.Run("And protocol HTTP2 configured should return expected path", func(t *testing.T) {
|
|
rs.Cfg.ServeFromSubPath = false
|
|
rs.Cfg.AppSubURL = ""
|
|
rs.Cfg.Protocol = setting.HTTP2Scheme
|
|
url := rs.getURL(path)
|
|
require.Equal(t, "https://localhost:3000/"+path+"&render=1", url)
|
|
})
|
|
})
|
|
}
|