@@ -7,24 +7,30 @@ import (
77 "github.com/stretchr/testify/require"
88 "github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
99 "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Issue"
10+
11+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest"
1012)
1113
1214func TestIsOperationError (t * testing.T ) {
1315 for _ , tt := range []struct {
16+ name string
1417 err error
1518 codes []Ydb.StatusIds_StatusCode
1619 match bool
1720 }{
1821 // check only operation error with any ydb status code
1922 {
23+ name : xtest .CurrentFileLine (),
2024 err : & operationError {code : Ydb .StatusIds_BAD_REQUEST },
2125 match : true ,
2226 },
2327 {
28+ name : xtest .CurrentFileLine (),
2429 err : fmt .Errorf ("wrapped: %w" , & operationError {code : Ydb .StatusIds_BAD_REQUEST }),
2530 match : true ,
2631 },
2732 {
33+ name : xtest .CurrentFileLine (),
2834 err : Join (
2935 fmt .Errorf ("test" ),
3036 & operationError {code : Ydb .StatusIds_BAD_REQUEST },
@@ -34,16 +40,19 @@ func TestIsOperationError(t *testing.T) {
3440 },
3541 // match ydb status code
3642 {
43+ name : xtest .CurrentFileLine (),
3744 err : & operationError {code : Ydb .StatusIds_BAD_REQUEST },
3845 codes : []Ydb.StatusIds_StatusCode {Ydb .StatusIds_BAD_REQUEST },
3946 match : true ,
4047 },
4148 {
49+ name : xtest .CurrentFileLine (),
4250 err : fmt .Errorf ("wrapped: %w" , & operationError {code : Ydb .StatusIds_BAD_REQUEST }),
4351 codes : []Ydb.StatusIds_StatusCode {Ydb .StatusIds_BAD_REQUEST },
4452 match : true ,
4553 },
4654 {
55+ name : xtest .CurrentFileLine (),
4756 err : Join (
4857 fmt .Errorf ("test" ),
4958 & operationError {code : Ydb .StatusIds_BAD_REQUEST },
@@ -54,16 +63,19 @@ func TestIsOperationError(t *testing.T) {
5463 },
5564 // no match ydb status code
5665 {
66+ name : xtest .CurrentFileLine (),
5767 err : & operationError {code : Ydb .StatusIds_BAD_REQUEST },
5868 codes : []Ydb.StatusIds_StatusCode {Ydb .StatusIds_ABORTED },
5969 match : false ,
6070 },
6171 {
72+ name : xtest .CurrentFileLine (),
6273 err : fmt .Errorf ("wrapped: %w" , & operationError {code : Ydb .StatusIds_BAD_REQUEST }),
6374 codes : []Ydb.StatusIds_StatusCode {Ydb .StatusIds_ABORTED },
6475 match : false ,
6576 },
6677 {
78+ name : xtest .CurrentFileLine (),
6779 err : Join (
6880 fmt .Errorf ("test" ),
6981 & operationError {code : Ydb .StatusIds_BAD_REQUEST },
@@ -73,18 +85,20 @@ func TestIsOperationError(t *testing.T) {
7385 match : false ,
7486 },
7587 } {
76- t .Run ("" , func (t * testing.T ) {
88+ t .Run (tt . name , func (t * testing.T ) {
7789 require .Equal (t , tt .match , IsOperationError (tt .err , tt .codes ... ))
7890 })
7991 }
8092}
8193
8294func TestIsOperationErrorTransactionLocksInvalidated (t * testing.T ) {
8395 for _ , tt := range [... ]struct {
96+ name string
8497 err error
8598 isTLI bool
8699 }{
87100 {
101+ name : xtest .CurrentFileLine (),
88102 err : Operation (
89103 WithStatusCode (Ydb .StatusIds_ABORTED ),
90104 WithIssues ([]* Ydb_Issue.IssueMessage {{
@@ -94,6 +108,7 @@ func TestIsOperationErrorTransactionLocksInvalidated(t *testing.T) {
94108 isTLI : true ,
95109 },
96110 {
111+ name : xtest .CurrentFileLine (),
97112 err : Operation (
98113 WithStatusCode (Ydb .StatusIds_OVERLOADED ),
99114 WithIssues ([]* Ydb_Issue.IssueMessage {{
@@ -103,12 +118,14 @@ func TestIsOperationErrorTransactionLocksInvalidated(t *testing.T) {
103118 isTLI : false ,
104119 },
105120 {
121+ name : xtest .CurrentFileLine (),
106122 err : Operation (
107123 WithStatusCode (Ydb .StatusIds_ABORTED ),
108124 ),
109125 isTLI : false ,
110126 },
111127 {
128+ name : xtest .CurrentFileLine (),
112129 err : Operation (
113130 WithStatusCode (Ydb .StatusIds_ABORTED ),
114131 WithIssues ([]* Ydb_Issue.IssueMessage {{
@@ -120,30 +137,40 @@ func TestIsOperationErrorTransactionLocksInvalidated(t *testing.T) {
120137 isTLI : true ,
121138 },
122139 } {
123- t .Run ("" , func (t * testing.T ) {
140+ t .Run (tt . name , func (t * testing.T ) {
124141 require .Equal (t , tt .isTLI , IsOperationErrorTransactionLocksInvalidated (tt .err ))
125142 })
126143 }
127144}
128145
129146func Test_operationError_Error (t * testing.T ) {
130147 for _ , tt := range []struct {
148+ name string
131149 err error
132150 text string
133151 }{
134152 {
153+ name : xtest .CurrentFileLine (),
135154 err : Operation (WithStatusCode (Ydb .StatusIds_BAD_REQUEST ), WithAddress ("localhost" )),
136155 text : "operation/BAD_REQUEST (code = 400010, address = localhost)" ,
137156 },
138157 {
158+ name : xtest .CurrentFileLine (),
159+ err : Operation (WithStatusCode (Ydb .StatusIds_BAD_REQUEST ), WithNodeID (100500 )),
160+ text : "operation/BAD_REQUEST (code = 400010, nodeID = 100500)" ,
161+ },
162+ {
163+ name : xtest .CurrentFileLine (),
139164 err : Operation (WithStatusCode (Ydb .StatusIds_BAD_REQUEST )),
140165 text : "operation/BAD_REQUEST (code = 400010)" ,
141166 },
142167 {
168+ name : xtest .CurrentFileLine (),
143169 err : Operation (WithStatusCode (Ydb .StatusIds_BAD_SESSION )),
144170 text : "operation/BAD_SESSION (code = 400100)" ,
145171 },
146172 {
173+ name : xtest .CurrentFileLine (),
147174 err : Operation (WithStatusCode (Ydb .StatusIds_PRECONDITION_FAILED ), WithIssues ([]* Ydb_Issue.IssueMessage {
148175 {
149176 Message : "issue one" ,
@@ -177,7 +204,7 @@ func Test_operationError_Error(t *testing.T) {
177204 text : "operation/PRECONDITION_FAILED (code = 400120, issues = [{15:3 => #1 'issue one'},{#2 'issue two' [{test.yql:16:4 => #3 'issue three'},{#4 'issue four'}]}])" , //nolint:lll
178205 },
179206 } {
180- t .Run ("" , func (t * testing.T ) {
207+ t .Run (tt . name , func (t * testing.T ) {
181208 require .Equal (t , tt .text , tt .err .Error ())
182209 })
183210 }
0 commit comments