-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_test.go
81 lines (56 loc) · 1.36 KB
/
process_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"
"testing"
)
func TestProcessJob(t *testing.T) {
ctx := context.Background()
db_uri := "syncmap://"
db, err := NewDatabase(ctx, db_uri)
if err != nil {
t.Fatalf("Failed to create new database, %v", err)
}
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)
job, err := NewJob(ctx, "testing", job_type, str_instructions)
if err != nil {
t.Fatalf("Failed to create new job, %v", err)
}
err = db.AddJob(ctx, job)
if err != nil {
t.Fatalf("Failed to add job, %v", err)
}
job.Status = Queued
err = db.UpdateJob(ctx, job)
if err != nil {
t.Fatalf("Failed to update job, %v", err)
}
process_cb := func(ctx context.Context, job *Job) (string, error) {
return "OK", nil
}
process_opts := &ProcessJobOptions{
Database: db,
Callback: process_cb,
JobId: job.Id,
}
err = ProcessJob(ctx, process_opts)
if err != nil {
t.Fatalf("Failed to process job, %v", err)
}
job2, err := db.GetJob(ctx, job.Id)
if err != nil {
t.Fatalf("Failed to retrieve job %d, %v", job.Id, err)
}
if job2.Results != "OK" {
t.Fatalf("Unexpected job results, %s", job2.Results)
}
}