-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathjob_test.go
More file actions
147 lines (142 loc) · 2.63 KB
/
job_test.go
File metadata and controls
147 lines (142 loc) · 2.63 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package cronx
import (
"context"
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestJob_Run(t *testing.T) {
type fields struct {
Name string
Status StatusCode
Latency string
inner JobItf
status uint32
}
tests := []struct {
name string
fields fields
}{
{
name: "Success with run resulting error",
fields: fields{
Name: "Func",
Status: StatusCodeSuccess,
inner: Func(func(ctx context.Context) error { return errors.New("error") }),
},
},
{
name: "Success",
fields: fields{
Name: "Func",
Status: StatusCodeSuccess,
inner: Func(func(ctx context.Context) error { return nil }),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
manager := NewManager()
j := &Job{
manager: manager,
Name: tt.fields.Name,
Status: tt.fields.Status,
Latency: tt.fields.Latency,
inner: tt.fields.inner,
status: tt.fields.status,
}
j.Run()
})
}
}
func TestJob_UpdateStatus(t *testing.T) {
type fields struct {
Name string
Status StatusCode
Latency string
inner JobItf
status uint32
}
tests := []struct {
name string
fields fields
want StatusCode
}{
{
name: "StatusCodeUp",
fields: fields{
status: statusUp,
},
want: StatusCodeUp,
},
{
name: "StatusCodeRunning",
fields: fields{
status: statusRunning,
},
want: StatusCodeRunning,
},
{
name: "StatusCodeSuccess",
fields: fields{
status: statusSuccess,
},
want: StatusCodeSuccess,
},
{
name: "StatusCodeDown",
fields: fields{
status: statusDown,
},
want: StatusCodeDown,
},
{
name: "StatusCodeError",
fields: fields{
status: statusError,
},
want: StatusCodeError,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
j := &Job{
Name: tt.fields.Name,
Status: tt.fields.Status,
Latency: tt.fields.Latency,
inner: tt.fields.inner,
status: tt.fields.status,
}
if got := j.UpdateStatus(); got != tt.want {
t.Errorf("UpdateStatus() = %v, want %v", got, tt.want)
}
})
}
}
func TestNewJob(t *testing.T) {
type args struct {
job JobItf
waveNumber int64
totalWave int64
}
tests := []struct {
name string
args args
}{
{
name: "Success",
args: args{
job: Func(func(ctx context.Context) error { return nil }),
waveNumber: 1,
totalWave: 1,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
manager := NewManager()
got := NewJob(manager, tt.args.job, tt.args.waveNumber, tt.args.totalWave)
assert.NotNil(t, got)
})
}
}