TestClientHandshakeInfoDialer adds attributes to the resolver.Address passes to NewHTTP2Client and verifies that these attributes are received by a custom dialer.
(t *testing.T)
| 2735 | // NewHTTP2Client and verifies that these attributes are received by a custom |
| 2736 | // dialer. |
| 2737 | func (s) TestClientHandshakeInfoDialer(t *testing.T) { |
| 2738 | server := setUpServerOnly(t, 0, &ServerConfig{BufferPool: mem.DefaultBufferPool()}, pingpong) |
| 2739 | defer server.stop() |
| 2740 | |
| 2741 | const ( |
| 2742 | testAttrKey = "foo" |
| 2743 | testAttrVal = "bar" |
| 2744 | ) |
| 2745 | addr := resolver.Address{ |
| 2746 | Addr: "localhost:" + server.port, |
| 2747 | Attributes: attributes.New(testAttrKey, testAttrVal), |
| 2748 | } |
| 2749 | ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) |
| 2750 | defer cancel() |
| 2751 | |
| 2752 | var attr *attributes.Attributes |
| 2753 | dialer := func(ctx context.Context, addr string) (net.Conn, error) { |
| 2754 | ai := credentials.ClientHandshakeInfoFromContext(ctx) |
| 2755 | attr = ai.Attributes |
| 2756 | return (&net.Dialer{}).DialContext(ctx, "tcp", addr) |
| 2757 | } |
| 2758 | |
| 2759 | copts := ConnectOptions{ |
| 2760 | Dialer: dialer, |
| 2761 | ChannelzParent: channelzSubChannel(t), |
| 2762 | BufferPool: mem.DefaultBufferPool(), |
| 2763 | } |
| 2764 | tr, err := NewHTTP2Client(ctx, ctx, addr, copts, func(GoAwayInfo) {}) |
| 2765 | if err != nil { |
| 2766 | t.Fatalf("NewHTTP2Client(): %v", err) |
| 2767 | } |
| 2768 | defer tr.Close(fmt.Errorf("closed manually by test")) |
| 2769 | |
| 2770 | wantAttr := attributes.New(testAttrKey, testAttrVal) |
| 2771 | if gotAttr := attr; !cmp.Equal(gotAttr, wantAttr, cmp.AllowUnexported(attributes.Attributes{})) { |
| 2772 | t.Errorf("Received attributes %v in custom dialer, want %v", gotAttr, wantAttr) |
| 2773 | } |
| 2774 | } |
| 2775 | |
| 2776 | func newTestClientStream() *ClientStream { |
| 2777 | return &ClientStream{ |
nothing calls this directly
no test coverage detected