mukan-ignite/ignite/pkg/errors/xerrors_test.go
Mukan Erkin Törük 26b204bd04
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
feat: fork Ignite CLI v29 as Mukan Ignite — remove cosmos-sdk restrictions
2026-05-11 03:31:37 +03:00

71 lines
1.7 KiB
Go

package errors
import (
"context"
stdErrors "errors"
"testing"
"github.com/stretchr/testify/require"
)
type customErr struct {
msg string
}
func (e customErr) Error() string { return e.msg }
func TestBasicHelpers(t *testing.T) {
err := New("boom")
require.EqualError(t, err, "boom")
err = Errorf("value: %d", 10)
require.EqualError(t, err, "value: 10")
}
func TestWrapHelpers(t *testing.T) {
base := stdErrors.New("base")
require.Nil(t, Wrap(nil, "prefix"))
require.Nil(t, Wrapf(nil, "prefix %s", "x"))
wrapped := Wrap(base, "prefix")
require.Error(t, wrapped)
require.True(t, Is(wrapped, base))
wrapped = Wrapf(base, "prefix %s", "x")
require.Error(t, wrapped)
require.True(t, Is(wrapped, base))
}
func TestJoinUnwrapAs(t *testing.T) {
e1 := customErr{msg: "one"}
e2 := stdErrors.New("two")
j := Join(e1, e2)
require.Error(t, j)
require.True(t, Is(j, e2))
var target customErr
require.True(t, As(j, &target))
require.Equal(t, "one", target.msg)
wrapped := Wrap(e2, "prefix")
require.True(t, Is(Unwrap(wrapped), e2))
}
func TestWithStack(t *testing.T) {
base := stdErrors.New("base")
require.True(t, Is(WithStack(base), base))
}
func TestShouldCaptureException(t *testing.T) {
t.Run("canceled errors are ignored", func(t *testing.T) {
require.False(t, shouldCaptureException(context.Canceled))
require.False(t, shouldCaptureException(Wrap(context.Canceled, "prefix")))
require.False(t, shouldCaptureException(Wrapf(context.Canceled, "prefix %s", "x")))
require.False(t, shouldCaptureException(WithStack(context.Canceled)))
})
t.Run("other errors are reported", func(t *testing.T) {
require.True(t, shouldCaptureException(stdErrors.New("boom")))
})
}