d91ef1832b
Function Test Coverage * test * scripts
29 lines
717 B
Go
29 lines
717 B
Go
package logger
|
|
|
|
import (
|
|
"log/slog"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestTestLogger(t *testing.T) {
|
|
tl := &TestLogger{T: t}
|
|
logger := slog.New(tl)
|
|
slog.SetDefault(logger)
|
|
|
|
slog.Info("test message", "field", "value")
|
|
slog.Info("test message", "field", "second")
|
|
slog.Warn("test message", "field", "warn")
|
|
slog.Error("test message", "field", "error")
|
|
|
|
assert.Len(t, tl.Logs, 4)
|
|
assert.Equal(t, "value", tl.Logs[0]["field"])
|
|
assert.Equal(t, "second", tl.Logs[1]["field"])
|
|
assert.Equal(t, "warn", tl.Logs[2]["field"])
|
|
assert.Equal(t, "error", tl.Logs[3]["field"])
|
|
|
|
assert.NotNil(t, logger.Handler().WithAttrs([]slog.Attr{}))
|
|
assert.NotNil(t, logger.Handler().WithGroup("group"))
|
|
}
|