Added panic test
This commit is contained in:
parent
0e00f870de
commit
812147b601
1 changed files with 23 additions and 1 deletions
|
@ -11,7 +11,7 @@ import (
|
||||||
"git.akyoto.dev/go/server"
|
"git.akyoto.dev/go/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestServer(t *testing.T) {
|
func TestRouter(t *testing.T) {
|
||||||
s := server.New()
|
s := server.New()
|
||||||
|
|
||||||
s.Get("/", func(ctx server.Context) error {
|
s.Get("/", func(ctx server.Context) error {
|
||||||
|
@ -52,3 +52,25 @@ func TestServer(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPanic(t *testing.T) {
|
||||||
|
s := server.New()
|
||||||
|
|
||||||
|
s.Get("/panic", func(ctx server.Context) error {
|
||||||
|
panic("Something unbelievable happened")
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("example.com/panic", func(t *testing.T) {
|
||||||
|
defer func() {
|
||||||
|
r := recover()
|
||||||
|
|
||||||
|
if r == nil {
|
||||||
|
t.Error("Didn't panic")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
request := httptest.NewRequest(http.MethodGet, "/panic", nil)
|
||||||
|
response := httptest.NewRecorder()
|
||||||
|
s.ServeHTTP(response, request)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue