diff --git a/slogr_test.go b/slogr_test.go index fff6fb5..cb5a339 100644 --- a/slogr_test.go +++ b/slogr_test.go @@ -93,6 +93,10 @@ func TestWithCallDepth(t *testing.T) { var buffer bytes.Buffer logger := logr.FromSlogHandler(slog.NewTextHandler(&buffer, &debugWithCaller)) + logHelper := func(logger logr.Logger) { + logger.WithCallDepth(1).Info("hello") + } + logHelper(logger) _, file, line, _ := runtime.Caller(0) expectedSource := fmt.Sprintf("%s:%d", path.Base(file), line-1) @@ -102,10 +106,6 @@ func TestWithCallDepth(t *testing.T) { } } -func logHelper(logger logr.Logger) { - logger.WithCallDepth(1).Info("hello") -} - func TestJSONHandler(t *testing.T) { testSlog(t, func(buffer *bytes.Buffer) logr.Logger { handler := slog.NewJSONHandler(buffer, nil) @@ -141,10 +141,11 @@ func (s testSlogSink) WithGroup(name string) logr.SlogSink { } func TestFuncrHandler(t *testing.T) { - testSlog(t, func(buffer *bytes.Buffer) logr.Logger { - logger := funcr.NewJSON(func(obj string) { + fn := func(buffer *bytes.Buffer) logr.Logger { + printfn := func(obj string) { fmt.Fprintln(buffer, obj) - }, funcr.Options{ + } + opts := funcr.Options{ LogTimestamp: true, Verbosity: 10, RenderBuiltinsHook: func(kvList []any) []any { @@ -161,9 +162,10 @@ func TestFuncrHandler(t *testing.T) { } return mappedKVList }, - }) - return logger - }, + } + return funcr.NewJSON(printfn, opts) + } + exceptions := []string{ "a Handler should ignore a zero Record.Time", // Time is generated by sink. "a Handler should handle Group attributes", // funcr doesn't. "a Handler should inline the Attrs of a group with an empty key", // funcr doesn't know about groups. @@ -171,7 +173,8 @@ func TestFuncrHandler(t *testing.T) { "a Handler should handle the WithGroup method", // logHandler does by prefixing keys, which is not what the test expects. "a Handler should handle multiple WithGroup and WithAttr calls", // Same. "a Handler should call Resolve on attribute values in groups", // funcr doesn't do that and slogHandler can't do it for it. - ) + } + testSlog(t, fn, exceptions...) } func testSlog(t *testing.T, createLogger func(buffer *bytes.Buffer) logr.Logger, exceptions ...string) {