From fbb0399b391f27d1d09de09e42c1d9df16556d8d Mon Sep 17 00:00:00 2001 From: komuw Date: Sat, 17 Aug 2024 12:24:39 +0300 Subject: [PATCH] g --- middleware/log_test.go | 22 ++++++++++++++++++++++ middleware/recoverer_test.go | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) 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) {