@@ -7,24 +7,30 @@ import (
7
7
"github.com/stretchr/testify/require"
8
8
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
9
9
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Issue"
10
+
11
+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest"
10
12
)
11
13
12
14
func TestIsOperationError (t * testing.T ) {
13
15
for _ , tt := range []struct {
16
+ name string
14
17
err error
15
18
codes []Ydb.StatusIds_StatusCode
16
19
match bool
17
20
}{
18
21
// check only operation error with any ydb status code
19
22
{
23
+ name : xtest .CurrentFileLine (),
20
24
err : & operationError {code : Ydb .StatusIds_BAD_REQUEST },
21
25
match : true ,
22
26
},
23
27
{
28
+ name : xtest .CurrentFileLine (),
24
29
err : fmt .Errorf ("wrapped: %w" , & operationError {code : Ydb .StatusIds_BAD_REQUEST }),
25
30
match : true ,
26
31
},
27
32
{
33
+ name : xtest .CurrentFileLine (),
28
34
err : Join (
29
35
fmt .Errorf ("test" ),
30
36
& operationError {code : Ydb .StatusIds_BAD_REQUEST },
@@ -34,16 +40,19 @@ func TestIsOperationError(t *testing.T) {
34
40
},
35
41
// match ydb status code
36
42
{
43
+ name : xtest .CurrentFileLine (),
37
44
err : & operationError {code : Ydb .StatusIds_BAD_REQUEST },
38
45
codes : []Ydb.StatusIds_StatusCode {Ydb .StatusIds_BAD_REQUEST },
39
46
match : true ,
40
47
},
41
48
{
49
+ name : xtest .CurrentFileLine (),
42
50
err : fmt .Errorf ("wrapped: %w" , & operationError {code : Ydb .StatusIds_BAD_REQUEST }),
43
51
codes : []Ydb.StatusIds_StatusCode {Ydb .StatusIds_BAD_REQUEST },
44
52
match : true ,
45
53
},
46
54
{
55
+ name : xtest .CurrentFileLine (),
47
56
err : Join (
48
57
fmt .Errorf ("test" ),
49
58
& operationError {code : Ydb .StatusIds_BAD_REQUEST },
@@ -54,16 +63,19 @@ func TestIsOperationError(t *testing.T) {
54
63
},
55
64
// no match ydb status code
56
65
{
66
+ name : xtest .CurrentFileLine (),
57
67
err : & operationError {code : Ydb .StatusIds_BAD_REQUEST },
58
68
codes : []Ydb.StatusIds_StatusCode {Ydb .StatusIds_ABORTED },
59
69
match : false ,
60
70
},
61
71
{
72
+ name : xtest .CurrentFileLine (),
62
73
err : fmt .Errorf ("wrapped: %w" , & operationError {code : Ydb .StatusIds_BAD_REQUEST }),
63
74
codes : []Ydb.StatusIds_StatusCode {Ydb .StatusIds_ABORTED },
64
75
match : false ,
65
76
},
66
77
{
78
+ name : xtest .CurrentFileLine (),
67
79
err : Join (
68
80
fmt .Errorf ("test" ),
69
81
& operationError {code : Ydb .StatusIds_BAD_REQUEST },
@@ -73,18 +85,20 @@ func TestIsOperationError(t *testing.T) {
73
85
match : false ,
74
86
},
75
87
} {
76
- t .Run ("" , func (t * testing.T ) {
88
+ t .Run (tt . name , func (t * testing.T ) {
77
89
require .Equal (t , tt .match , IsOperationError (tt .err , tt .codes ... ))
78
90
})
79
91
}
80
92
}
81
93
82
94
func TestIsOperationErrorTransactionLocksInvalidated (t * testing.T ) {
83
95
for _ , tt := range [... ]struct {
96
+ name string
84
97
err error
85
98
isTLI bool
86
99
}{
87
100
{
101
+ name : xtest .CurrentFileLine (),
88
102
err : Operation (
89
103
WithStatusCode (Ydb .StatusIds_ABORTED ),
90
104
WithIssues ([]* Ydb_Issue.IssueMessage {{
@@ -94,6 +108,7 @@ func TestIsOperationErrorTransactionLocksInvalidated(t *testing.T) {
94
108
isTLI : true ,
95
109
},
96
110
{
111
+ name : xtest .CurrentFileLine (),
97
112
err : Operation (
98
113
WithStatusCode (Ydb .StatusIds_OVERLOADED ),
99
114
WithIssues ([]* Ydb_Issue.IssueMessage {{
@@ -103,12 +118,14 @@ func TestIsOperationErrorTransactionLocksInvalidated(t *testing.T) {
103
118
isTLI : false ,
104
119
},
105
120
{
121
+ name : xtest .CurrentFileLine (),
106
122
err : Operation (
107
123
WithStatusCode (Ydb .StatusIds_ABORTED ),
108
124
),
109
125
isTLI : false ,
110
126
},
111
127
{
128
+ name : xtest .CurrentFileLine (),
112
129
err : Operation (
113
130
WithStatusCode (Ydb .StatusIds_ABORTED ),
114
131
WithIssues ([]* Ydb_Issue.IssueMessage {{
@@ -120,30 +137,40 @@ func TestIsOperationErrorTransactionLocksInvalidated(t *testing.T) {
120
137
isTLI : true ,
121
138
},
122
139
} {
123
- t .Run ("" , func (t * testing.T ) {
140
+ t .Run (tt . name , func (t * testing.T ) {
124
141
require .Equal (t , tt .isTLI , IsOperationErrorTransactionLocksInvalidated (tt .err ))
125
142
})
126
143
}
127
144
}
128
145
129
146
func Test_operationError_Error (t * testing.T ) {
130
147
for _ , tt := range []struct {
148
+ name string
131
149
err error
132
150
text string
133
151
}{
134
152
{
153
+ name : xtest .CurrentFileLine (),
135
154
err : Operation (WithStatusCode (Ydb .StatusIds_BAD_REQUEST ), WithAddress ("localhost" )),
136
155
text : "operation/BAD_REQUEST (code = 400010, address = localhost)" ,
137
156
},
138
157
{
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 (),
139
164
err : Operation (WithStatusCode (Ydb .StatusIds_BAD_REQUEST )),
140
165
text : "operation/BAD_REQUEST (code = 400010)" ,
141
166
},
142
167
{
168
+ name : xtest .CurrentFileLine (),
143
169
err : Operation (WithStatusCode (Ydb .StatusIds_BAD_SESSION )),
144
170
text : "operation/BAD_SESSION (code = 400100)" ,
145
171
},
146
172
{
173
+ name : xtest .CurrentFileLine (),
147
174
err : Operation (WithStatusCode (Ydb .StatusIds_PRECONDITION_FAILED ), WithIssues ([]* Ydb_Issue.IssueMessage {
148
175
{
149
176
Message : "issue one" ,
@@ -177,7 +204,7 @@ func Test_operationError_Error(t *testing.T) {
177
204
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
178
205
},
179
206
} {
180
- t .Run ("" , func (t * testing.T ) {
207
+ t .Run (tt . name , func (t * testing.T ) {
181
208
require .Equal (t , tt .text , tt .err .Error ())
182
209
})
183
210
}
0 commit comments