-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob_test.go
81 lines (55 loc) · 1.43 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
package offline
import (
"context"
"encoding/json"
"github.com/tidwall/gjson"
"strconv"
"testing"
)
func TestNewJob(t *testing.T) {
ctx := context.Background()
job_type := "testing"
instructions := map[string]interface{}{
"name": "testing",
"id": 1234,
}
enc_instructions, err := json.Marshal(instructions)
if err != nil {
t.Fatalf("Failed to marshal instructions, %v", err)
}
str_instructions := string(enc_instructions)
j, err := NewJob(ctx, "testing", job_type, str_instructions)
if err != nil {
t.Fatalf("Failed to create new job, %v", err)
}
if j.Status != Pending {
t.Fatalf("Unexpected status: %v", j.Status)
}
if j.Type != job_type {
t.Fatalf("Invalid job type. Expected '%s' but got '%s'", job_type, j.Type)
}
}
func TestJobStatusResponse(t *testing.T) {
ctx := context.Background()
j, err := NewJob(ctx, "testing", "testing", "testing")
if err != nil {
t.Fatalf("Failed to create new job, %v", err)
}
j.Id = 1592265428804046848
s := j.AsStatusResponse()
s_id, err := strconv.ParseInt(s.JobId, 10, 64)
if err != nil {
t.Fatalf("Failed to parse job status ID, %v", err)
}
if s_id != j.Id {
t.Fatalf("Invalid job status ID, %d", s_id)
}
enc_s, err := json.Marshal(s)
if err != nil {
t.Fatalf("Failed to marshal job status, %v", err)
}
id_rsp := gjson.GetBytes(enc_s, "job_id")
if id_rsp.Int() != j.Id {
t.Fatalf("Invalid job status ID (encoded), %d", id_rsp.Int())
}
}