-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintaware_test.go
More file actions
54 lines (44 loc) · 1.25 KB
/
printaware_test.go
File metadata and controls
54 lines (44 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package eslog
import (
"bytes"
"log/slog"
"testing"
)
func TestPrintAwareHandler_WithAttrs(t *testing.T) {
var buf bytes.Buffer
innerHandler := slog.NewTextHandler(&buf, nil)
handler := &printAwareHandler{h: innerHandler, w: &buf}
attrs := []slog.Attr{
slog.String("key", "value"),
slog.Int("count", 42),
}
newHandler := handler.WithAttrs(attrs)
if newHandler == nil {
t.Errorf("WithAttrs returned nil")
}
// Verify it returns a new handler
if newHandler == handler {
t.Errorf("WithAttrs should return a new handler instance")
}
// Verify it's the correct type
if _, ok := newHandler.(*printAwareHandler); !ok {
t.Errorf("WithAttrs should return a *printAwareHandler")
}
}
func TestPrintAwareHandler_WithGroup(t *testing.T) {
var buf bytes.Buffer
innerHandler := slog.NewTextHandler(&buf, nil)
handler := &printAwareHandler{h: innerHandler, w: &buf}
newHandler := handler.WithGroup("testgroup")
if newHandler == nil {
t.Errorf("WithGroup returned nil")
}
// Verify it returns a new handler
if newHandler == handler {
t.Errorf("WithGroup should return a new handler instance")
}
// Verify it's the correct type
if _, ok := newHandler.(*printAwareHandler); !ok {
t.Errorf("WithGroup should return a *printAwareHandler")
}
}