(t *testing.T)
| 60 | } |
| 61 | |
| 62 | func TestLoggerMethods(t *testing.T) { |
| 63 | tests := []struct { |
| 64 | name string |
| 65 | logFunc func(*slog.Logger, context.Context, string, ...any) |
| 66 | level string |
| 67 | expected string |
| 68 | }{ |
| 69 | { |
| 70 | name: "debug", |
| 71 | logFunc: (*slog.Logger).DebugContext, |
| 72 | level: "debug", |
| 73 | expected: "DEBUG", |
| 74 | }, |
| 75 | { |
| 76 | name: "info", |
| 77 | logFunc: (*slog.Logger).InfoContext, |
| 78 | level: "info", |
| 79 | expected: "INFO", |
| 80 | }, |
| 81 | { |
| 82 | name: "warn", |
| 83 | logFunc: (*slog.Logger).WarnContext, |
| 84 | level: "warn", |
| 85 | expected: "WARN", |
| 86 | }, |
| 87 | { |
| 88 | name: "error", |
| 89 | logFunc: (*slog.Logger).ErrorContext, |
| 90 | level: "error", |
| 91 | expected: "ERROR", |
| 92 | }, |
| 93 | } |
| 94 | |
| 95 | for _, tt := range tests { |
| 96 | t.Run(tt.name, func(t *testing.T) { |
| 97 | var buf bytes.Buffer |
| 98 | logger := NewSlogLogger( |
| 99 | WithOutput(&buf), |
| 100 | WithFormat(FormatJSON), // Explicitly use JSON mode for predictable output |
| 101 | WithLevel(slog.LevelDebug), // Set to debug to capture all levels |
| 102 | ) |
| 103 | |
| 104 | tt.logFunc(logger, t.Context(), "test message", slog.String("key", "value")) |
| 105 | |
| 106 | output := buf.String() |
| 107 | assert.Contains(t, output, "test message") |
| 108 | assert.Contains(t, output, `"key":"value"`) |
| 109 | assert.Contains(t, output, tt.expected) |
| 110 | }) |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | func TestWithLevel(t *testing.T) { |
| 115 | tests := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…