@@ -39,7 +39,7 @@ func TestError(t *testing.T) {
39
39
40
40
func TestErrWrapper_Extend (t * testing.T ) {
41
41
// create error context with some metadata
42
- errMeta := Metadata ( "k1" , "v1" )
42
+ errMeta := Metadata { "k1" , "v1" }
43
43
// extend the error context with additional metadata
44
44
extendedMetadata := errMeta .Extend ("k2" , "v2" )
45
45
// verify that the extended context contains both original and new metadata
@@ -50,15 +50,15 @@ func TestWithMetadata(t *testing.T) {
50
50
fooError := errors .New ("foo" )
51
51
testCases := []struct {
52
52
name string
53
- curMetadata errorMetadata
53
+ curMetadata Metadata
54
54
newMetadata []string
55
55
err error
56
56
expected * errWithMetadata
57
57
}{
58
58
{
59
59
name : "when error is nil" ,
60
60
err : nil ,
61
- curMetadata : errorMetadata {"k1" , "v1" },
61
+ curMetadata : Metadata {"k1" , "v1" },
62
62
newMetadata : []string {"k2" , "v2" },
63
63
expected : nil ,
64
64
},
@@ -75,7 +75,7 @@ func TestWithMetadata(t *testing.T) {
75
75
{
76
76
name : "when current metadata is empty" ,
77
77
err : fooError ,
78
- curMetadata : errorMetadata {},
78
+ curMetadata : Metadata {},
79
79
newMetadata : []string {"k2" , "v2" },
80
80
expected : & errWithMetadata {
81
81
err : fooError ,
@@ -85,7 +85,7 @@ func TestWithMetadata(t *testing.T) {
85
85
{
86
86
name : "when new metadata is nil" ,
87
87
err : fooError ,
88
- curMetadata : errorMetadata {"k1" , "v1" },
88
+ curMetadata : Metadata {"k1" , "v1" },
89
89
newMetadata : nil ,
90
90
expected : & errWithMetadata {
91
91
err : fooError ,
@@ -95,7 +95,7 @@ func TestWithMetadata(t *testing.T) {
95
95
{
96
96
name : "when new metadata is empty" ,
97
97
err : fooError ,
98
- curMetadata : errorMetadata {"k1" , "v1" },
98
+ curMetadata : Metadata {"k1" , "v1" },
99
99
newMetadata : []string {},
100
100
expected : & errWithMetadata {
101
101
err : fooError ,
@@ -115,7 +115,7 @@ func TestWithMetadata(t *testing.T) {
115
115
{
116
116
name : "when both current and new metadata are not empty" ,
117
117
err : fooError ,
118
- curMetadata : errorMetadata {"k1" , "v1" },
118
+ curMetadata : Metadata {"k1" , "v1" },
119
119
newMetadata : []string {"k2" , "v2" },
120
120
expected : & errWithMetadata {
121
121
err : fooError ,
@@ -125,7 +125,7 @@ func TestWithMetadata(t *testing.T) {
125
125
{
126
126
name : "when current metadata misses a value" ,
127
127
err : fooError ,
128
- curMetadata : errorMetadata {"k1" },
128
+ curMetadata : Metadata {"k1" },
129
129
newMetadata : []string {"k2" , "v2" },
130
130
expected : & errWithMetadata {
131
131
err : fooError ,
@@ -135,7 +135,7 @@ func TestWithMetadata(t *testing.T) {
135
135
{
136
136
name : "when new metadata misses a value" ,
137
137
err : fooError ,
138
- curMetadata : errorMetadata {"k1" , "v1" },
138
+ curMetadata : Metadata {"k1" , "v1" },
139
139
newMetadata : []string {"k2" },
140
140
expected : & errWithMetadata {
141
141
err : fooError ,
@@ -145,7 +145,7 @@ func TestWithMetadata(t *testing.T) {
145
145
{
146
146
name : "when both current and new metadata misses a value" ,
147
147
err : fooError ,
148
- curMetadata : errorMetadata {"k1" },
148
+ curMetadata : Metadata {"k1" },
149
149
newMetadata : []string {"k2" },
150
150
expected : & errWithMetadata {
151
151
err : fooError ,
@@ -155,7 +155,7 @@ func TestWithMetadata(t *testing.T) {
155
155
{
156
156
name : "when provided error is already wrapped with metadata" ,
157
157
err : WithMetadata (fooError , "k0" , "v0" ),
158
- curMetadata : errorMetadata {"k1" , "v1" },
158
+ curMetadata : Metadata {"k1" , "v1" },
159
159
newMetadata : []string {"k2" , "v2" },
160
160
expected : & errWithMetadata {
161
161
err : WithMetadata (fooError , "k0" , "v0" ),
@@ -165,7 +165,7 @@ func TestWithMetadata(t *testing.T) {
165
165
{
166
166
name : "when provided error is already wrapped with custom message" ,
167
167
err : fmt .Errorf ("bar: %w" , fooError ),
168
- curMetadata : errorMetadata {"k1" , "v1" },
168
+ curMetadata : Metadata {"k1" , "v1" },
169
169
newMetadata : []string {"k2" , "v2" },
170
170
expected : & errWithMetadata {
171
171
err : fmt .Errorf ("bar: %w" , fooError ),
@@ -299,103 +299,3 @@ func TestGetMetadata(t *testing.T) {
299
299
})
300
300
}
301
301
}
302
-
303
- func TestIsNonRetryableError (t * testing.T ) {
304
- testCases := []struct {
305
- name string
306
- err error
307
- isNonRetryable bool
308
- }{
309
- {
310
- name : "error without wrapping" ,
311
- err : errors .New ("foo" ),
312
- isNonRetryable : false ,
313
- },
314
- {
315
- name : "error wrapped with message" ,
316
- err : fmt .Errorf ("foo: %w" , errors .New ("bar" )),
317
- isNonRetryable : false ,
318
- },
319
- {
320
- name : "error wrapped with metadata" ,
321
- err : WithMetadata (errors .New ("foo" ), "key" , "value" ),
322
- isNonRetryable : false ,
323
- },
324
- {
325
- name : "non-retryable error wrapped with metadata" ,
326
- err : AsNonRetryableError (errors .New ("foo" ), "key" , "value" ),
327
- isNonRetryable : true ,
328
- },
329
- {
330
- name : "non-retryable error without wrapping" ,
331
- err : & nonRetryableError {err : errors .New ("foo" )},
332
- isNonRetryable : true ,
333
- },
334
- {
335
- name : "non-retryable error in the error chain" ,
336
- err : fmt .Errorf ("foo: %w" , & nonRetryableError {err : errors .New ("bar" )}),
337
- isNonRetryable : true ,
338
- },
339
- {
340
- name : "retryable error" ,
341
- err : & retryableError {err : errors .New ("foo" )},
342
- isNonRetryable : false ,
343
- },
344
- }
345
-
346
- for _ , tc := range testCases {
347
- t .Run (tc .name , func (t * testing.T ) {
348
- require .Equal (t , tc .isNonRetryable , IsNonRetryableError (tc .err ))
349
- })
350
- }
351
- }
352
-
353
- func TestIsRetryableError (t * testing.T ) {
354
- testCases := []struct {
355
- name string
356
- err error
357
- isRetryable bool
358
- }{
359
- {
360
- name : "error without wrapping" ,
361
- err : errors .New ("foo" ),
362
- isRetryable : false ,
363
- },
364
- {
365
- name : "error wrapped with message" ,
366
- err : fmt .Errorf ("foo: %w" , errors .New ("bar" )),
367
- isRetryable : false ,
368
- },
369
- {
370
- name : "error wrapped with metadata" ,
371
- err : WithMetadata (errors .New ("foo" ), "key" , "value" ),
372
- isRetryable : false ,
373
- },
374
- {
375
- name : "retryable error wrapped with metadata" ,
376
- err : AsRetryableError (errors .New ("foo" ), "key" , "value" ),
377
- isRetryable : true ,
378
- },
379
- {
380
- name : "retryable error without wrapping" ,
381
- err : & retryableError {err : errors .New ("foo" )},
382
- isRetryable : true ,
383
- },
384
- {
385
- name : "retryable error in the error chain" ,
386
- err : fmt .Errorf ("foo: %w" , & retryableError {err : errors .New ("bar" )}),
387
- isRetryable : true ,
388
- },
389
- {
390
- name : "non-retryable error" ,
391
- err : & nonRetryableError {err : errors .New ("foo" )},
392
- isRetryable : false ,
393
- },
394
- }
395
-
396
- for _ , tc := range testCases {
397
- t .Run (tc .name , func (t * testing.T ) {
398
- require .Equal (t , tc .isRetryable , IsRetryableError (tc .err ))
399
- })
400
- }
401
- }
0 commit comments