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

Method TestGet

internal/proxyattributes/proxyattributes_test.go:39–93  ·  view source on GitHub ↗

Tests that Get returns a valid proxy attribute.

(t *testing.T)

Source from the content-addressed store, hash-verified

37
38// Tests that Get returns a valid proxy attribute.
39func (s) TestGet(t *testing.T) {
40 user := url.UserPassword("username", "password")
41 tests := []struct {
42 name string
43 addr resolver.Address
44 wantConnectAddr string
45 wantUser *url.Userinfo
46 wantAttrPresent bool
47 }{
48 {
49 name: "connect_address_in_attribute",
50 addr: resolver.Address{
51 Addr: "test-address",
52 Attributes: attributes.New(proxyOptionsKey, Options{
53 ConnectAddr: "proxy-address",
54 }),
55 },
56 wantConnectAddr: "proxy-address",
57 wantAttrPresent: true,
58 },
59 {
60 name: "user_in_attribute",
61 addr: resolver.Address{
62 Addr: "test-address",
63 Attributes: attributes.New(proxyOptionsKey, Options{
64 User: user,
65 }),
66 },
67 wantUser: user,
68 wantAttrPresent: true,
69 },
70 {
71 name: "no_attribute",
72 addr: resolver.Address{Addr: "test-address"},
73 wantAttrPresent: false,
74 },
75 }
76
77 for _, tt := range tests {
78 t.Run(tt.name, func(t *testing.T) {
79 gotOption, attrPresent := Get(tt.addr)
80 if attrPresent != tt.wantAttrPresent {
81 t.Errorf("Get(%v) = %v, want %v", tt.addr, attrPresent, tt.wantAttrPresent)
82 }
83
84 if gotOption.ConnectAddr != tt.wantConnectAddr {
85 t.Errorf("ConnectAddr(%v) = %v, want %v", tt.addr, gotOption.ConnectAddr, tt.wantConnectAddr)
86 }
87
88 if gotOption.User != tt.wantUser {
89 t.Errorf("User(%v) = %v, want %v", tt.addr, gotOption.User, tt.wantUser)
90 }
91 })
92 }
93}
94
95// Tests that Set returns a copy of addr with attributes containing correct
96// user and connect address.

Callers

nothing calls this directly

Calls 3

NewFunction · 0.92
GetFunction · 0.70
ErrorfMethod · 0.65

Tested by

no test coverage detected