From e8800976edc0e52fdbff19f193620985e8236c61 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 19 Jul 2023 12:31:33 +0200 Subject: [PATCH] Added panic test --- Server_test.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Server_test.go b/Server_test.go index c33f9cf..aa65971 100644 --- a/Server_test.go +++ b/Server_test.go @@ -11,7 +11,7 @@ import ( "git.akyoto.dev/go/server" ) -func TestServer(t *testing.T) { +func TestRouter(t *testing.T) { s := server.New() 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) + }) +}