forked from cyverse-de/interapps-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
status_test.go
108 lines (100 loc) · 2.89 KB
/
status_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"errors"
"testing"
"gopkg.in/cyverse-de/messaging.v4"
"gopkg.in/cyverse-de/model.v3"
)
type TestJobUpdatePublisher struct {
fail bool
updates []*messaging.UpdateMessage
}
func NewTestJobUpdatePublisher(fail bool) *TestJobUpdatePublisher {
return &TestJobUpdatePublisher{
fail: fail,
updates: []*messaging.UpdateMessage{},
}
}
func (j *TestJobUpdatePublisher) PublishJobUpdate(m *messaging.UpdateMessage) error {
if j.fail {
return errors.New("failed to publish job update")
}
j.updates = append(j.updates, m)
return nil
}
func TestFail(t *testing.T) {
j := NewTestJobUpdatePublisher(false)
job := &model.Job{InvocationID: "test-id"}
err := fail(j, job, "test message")
if err != nil {
t.Error(err)
}
expectedlen := 1
actuallen := len(j.updates)
if actuallen != expectedlen {
t.Errorf("length of updates was %d instead of %d", actuallen, expectedlen)
}
actualid := j.updates[0].Job.InvocationID
expectedid := "test-id"
if actualid != expectedid {
t.Errorf("invocation id was %s instead of %s", actualid, expectedid)
}
actualstate := j.updates[0].State
expectedstate := messaging.FailedState
if actualstate != expectedstate {
t.Errorf("state was %s instead of %s", actualstate, expectedstate)
}
actualmsg := j.updates[0].Message
expectedmsg := "test message"
if actualmsg != expectedmsg {
t.Errorf("message was %s instead of %s", actualmsg, expectedmsg)
}
}
func TestSuccess(t *testing.T) {
j := NewTestJobUpdatePublisher(false)
job := &model.Job{InvocationID: "test-id"}
err := success(j, job)
if err != nil {
t.Error(err)
}
expectedlen := 1
actuallen := len(j.updates)
if actuallen != expectedlen {
t.Errorf("length of updates was %d instead of %d", actuallen, expectedlen)
}
actualid := j.updates[0].Job.InvocationID
expectedid := "test-id"
if actualid != expectedid {
t.Errorf("invocation id was %s instead of %s", actualid, expectedid)
}
actualstate := j.updates[0].State
expectedstate := messaging.SucceededState
if actualstate != expectedstate {
t.Errorf("state was %s instead of %s", actualstate, expectedstate)
}
}
func TestRunning(t *testing.T) {
j := NewTestJobUpdatePublisher(false)
job := &model.Job{InvocationID: "test-id"}
running(j, job, "test message")
expectedlen := 1
actuallen := len(j.updates)
if actuallen != expectedlen {
t.Errorf("length of updates was %d instead of %d", actuallen, expectedlen)
}
actualid := j.updates[0].Job.InvocationID
expectedid := "test-id"
if actualid != expectedid {
t.Errorf("invocation id was %s instead of %s", actualid, expectedid)
}
actualstate := j.updates[0].State
expectedstate := messaging.RunningState
if actualstate != expectedstate {
t.Errorf("state was %s instead of %s", actualstate, expectedstate)
}
actualmsg := j.updates[0].Message
expectedmsg := "test message"
if actualmsg != expectedmsg {
t.Errorf("message was %s instead of %s", actualmsg, expectedmsg)
}
}