@@ -32,6 +32,8 @@ import (
3232
3333var _ context.Context = (* Context )(nil )
3434
35+ var errTestRender = errors .New ("TestRender" )
36+
3537// Unit tests TODO
3638// func (c *Context) File(filepath string) {
3739// func (c *Context) Negotiate(code int, config Negotiate) {
@@ -643,25 +645,21 @@ func TestContextBodyAllowedForStatus(t *testing.T) {
643645 assert .True (t , true , bodyAllowedForStatus (http .StatusInternalServerError ))
644646}
645647
646- type TestPanicRender struct {}
648+ type TestRender struct {}
647649
648- func (* TestPanicRender ) Render (http.ResponseWriter ) error {
649- return errors . New ( "TestPanicRender" )
650+ func (* TestRender ) Render (http.ResponseWriter ) error {
651+ return errTestRender
650652}
651653
652- func (* TestPanicRender ) WriteContentType (http.ResponseWriter ) {}
654+ func (* TestRender ) WriteContentType (http.ResponseWriter ) {}
653655
654- func TestContextRenderPanicIfErr (t * testing.T ) {
655- defer func () {
656- r := recover ()
657- assert .Equal (t , "TestPanicRender" , fmt .Sprint (r ))
658- }()
656+ func TestContextRenderIfErr (t * testing.T ) {
659657 w := httptest .NewRecorder ()
660658 c , _ := CreateTestContext (w )
661659
662- c .Render (http .StatusOK , & TestPanicRender {})
660+ c .Render (http .StatusOK , & TestRender {})
663661
664- assert .Fail (t , "Panic not detected" )
662+ assert .Equal (t , errorMsgs { & Error { Err : errTestRender , Type : 1 }}, c . Errors )
665663}
666664
667665// Tests that the response is serialized as JSON
0 commit comments