@@ -132,17 +132,64 @@ func TestWaitUntilDeployLive_Timeout(t *testing.T) {
132132 }))
133133 defer server .Close ()
134134
135- hu , _ := url .Parse (server .URL )
135+ hu , err := url .Parse (server .URL )
136+ require .NoError (t , err )
136137 tr := apiClient .NewWithClient (hu .Host , "/api/v1" , []string {"http" }, http .DefaultClient )
137138 client := NewRetryable (tr , strfmt .Default , 1 )
138139
139140 ctx := context .WithAuthInfo (gocontext .Background (), apiClient .BearerToken ("token" ))
140141 ctx , _ = gocontext .WithTimeout (ctx , 50 * time .Millisecond )
141- _ , err : = client .WaitUntilDeployLive (ctx , & models.Deploy {})
142+ _ , err = client .WaitUntilDeployLive (ctx , & models.Deploy {})
142143 assert .Error (t , err )
143144 assert .Contains (t , err .Error (), "timed out" )
144145}
145146
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+
146193func TestWalk_IgnoreNodeModulesInRoot (t * testing.T ) {
147194 dir , err := ioutil .TempDir ("" , "deploy" )
148195 require .Nil (t , err )
0 commit comments