@@ -24,85 +24,6 @@ import (
24
24
"testing"
25
25
)
26
26
27
- // testLogSink is a Logger just for testing that calls optional hooks on each method.
28
- type testLogSink struct {
29
- fnInit func (ri RuntimeInfo )
30
- fnEnabled func (lvl int ) bool
31
- fnInfo func (lvl int , msg string , kv ... any )
32
- fnError func (err error , msg string , kv ... any )
33
- fnWithValues func (kv ... any )
34
- fnWithName func (name string )
35
-
36
- withValues []any
37
-
38
- // testSlogSink contains some additional fields if (and only if) slog is supported by Go.
39
- // See logr_slog_test.go.
40
- //nolint:unused // Only unused with Go < 1.21.
41
- testSlogSink
42
- }
43
-
44
- var _ LogSink = & testLogSink {}
45
-
46
- func (l * testLogSink ) Init (ri RuntimeInfo ) {
47
- if l .fnInit != nil {
48
- l .fnInit (ri )
49
- }
50
- }
51
-
52
- func (l * testLogSink ) Enabled (lvl int ) bool {
53
- if l .fnEnabled != nil {
54
- return l .fnEnabled (lvl )
55
- }
56
- return false
57
- }
58
-
59
- func (l * testLogSink ) Info (lvl int , msg string , kv ... any ) {
60
- if l .fnInfo != nil {
61
- l .fnInfo (lvl , msg , kv ... )
62
- }
63
- }
64
-
65
- func (l * testLogSink ) Error (err error , msg string , kv ... any ) {
66
- if l .fnError != nil {
67
- l .fnError (err , msg , kv ... )
68
- }
69
- }
70
-
71
- func (l * testLogSink ) WithValues (kv ... any ) LogSink {
72
- if l .fnWithValues != nil {
73
- l .fnWithValues (kv ... )
74
- }
75
- out := * l
76
- n := len (out .withValues )
77
- out .withValues = append (out .withValues [:n :n ], kv ... )
78
- return & out
79
- }
80
-
81
- func (l * testLogSink ) WithName (name string ) LogSink {
82
- if l .fnWithName != nil {
83
- l .fnWithName (name )
84
- }
85
- out := * l
86
- return & out
87
- }
88
-
89
- type testCallDepthLogSink struct {
90
- testLogSink
91
- callDepth int
92
- fnWithCallDepth func (depth int )
93
- }
94
-
95
- var _ CallDepthLogSink = & testCallDepthLogSink {}
96
-
97
- func (l * testCallDepthLogSink ) WithCallDepth (depth int ) LogSink {
98
- if l .fnWithCallDepth != nil {
99
- l .fnWithCallDepth (depth )
100
- }
101
- out := * l
102
- out .callDepth += depth
103
- return & out
104
- }
105
-
106
27
func TestNew (t * testing.T ) {
107
28
calledInit := 0
108
29
0 commit comments