1515// specific language governing permissions and limitations
1616// under the License.
1717
18- package apisix
18+ package v2
1919
2020import (
2121 "fmt"
@@ -275,9 +275,6 @@ spec:
275275`
276276 )
277277
278- request := func (path string , username , password string ) int {
279- return s .NewAPISIXClient ().GET (path ).WithBasicAuth (username , password ).WithHost ("httpbin" ).Expect ().Raw ().StatusCode
280- }
281278 It ("Basic tests" , func () {
282279 By ("apply ApisixRoute" )
283280 applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "default" }, & apiv2.ApisixRoute {}, defaultApisixRoute )
@@ -286,22 +283,50 @@ spec:
286283 applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "test-consumer" }, & apiv2.ApisixConsumer {}, basicAuth )
287284
288285 By ("verify ApisixRoute with ApisixConsumer" )
289- Eventually (request ).WithArguments ("/get" , "invalid-username" , "invalid-password" ).
290- WithTimeout (5 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusUnauthorized ))
291-
292- Eventually (request ).WithArguments ("/get" , "test-user" , "test-password" ).WithTimeout (5 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusOK ))
286+ s .RequestAssert (& scaffold.RequestAssert {
287+ Method : "GET" ,
288+ Path : "/get" ,
289+ Host : "httpbin" ,
290+ BasicAuth : & scaffold.BasicAuth {
291+ Username : "invalid-username" ,
292+ Password : "invalid-password" ,
293+ },
294+ Check : scaffold .WithExpectedStatus (http .StatusUnauthorized ),
295+ })
296+ s .RequestAssert (& scaffold.RequestAssert {
297+ Method : "GET" ,
298+ Path : "/get" ,
299+ Host : "httpbin" ,
300+ BasicAuth : & scaffold.BasicAuth {
301+ Username : "test-user" ,
302+ Password : "test-password" ,
303+ },
304+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
305+ })
293306
294307 By ("Delete ApisixConsumer" )
295308 err := s .DeleteResource ("ApisixConsumer" , "test-consumer" )
296309 Expect (err ).ShouldNot (HaveOccurred (), "deleting ApisixConsumer" )
297- Eventually (request ).WithArguments ("/get" , "test-user" , "test-password" ).
298- WithTimeout (5 * time .Second ).ProbeEvery (time .Second ).
299- Should (Equal (http .StatusUnauthorized ))
310+ s .RequestAssert (& scaffold.RequestAssert {
311+ Method : "GET" ,
312+ Path : "/get" ,
313+ Host : "httpbin" ,
314+ BasicAuth : & scaffold.BasicAuth {
315+ Username : "test-user" ,
316+ Password : "test-password" ,
317+ },
318+ Check : scaffold .WithExpectedStatus (http .StatusUnauthorized ),
319+ })
300320
301321 By ("delete ApisixRoute" )
302322 err = s .DeleteResource ("ApisixRoute" , "default" )
303323 Expect (err ).ShouldNot (HaveOccurred (), "deleting ApisixRoute" )
304- Eventually (request ).WithArguments ("/headers" , "" , "" ).WithTimeout (5 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusNotFound ))
324+ s .RequestAssert (& scaffold.RequestAssert {
325+ Method : "GET" ,
326+ Path : "/get" ,
327+ Host : "httpbin" ,
328+ Check : scaffold .WithExpectedStatus (http .StatusNotFound ),
329+ })
305330 })
306331
307332 It ("SecretRef tests" , func () {
@@ -316,29 +341,70 @@ spec:
316341 applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "test-consumer" }, & apiv2.ApisixConsumer {}, basicAuthWithSecret )
317342
318343 By ("verify ApisixRoute with ApisixConsumer" )
319- Eventually (request ).WithArguments ("/get" , "" , "" ).WithTimeout (5 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusUnauthorized ))
320- Eventually (request ).WithArguments ("/get" , "foo" , "bar" ).WithTimeout (5 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusOK ))
344+ s .RequestAssert (& scaffold.RequestAssert {
345+ Method : "GET" ,
346+ Path : "/get" ,
347+ Host : "httpbin" ,
348+ Check : scaffold .WithExpectedStatus (http .StatusUnauthorized ),
349+ })
350+ s .RequestAssert (& scaffold.RequestAssert {
351+ Method : "GET" ,
352+ Path : "/get" ,
353+ Host : "httpbin" ,
354+ BasicAuth : & scaffold.BasicAuth {
355+ Username : "foo" ,
356+ Password : "bar" ,
357+ },
358+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
359+ })
321360
322361 By ("update Secret" )
323362 err = s .CreateResourceFromString (secretUpdated )
324363 Expect (err ).ShouldNot (HaveOccurred (), "updating Secret for ApisixConsumer" )
325-
326- Eventually (request ).WithArguments ("/get" , "foo" , "bar" ).WithTimeout (5 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusUnauthorized ))
327- Eventually (request ).WithArguments ("/get" , "foo-new-user" , "bar-new-password" ).
328- WithTimeout (5 * time .Second ).ProbeEvery (time .Second ).
329- Should (Equal (http .StatusOK ))
364+ s .RequestAssert (& scaffold.RequestAssert {
365+ Method : "GET" ,
366+ Path : "/get" ,
367+ Host : "httpbin" ,
368+ BasicAuth : & scaffold.BasicAuth {
369+ Username : "foo" ,
370+ Password : "bar" ,
371+ },
372+ Check : scaffold .WithExpectedStatus (http .StatusUnauthorized ),
373+ })
374+ s .RequestAssert (& scaffold.RequestAssert {
375+ Method : "GET" ,
376+ Path : "/get" ,
377+ Host : "httpbin" ,
378+ BasicAuth : & scaffold.BasicAuth {
379+ Username : "foo-new-user" ,
380+ Password : "bar-new-password" ,
381+ },
382+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
383+ })
330384
331385 By ("Delete ApisixConsumer" )
332386 err = s .DeleteResource ("ApisixConsumer" , "test-consumer" )
333387 Expect (err ).ShouldNot (HaveOccurred (), "deleting ApisixConsumer" )
334- Eventually (request ).WithArguments ("/get" , "foo-new-user" , "bar-new-password" ).
335- WithTimeout (5 * time .Second ).ProbeEvery (time .Second ).
336- Should (Equal (http .StatusUnauthorized ))
388+ s .RequestAssert (& scaffold.RequestAssert {
389+ Method : "GET" ,
390+ Path : "/get" ,
391+ Host : "httpbin" ,
392+ BasicAuth : & scaffold.BasicAuth {
393+ Username : "foo-new-user" ,
394+ Password : "bar-new-password" ,
395+ },
396+ Check : scaffold .WithExpectedStatus (http .StatusUnauthorized ),
397+ })
337398
338399 By ("delete ApisixRoute" )
339400 err = s .DeleteResource ("ApisixRoute" , "default" )
340401 Expect (err ).ShouldNot (HaveOccurred (), "deleting ApisixRoute" )
341- Eventually (request ).WithArguments ("/get" , "" , "" ).WithTimeout (5 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusNotFound ))
402+ s .RequestAssert (& scaffold.RequestAssert {
403+ Method : "GET" ,
404+ Path : "/get" ,
405+ Host : "httpbin" ,
406+ Check : scaffold .WithExpectedStatus (http .StatusNotFound ),
407+ })
342408 })
343409 })
344410})
0 commit comments