-
Notifications
You must be signed in to change notification settings - Fork 29
/
config_test.go
70 lines (56 loc) · 1.5 KB
/
config_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
package joe
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
)
func TestConfig(t *testing.T) {
logger := zaptest.NewLogger(t)
brain := NewBrain(logger)
store := NewStorage(logger)
conf := Config{
brain: brain,
store: store,
logger: logger,
}
assert.Equal(t, brain, conf.EventEmitter())
assert.NotNil(t, logger, conf.Logger("test"))
adapter := new(MockAdapter)
conf.SetAdapter(adapter)
assert.Equal(t, adapter, conf.adapter)
mem := newInMemory()
conf.SetMemory(mem)
assert.Equal(t, mem, store.memory)
enc := jsonEncoder{}
conf.SetMemoryEncoder(enc)
assert.Equal(t, enc, store.encoder)
conf.RegisterHandler(func(InitEvent) {})
}
func TestWithContext(t *testing.T) {
var conf Config
mod := WithContext(ctx)
err := mod.Apply(&conf)
assert.NoError(t, err)
assert.Equal(t, ctx, conf.Context)
}
func TestWithHandlerTimeout(t *testing.T) {
var conf Config
mod := WithHandlerTimeout(42 * time.Millisecond)
err := mod.Apply(&conf)
assert.NoError(t, err)
assert.Equal(t, 42*time.Millisecond, conf.HandlerTimeout)
}
func TestWithLogLevel(t *testing.T) {
mod := WithLogLevel(zap.ErrorLevel)
logger := newLogger([]Module{mod})
assert.Nil(t, logger.Check(zap.DebugLevel, "test"))
assert.Nil(t, logger.Check(zap.InfoLevel, "test"))
assert.NotNil(t, logger.Check(zap.ErrorLevel, "test"))
}
// TestNewLogger simply tests that the zap logger configuration in newLogger()
// doesn't panic.
func TestNewLogger(t *testing.T) {
newLogger(nil)
}