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

Method TestClientHandshakeInfo

internal/transport/transport_test.go:2701–2732  ·  view source on GitHub ↗

TestClientHandshakeInfo adds attributes to the resolver.Address passes to NewHTTP2Client and verifies that these attributes are received by the transport credential handshaker.

(t *testing.T)

Source from the content-addressed store, hash-verified

2699// NewHTTP2Client and verifies that these attributes are received by the
2700// transport credential handshaker.
2701func (s) TestClientHandshakeInfo(t *testing.T) {
2702 server := setUpServerOnly(t, 0, &ServerConfig{BufferPool: mem.DefaultBufferPool()}, pingpong)
2703 defer server.stop()
2704
2705 const (
2706 testAttrKey = "foo"
2707 testAttrVal = "bar"
2708 )
2709 addr := resolver.Address{
2710 Addr: "localhost:" + server.port,
2711 Attributes: attributes.New(testAttrKey, testAttrVal),
2712 }
2713 ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
2714 defer cancel()
2715 creds := &attrTransportCreds{}
2716
2717 copts := ConnectOptions{
2718 TransportCredentials: creds,
2719 ChannelzParent: channelzSubChannel(t),
2720 BufferPool: mem.DefaultBufferPool(),
2721 }
2722 tr, err := NewHTTP2Client(ctx, ctx, addr, copts, func(GoAwayInfo) {})
2723 if err != nil {
2724 t.Fatalf("NewHTTP2Client(): %v", err)
2725 }
2726 defer tr.Close(fmt.Errorf("closed manually by test"))
2727
2728 wantAttr := attributes.New(testAttrKey, testAttrVal)
2729 if gotAttr := creds.attr; !cmp.Equal(gotAttr, wantAttr, cmp.AllowUnexported(attributes.Attributes{})) {
2730 t.Fatalf("received attributes %v in creds, want %v", gotAttr, wantAttr)
2731 }
2732}
2733
2734// TestClientHandshakeInfoDialer adds attributes to the resolver.Address passes to
2735// NewHTTP2Client and verifies that these attributes are received by a custom

Callers

nothing calls this directly

Calls 10

DefaultBufferPoolFunction · 0.92
NewFunction · 0.92
setUpServerOnlyFunction · 0.85
channelzSubChannelFunction · 0.85
NewHTTP2ClientFunction · 0.85
stopMethod · 0.65
FatalfMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected