@@ -295,11 +295,25 @@ func TestConditionEventuallyNoLeak(t *testing.T) {
295295 })
296296}
297297
298- //nolint:gocognit,gocyclo,cyclop,maintidx // subtests are actually not complex
299298func TestConditionEventuallyWith (t * testing.T ) {
300299 t .Parallel ()
301300
302- t .Run ("should complete with false" , func (t * testing.T ) {
301+ t .Run ("should complete with false" , testEventuallyWithShouldCompleteWithFalse ())
302+ t .Run ("should complete with true" , testEventuallyWithShouldCompleteWithTrue ())
303+ t .Run ("should complete with fail, on a nanosecond tick" , testEventuallyWithShouldCompleteWithFail ())
304+ t .Run ("should complete with fail, with latest failed condition" , testEventuallyWithShouldCompleteWithFailLatest ())
305+ t .Run ("should complete with success, with the ticker never used" , testEventuallyWithShouldCompleteWithSuccess ())
306+ t .Run ("collect.FailNow only fails the current tick (poller retries)" , testEventuallyWithFailNowRetries ())
307+ t .Run ("collect.FailNow allows convergence on a later tick" , testEventuallyWithFailNowConverges ())
308+ t .Run ("collect.Cancel aborts the whole assertion immediately" , testEventuallyWithCancelAborts ())
309+ t .Run ("collect.Cancelf aborts with a custom message" , testEventuallyWithCancelfAborts ())
310+ }
311+
312+ // =====================================================
313+ // Sub tests EventuallyWith
314+ // =====================================================.
315+ func testEventuallyWithShouldCompleteWithFalse () func (* testing.T ) {
316+ return func (t * testing.T ) {
303317 t .Parallel ()
304318
305319 mock := new (errorsCapturingT )
@@ -323,9 +337,11 @@ func TestConditionEventuallyWith(t *testing.T) {
323337 if counter < expectedCalls - 1 || counter > expectedCalls + 1 { // it may be 4, 5 or 6 depending on how the test schedules
324338 t .Errorf ("expected %d calls to the condition, but got %d" , expectedCalls , counter )
325339 }
326- })
340+ }
341+ }
327342
328- t .Run ("should complete with true" , func (t * testing.T ) {
343+ func testEventuallyWithShouldCompleteWithTrue () func (* testing.T ) {
344+ return func (t * testing.T ) {
329345 t .Parallel ()
330346
331347 mock := new (errorsCapturingT )
@@ -345,9 +361,11 @@ func TestConditionEventuallyWith(t *testing.T) {
345361 if expectedCalls != counter {
346362 t .Errorf ("expected condition to be called %d times, got %d" , expectedCalls , counter )
347363 }
348- })
364+ }
365+ }
349366
350- t .Run ("should complete with fail, on a nanosecond tick" , func (t * testing.T ) {
367+ func testEventuallyWithShouldCompleteWithFail () func (* testing.T ) {
368+ return func (t * testing.T ) {
351369 t .Parallel ()
352370
353371 mock := new (errorsCapturingT )
@@ -363,9 +381,11 @@ func TestConditionEventuallyWith(t *testing.T) {
363381 if len (mock .errors ) != expectedErrors {
364382 t .Errorf ("expected %d errors (1 from condition, 2 from Eventually), got %d" , expectedErrors , len (mock .errors ))
365383 }
366- })
384+ }
385+ }
367386
368- t .Run ("should complete with fail, with latest failed condition" , func (t * testing.T ) {
387+ func testEventuallyWithShouldCompleteWithFailLatest () func (* testing.T ) {
388+ return func (t * testing.T ) {
369389 t .Parallel ()
370390
371391 mock := new (errorsCapturingT )
@@ -393,9 +413,11 @@ func TestConditionEventuallyWith(t *testing.T) {
393413 if len (mock .errors ) != expectedErrors {
394414 t .Errorf ("expected %d errors (1 from condition, 2 from Eventually), got %d" , expectedErrors , len (mock .errors ))
395415 }
396- })
416+ }
417+ }
397418
398- t .Run ("should complete with success, with the ticker never used" , func (t * testing.T ) {
419+ func testEventuallyWithShouldCompleteWithSuccess () func (* testing.T ) {
420+ return func (t * testing.T ) {
399421 t .Parallel ()
400422
401423 mock := new (errorsCapturingT )
@@ -406,9 +428,11 @@ func TestConditionEventuallyWith(t *testing.T) {
406428 if ! EventuallyWith (mock , condition , testTimeout , time .Second ) {
407429 t .Error ("expected EventuallyWith to return true" )
408430 }
409- })
431+ }
432+ }
410433
411- t .Run ("collect.FailNow only fails the current tick (poller retries)" , func (t * testing.T ) {
434+ func testEventuallyWithFailNowRetries () func (* testing.T ) {
435+ return func (t * testing.T ) {
412436 t .Parallel ()
413437
414438 mock := new (errorsCapturingT )
@@ -432,9 +456,11 @@ func TestConditionEventuallyWith(t *testing.T) {
432456 if got < 2 {
433457 t .Errorf ("expected the condition to be retried multiple times, got %d call(s)" , got )
434458 }
435- })
459+ }
460+ }
436461
437- t .Run ("collect.FailNow allows convergence on a later tick" , func (t * testing.T ) {
462+ func testEventuallyWithFailNowConverges () func (* testing.T ) {
463+ return func (t * testing.T ) {
438464 t .Parallel ()
439465
440466 mock := new (errorsCapturingT )
@@ -458,9 +484,11 @@ func TestConditionEventuallyWith(t *testing.T) {
458484 if len (mock .errors ) != 0 {
459485 t .Errorf ("expected no errors reported on parent t after success, got %d: %v" , len (mock .errors ), mock .errors )
460486 }
461- })
487+ }
488+ }
462489
463- t .Run ("collect.Cancel aborts the whole assertion immediately" , func (t * testing.T ) {
490+ func testEventuallyWithCancelAborts () func (* testing.T ) {
491+ return func (t * testing.T ) {
464492 t .Parallel ()
465493
466494 mock := new (errorsCapturingT )
@@ -491,9 +519,11 @@ func TestConditionEventuallyWith(t *testing.T) {
491519 if len (mock .errors ) == 0 {
492520 t .Error ("expected at least one error reported on parent t after Cancel" )
493521 }
494- })
522+ }
523+ }
495524
496- t .Run ("collect.Cancelf aborts with a custom message" , func (t * testing.T ) {
525+ func testEventuallyWithCancelfAborts () func (* testing.T ) {
526+ return func (t * testing.T ) {
497527 t .Parallel ()
498528
499529 mock := new (errorsCapturingT )
@@ -532,7 +562,7 @@ func TestConditionEventuallyWith(t *testing.T) {
532562 if ! foundCustom {
533563 t .Errorf ("expected custom Cancelf message in errors, got: %v" , mock .errors )
534564 }
535- })
565+ }
536566}
537567
538568func TestConditionPollUntilTimeout (t * testing.T ) {
0 commit comments