Skip to content

Commit

Permalink
adds tests on recovery middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
rvflash committed Mar 2, 2019
1 parent 2a844ba commit fc04a9f
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,32 @@ import (
)

func TestRecovery(t *testing.T) {
defer func() {
if r := recover(); r != nil {
t.Error("expected no panic")
}
}()
srv := tcp.New()
srv.Use(tcp.Recovery())
req := tcp.NewRequest(tcp.SYN, nil)
srv.SYN(oops)

w := tcp.NewRecorder()
srv.ServeTCP(w, tcp.NewRequest(tcp.SYN, nil))
}

func TestRecovery2(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Error("expected panic")
}
}()
srv := tcp.New()
srv.SYN(oops)

w := tcp.NewRecorder()
srv.ServeTCP(w, req)
srv.ServeTCP(w, tcp.NewRequest(tcp.SYN, nil))
}

func oops(c *tcp.Context) {
panic("oops, sorry!")
}

0 comments on commit fc04a9f

Please sign in to comment.