mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-20 03:47:54 +02:00
Update error message to make it clearer when it shows up in test logs
This commit is contained in:
parent
cfefbb9b19
commit
299617ba7e
@ -32,7 +32,7 @@ func TestLoggerMiddleware(t *testing.T) {
|
|||||||
|
|
||||||
func TestLoggerMiddlewareWithPanic(t *testing.T) {
|
func TestLoggerMiddlewareWithPanic(t *testing.T) {
|
||||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
panic(fmt.Errorf("oh no"))
|
panic(fmt.Errorf("synthetic panic for tests"))
|
||||||
})
|
})
|
||||||
|
|
||||||
var out strings.Builder
|
var out strings.Builder
|
||||||
@ -62,7 +62,7 @@ func TestLoggerMiddlewareWithPanic(t *testing.T) {
|
|||||||
t.Errorf("expected %d, got %d", http.StatusOK, w.Code)
|
t.Errorf("expected %d, got %d", http.StatusOK, w.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
const expectedPiece1 = `oh no`
|
const expectedPiece1 = `synthetic panic for tests`
|
||||||
const expectedPiece2 = `127.0.0.1 GET "/"`
|
const expectedPiece2 = `127.0.0.1 GET "/"`
|
||||||
outString := out.String()
|
outString := out.String()
|
||||||
if !strings.Contains(outString, expectedPiece1) {
|
if !strings.Contains(outString, expectedPiece1) {
|
||||||
@ -73,14 +73,14 @@ func TestLoggerMiddlewareWithPanic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
panicStr := fmt.Sprintf("%v", panicError)
|
panicStr := fmt.Sprintf("%v", panicError)
|
||||||
if !strings.Contains(panicStr, "oh no") {
|
if !strings.Contains(panicStr, "synthetic panic for tests") {
|
||||||
t.Errorf("expected panic error to contain %q, got %q", "oh no", panicStr)
|
t.Errorf("expected panic error to contain %q, got %q", "synthetic panic for tests", panicStr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPanicGuard(t *testing.T) {
|
func TestPanicGuard(t *testing.T) {
|
||||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
panic(fmt.Errorf("oh no"))
|
panic(fmt.Errorf("synthetic panic for tests"))
|
||||||
})
|
})
|
||||||
|
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
@ -141,7 +141,7 @@ func TestMergeMiddlewares(t *testing.T) {
|
|||||||
w.Write([]byte("test"))
|
w.Write([]byte("test"))
|
||||||
})
|
})
|
||||||
panicHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
panicHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
panic(fmt.Errorf("oh no"))
|
panic(fmt.Errorf("synthetic panic for tests"))
|
||||||
})
|
})
|
||||||
|
|
||||||
// ===
|
// ===
|
||||||
@ -164,7 +164,7 @@ func TestMergeMiddlewares(t *testing.T) {
|
|||||||
handler: panicHandler,
|
handler: panicHandler,
|
||||||
expectedStatusCode: http.StatusServiceUnavailable,
|
expectedStatusCode: http.StatusServiceUnavailable,
|
||||||
expectedPieces: []string{
|
expectedPieces: []string{
|
||||||
`oh no`,
|
`synthetic panic for tests`,
|
||||||
`127.0.0.1 GET "/"`,
|
`127.0.0.1 GET "/"`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user