forked from benmanns/goworker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker_test.go
79 lines (72 loc) · 1.62 KB
/
worker_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
package goworker
import (
"reflect"
"testing"
)
var workerMarshalJSONTests = []struct {
w worker
expected []byte
}{
{
worker{},
[]byte(`":0-:"`),
},
{
worker{
process: process{
Hostname: "hostname",
Pid: 12345,
ID: "123",
Queues: []string{"high", "low"},
},
},
[]byte(`"hostname:12345-123:high,low"`),
},
}
func TestWorkerMarshalJSON(t *testing.T) {
for _, tt := range workerMarshalJSONTests {
actual, err := tt.w.MarshalJSON()
if err != nil {
t.Errorf("Worker(%#v): error %s", tt.w, err)
} else {
if string(actual) != string(tt.expected) {
t.Errorf("Worker(%#v): expected %s, actual %s", tt.w, tt.expected, actual)
}
}
}
}
func TestEnqueue(t *testing.T) {
expectedArgs := []interface{}{"a", "lot", "of", "params"}
jobName := "SomethingCool"
queueName := "testQueue"
expectedJob := &Job{
Queue: queueName,
Payload: Payload{
Class: jobName,
Args: expectedArgs,
},
}
queues = []string{queueName}
useNumber = true
exitOnComplete = true
err := Enqueue(expectedJob)
if err != nil {
t.Errorf("Error while enqueue %s", err)
}
actualArgs := []interface{}{}
actualQueueName := ""
Register(jobName, func(queue string, args ...interface{}) error {
actualArgs = args
actualQueueName = queue
return nil
})
if err := Work(); err != nil {
t.Errorf("(Enqueue) Failed on work %s", err)
}
if !reflect.DeepEqual(actualArgs, expectedArgs) {
t.Errorf("(Enqueue) Expected %v, actual %v", actualArgs, expectedArgs)
}
if !reflect.DeepEqual(actualQueueName, queueName) {
t.Errorf("(Enqueue) Expected %v, actual %v", actualQueueName, queueName)
}
}