diff --git a/middleware/log_test.go b/middleware/log_test.go index c61bc1ae..135e516b 100644 --- a/middleware/log_test.go +++ b/middleware/log_test.go @@ -214,6 +214,28 @@ func TestLogMiddleware(t *testing.T) { attest.Zero(t, logOutput.String()) }) + t.Run("nil logger and logfunc", func(t *testing.T) { + t.Parallel() + + logOutput := &bytes.Buffer{} + successMsg := "hello" + wrappedHandler := logger(someLogHandler(successMsg), nil, nil) + + rec := httptest.NewRecorder() + req := httptest.NewRequest(http.MethodHead, "/someUri", nil) + wrappedHandler.ServeHTTP(rec, req) + + res := rec.Result() + defer res.Body.Close() + + rb, err := io.ReadAll(res.Body) + attest.Ok(t, err) + + attest.Equal(t, res.StatusCode, http.StatusOK) + attest.Equal(t, string(rb), successMsg) + attest.Zero(t, logOutput.String()) + }) + t.Run("concurrency safe", func(t *testing.T) { t.Parallel() diff --git a/middleware/recoverer_test.go b/middleware/recoverer_test.go index bb527268..aeb7a6fc 100644 --- a/middleware/recoverer_test.go +++ b/middleware/recoverer_test.go @@ -140,7 +140,7 @@ func TestPanic(t *testing.T) { res := rec.Result() defer res.Body.Close() attest.Equal(t, res.StatusCode, http.StatusInternalServerError) - attest.Subsequence(t, logOutput.String(), "middleware/recoverer_test.go:37") // line where panic happened. + attest.Subsequence(t, logOutput.String(), "middleware/recoverer_test.go:41") // line where panic happened. }) t.Run("concurrency safe", func(t *testing.T) {