Chore: Refactor render via http (#84613)

This commit is contained in:
Ezequiel Victorero
2024-05-14 07:24:18 -03:00
committed by GitHub
parent a7a503501a
commit c9c6445554
9 changed files with 163 additions and 154 deletions

View File

@ -27,7 +27,7 @@ func TestGetUrl(t *testing.T) {
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)
url := rs.getGrafanaCallbackURL(path)
require.Equal(t, rs.Cfg.RendererCallbackUrl+path+"&render=1", url)
})
@ -40,13 +40,13 @@ func TestGetUrl(t *testing.T) {
rs.Cfg.ServeFromSubPath = false
rs.Cfg.AppSubURL = ""
rs.Cfg.Protocol = setting.HTTPScheme
url := rs.getURL(path)
url := rs.getGrafanaCallbackURL(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)
url := rs.getGrafanaCallbackURL(path)
require.Equal(t, "http://localhost:3000/grafana/"+path+"&render=1", url)
})
})
@ -55,7 +55,7 @@ func TestGetUrl(t *testing.T) {
rs.Cfg.ServeFromSubPath = false
rs.Cfg.AppSubURL = ""
rs.Cfg.Protocol = setting.HTTPSScheme
url := rs.getURL(path)
url := rs.getGrafanaCallbackURL(path)
require.Equal(t, "https://localhost:3000/"+path+"&render=1", url)
})
@ -63,7 +63,7 @@ func TestGetUrl(t *testing.T) {
rs.Cfg.ServeFromSubPath = false
rs.Cfg.AppSubURL = ""
rs.Cfg.Protocol = setting.HTTP2Scheme
url := rs.getURL(path)
url := rs.getGrafanaCallbackURL(path)
require.Equal(t, "https://localhost:3000/"+path+"&render=1", url)
})
})
@ -151,7 +151,7 @@ func TestRenderLimitImage(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
opts := Opts{Theme: tc.theme, ConcurrentLimit: 1}
opts := Opts{Theme: tc.theme, CommonOpts: CommonOpts{ConcurrentLimit: 1}}
result, err := rs.Render(context.Background(), RenderPNG, opts, nil)
assert.NoError(t, err)
assert.Equal(t, tc.expected, result.FilePath)
@ -166,9 +166,9 @@ func TestRenderLimitImageError(t *testing.T) {
log: log.New("test"),
}
opts := Opts{
ErrorOpts: ErrorOpts{ErrorConcurrentLimitReached: true},
ConcurrentLimit: 1,
Theme: models.ThemeDark,
CommonOpts: CommonOpts{ConcurrentLimit: 1},
ErrorOpts: ErrorOpts{ErrorConcurrentLimitReached: true},
Theme: models.ThemeDark,
}
result, err := rs.Render(context.Background(), RenderPNG, opts, nil)
assert.Equal(t, ErrConcurrentLimitReached, err)