-
Notifications
You must be signed in to change notification settings - Fork 1
/
provider_test.go
119 lines (101 loc) · 2.39 KB
/
provider_test.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package log
import (
"github.com/echocat/slf4g/fields"
"github.com/echocat/slf4g/level"
)
func newMockProvider(name string) *mockProvider {
return &mockProvider{
name: name,
fieldKeysSpec: &mockFieldKeysSpec{
timestamp: "aTimestamp",
message: "aMessage",
error: "anError",
logger: "aLogger",
},
}
}
type mockProvider struct {
rootProvider func() Logger
provider func(name string) Logger
name string
fieldKeysSpec fields.KeysSpec
levels level.Levels
}
func (instance *mockProvider) GetName() string {
if v := instance.name; v != "" {
return v
}
panic("not implemented in tests")
}
func (instance *mockProvider) GetRootLogger() Logger {
if v := instance.rootProvider; v != nil {
return v()
}
panic("not implemented in tests")
}
func (instance *mockProvider) GetLogger(name string) Logger {
if v := instance.provider; v != nil {
return v(name)
}
panic("not implemented in tests")
}
func (instance *mockProvider) GetAllLevels() level.Levels {
if v := instance.levels; v != nil {
return v
}
panic("not implemented in tests")
}
func (instance *mockProvider) GetFieldKeysSpec() fields.KeysSpec {
if v := instance.fieldKeysSpec; v != nil {
return v
}
panic("not implemented in tests")
}
func (instance *mockProvider) newEvent(l level.Level) Event {
return instance.GetRootLogger().NewEvent(l, nil)
}
func (instance *mockProvider) withRootLogger() *mockProvider {
instance.rootProvider = func() Logger {
return newMockLogger("ROOT")
}
return instance
}
func newWrappingProvider(in Provider) *wrappingProvider {
return &wrappingProvider{in}
}
type wrappingProvider struct {
Provider
}
func (instance *wrappingProvider) Unwrap() Provider {
return instance.Provider
}
type mockFieldKeysSpec struct {
timestamp string
message string
error string
logger string
}
func (instance *mockFieldKeysSpec) GetTimestamp() string {
if v := instance.timestamp; v != "" {
return v
}
panic("not implemented in tests")
}
func (instance *mockFieldKeysSpec) GetMessage() string {
if v := instance.message; v != "" {
return v
}
panic("not implemented in tests")
}
func (instance *mockFieldKeysSpec) GetError() string {
if v := instance.error; v != "" {
return v
}
panic("not implemented in tests")
}
func (instance *mockFieldKeysSpec) GetLogger() string {
if v := instance.logger; v != "" {
return v
}
panic("not implemented in tests")
}