...
1
18
19 package testutils
20
21 import (
22 "testing"
23
24 spb "google.golang.org/genproto/googleapis/rpc/status"
25 "google.golang.org/grpc/codes"
26 "google.golang.org/grpc/internal/grpctest"
27 "google.golang.org/grpc/status"
28 "google.golang.org/protobuf/types/known/anypb"
29 )
30
31 type s struct {
32 grpctest.Tester
33 }
34
35 func Test(t *testing.T) {
36 grpctest.RunSubTests(t, s{})
37 }
38
39 var statusErr = status.ErrorProto(&spb.Status{
40 Code: int32(codes.DataLoss),
41 Message: "error for testing",
42 Details: []*anypb.Any{{
43 TypeUrl: "url",
44 Value: []byte{6, 0, 0, 6, 1, 3},
45 }},
46 })
47
48 func (s) TestStatusErrEqual(t *testing.T) {
49 tests := []struct {
50 name string
51 err1 error
52 err2 error
53 wantEqual bool
54 }{
55 {"nil errors", nil, nil, true},
56 {"equal OK status", status.New(codes.OK, "").Err(), status.New(codes.OK, "").Err(), true},
57 {"equal status errors", statusErr, statusErr, true},
58 {"different status errors", statusErr, status.New(codes.OK, "").Err(), false},
59 }
60
61 for _, test := range tests {
62 if gotEqual := StatusErrEqual(test.err1, test.err2); gotEqual != test.wantEqual {
63 t.Errorf("%v: StatusErrEqual(%v, %v) = %v, want %v", test.name, test.err1, test.err2, gotEqual, test.wantEqual)
64 }
65 }
66 }
67
View as plain text