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

Function xdsChannelForTest

internal/xds/clients/xdsclient/channel_test.go:53–88  ·  view source on GitHub ↗

xdsChannelForTest creates an xdsChannel to the specified serverURI for testing purposes.

(t *testing.T, serverURI, nodeID string, watchExpiryTimeout time.Duration)

Source from the content-addressed store, hash-verified

51// xdsChannelForTest creates an xdsChannel to the specified serverURI for
52// testing purposes.
53func xdsChannelForTest(t *testing.T, serverURI, nodeID string, watchExpiryTimeout time.Duration) *xdsChannel {
54 t.Helper()
55
56 // Create a grpc transport to the above management server.
57 si := clients.ServerIdentifier{
58 ServerURI: serverURI,
59 Extensions: grpctransport.ServerIdentifierExtension{ConfigName: "insecure"},
60 }
61 configs := map[string]grpctransport.Config{"insecure": {Credentials: insecure.NewBundle()}}
62 tr, err := (grpctransport.NewBuilder(configs)).Build(si)
63 if err != nil {
64 t.Fatalf("Failed to create a transport for server config %v: %v", si, err)
65 }
66
67 serverCfg := ServerConfig{
68 ServerIdentifier: si,
69 }
70 clientConfig := Config{
71 Servers: []ServerConfig{serverCfg},
72 Node: clients.Node{ID: nodeID},
73 ResourceTypes: map[string]ResourceType{xdsresource.V3ListenerURL: listenerType},
74 }
75 // Create an xdsChannel that uses everything set up above.
76 xc, err := newXDSChannel(xdsChannelOpts{
77 transport: tr,
78 serverConfig: &serverCfg,
79 clientConfig: &clientConfig,
80 eventHandler: newTestEventHandler(),
81 watchExpiryTimeout: watchExpiryTimeout,
82 })
83 if err != nil {
84 t.Fatalf("Failed to create xdsChannel: %v", err)
85 }
86 t.Cleanup(func() { xc.close() })
87 return xc
88}
89
90// verifyUpdateAndMetadata verifies that the event handler received the expected
91// updates and metadata. It checks that the received resource type matches the

Calls 7

NewBundleFunction · 0.92
NewBuilderFunction · 0.92
newXDSChannelFunction · 0.85
newTestEventHandlerFunction · 0.85
BuildMethod · 0.65
FatalfMethod · 0.65
closeMethod · 0.45

Tested by

no test coverage detected