-
Notifications
You must be signed in to change notification settings - Fork 11.6k
/
fake.go
78 lines (61 loc) · 1.64 KB
/
fake.go
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package log
import (
"context"
"sync"
)
var _ Logger = (*TestLogger)(nil)
type TestLogger struct {
DebugLogs Logs
InfoLogs Logs
WarnLogs Logs
ErrorLogs Logs
}
func NewTestLogger() *TestLogger {
return &TestLogger{}
}
func (f *TestLogger) New(_ ...any) Logger {
return NewTestLogger()
}
func (f *TestLogger) Info(msg string, ctx ...any) {
f.InfoLogs.Call(msg, ctx)
}
func (f *TestLogger) Warn(msg string, ctx ...any) {
f.WarnLogs.Call(msg, ctx)
}
func (f *TestLogger) Debug(msg string, ctx ...any) {
f.DebugLogs.Call(msg, ctx)
}
func (f *TestLogger) Error(msg string, ctx ...any) {
f.ErrorLogs.Call(msg, ctx)
}
func (f *TestLogger) FromContext(_ context.Context) Logger {
return NewTestLogger()
}
type Logs struct {
Calls int
Message string
Ctx []any
mu sync.Mutex
}
func (l *Logs) Call(msg string, ctx ...any) {
l.mu.Lock()
defer l.mu.Unlock()
l.Calls++
l.Message = msg
l.Ctx = ctx
}
var _ PrettyLogger = (*TestPrettyLogger)(nil)
type TestPrettyLogger struct{}
func NewTestPrettyLogger() *TestPrettyLogger {
return &TestPrettyLogger{}
}
func (f *TestPrettyLogger) Successf(_ string, _ ...any) {}
func (f *TestPrettyLogger) Failuref(_ string, _ ...any) {}
func (f *TestPrettyLogger) Info(_ ...any) {}
func (f *TestPrettyLogger) Infof(_ string, _ ...any) {}
func (f *TestPrettyLogger) Debug(_ ...any) {}
func (f *TestPrettyLogger) Debugf(_ string, _ ...any) {}
func (f *TestPrettyLogger) Warn(_ ...any) {}
func (f *TestPrettyLogger) Warnf(_ string, _ ...any) {}
func (f *TestPrettyLogger) Error(_ ...any) {}
func (f *TestPrettyLogger) Errorf(_ string, _ ...any) {}