-
Notifications
You must be signed in to change notification settings - Fork 0
/
core_test.go
58 lines (47 loc) · 1.65 KB
/
core_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
package glog
import (
"github.com/stretchr/testify/assert"
"go.uber.org/zap/zapcore"
"testing"
)
func TestCoreConfig_buildEncoder(t *testing.T) {
cfg := CoreConfig{
Encoding: "json",
EncoderConfig: zapcore.EncoderConfig{},
}
enc, err := cfg.buildEncoder()
assert.NoError(t, err, "Expected no error when building JSON encoder")
assert.IsType(t, zapcore.NewJSONEncoder(zapcore.EncoderConfig{}), enc, "Expected JSON encoder")
cfg.Encoding = "console"
enc, err = cfg.buildEncoder()
assert.NoError(t, err, "Expected no error when building Console encoder")
assert.IsType(t, zapcore.NewConsoleEncoder(zapcore.EncoderConfig{}), enc, "Expected Console encoder")
cfg.Encoding = "unsupported"
enc, err = cfg.buildEncoder()
assert.Error(t, err, "Expected error for unsupported encoding")
}
func TestCoreConfig_openSinks(t *testing.T) {
cfg := CoreConfig{
OutputPaths: []string{"stdout"},
}
sink, err := cfg.openSinks()
assert.NoError(t, err, "Expected no error when opening stdout sink")
assert.NotNil(t, sink, "Expected valid WriteSyncer sink")
cfg.OutputPaths = []string{""}
sink, err = cfg.openSinks()
assert.Error(t, err, "Expected error when opening invalid path sink")
}
func TestCoreConfig_Build(t *testing.T) {
lvl := zapcore.InfoLevel
cfg := CoreConfig{
Encoding: "json",
EncoderConfig: zapcore.EncoderConfig{},
OutputPaths: []string{"stdout"},
}
core, err := cfg.Build(lvl)
assert.NoError(t, err, "Expected no error when building Core")
assert.NotNil(t, core, "Expected valid Core")
cfg.Encoding = "unsupported"
core, err = cfg.Build(lvl)
assert.Error(t, err, "Expected error when building Core with unsupported encoding")
}