use logger context in cloudwatch (#57842)
This commit is contained in:
@@ -8,8 +8,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
|
||||
)
|
||||
|
||||
func Test_Middleware(t *testing.T) {
|
||||
@@ -18,7 +19,7 @@ func Test_Middleware(t *testing.T) {
|
||||
req := httptest.NewRequest("POST", "/dimension-keys?region=us-east-1", nil)
|
||||
handler := http.HandlerFunc(ResourceRequestMiddleware(func(pluginCtx backend.PluginContext, reqCtxFactory models.RequestContextFactoryFunc, parameters url.Values) ([]byte, *models.HttpError) {
|
||||
return []byte{}, nil
|
||||
}, nil))
|
||||
}, logger, nil))
|
||||
handler.ServeHTTP(rr, req)
|
||||
assert.Equal(t, http.StatusMethodNotAllowed, rr.Code)
|
||||
})
|
||||
@@ -30,7 +31,7 @@ func Test_Middleware(t *testing.T) {
|
||||
handler := http.HandlerFunc(ResourceRequestMiddleware(func(pluginCtx backend.PluginContext, reqCtxFactory models.RequestContextFactoryFunc, parameters url.Values) ([]byte, *models.HttpError) {
|
||||
testPluginContext = pluginCtx
|
||||
return []byte{}, nil
|
||||
}, nil))
|
||||
}, logger, nil))
|
||||
handler.ServeHTTP(rr, req)
|
||||
assert.NotNil(t, testPluginContext)
|
||||
})
|
||||
@@ -40,7 +41,7 @@ func Test_Middleware(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/some-path", nil)
|
||||
handler := http.HandlerFunc(ResourceRequestMiddleware(func(pluginCtx backend.PluginContext, reqCtxFactory models.RequestContextFactoryFunc, parameters url.Values) ([]byte, *models.HttpError) {
|
||||
return []byte{}, models.NewHttpError("error", http.StatusBadRequest, fmt.Errorf("error from handler"))
|
||||
}, nil))
|
||||
}, logger, nil))
|
||||
handler.ServeHTTP(rr, req)
|
||||
assert.Equal(t, http.StatusBadRequest, rr.Code)
|
||||
assert.Equal(t, `{"Message":"error: error from handler","Error":"error from handler","StatusCode":400}`, rr.Body.String())
|
||||
|
||||
Reference in New Issue
Block a user