@@ -132,17 +132,64 @@ func TestWaitUntilDeployLive_Timeout(t *testing.T) {
132
132
}))
133
133
defer server .Close ()
134
134
135
- hu , _ := url .Parse (server .URL )
135
+ hu , err := url .Parse (server .URL )
136
+ require .NoError (t , err )
136
137
tr := apiClient .NewWithClient (hu .Host , "/api/v1" , []string {"http" }, http .DefaultClient )
137
138
client := NewRetryable (tr , strfmt .Default , 1 )
138
139
139
140
ctx := context .WithAuthInfo (gocontext .Background (), apiClient .BearerToken ("token" ))
140
141
ctx , _ = gocontext .WithTimeout (ctx , 50 * time .Millisecond )
141
- _ , err : = client .WaitUntilDeployLive (ctx , & models.Deploy {})
142
+ _ , err = client .WaitUntilDeployLive (ctx , & models.Deploy {})
142
143
assert .Error (t , err )
143
144
assert .Contains (t , err .Error (), "timed out" )
144
145
}
145
146
147
+ func TestWaitUntilDeployProcessed_Success (t * testing.T ) {
148
+ reqNum := 0
149
+ server := httptest .NewServer (http .HandlerFunc (func (rw http.ResponseWriter , req * http.Request ) {
150
+ reqNum ++
151
+ rw .Header ().Set ("Content-Type" , "application/json; charset=utf-8" )
152
+
153
+ // validate the polling actually works
154
+ if reqNum > 1 {
155
+ rw .Write ([]byte (`{ "state": "processed" }` ))
156
+ } else {
157
+ rw .Write ([]byte (`{ "state": "processing" }` ))
158
+ }
159
+ }))
160
+ defer server .Close ()
161
+
162
+ hu , err := url .Parse (server .URL )
163
+ require .NoError (t , err )
164
+ tr := apiClient .NewWithClient (hu .Host , "/api/v1" , []string {"http" }, http .DefaultClient )
165
+ client := NewRetryable (tr , strfmt .Default , 1 )
166
+
167
+ ctx := context .WithAuthInfo (gocontext .Background (), apiClient .BearerToken ("token" ))
168
+ ctx , _ = gocontext .WithTimeout (ctx , 30 * time .Second )
169
+ d , err := client .WaitUntilDeployProcessed (ctx , & models.Deploy {})
170
+ require .NoError (t , err )
171
+ assert .Equal (t , "processed" , d .State )
172
+ }
173
+
174
+ func TestWaitUntilDeployProcessed_Timeout (t * testing.T ) {
175
+ server := httptest .NewServer (http .HandlerFunc (func (rw http.ResponseWriter , req * http.Request ) {
176
+ rw .Header ().Set ("Content-Type" , "application/json; charset=utf-8" )
177
+ rw .Write ([]byte (`{ "state": "processing" }` ))
178
+ }))
179
+ defer server .Close ()
180
+
181
+ hu , err := url .Parse (server .URL )
182
+ require .NoError (t , err )
183
+ tr := apiClient .NewWithClient (hu .Host , "/api/v1" , []string {"http" }, http .DefaultClient )
184
+ client := NewRetryable (tr , strfmt .Default , 1 )
185
+
186
+ ctx := context .WithAuthInfo (gocontext .Background (), apiClient .BearerToken ("token" ))
187
+ ctx , _ = gocontext .WithTimeout (ctx , 50 * time .Millisecond )
188
+ _ , err = client .WaitUntilDeployProcessed (ctx , & models.Deploy {})
189
+ require .Error (t , err )
190
+ assert .Contains (t , err .Error (), "timed out" )
191
+ }
192
+
146
193
func TestWalk_IgnoreNodeModulesInRoot (t * testing.T ) {
147
194
dir , err := ioutil .TempDir ("" , "deploy" )
148
195
require .Nil (t , err )
0 commit comments