@@ -31,7 +31,6 @@ import (
31
31
"google.golang.org/protobuf/proto"
32
32
"google.golang.org/protobuf/protoadapt"
33
33
"google.golang.org/protobuf/reflect/protoreflect"
34
- "google.golang.org/protobuf/runtime/protoimpl"
35
34
"google.golang.org/protobuf/types/known/anypb"
36
35
"google.golang.org/protobuf/types/known/durationpb"
37
36
@@ -378,23 +377,23 @@ func (s) TestStatus_WithDetails_Fail(t *testing.T) {
378
377
379
378
func (s ) TestStatus_ErrorDetails_Fail (t * testing.T ) {
380
379
tests := []struct {
381
- s * Status
382
- i []any
380
+ s * Status
381
+ want []any
383
382
}{
384
383
{
385
- nil ,
386
- nil ,
384
+ s : nil ,
385
+ want : nil ,
387
386
},
388
387
{
389
- FromProto (nil ),
390
- nil ,
388
+ s : FromProto (nil ),
389
+ want : nil ,
391
390
},
392
391
{
393
- New (codes .OK , "" ),
394
- []any {},
392
+ s : New (codes .OK , "" ),
393
+ want : []any {},
395
394
},
396
395
{
397
- FromProto (& spb.Status {
396
+ s : FromProto (& spb.Status {
398
397
Code : int32 (cpb .Code_CANCELLED ),
399
398
Details : []* anypb.Any {
400
399
{
@@ -408,8 +407,8 @@ func (s) TestStatus_ErrorDetails_Fail(t *testing.T) {
408
407
}),
409
408
},
410
409
}),
411
- []any {
412
- protoimpl . X . NewError ("invalid empty type URL" ),
410
+ want : []any {
411
+ errors . New ("invalid empty type URL" ),
413
412
& epb.ResourceInfo {
414
413
ResourceType : "book" ,
415
414
ResourceName : "projects/1234/books/5678" ,
@@ -419,17 +418,27 @@ func (s) TestStatus_ErrorDetails_Fail(t *testing.T) {
419
418
},
420
419
}
421
420
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
+ }
425
438
}
426
439
}
427
440
}
428
441
429
- func equalError (x , y error ) bool {
430
- return x == y || (x != nil && y != nil && x .Error () == y .Error ())
431
- }
432
-
433
442
func str (s * Status ) string {
434
443
if s == nil {
435
444
return "nil"
0 commit comments