forked from streamingfast/dgrpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
30 lines (27 loc) · 809 Bytes
/
Copy patherrors_test.go
File metadata and controls
30 lines (27 loc) · 809 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
package dgrpc
import (
"errors"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func TestAsGRPCError(t *testing.T) {
tests := []struct {
name string
err error
want *status.Status
}{
{"nil", nil, nil},
{"not grpc status, direct level", errors.New("level 1"), nil},
{"not grpc status, second level", fmt.Errorf("level 1: %w", errors.New("level 2")), nil},
{"grpc status, direct level", status.Error(codes.Aborted, "err"), status.New(codes.Aborted, "err")},
{"grpc status, second level", fmt.Errorf("level 1: %w", status.Error(codes.Aborted, "err")), status.New(codes.Aborted, "err")},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, AsGRPCError(tt.err))
})
}
}