@@ -190,9 +190,18 @@ var _ = Describe("Task", func() {
190
190
warnings Warnings
191
191
executeErr error
192
192
)
193
+ BeforeEach (func () {
194
+ // This is required because ginkgo does not instantiate variable per test context so the tests pollute the
195
+ // variables for the next tests.
196
+ submitQuery = Query {}
197
+ })
193
198
194
199
JustBeforeEach (func () {
195
- tasks , warnings , executeErr = client .GetApplicationTasks ("some-app-guid" , submitQuery )
200
+ if submitQuery .Key == "" {
201
+ tasks , warnings , executeErr = client .GetApplicationTasks ("some-app-guid" )
202
+ } else {
203
+ tasks , warnings , executeErr = client .GetApplicationTasks ("some-app-guid" , submitQuery )
204
+ }
196
205
})
197
206
198
207
When ("the application exists" , func () {
@@ -201,7 +210,8 @@ var _ = Describe("Task", func() {
201
210
"pagination": {
202
211
"next": {
203
212
"href": "%s/v3/apps/some-app-guid/tasks?per_page=2&page=2"
204
- }
213
+ },
214
+ "total_results": 3
205
215
},
206
216
"resources": [
207
217
{
@@ -245,7 +255,7 @@ var _ = Describe("Task", func() {
245
255
)
246
256
server .AppendHandlers (
247
257
CombineHandlers (
248
- VerifyRequest (http .MethodGet , "/v3/apps/some-app-guid/tasks" , "per_page =2&page =2" ),
258
+ VerifyRequest (http .MethodGet , "/v3/apps/some-app-guid/tasks" , "page =2&per_page =2" ),
249
259
RespondWith (http .StatusOK , response2 , http.Header {"X-Cf-Warnings" : {"warning-2" }}),
250
260
),
251
261
)
@@ -353,6 +363,154 @@ var _ = Describe("Task", func() {
353
363
Expect (warnings ).To (ConsistOf ("warning" ))
354
364
})
355
365
})
366
+
367
+ When ("the application has 10000 tasks" , func () {
368
+ BeforeEach (func () {
369
+ response2 := fmt .Sprintf (`{
370
+ "pagination": {
371
+ "next": {
372
+ "href": "%s/v3/apps/some-app-guid/tasks?per_page=5000&page=2"
373
+ },
374
+ "total_results": 10000
375
+ },
376
+ "resources": [
377
+ {
378
+ "guid": "task-1-guid",
379
+ "sequence_id": 1,
380
+ "name": "task-1",
381
+ "command": "some-command",
382
+ "state": "SUCCEEDED",
383
+ "created_at": "2016-11-07T05:59:01Z"
384
+ },
385
+ {
386
+ "guid": "task-2-guid",
387
+ "sequence_id": 2,
388
+ "name": "task-2",
389
+ "command": "some-command",
390
+ "state": "FAILED",
391
+ "created_at": "2016-11-07T06:59:01Z"
392
+ }
393
+ ]
394
+ }` , server .URL ())
395
+ response3 := fmt .Sprintf (`{
396
+ "pagination": {
397
+ "total_results": 10000
398
+ },
399
+ "resources": [
400
+ {
401
+ "guid": "task-1-guid",
402
+ "sequence_id": 1,
403
+ "name": "task-1",
404
+ "command": "some-command",
405
+ "state": "SUCCEEDED",
406
+ "created_at": "2016-11-07T05:59:01Z"
407
+ },
408
+ {
409
+ "guid": "task-2-guid",
410
+ "sequence_id": 2,
411
+ "name": "task-2",
412
+ "command": "some-command",
413
+ "state": "FAILED",
414
+ "created_at": "2016-11-07T06:59:01Z"
415
+ }
416
+ ]
417
+ }` )
418
+
419
+ server .AppendHandlers (
420
+ CombineHandlers (
421
+ VerifyRequest (http .MethodGet , "/v3/apps/some-app-guid/tasks" , "per_page=5000" ),
422
+ RespondWith (http .StatusOK , response2 , http.Header {"X-Cf-Warnings" : {"warning-2" }}),
423
+ ),
424
+ )
425
+ server .AppendHandlers (
426
+ CombineHandlers (
427
+ VerifyRequest (http .MethodGet , "/v3/apps/some-app-guid/tasks" , "page=2&per_page=5000" ),
428
+ RespondWith (http .StatusOK , response3 , http.Header {"X-Cf-Warnings" : {"warning-2" }}),
429
+ ),
430
+ )
431
+ })
432
+
433
+ It ("calls CAPI 2 times" , func () {
434
+ Expect (executeErr ).ToNot (HaveOccurred ())
435
+ })
436
+ })
437
+
438
+ When ("the application has 4999 tasks" , func () {
439
+ BeforeEach (func () {
440
+ response2 := fmt .Sprintf (`{
441
+ "pagination": {
442
+ "total_results": 4999
443
+ },
444
+ "resources": [
445
+ {
446
+ "guid": "task-1-guid",
447
+ "sequence_id": 1,
448
+ "name": "task-1",
449
+ "command": "some-command",
450
+ "state": "SUCCEEDED",
451
+ "created_at": "2016-11-07T05:59:01Z"
452
+ },
453
+ {
454
+ "guid": "task-2-guid",
455
+ "sequence_id": 2,
456
+ "name": "task-2",
457
+ "command": "some-command",
458
+ "state": "FAILED",
459
+ "created_at": "2016-11-07T06:59:01Z"
460
+ }
461
+ ]
462
+ }` )
463
+ server .AppendHandlers (
464
+ CombineHandlers (
465
+ VerifyRequest (http .MethodGet , "/v3/apps/some-app-guid/tasks" , "per_page=5000" ),
466
+ RespondWith (http .StatusOK , response2 , http.Header {"X-Cf-Warnings" : {"warning-2" }}),
467
+ ),
468
+ )
469
+ })
470
+
471
+ It ("calls CAPI 2 times" , func () {
472
+ Expect (executeErr ).ToNot (HaveOccurred ())
473
+ })
474
+ })
475
+
476
+ When ("the application has 2 tasks" , func () {
477
+ BeforeEach (func () {
478
+ response1 := fmt .Sprintf (`{
479
+ "pagination": {
480
+ "total_results": 2
481
+ },
482
+ "resources": [
483
+ {
484
+ "guid": "task-1-guid",
485
+ "sequence_id": 1,
486
+ "name": "task-1",
487
+ "command": "some-command",
488
+ "state": "SUCCEEDED",
489
+ "created_at": "2016-11-07T05:59:01Z"
490
+ },
491
+ {
492
+ "guid": "task-2-guid",
493
+ "sequence_id": 2,
494
+ "name": "task-2",
495
+ "command": "some-command",
496
+ "state": "FAILED",
497
+ "created_at": "2016-11-07T06:59:01Z"
498
+ }
499
+ ]
500
+ }` )
501
+
502
+ server .AppendHandlers (
503
+ CombineHandlers (
504
+ VerifyRequest (http .MethodGet , "/v3/apps/some-app-guid/tasks" ),
505
+ RespondWith (http .StatusAccepted , response1 , http.Header {"X-Cf-Warnings" : {"warning" }}),
506
+ ),
507
+ )
508
+ })
509
+
510
+ It ("calls CAPI 1 time" , func () {
511
+ Expect (executeErr ).ToNot (HaveOccurred ())
512
+ })
513
+ })
356
514
})
357
515
358
516
Describe ("UpdateTaskCancel" , func () {
0 commit comments