-
Notifications
You must be signed in to change notification settings - Fork 0
/
job_test.go
84 lines (73 loc) · 1.57 KB
/
job_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
package resque
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestNewJob(t *testing.T) {
tests := []struct {
args []interface{}
klass string
}{
{
args: []interface{}{},
klass: "",
},
{
args: []interface{}{"a", 3, true},
klass: "test",
},
{
args: []interface{}{"a", "a", "a", 3.14159265},
klass: "pi",
},
{
args: []interface{}{"{json: true}"},
klass: "json",
},
}
for _, test := range tests {
job := NewJob(test.klass, test.args...)
require.Equal(t, Job{
Args: test.args,
Class: test.klass,
}, job, "should be equal")
}
}
func TestJob_Marshal(t *testing.T) {
tests := []struct {
args []interface{}
klass string
expected []byte
}{
{
args: []interface{}{},
klass: "",
expected: []byte("{\"class\":\"\",\"args\":[]}"),
},
{
args: []interface{}{"a", 3, true},
klass: "test",
expected: []byte("{\"class\":\"test\",\"args\":[\"a\",3,true]}"),
},
{
args: []interface{}{"a", "a", "a", 3.14159265},
klass: "pi",
expected: []byte("{\"class\":\"pi\",\"args\":[\"a\",\"a\",\"a\",3.14159265]}"),
},
{
args: []interface{}{"{a: true}"},
klass: "json",
expected: []byte("{\"class\":\"json\",\"args\":[\"{a: true}\"]}"),
},
}
for _, test := range tests {
job := NewJob(test.klass, test.args...)
require.Equal(t, Job{
Args: test.args,
Class: test.klass,
}, job, "should be equal")
buffer, err := job.Marshal()
require.Nil(t, err, "should be nil")
require.Equal(t, buffer, test.expected, "should be equal")
}
}