(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func TestPanicClean(t *testing.T) { |
| 19 | buffer := new(strings.Builder) |
| 20 | router := New() |
| 21 | password := "my-super-secret-password" |
| 22 | router.Use(RecoveryWithWriter(buffer)) |
| 23 | router.GET("/recovery", func(c *Context) { |
| 24 | c.AbortWithStatus(http.StatusBadRequest) |
| 25 | panic("Oops, Houston, we have a problem") |
| 26 | }) |
| 27 | // RUN |
| 28 | w := PerformRequest(router, http.MethodGet, "/recovery", |
| 29 | header{ |
| 30 | Key: "Host", |
| 31 | Value: "www.google.com", |
| 32 | }, |
| 33 | header{ |
| 34 | Key: "Authorization", |
| 35 | Value: "Bearer " + password, |
| 36 | }, |
| 37 | header{ |
| 38 | Key: "Content-Type", |
| 39 | Value: "application/json", |
| 40 | }, |
| 41 | ) |
| 42 | // TEST |
| 43 | assert.Equal(t, http.StatusBadRequest, w.Code) |
| 44 | |
| 45 | // Check the buffer does not have the secret key |
| 46 | assert.NotContains(t, buffer.String(), password) |
| 47 | } |
| 48 | |
| 49 | // TestPanicInHandler assert that panic has been recovered. |
| 50 | func TestPanicInHandler(t *testing.T) { |
nothing calls this directly
no test coverage detected