-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassthrough_test.go
More file actions
96 lines (85 loc) · 2.78 KB
/
Copy pathpassthrough_test.go
File metadata and controls
96 lines (85 loc) · 2.78 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package errors
import (
"context"
"testing"
assert "github.com/stretchr/testify/assert"
status "google.golang.org/grpc/status"
)
func TestNewPassthroughError(t *testing.T) {
var tests = []struct {
msg string
err error
exp error
}{
{
msg: "foo",
err: context.Canceled,
exp: NewCanceledError("foo", context.Canceled),
},
{
msg: "foo",
err: NewCanceledError("bar"),
exp: NewCanceledError("foo", NewCanceledError("bar")),
},
{
msg: "foo",
err: context.DeadlineExceeded,
exp: NewDeadlineExceededError("foo", context.DeadlineExceeded),
},
{
msg: "foo",
err: NewDeadlineExceededError("bar"),
exp: NewDeadlineExceededError("foo", NewDeadlineExceededError("bar")),
},
{
msg: "foo",
err: NewUnavailableError("bar"),
exp: NewUnavailableError("foo", NewUnavailableError("bar")),
},
{
msg: "foo",
err: NewUnknownError("bar"),
exp: NewUnknownError("foo", NewUnknownError("bar")),
},
{
msg: "foo",
err: NewInternalError("bar"),
exp: NewInternalError("foo", NewInternalError("bar")),
},
}
for _, test := range tests {
SetVerbosity(Info)
res := NewPassthroughError(test.msg, test.err)
resError, _ := res.(interface{ Error() string })
resTimeout, _ := res.(interface{ Timeout() bool })
resTemporary, _ := res.(interface{ Temporary() bool })
resGetCode, _ := res.(interface{ GetCode() int })
resGetMessage, _ := res.(interface{ GetMessage() string })
resGetCause, _ := res.(interface{ GetCause() error })
resGetStack, _ := res.(interface{ GetStack() stack })
resGRPCStatus, _ := res.(interface{ GRPCStatus() *(status.Status) })
expError, _ := test.exp.(interface{ Error() string })
expTimeout, _ := test.exp.(interface{ Timeout() bool })
expTemporary, _ := test.exp.(interface{ Temporary() bool })
expGetCode, _ := test.exp.(interface{ GetCode() int })
expGetMessage, _ := test.exp.(interface{ GetMessage() string })
expGetCause, _ := test.exp.(interface{ GetCause() error })
expGRPCStatus, _ := test.exp.(interface{ GRPCStatus() *(status.Status) })
assert.Equal(t, resError.Error(), expError.Error())
assert.Equal(t, resTimeout.Timeout(), expTimeout.Timeout())
assert.Equal(t, resTemporary.Temporary(), expTemporary.Temporary())
assert.Equal(t, resGetCode.GetCode(), expGetCode.GetCode())
assert.Equal(t, resGetMessage.GetMessage(), expGetMessage.GetMessage())
if resGetCause.GetCause() == nil {
assert.Nil(t, expGetCause.GetCause())
} else {
assert.Equal(t, resGetCause.GetCause().Error(), expGetCause.GetCause().Error())
}
// trace output prevents testing for string match in different contexts
assert.NotNil(t, resGetStack.GetStack())
r := resGRPCStatus.GRPCStatus()
e := expGRPCStatus.GRPCStatus()
assert.Equal(t, r.Code(), e.Code())
assert.Equal(t, r.Message(), e.Message())
}
}