Updated context's unit tests

This commit is contained in:
eeonevision 2019-11-25 11:52:19 +03:00
parent e0ca0b16ab
commit edbd1abf2e

View File

@ -31,6 +31,8 @@ import (
var _ context.Context = &Context{} var _ context.Context = &Context{}
var errTestPanicRender = errors.New("TestPanicRender")
// Unit tests TODO // Unit tests TODO
// func (c *Context) File(filepath string) { // func (c *Context) File(filepath string) {
// func (c *Context) Negotiate(code int, config Negotiate) { // func (c *Context) Negotiate(code int, config Negotiate) {
@ -634,22 +636,18 @@ type TestPanicRender struct {
} }
func (*TestPanicRender) Render(http.ResponseWriter) error { func (*TestPanicRender) Render(http.ResponseWriter) error {
return errors.New("TestPanicRender") return errTestPanicRender
} }
func (*TestPanicRender) WriteContentType(http.ResponseWriter) {} func (*TestPanicRender) WriteContentType(http.ResponseWriter) {}
func TestContextRenderPanicIfErr(t *testing.T) { func TestContextRenderIfErr(t *testing.T) {
defer func() {
r := recover()
assert.Equal(t, "TestPanicRender", fmt.Sprint(r))
}()
w := httptest.NewRecorder() w := httptest.NewRecorder()
c, _ := CreateTestContext(w) c, _ := CreateTestContext(w)
c.Render(http.StatusOK, &TestPanicRender{}) c.Render(http.StatusOK, &TestPanicRender{})
assert.Fail(t, "Panic not detected") assert.Equal(t, errorMsgs{&Error{Err: errTestPanicRender, Type: 1}}, c.Errors)
} }
// Tests that the response is serialized as JSON // Tests that the response is serialized as JSON