From 821f9913e734c7358cb996fd7083a3b7f591ce89 Mon Sep 17 00:00:00 2001 From: Aleksey Myasnikov Date: Tue, 24 Oct 2023 00:00:18 +0300 Subject: [PATCH] fix TestErrorBrief --- metrics/error_brief_test.go | 90 +++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 50 deletions(-) diff --git a/metrics/error_brief_test.go b/metrics/error_brief_test.go index 072e440c6..021dc3b44 100644 --- a/metrics/error_brief_test.go +++ b/metrics/error_brief_test.go @@ -12,20 +12,10 @@ import ( grpcCodes "google.golang.org/grpc/codes" grpcStatus "google.golang.org/grpc/status" - "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest" ) -func stackRecord() string { - return stack.Record(1, - stack.PackagePath(false), - stack.PackageName(false), - stack.StructName(false), - stack.FunctionName(false), - stack.Lambda(false), - ) -} - func TestErrorBrief(t *testing.T) { for _, tt := range []struct { name string @@ -33,42 +23,42 @@ func TestErrorBrief(t *testing.T) { brief string }{ { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: nil, brief: "OK", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: context.Canceled, brief: "context/Canceled", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.WithStackTrace(context.Canceled), brief: "context/Canceled", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: context.DeadlineExceeded, brief: "context/DeadlineExceeded", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.WithStackTrace(context.DeadlineExceeded), brief: "context/DeadlineExceeded", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: fmt.Errorf("test"), brief: "unknown", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: io.EOF, brief: "io/EOF", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: &net.OpError{ Op: "write", Addr: &net.TCPAddr{ @@ -80,29 +70,29 @@ func TestErrorBrief(t *testing.T) { brief: "network/write[0.0.0.0:2135](transport/Unavailable)", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Retryable(fmt.Errorf("test")), brief: "retryable/CUSTOM", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Retryable(fmt.Errorf("test"), xerrors.WithName("SomeName")), brief: "retryable/SomeName", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.WithStackTrace(xerrors.Retryable(fmt.Errorf("test"))), brief: "retryable/CUSTOM", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.WithStackTrace( xerrors.Retryable(fmt.Errorf("test"), xerrors.WithName("SomeName")), ), brief: "retryable/SomeName", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.WithStackTrace(&net.OpError{ Op: "write", Addr: &net.TCPAddr{ @@ -114,19 +104,19 @@ func TestErrorBrief(t *testing.T) { brief: "network/write[0.0.0.0:2135](transport/Unavailable)", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: grpcStatus.Error(grpcCodes.Unavailable, ""), brief: "transport/Unavailable", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Transport( grpcStatus.Error(grpcCodes.Unavailable, ""), ), brief: "transport/Unavailable", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Operation( xerrors.WithStatusCode(Ydb.StatusIds_BAD_REQUEST), ), @@ -134,31 +124,31 @@ func TestErrorBrief(t *testing.T) { }, // errors with stack trace { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.WithStackTrace(fmt.Errorf("test")), brief: "unknown", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.WithStackTrace(io.EOF), brief: "io/EOF", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.WithStackTrace( grpcStatus.Error(grpcCodes.Unavailable, ""), ), brief: "transport/Unavailable", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.WithStackTrace(xerrors.Transport( grpcStatus.Error(grpcCodes.Unavailable, ""), )), brief: "transport/Unavailable", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.WithStackTrace(xerrors.Operation( xerrors.WithStatusCode(Ydb.StatusIds_BAD_REQUEST), )), @@ -166,12 +156,12 @@ func TestErrorBrief(t *testing.T) { }, // joined errors { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Join(fmt.Errorf("test")), brief: "unknown", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Join( fmt.Errorf("test"), xerrors.Retryable(fmt.Errorf("test")), @@ -179,7 +169,7 @@ func TestErrorBrief(t *testing.T) { brief: "retryable/CUSTOM", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Join( fmt.Errorf("test"), xerrors.Retryable(fmt.Errorf("test"), xerrors.WithName("SomeName")), @@ -187,7 +177,7 @@ func TestErrorBrief(t *testing.T) { brief: "retryable/SomeName", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Join( fmt.Errorf("test"), xerrors.Retryable(fmt.Errorf("test"), xerrors.WithName("SomeName")), @@ -196,26 +186,26 @@ func TestErrorBrief(t *testing.T) { brief: "transport/Unavailable", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Join(io.EOF), brief: "io/EOF", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Join( grpcStatus.Error(grpcCodes.Unavailable, ""), ), brief: "transport/Unavailable", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Join(xerrors.Transport( grpcStatus.Error(grpcCodes.Unavailable, ""), )), brief: "transport/Unavailable", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Join(xerrors.Operation( xerrors.WithStatusCode(Ydb.StatusIds_BAD_REQUEST), )), @@ -223,24 +213,24 @@ func TestErrorBrief(t *testing.T) { }, // joined errors with stack trace { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Join(xerrors.WithStackTrace(fmt.Errorf("test"))), brief: "unknown", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Join(xerrors.WithStackTrace(io.EOF)), brief: "io/EOF", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Join(xerrors.WithStackTrace(xerrors.Transport( grpcStatus.Error(grpcCodes.Unavailable, ""), ))), brief: "transport/Unavailable", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Join(xerrors.WithStackTrace(xerrors.Operation( xerrors.WithStatusCode(Ydb.StatusIds_BAD_REQUEST), ))), @@ -248,7 +238,7 @@ func TestErrorBrief(t *testing.T) { }, // joined errors (mixed types) { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Join( xerrors.WithStackTrace(fmt.Errorf("test")), xerrors.WithStackTrace(io.EOF), @@ -256,7 +246,7 @@ func TestErrorBrief(t *testing.T) { brief: "io/EOF", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.WithStackTrace(xerrors.Join( xerrors.WithStackTrace(fmt.Errorf("test")), xerrors.WithStackTrace(io.EOF), @@ -264,7 +254,7 @@ func TestErrorBrief(t *testing.T) { brief: "io/EOF", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Join( io.EOF, grpcStatus.Error(grpcCodes.Unavailable, ""), @@ -275,7 +265,7 @@ func TestErrorBrief(t *testing.T) { brief: "io/EOF", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Join( &net.OpError{ Op: "write", @@ -294,7 +284,7 @@ func TestErrorBrief(t *testing.T) { brief: "io/EOF", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.Join( grpcStatus.Error(grpcCodes.Unavailable, ""), xerrors.WithStackTrace(xerrors.Operation( @@ -304,7 +294,7 @@ func TestErrorBrief(t *testing.T) { brief: "transport/Unavailable", }, { - name: stackRecord(), + name: xtest.CurrentFileLine(), err: xerrors.WithStackTrace(xerrors.Join( xerrors.WithStackTrace(xerrors.Transport( grpcStatus.Error(grpcCodes.Unavailable, ""),