github.com/telepresenceio/telepresence/v2@v2.20.0-pro.6.0.20240517030216-236ea954e789/integration_test/itest/assertions.go (about)

     1  package itest
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  type Requirements struct {
    12  	*require.Assertions
    13  }
    14  
    15  func (r *Requirements) EventuallyContext(ctx context.Context, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...any) {
    16  	r.Eventually(func() bool {
    17  		if ctx.Err() != nil {
    18  			return true
    19  		}
    20  		return condition()
    21  	}, waitFor, tick, msgAndArgs...)
    22  	r.NoError(ctx.Err())
    23  }
    24  
    25  type Assertions struct {
    26  	*assert.Assertions
    27  }
    28  
    29  func (r *Assertions) EventuallyContext(ctx context.Context, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...any) bool {
    30  	return r.Eventually(func() bool {
    31  		if ctx.Err() != nil {
    32  			return true
    33  		}
    34  		return condition()
    35  	}, waitFor, tick, msgAndArgs...) || r.NoError(ctx.Err())
    36  }