@@ -32,6 +32,8 @@ import (
32
32
33
33
var _ context.Context = (* Context )(nil )
34
34
35
+ var errTestRender = errors .New ("TestRender" )
36
+
35
37
// Unit tests TODO
36
38
// func (c *Context) File(filepath string) {
37
39
// func (c *Context) Negotiate(code int, config Negotiate) {
@@ -643,25 +645,21 @@ func TestContextBodyAllowedForStatus(t *testing.T) {
643
645
assert .True (t , true , bodyAllowedForStatus (http .StatusInternalServerError ))
644
646
}
645
647
646
- type TestPanicRender struct {}
648
+ type TestRender struct {}
647
649
648
- func (* TestPanicRender ) Render (http.ResponseWriter ) error {
649
- return errors . New ( "TestPanicRender" )
650
+ func (* TestRender ) Render (http.ResponseWriter ) error {
651
+ return errTestRender
650
652
}
651
653
652
- func (* TestPanicRender ) WriteContentType (http.ResponseWriter ) {}
654
+ func (* TestRender ) WriteContentType (http.ResponseWriter ) {}
653
655
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 ) {
659
657
w := httptest .NewRecorder ()
660
658
c , _ := CreateTestContext (w )
661
659
662
- c .Render (http .StatusOK , & TestPanicRender {})
660
+ c .Render (http .StatusOK , & TestRender {})
663
661
664
- assert .Fail (t , "Panic not detected" )
662
+ assert .Equal (t , errorMsgs { & Error { Err : errTestRender , Type : 1 }}, c . Errors )
665
663
}
666
664
667
665
// Tests that the response is serialized as JSON
0 commit comments