-
Notifications
You must be signed in to change notification settings - Fork 1
/
provider_facade_test.go
77 lines (58 loc) · 2.16 KB
/
provider_facade_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
package log
import (
"testing"
"github.com/echocat/slf4g/level"
"github.com/echocat/slf4g/internal/test/assert"
)
func Test_providerFacade_GetName(t *testing.T) {
givenProvider := newMockProvider("foo")
instance := providerFacade(func() Provider { return givenProvider })
actual := instance.GetName()
assert.ToBeEqual(t, "foo", actual)
}
func Test_providerFacade_GetRootLogger(t *testing.T) {
givenRootLogger := newMockLogger("root")
givenProvider := newMockProvider("foo")
givenProvider.rootProvider = func() Logger { return givenRootLogger }
instance := providerFacade(func() Provider { return givenProvider })
actual := instance.GetRootLogger()
assert.ToBeOfType(t, &loggerImpl{}, actual)
assert.ToBeSame(t, givenRootLogger, actual.(*loggerImpl).Unwrap())
}
func Test_providerFacade_GetLogger(t *testing.T) {
givenLogger1 := newMockLogger("1")
givenLogger2 := newMockLogger("2")
givenProvider := newMockProvider("foo")
givenProvider.provider = func(name string) Logger {
switch name {
case "1":
return givenLogger1
case "2":
return givenLogger2
default:
panic(name)
}
}
instance := providerFacade(func() Provider { return givenProvider })
actual1 := instance.GetLogger("1")
actual2 := instance.GetLogger("2")
assert.ToBeOfType(t, &loggerImpl{}, actual1)
assert.ToBeOfType(t, &loggerImpl{}, actual2)
assert.ToBeSame(t, givenLogger1, actual1.(*loggerImpl).Unwrap())
assert.ToBeSame(t, givenLogger2, actual2.(*loggerImpl).Unwrap())
}
func Test_providerFacade_GetAllLevels(t *testing.T) {
givenProvider := newMockProvider("foo")
givenProvider.levels = []level.Level{level.Info, level.Fatal}
instance := providerFacade(func() Provider { return givenProvider })
actual := instance.GetAllLevels()
assert.ToBeEqual(t, givenProvider.levels, actual)
}
func Test_providerFacade_GetFieldKeysSpec(t *testing.T) {
givenProvider := newMockProvider("foo")
givenProvider.fieldKeysSpec = &mockFieldKeysSpec{"1", "2", "3", "4"}
givenProvider.levels = []level.Level{level.Info, level.Fatal}
instance := providerFacade(func() Provider { return givenProvider })
actual := instance.GetFieldKeysSpec()
assert.ToBeEqual(t, givenProvider.fieldKeysSpec, actual)
}