@@ -28,15 +28,17 @@ package service
2828
2929import (
3030 "context"
31- "reflect"
3231 "strconv"
3332 "testing"
3433
3534 "github.com/golang/protobuf/ptypes"
3635 durpb "github.com/golang/protobuf/ptypes/duration"
36+ "github.com/google/go-cmp/cmp"
37+ "github.com/google/go-cmp/cmp/cmpopts"
3738 "golang.org/x/sys/unix"
3839 channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
3940 "google.golang.org/grpc/internal/channelz"
41+ "google.golang.org/protobuf/testing/protocmp"
4042)
4143
4244func init () {
@@ -139,20 +141,27 @@ func (s) TestGetSocketOptions(t *testing.T) {
139141 },
140142 }
141143 svr := newCZServer ()
142- ids := make ([]int64 , len (ss ))
144+ ids := make ([]* channelz. Identifier , len (ss ))
143145 svrID := channelz .RegisterServer (& dummyServer {}, "" )
144146 defer channelz .RemoveEntry (svrID )
145147 for i , s := range ss {
146- ids [i ] = channelz .RegisterNormalSocket (s , svrID , strconv .Itoa (i ))
148+ ids [i ], _ = channelz .RegisterNormalSocket (s , svrID , strconv .Itoa (i ))
147149 defer channelz .RemoveEntry (ids [i ])
148150 }
149151 ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
150152 defer cancel ()
151153 for i , s := range ss {
152- resp , _ := svr .GetSocket (ctx , & channelzpb.GetSocketRequest {SocketId : ids [i ]})
153- metrics := resp .GetSocket ()
154- if ! reflect .DeepEqual (metrics .GetRef (), & channelzpb.SocketRef {SocketId : ids [i ], Name : strconv .Itoa (i )}) || ! reflect .DeepEqual (socketProtoToStruct (metrics ), s ) {
155- t .Fatalf ("resp.GetSocket() want: metrics.GetRef() = %#v and %#v, got: metrics.GetRef() = %#v and %#v" , & channelzpb.SocketRef {SocketId : ids [i ], Name : strconv .Itoa (i )}, s , metrics .GetRef (), socketProtoToStruct (metrics ))
154+ resp , _ := svr .GetSocket (ctx , & channelzpb.GetSocketRequest {SocketId : ids [i ].Int ()})
155+ got , want := resp .GetSocket ().GetRef (), & channelzpb.SocketRef {SocketId : ids [i ].Int (), Name : strconv .Itoa (i )}
156+ if ! cmp .Equal (got , want , cmpopts .IgnoreUnexported (channelzpb.SocketRef {})) {
157+ t .Fatalf ("resp.GetSocket() returned metrics.GetRef() = %#v, want %#v" , got , want )
158+ }
159+ socket , err := socketProtoToStruct (resp .GetSocket ())
160+ if err != nil {
161+ t .Fatal (err )
162+ }
163+ if diff := cmp .Diff (s , socket , protocmp .Transform (), cmp .AllowUnexported (dummySocket {})); diff != "" {
164+ t .Fatalf ("unexpected socket, diff (-want +got):\n %s" , diff )
156165 }
157166 }
158167}
0 commit comments