-
Notifications
You must be signed in to change notification settings - Fork 0
/
resque_test.go
80 lines (73 loc) · 1.46 KB
/
resque_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
package resque
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestNew(t *testing.T) {
tests := []struct {
cfg Configuration
shouldSuccess bool
}{
{
cfg: Configuration{},
shouldSuccess: false,
},
{
cfg: Configuration{
RedisURI: "lolo",
},
shouldSuccess: false,
},
{
cfg: Configuration{
RedisURI: "redis://localhost:6379",
},
shouldSuccess: true,
},
{
cfg: Configuration{
RedisURI: "redis://localhost:6379",
Namespace: "test",
},
shouldSuccess: true,
},
{
cfg: Configuration{
Redis: RedisOptions{
Addr: "localhost:6379",
DB: 1,
DialTimeout: time.Second,
},
Namespace: "test",
},
shouldSuccess: true,
},
{
cfg: Configuration{
Redis: RedisOptions{
Addr: "localhost:6378",
DB: 1,
DialTimeout: 100 * time.Millisecond,
},
Namespace: "test",
},
shouldSuccess: false,
},
}
for _, test := range tests {
cli, err := New(test.cfg)
if test.shouldSuccess {
require.Nil(t, err, "should be nil")
require.NotNil(t, cli, "should not be nil")
if test.cfg.Namespace != "" {
require.Equal(t, cli.namespace, test.cfg.Namespace, "should have set namespace")
} else {
require.Equal(t, "resque", cli.namespace, "should have set default namespace")
}
} else {
require.NotNil(t, err, "should not be nil")
require.Nil(t, cli, "should be nil")
}
}
}