-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgrpc_test.go
78 lines (72 loc) · 1.94 KB
/
grpc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package ydb
import (
"context"
"errors"
"fmt"
"testing"
)
func TestIsTransportError(t *testing.T) {
code := TransportErrorCanceled
for _, err := range []error{
&TransportError{Reason: code},
&TransportError{Reason: code, err: context.Canceled},
fmt.Errorf("wrapped: %w", &TransportError{Reason: code}),
} {
t.Run("", func(t *testing.T) {
if !IsTransportError(err, code) {
t.Errorf("expected %v to be TransportError with code=%v", err, code)
}
})
}
}
func TestIsNotTransportError(t *testing.T) {
code := TransportErrorCanceled
for _, err := range []error{
&TransportError{Reason: TransportErrorAborted},
&TransportError{Reason: TransportErrorAborted, err: context.Canceled},
fmt.Errorf("wrapped: %w", &TransportError{Reason: TransportErrorAborted}),
&OpError{Reason: StatusBadRequest},
} {
t.Run("", func(t *testing.T) {
if IsTransportError(err, code) {
t.Errorf("expected %v not to be TransportError with code=%v", err, code)
}
})
}
}
func TestTransportErrorWrapsContextError(t *testing.T) {
err := fmt.Errorf("wrapped: %w", &TransportError{
Reason: TransportErrorCanceled,
err: context.Canceled,
})
if !errors.Is(err, context.Canceled) {
t.Errorf("expected %v to wrap context.Canceled", err)
}
}
func TestIsOpError(t *testing.T) {
code := StatusBadRequest
for _, err := range []error{
&OpError{Reason: code},
fmt.Errorf("wrapped: %w", &OpError{Reason: code}),
} {
t.Run("", func(t *testing.T) {
if !IsOpError(err, code) {
t.Errorf("expected %v to be OpError with code=%v", err, code)
}
})
}
}
func TestIsNotOpError(t *testing.T) {
code := StatusBadRequest
for _, err := range []error{
&OpError{Reason: StatusTimeout},
fmt.Errorf("wrapped: %w", &OpError{Reason: StatusTimeout}),
&TransportError{Reason: TransportErrorAborted},
} {
t.Run("", func(t *testing.T) {
if IsOpError(err, code) {
t.Errorf("expected %v not to be OpError with code=%v", err, code)
}
})
}
}