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
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package clictx_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/ignite/cli/v29/ignite/pkg/clictx"
|
|
"github.com/ignite/cli/v29/ignite/pkg/errors"
|
|
)
|
|
|
|
func TestDo(t *testing.T) {
|
|
ctxCanceled, cancel := context.WithCancel(context.Background())
|
|
cancel()
|
|
tests := []struct {
|
|
name string
|
|
ctx context.Context
|
|
f func() error
|
|
expectedErr string
|
|
}{
|
|
{
|
|
name: "f returns nil",
|
|
ctx: context.Background(),
|
|
f: func() error { return nil },
|
|
},
|
|
{
|
|
name: "f returns an error",
|
|
ctx: context.Background(),
|
|
f: func() error { return errors.New("oups") },
|
|
expectedErr: "oups",
|
|
},
|
|
{
|
|
name: "ctx is canceled",
|
|
ctx: ctxCanceled,
|
|
f: func() error {
|
|
time.Sleep(time.Second)
|
|
return nil
|
|
},
|
|
expectedErr: context.Canceled.Error(),
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := clictx.Do(tt.ctx, tt.f)
|
|
|
|
if tt.expectedErr != "" {
|
|
require.EqualError(t, err, tt.expectedErr)
|
|
return
|
|
}
|
|
require.NoError(t, err)
|
|
})
|
|
}
|
|
}
|