Skip to content

Commit

Permalink
g
Browse files Browse the repository at this point in the history
  • Loading branch information
komuw committed Aug 17, 2024
1 parent c0b9021 commit fbb0399
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions middleware/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion middleware/recoverer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit fbb0399

Please sign in to comment.