Skip to content

Commit

Permalink
test: add tests for custom slog levels
Browse files Browse the repository at this point in the history
  • Loading branch information
lvlcn-t committed Apr 5, 2024
1 parent 252aa4e commit 347c886
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions logger_121_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ package log

import (
"bytes"
"context"
"testing"
"time"

"log/slog"

Expand Down Expand Up @@ -149,3 +151,35 @@ func TestSlogWithGroup(t *testing.T) {
})
}
}

func TestSlogCustomLevel(t *testing.T) {
var buf bytes.Buffer
cases := []struct {
name string
expected string
level slog.Level
minLevel Level
}{
{
name: "custom level not enabled",
expected: "",
level: slog.Level(500),
minLevel: Level(600),
},
{
name: "custom level enabled",
expected: "foo\n",
level: slog.Level(500),
minLevel: Level(100),
},
}
for _, c := range cases {
buf.Reset()
t.Run(c.name, func(t *testing.T) {
l := New(&buf)
l.SetLevel(c.minLevel)
l.Handle(context.Background(), slog.NewRecord(time.Now(), c.level, "foo", 0))
assert.Equal(t, c.expected, buf.String())
})
}
}

0 comments on commit 347c886

Please sign in to comment.