mirror of
https://github.com/grafana/grafana.git
synced 2025-01-27 00:37:04 -06:00
040b7d2571
Add helpers for the errutil package in favor of errutil.NewBase.
30 lines
746 B
Go
30 lines
746 B
Go
package errhttp
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/grafana/grafana/pkg/util/errutil"
|
|
)
|
|
|
|
func TestWrite(t *testing.T) {
|
|
ctx := context.Background()
|
|
const msgID = "test.thisIsExpected"
|
|
base := errutil.Timeout(msgID)
|
|
handler := func(writer http.ResponseWriter, request *http.Request) {
|
|
Write(ctx, base.Errorf("got expected error"), writer)
|
|
}
|
|
|
|
req := httptest.NewRequest("GET", "http://localhost:3000/fake", nil)
|
|
recorder := httptest.NewRecorder()
|
|
|
|
handler(recorder, req)
|
|
|
|
assert.Equal(t, http.StatusGatewayTimeout, recorder.Code)
|
|
assert.JSONEq(t, `{"message": "Timeout", "messageId": "test.thisIsExpected", "statusCode": 504}`, recorder.Body.String())
|
|
}
|