Skip to content

Commit

Permalink
Merge branch 'main' into romain.marcadier/dev-branchg
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainMuller authored Dec 11, 2024
2 parents d84693e + 2276949 commit 90d0ee7
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions contrib/log/slog/slog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strconv"
"strings"
"testing"
"testing/slogtest"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -84,13 +85,33 @@ func TestNewJSONHandler(t *testing.T) {
}

func TestWrapHandler(t *testing.T) {
testLogger(
t,
func(w io.Writer) *slog.Logger {
return slog.New(WrapHandler(slog.NewJSONHandler(w, nil)))
},
nil,
)
t.Run("testLogger", func(t *testing.T) {
testLogger(
t,
func(w io.Writer) *slog.Logger {
return slog.New(WrapHandler(slog.NewJSONHandler(w, nil)))
},
nil,
)
})

t.Run("slogtest", func(t *testing.T) {
var buf bytes.Buffer
h := WrapHandler(slog.NewJSONHandler(&buf, nil))
results := func() []map[string]any {
var ms []map[string]any
for _, line := range bytes.Split(buf.Bytes(), []byte{'\n'}) {
if len(line) == 0 {
continue
}
var m map[string]any
require.NoError(t, json.Unmarshal(line, &m))
ms = append(ms, m)
}
return ms
}
require.NoError(t, slogtest.TestHandler(h, results))
})
}

func TestHandlerWithAttrs(t *testing.T) {
Expand Down

0 comments on commit 90d0ee7

Please sign in to comment.