-
Notifications
You must be signed in to change notification settings - Fork 1
/
job_actions_test.go
182 lines (166 loc) · 4.92 KB
/
job_actions_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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package modzy
import (
"context"
"fmt"
"testing"
"time"
"github.com/modzy/sdk-go/model"
)
type testContextKey string
func TestJobActionsGetDetails(t *testing.T) {
expectedCtx := context.WithValue(context.TODO(), testContextKey(testContextKey("ck")), "v")
jobID := "jobid"
client := &ClientFake{
JobsFunc: func() JobsClient {
return &JobsClientFake{
GetJobDetailsFunc: func(ctx context.Context, input *GetJobDetailsInput) (*GetJobDetailsOutput, error) {
if expectedCtx != ctx {
t.Errorf("ctx not passed through")
}
if input.JobIdentifier != jobID {
t.Errorf("JobIdentifier not passed through")
}
return nil, fmt.Errorf("made it")
},
}
},
}
_, err := NewJobActions(client, jobID).GetDetails(expectedCtx)
if err.Error() != "made it" {
t.Errorf("Did not hit test code")
}
}
func TestJobActionsWaitForCompletion(t *testing.T) {
expectedCtx := context.WithValue(context.TODO(), testContextKey("ck"), "v")
jobID := "jobid"
client := &ClientFake{
JobsFunc: func() JobsClient {
return &JobsClientFake{
WaitForJobCompletionFunc: func(ctx context.Context, input *WaitForJobCompletionInput, pollInterval time.Duration) (*GetJobDetailsOutput, error) {
if expectedCtx != ctx {
t.Errorf("ctx not passed through")
}
if input.JobIdentifier != jobID {
t.Errorf("JobIdentifier not passed through")
}
if pollInterval != time.Second*10 {
t.Errorf("pollInterval not passed through")
}
return nil, fmt.Errorf("made it")
},
}
},
}
_, err := NewJobActions(client, jobID).WaitForCompletion(expectedCtx, time.Second*10)
if err.Error() != "made it" {
t.Errorf("Did not hit test code")
}
}
func TestJobActionsCancel(t *testing.T) {
expectedCtx := context.WithValue(context.TODO(), testContextKey("ck"), "v")
jobID := "jobid"
client := &ClientFake{
JobsFunc: func() JobsClient {
return &JobsClientFake{
CancelJobFunc: func(ctx context.Context, input *CancelJobInput) (*CancelJobOutput, error) {
if expectedCtx != ctx {
t.Errorf("ctx not passed through")
}
if input.JobIdentifier != jobID {
t.Errorf("JobIdentifier not passed through")
}
return nil, fmt.Errorf("made it")
},
}
},
}
_, err := NewJobActions(client, jobID).Cancel(expectedCtx)
if err.Error() != "made it" {
t.Errorf("Did not hit test code")
}
}
func TestJobActionsGetResults(t *testing.T) {
expectedCtx := context.WithValue(context.TODO(), testContextKey("ck"), "v")
jobID := "jobid"
client := &ClientFake{
JobsFunc: func() JobsClient {
return &JobsClientFake{
GetJobResultsFunc: func(ctx context.Context, input *GetJobResultsInput) (*GetJobResultsOutput, error) {
if expectedCtx != ctx {
t.Errorf("ctx not passed through")
}
if input.JobIdentifier != jobID {
t.Errorf("JobIdentifier not passed through")
}
return nil, fmt.Errorf("made it")
},
}
},
}
_, err := NewJobActions(client, jobID).GetResults(expectedCtx)
if err.Error() != "made it" {
t.Errorf("Did not hit test code")
}
}
func TestJobActionsGetModelDetailsError(t *testing.T) {
expectedCtx := context.WithValue(context.TODO(), testContextKey("ck"), "v")
client := &ClientFake{
JobsFunc: func() JobsClient {
return &JobsClientFake{
GetJobDetailsFunc: func(ctx context.Context, input *GetJobDetailsInput) (*GetJobDetailsOutput, error) {
return nil, fmt.Errorf("nope")
},
}
},
}
_, err := NewJobActions(client, "do not care").GetModelDetails(expectedCtx)
if err.Error() != "nope" {
t.Errorf("Did not hit error condition")
}
}
func TestJobActionsGetModelDetails(t *testing.T) {
expectedCtx := context.WithValue(context.TODO(), testContextKey("ck"), "v")
jobID := "jobid"
client := &ClientFake{
JobsFunc: func() JobsClient {
return &JobsClientFake{
GetJobDetailsFunc: func(ctx context.Context, input *GetJobDetailsInput) (*GetJobDetailsOutput, error) {
if expectedCtx != ctx {
t.Errorf("ctx not passed through")
}
if input.JobIdentifier != jobID {
t.Errorf("JobIdentifier not passed through")
}
return &GetJobDetailsOutput{
Details: model.JobDetails{
Model: model.ModelNamedIdentifier{
Identifier: "modelID",
Version: "modelVersion",
},
},
}, nil
},
}
},
ModelsFunc: func() ModelsClient {
return &ModelsClientFake{
GetModelVersionDetailsFunc: func(ctx context.Context, input *GetModelVersionDetailsInput) (*GetModelVersionDetailsOutput, error) {
if expectedCtx != ctx {
t.Errorf("ctx not passed through")
}
if input.ModelID != "modelID" {
t.Errorf("model ID not passed through")
}
if input.Version != "modelVersion" {
t.Errorf("model version not passed through")
}
return nil, fmt.Errorf("made it")
},
}
},
}
_, err := NewJobActions(client, jobID).GetModelDetails(expectedCtx)
if err.Error() != "made it" {
t.Errorf("Did not hit test code")
}
}