-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
45 lines (40 loc) · 972 Bytes
/
errors_test.go
File metadata and controls
45 lines (40 loc) · 972 Bytes
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
package errors
import (
"io"
"testing"
grpcstatus "google.golang.org/grpc/status"
)
func TestWrap(t *testing.T) {
var tests = []struct {
name string
err error
message string
expected string
}{
{
"original error is wrapped",
io.EOF,
"read error",
"read error: EOF",
},
{
"wrapping a wrapped error results in an error wrapped twice",
Wrap(io.EOF, "read error"),
"client error",
"client error: read error: EOF",
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
err := Wrap(tt.err, tt.message)
if err.Error() != tt.expected {
t.Errorf("(%+v, %+v): expected %+v, got %+v", tt.err, tt.message, tt.expected, err)
}
// ensure GRPC status msg has wrapped content no matter you wrap how many times
if grpcstatus.Convert(err).Message() != tt.expected {
t.Errorf("GRPC status msg expected %+v, got %+v", tt.expected, grpcstatus.Convert(err).Message())
}
})
}
}