mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-18 06:42:10 +08:00
Updated context's unit tests
This commit is contained in:
parent
e0ca0b16ab
commit
edbd1abf2e
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user