github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/xerrors/stacktrace_test.go (about) 1 package xerrors 2 3 import ( 4 "errors" 5 "fmt" 6 "testing" 7 8 "github.com/stretchr/testify/require" 9 grpcCodes "google.golang.org/grpc/codes" 10 grpcStatus "google.golang.org/grpc/status" 11 ) 12 13 func TestStackTraceError(t *testing.T) { 14 for _, test := range []struct { 15 error error 16 text string 17 }{ 18 { 19 error: WithStackTrace(fmt.Errorf("fmt.Errorf")), 20 //nolint:lll 21 text: "fmt.Errorf at `github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors.TestStackTraceError(stacktrace_test.go:19)`", 22 }, 23 { 24 error: WithStackTrace(fmt.Errorf("fmt.Errorf %s", "Printf")), 25 //nolint:lll 26 text: "fmt.Errorf Printf at `github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors.TestStackTraceError(stacktrace_test.go:24)`", 27 }, 28 { 29 error: WithStackTrace( 30 WithStackTrace(errors.New("errors.New")), 31 ), 32 //nolint:lll 33 text: "errors.New at `github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors.TestStackTraceError(stacktrace_test.go:30)` at `github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors.TestStackTraceError(stacktrace_test.go:29)`", 34 }, 35 } { 36 t.Run(test.text, func(t *testing.T) { 37 require.Equal(t, test.text, test.error.Error()) 38 }) 39 } 40 } 41 42 func TestTransportStackTraceError(t *testing.T) { 43 for _, test := range []struct { 44 error error 45 text string 46 }{ 47 { 48 error: WithStackTrace( 49 Transport( 50 grpcStatus.Error(grpcCodes.Aborted, "some error"), 51 WithAddress("example.com"), 52 ), 53 ), 54 //nolint:lll 55 text: "transport/Aborted (code = 10, source error = \"rpc error: code = Aborted desc = some error\", address: \"example.com\") at `github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors.TestTransportStackTraceError(stacktrace_test.go:48)`", 56 }, 57 { 58 error: WithStackTrace( 59 WithStackTrace( 60 Transport( 61 grpcStatus.Error(grpcCodes.Aborted, "some error"), 62 ), 63 ), 64 ), 65 //nolint:lll 66 text: "transport/Aborted (code = 10, source error = \"rpc error: code = Aborted desc = some error\") at `github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors.TestTransportStackTraceError(stacktrace_test.go:59)` at `github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors.TestTransportStackTraceError(stacktrace_test.go:58)`", 67 }, 68 { 69 error: WithStackTrace( 70 WithStackTrace( 71 WithStackTrace( 72 Transport( 73 grpcStatus.Error(grpcCodes.Aborted, "some error"), 74 ), 75 ), 76 ), 77 ), 78 //nolint:lll 79 text: "transport/Aborted (code = 10, source error = \"rpc error: code = Aborted desc = some error\") at `github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors.TestTransportStackTraceError(stacktrace_test.go:71)` at `github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors.TestTransportStackTraceError(stacktrace_test.go:70)` at `github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors.TestTransportStackTraceError(stacktrace_test.go:69)`", 80 }, 81 } { 82 t.Run(test.text, func(t *testing.T) { 83 require.Equal(t, test.text, test.error.Error()) 84 }) 85 } 86 }