package xerr import ( "errors" "fmt" "runtime" "testing" "github.com/getsentry/sentry-go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestStackTraceInSentry(t *testing.T) { err := WithStack(errors.New("test error")) stackTrace := sentry.ExtractStacktrace(err) require.NotNil(t, stackTrace) assert.Equal(t, 1, len(stackTrace.Frames)) } func TestWithStackRepeat(t *testing.T) { err := WithStack(errors.New("test error")) err = wrapErr(err) _, ok := err.(*withStack) require.True(t, ok) } func TestWrapStack(t *testing.T) { err := wrapStack(nil, 0) require.Nil(t, err, "wrap nil") err = wrapStack(errors.New("test error"), 0) require.NotNil(t, err) assert.Equal(t, "test error", err.Error(), "wrap normal error") } func wrapErr(err error) error { return wrapStack(err, 1) } func funcStack(s *stack) string { frame, _ := runtime.CallersFrames(*s).Next() return fmt.Sprintf("pkg.xerr.%s", funcname(frame.Function)) }