Skip to content

Commit 8da3e23

Browse files
authored
status: modify TestStatus_ErrorDetails_Fail to replace protoimpl package (#6953)
1 parent a3f5ed6 commit 8da3e23

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

status/status_test.go

+28-19
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"google.golang.org/protobuf/proto"
3232
"google.golang.org/protobuf/protoadapt"
3333
"google.golang.org/protobuf/reflect/protoreflect"
34-
"google.golang.org/protobuf/runtime/protoimpl"
3534
"google.golang.org/protobuf/types/known/anypb"
3635
"google.golang.org/protobuf/types/known/durationpb"
3736

@@ -378,23 +377,23 @@ func (s) TestStatus_WithDetails_Fail(t *testing.T) {
378377

379378
func (s) TestStatus_ErrorDetails_Fail(t *testing.T) {
380379
tests := []struct {
381-
s *Status
382-
i []any
380+
s *Status
381+
want []any
383382
}{
384383
{
385-
nil,
386-
nil,
384+
s: nil,
385+
want: nil,
387386
},
388387
{
389-
FromProto(nil),
390-
nil,
388+
s: FromProto(nil),
389+
want: nil,
391390
},
392391
{
393-
New(codes.OK, ""),
394-
[]any{},
392+
s: New(codes.OK, ""),
393+
want: []any{},
395394
},
396395
{
397-
FromProto(&spb.Status{
396+
s: FromProto(&spb.Status{
398397
Code: int32(cpb.Code_CANCELLED),
399398
Details: []*anypb.Any{
400399
{
@@ -408,8 +407,8 @@ func (s) TestStatus_ErrorDetails_Fail(t *testing.T) {
408407
}),
409408
},
410409
}),
411-
[]any{
412-
protoimpl.X.NewError("invalid empty type URL"),
410+
want: []any{
411+
errors.New("invalid empty type URL"),
413412
&epb.ResourceInfo{
414413
ResourceType: "book",
415414
ResourceName: "projects/1234/books/5678",
@@ -419,17 +418,27 @@ func (s) TestStatus_ErrorDetails_Fail(t *testing.T) {
419418
},
420419
}
421420
for _, tc := range tests {
422-
got := tc.s.Details()
423-
if !cmp.Equal(got, tc.i, cmp.Comparer(proto.Equal), cmp.Comparer(equalError)) {
424-
t.Errorf("(%v).Details() = %+v, want %+v", str(tc.s), got, tc.i)
421+
details := tc.s.Details()
422+
if len(details) != len(tc.want) {
423+
t.Fatalf("len(s.Details()) = %v, want = %v.", len(details), len(tc.want))
424+
}
425+
for i, d := range details {
426+
// s.Details can either contain an error or a proto message. We
427+
// want to do a compare the proto message for an Equal match, and
428+
// for errors only check for presence.
429+
if _, ok := d.(error); ok {
430+
if (d != nil) != (tc.want[i] != nil) {
431+
t.Fatalf("s.Details()[%v] was %v; want %v", i, d, tc.want[i])
432+
}
433+
continue
434+
}
435+
if !cmp.Equal(d, tc.want[i], cmp.Comparer(proto.Equal)) {
436+
t.Fatalf("s.Details()[%v] was %v; want %v", i, d, tc.want[i])
437+
}
425438
}
426439
}
427440
}
428441

429-
func equalError(x, y error) bool {
430-
return x == y || (x != nil && y != nil && x.Error() == y.Error())
431-
}
432-
433442
func str(s *Status) string {
434443
if s == nil {
435444
return "nil"

0 commit comments

Comments
 (0)