mirror of
https://github.com/grafana/grafana.git
synced 2024-12-28 01:41:24 -06:00
f5802878f1
* remove macaron binding dependency * completely purge macaron binding * move everything to pkg/web * remove non-go files from pkg/web * clean up leftovers of macaron imports * make linter happy
43 lines
935 B
Go
43 lines
935 B
Go
package web
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func Test_responseWriter_WriteHeader(t *testing.T) {
|
|
t.Run("it should set status code as expected", func(t *testing.T) {
|
|
f := fakeResponseWriter{}
|
|
rw := NewResponseWriter("GET", &f)
|
|
rw.WriteHeader(200)
|
|
require.Equal(t, 200, rw.Status())
|
|
require.Equal(t, 200, f.Status)
|
|
})
|
|
|
|
t.Run("it should set status code to 500 if WriteHeader is called with invalid HTTP status", func(t *testing.T) {
|
|
f := fakeResponseWriter{}
|
|
rw := NewResponseWriter("GET", &f)
|
|
rw.WriteHeader(0)
|
|
require.Equal(t, 500, rw.Status())
|
|
require.Equal(t, 500, f.Status)
|
|
})
|
|
}
|
|
|
|
type fakeResponseWriter struct {
|
|
Status int
|
|
}
|
|
|
|
func (f *fakeResponseWriter) Header() http.Header {
|
|
return http.Header{}
|
|
}
|
|
|
|
func (f *fakeResponseWriter) Write([]byte) (int, error) {
|
|
return 0, nil
|
|
}
|
|
|
|
func (f *fakeResponseWriter) WriteHeader(statusCode int) {
|
|
f.Status = statusCode
|
|
}
|