-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtask_test.go
58 lines (50 loc) · 1 KB
/
task_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
package async
import (
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
var (
testTask Task
testTaskJSON []byte
)
func init() {
jobName := "test-job"
argName := "foo"
argValue := "FOO"
testTask = NewTask(
jobName,
map[string]string{
argName: argValue,
},
)
testTaskJSONStr := fmt.Sprintf(
`{
"id":"%s",
"jobName":"%s",
"args":{"%s":"%s"},
"workerRejectionCount": %d,
"executeTime": null
}`,
testTask.GetID(),
jobName,
argName,
argValue,
0,
)
testTaskJSONStr = strings.Replace(testTaskJSONStr, " ", "", -1)
testTaskJSONStr = strings.Replace(testTaskJSONStr, "\n", "", -1)
testTaskJSONStr = strings.Replace(testTaskJSONStr, "\t", "", -1)
testTaskJSON = []byte(testTaskJSONStr)
}
func TestNewTaskFromJSON(t *testing.T) {
task, err := NewTaskFromJSON(testTaskJSON)
assert.Nil(t, err)
assert.Equal(t, testTask, task)
}
func TestTaskToJSON(t *testing.T) {
json, err := testTask.ToJSON()
assert.Nil(t, err)
assert.Equal(t, testTaskJSON, json)
}