MCPcopy
hub / github.com/grpc/grpc-go / StartClient

Method StartClient

internal/stubserver/stubserver.go:221–246  ·  view source on GitHub ↗

StartClient creates a client connected to this service that the test may use. The newly created client will be available in the Client field of StubServer.

(dopts ...grpc.DialOption)

Source from the content-addressed store, hash-verified

219// StartClient creates a client connected to this service that the test may use.
220// The newly created client will be available in the Client field of StubServer.
221func (ss *StubServer) StartClient(dopts ...grpc.DialOption) error {
222 opts := append([]grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}, dopts...)
223 if ss.R != nil {
224 ss.Target = ss.R.Scheme() + ":///" + ss.Address
225 opts = append(opts, grpc.WithResolvers(ss.R))
226 }
227
228 cc, err := grpc.NewClient(ss.Target, opts...)
229 if err != nil {
230 return fmt.Errorf("grpc.NewClient(%q) = %v", ss.Target, err)
231 }
232 cc.Connect()
233 ss.CC = cc
234 if ss.R != nil {
235 ss.R.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: ss.Address}}})
236 }
237 if err := waitForReady(cc); err != nil {
238 cc.Close()
239 return err
240 }
241
242 ss.cleanups = append(ss.cleanups, func() { cc.Close() })
243
244 ss.Client = testgrpc.NewTestServiceClient(cc)
245 return nil
246}
247
248// NewServiceConfig applies sc to ss.Client using the resolver (if present).
249func (ss *StubServer) NewServiceConfig(sc string) {

Calls 10

WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
WithResolversFunction · 0.92
NewClientFunction · 0.92
waitForReadyFunction · 0.85
SchemeMethod · 0.65
ErrorfMethod · 0.65
ConnectMethod · 0.65
UpdateStateMethod · 0.65
CloseMethod · 0.65