forked from jrallison/go-workers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
90 lines (69 loc) · 1.95 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package workers
import (
"github.com/customerio/gospec"
. "github.com/customerio/gospec"
)
func ConfigSpec(c gospec.Context) {
var recoverOnPanic = func(f func()) (err interface{}) {
defer func() {
if cause := recover(); cause != nil {
err = cause
}
}()
f()
return
}
c.Specify("sets redis pool size which defaults to 1", func() {
c.Expect(Config.Pool.MaxIdle, Equals, 1)
Configure(map[string]string{
"server": "localhost:6379",
"process": "1",
"pool": "20",
})
c.Expect(Config.Pool.MaxIdle, Equals, 20)
})
c.Specify("can specify custom process", func() {
c.Expect(Config.processId, Equals, "1")
Configure(map[string]string{
"server": "localhost:6379",
"process": "2",
})
c.Expect(Config.processId, Equals, "2")
})
c.Specify("requires a server parameter", func() {
err := recoverOnPanic(func() {
Configure(map[string]string{"process": "2"})
})
c.Expect(err, Equals, "Configure requires a 'server' option, which identifies a Redis instance")
})
c.Specify("requires a process parameter", func() {
err := recoverOnPanic(func() {
Configure(map[string]string{"server": "localhost:6379"})
})
c.Expect(err, Equals, "Configure requires a 'process' option, which uniquely identifies this instance")
})
c.Specify("adds ':' to the end of the namespace", func() {
c.Expect(Config.Namespace, Equals, "")
Configure(map[string]string{
"server": "localhost:6379",
"process": "1",
"namespace": "prod",
})
c.Expect(Config.Namespace, Equals, "prod:")
})
c.Specify("defaults poll interval to 15 seconds", func() {
Configure(map[string]string{
"server": "localhost:6379",
"process": "1",
})
c.Expect(Config.PollInterval, Equals, 15)
})
c.Specify("allows customization of poll interval", func() {
Configure(map[string]string{
"server": "localhost:6379",
"process": "1",
"poll_interval": "1",
})
c.Expect(Config.PollInterval, Equals, 1)
})
}