mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Move middleware context handler logic to service (#29605)
* middleware: Move context handler to own service Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> Co-authored-by: Emil Tullsted <sakjur@users.noreply.github.com> Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>
This commit is contained in:
@@ -18,7 +18,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"gopkg.in/macaron.v1"
|
||||
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -53,7 +52,7 @@ func setupTestEnvironment(t *testing.T, cfg *setting.Cfg) (*macaron.Macaron, *HT
|
||||
}
|
||||
|
||||
m := macaron.New()
|
||||
m.Use(middleware.GetContextHandler(nil, nil, nil))
|
||||
m.Use(getContextHandler(t).Middleware)
|
||||
m.Use(macaron.Renderer(macaron.RenderOptions{
|
||||
Directory: filepath.Join(setting.StaticRootPath, "views"),
|
||||
IndentJSON: true,
|
||||
@@ -84,10 +83,12 @@ func TestHTTPServer_GetFrontendSettings_hideVersionAnonyomus(t *testing.T) {
|
||||
setting.Env = "testing"
|
||||
|
||||
tests := []struct {
|
||||
desc string
|
||||
hideVersion bool
|
||||
expected settings
|
||||
}{
|
||||
{
|
||||
desc: "Not hiding version",
|
||||
hideVersion: false,
|
||||
expected: settings{
|
||||
BuildInfo: buildInfo{
|
||||
@@ -98,6 +99,7 @@ func TestHTTPServer_GetFrontendSettings_hideVersionAnonyomus(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "Hiding version",
|
||||
hideVersion: true,
|
||||
expected: settings{
|
||||
BuildInfo: buildInfo{
|
||||
@@ -110,16 +112,18 @@ func TestHTTPServer_GetFrontendSettings_hideVersionAnonyomus(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
hs.Cfg.AnonymousHideVersion = test.hideVersion
|
||||
expected := test.expected
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
hs.Cfg.AnonymousHideVersion = test.hideVersion
|
||||
expected := test.expected
|
||||
|
||||
recorder := httptest.NewRecorder()
|
||||
m.ServeHTTP(recorder, req)
|
||||
got := settings{}
|
||||
err := json.Unmarshal(recorder.Body.Bytes(), &got)
|
||||
require.NoError(t, err)
|
||||
require.GreaterOrEqual(t, 400, recorder.Code, "status codes higher than 400 indicates a failure")
|
||||
recorder := httptest.NewRecorder()
|
||||
m.ServeHTTP(recorder, req)
|
||||
got := settings{}
|
||||
err := json.Unmarshal(recorder.Body.Bytes(), &got)
|
||||
require.NoError(t, err)
|
||||
require.GreaterOrEqual(t, 400, recorder.Code, "status codes higher than 400 indicate a failure")
|
||||
|
||||
assert.EqualValues(t, expected, got)
|
||||
assert.EqualValues(t, expected, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user