github.com/hellofresh/janus@v0.0.0-20230925145208-ce8de8183c67/pkg/middleware/recovery_test.go (about) 1 package middleware_test 2 3 import ( 4 "testing" 5 6 "net/http" 7 8 "github.com/hellofresh/janus/pkg/errors" 9 "github.com/hellofresh/janus/pkg/middleware" 10 "github.com/hellofresh/janus/pkg/test" 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestSuccessfulRecovery(t *testing.T) { 15 mw := middleware.NewRecovery(errors.RecoveryHandler) 16 w, err := test.Record( 17 "GET", 18 "/", 19 map[string]string{ 20 "Content-Type": "application/json", 21 }, 22 mw(http.HandlerFunc(doPanic)), 23 ) 24 assert.NoError(t, err) 25 26 assert.Equal(t, http.StatusBadRequest, w.Code) 27 assert.Equal(t, "application/json", w.Header().Get("Content-Type")) 28 } 29 30 func doPanic(w http.ResponseWriter, r *http.Request) { 31 panic(errors.ErrInvalidID) 32 }