-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenqueue_test.go
More file actions
68 lines (59 loc) · 1.36 KB
/
enqueue_test.go
File metadata and controls
68 lines (59 loc) · 1.36 KB
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
package resque
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func TestClient_Enqueue(t *testing.T) {
tests := []struct {
job Job
queue string
shouldSuccess bool
}{
{
job: NewJob("test", "hello", "world"),
queue: "test",
shouldSuccess: true,
},
{
job: NewJob("tutu", 1, "world"),
queue: "tutu",
shouldSuccess: true,
},
{
job: NewJob("tutu", 1, "world"),
queue: "",
shouldSuccess: false,
},
}
cli, err := New(Configuration{
RedisURI: "redis://localhost:6379",
})
require.Nil(t, err, "should be nil")
require.NotNil(t, cli, "should not be nil")
for _, test := range tests {
err := cli.Enqueue(test.queue, test.job)
if test.shouldSuccess {
require.Nil(t, err, "should be nil")
require.Contains(
t,
cli.redisClient.SMembers(
fmt.Sprintf("%s:queues", cli.namespace),
).Val(),
test.queue,
"resque queues should contain +\""+test.queue+"\"",
)
require.Equal(
t,
int64(1),
cli.redisClient.LLen(
fmt.Sprintf("%s:queue:%s", cli.namespace, test.queue),
).Val(),
"resque queue length should be the same of the amount of jobs",
)
} else {
require.NotNil(t, err, "should not be nil")
}
require.Nil(t, cli.redisClient.FlushDb().Err(), "FLUSHDB should have succedeed")
}
}