github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/xerrors/retryable_test.go (about) 1 package xerrors 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 "github.com/ydb-platform/ydb-go-genproto/protos/Ydb" 9 grpcCodes "google.golang.org/grpc/codes" 10 grpcStatus "google.golang.org/grpc/status" 11 ) 12 13 func TestRetryableCode(t *testing.T) { 14 for _, tt := range []struct { 15 err error 16 code int32 17 }{ 18 { 19 err: Retryable(fmt.Errorf("some")), 20 code: -1, 21 }, 22 { 23 err: Retryable( 24 Transport(grpcStatus.Error(grpcCodes.Unavailable, "")), 25 ), 26 code: int32(grpcCodes.Unavailable), 27 }, 28 { 29 err: Retryable( 30 Operation(WithStatusCode(Ydb.StatusIds_BAD_REQUEST)), 31 ), 32 code: int32(Ydb.StatusIds_BAD_REQUEST), 33 }, 34 { 35 err: Retryable(Retryable( 36 Transport(grpcStatus.Error(grpcCodes.Unavailable, "")), 37 )), 38 code: int32(grpcCodes.Unavailable), 39 }, 40 { 41 err: Retryable(Retryable( 42 Operation(WithStatusCode(Ydb.StatusIds_BAD_REQUEST)), 43 )), 44 code: int32(Ydb.StatusIds_BAD_REQUEST), 45 }, 46 } { 47 t.Run("", func(t *testing.T) { 48 var err Error 49 require.ErrorAs(t, tt.err, &err) 50 require.Equal(t, tt.code, err.Code()) 51 }) 52 } 53 }