Some checks are pending
Docs Deploy / build_and_deploy (push) Waiting to run
Generate Docs / cli (push) Waiting to run
Generate Config Doc / cli (push) Waiting to run
Go formatting / go-formatting (push) Waiting to run
Check links / markdown-link-check (push) Waiting to run
Integration / pre-test (push) Waiting to run
Integration / test on (push) Blocked by required conditions
Integration / status (push) Blocked by required conditions
Lint / Lint Go code (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
42 lines
745 B
Go
42 lines
745 B
Go
package ctxticker
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/ignite/cli/v29/ignite/pkg/errors"
|
|
)
|
|
|
|
func TestDoNow(t *testing.T) {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
var callCount int
|
|
|
|
require.Error(t, context.Canceled, DoNow(ctx, time.Millisecond, func() error {
|
|
if callCount == 3 {
|
|
cancel()
|
|
return nil
|
|
}
|
|
callCount++
|
|
return nil
|
|
}))
|
|
|
|
require.True(t, callCount >= 3)
|
|
}
|
|
|
|
func TestDoNowError(t *testing.T) {
|
|
errDone := errors.New("done")
|
|
var callCount int
|
|
|
|
require.Error(t, errDone, DoNow(context.Background(), time.Millisecond, func() error {
|
|
if callCount == 3 {
|
|
return errDone
|
|
}
|
|
callCount++
|
|
return nil
|
|
}))
|
|
|
|
require.True(t, callCount >= 3)
|
|
}
|