@@ -26,126 +26,126 @@ import (
2626 "google.golang.org/grpc/resolver"
2727)
2828
29- func TestGet (t * testing.T ) {
29+ func TestFromEndpoint (t * testing.T ) {
3030 tests := []struct {
3131 name string
32- addr resolver.Address
32+ ep resolver.Endpoint
3333 want []string
3434 }{
3535 {
3636 name : "not set" ,
37- addr : resolver.Address {},
37+ ep : resolver.Endpoint {},
3838 want : nil ,
3939 },
4040 {
4141 name : "set" ,
42- addr : resolver.Address {
43- BalancerAttributes : attributes .New (pathKey , pathValue {"a" , "b" }),
42+ ep : resolver.Endpoint {
43+ Attributes : attributes .New (pathKey , pathValue {"a" , "b" }),
4444 },
4545 want : []string {"a" , "b" },
4646 },
4747 }
4848 for _ , tt := range tests {
4949 t .Run (tt .name , func (t * testing.T ) {
50- if got := Get (tt .addr ); ! cmp .Equal (got , tt .want ) {
51- t .Errorf ("Get () = %v, want %v" , got , tt .want )
50+ if got := FromEndpoint (tt .ep ); ! cmp .Equal (got , tt .want ) {
51+ t .Errorf ("FromEndpoint () = %v, want %v" , got , tt .want )
5252 }
5353 })
5454 }
5555}
5656
57- func TestSet (t * testing.T ) {
57+ func TestSetInEndpoint (t * testing.T ) {
5858 tests := []struct {
5959 name string
60- addr resolver.Address
60+ ep resolver.Endpoint
6161 path []string
6262 }{
6363 {
6464 name : "before is not set" ,
65- addr : resolver.Address {},
65+ ep : resolver.Endpoint {},
6666 path : []string {"a" , "b" },
6767 },
6868 {
6969 name : "before is set" ,
70- addr : resolver.Address {
71- BalancerAttributes : attributes .New (pathKey , pathValue {"before" , "a" , "b" }),
70+ ep : resolver.Endpoint {
71+ Attributes : attributes .New (pathKey , pathValue {"before" , "a" , "b" }),
7272 },
7373 path : []string {"a" , "b" },
7474 },
7575 }
7676 for _ , tt := range tests {
7777 t .Run (tt .name , func (t * testing.T ) {
78- newAddr := Set (tt .addr , tt .path )
79- newPath := Get ( newAddr )
78+ newEP := SetInEndpoint (tt .ep , tt .path )
79+ newPath := FromEndpoint ( newEP )
8080 if ! cmp .Equal (newPath , tt .path ) {
81- t .Errorf ("path after Set () = %v, want %v" , newPath , tt .path )
81+ t .Errorf ("path after SetInEndpoint () = %v, want %v" , newPath , tt .path )
8282 }
8383 })
8484 }
8585}
8686
8787func TestGroup (t * testing.T ) {
8888 tests := []struct {
89- name string
90- addrs []resolver.Address
91- want map [string ][]resolver.Address
89+ name string
90+ eps []resolver.Endpoint
91+ want map [string ][]resolver.Endpoint
9292 }{
9393 {
9494 name : "all with hierarchy" ,
95- addrs : []resolver.Address {
96- {Addr : "a0" , BalancerAttributes : attributes .New (pathKey , pathValue {"a" })},
97- {Addr : "a1" , BalancerAttributes : attributes .New (pathKey , pathValue {"a" })},
98- {Addr : "b0" , BalancerAttributes : attributes .New (pathKey , pathValue {"b" })},
99- {Addr : "b1" , BalancerAttributes : attributes .New (pathKey , pathValue {"b" })},
95+ eps : []resolver.Endpoint {
96+ {Addresses : []resolver. Address {{ Addr : "a0" }}, Attributes : attributes .New (pathKey , pathValue {"a" })},
97+ {Addresses : []resolver. Address {{ Addr : "a1" }}, Attributes : attributes .New (pathKey , pathValue {"a" })},
98+ {Addresses : []resolver. Address {{ Addr : "b0" }}, Attributes : attributes .New (pathKey , pathValue {"b" })},
99+ {Addresses : []resolver. Address {{ Addr : "b1" }}, Attributes : attributes .New (pathKey , pathValue {"b" })},
100100 },
101- want : map [string ][]resolver.Address {
101+ want : map [string ][]resolver.Endpoint {
102102 "a" : {
103- {Addr : "a0" , BalancerAttributes : attributes .New (pathKey , pathValue {})},
104- {Addr : "a1" , BalancerAttributes : attributes .New (pathKey , pathValue {})},
103+ {Addresses : []resolver. Address {{ Addr : "a0" }}, Attributes : attributes .New (pathKey , pathValue {})},
104+ {Addresses : []resolver. Address {{ Addr : "a1" }}, Attributes : attributes .New (pathKey , pathValue {})},
105105 },
106106 "b" : {
107- {Addr : "b0" , BalancerAttributes : attributes .New (pathKey , pathValue {})},
108- {Addr : "b1" , BalancerAttributes : attributes .New (pathKey , pathValue {})},
107+ {Addresses : []resolver. Address {{ Addr : "b0" }}, Attributes : attributes .New (pathKey , pathValue {})},
108+ {Addresses : []resolver. Address {{ Addr : "b1" }}, Attributes : attributes .New (pathKey , pathValue {})},
109109 },
110110 },
111111 },
112112 {
113- // Addresses without hierarchy are ignored.
113+ // Endpoints without hierarchy are ignored.
114114 name : "without hierarchy" ,
115- addrs : []resolver.Address {
116- {Addr : "a0" , BalancerAttributes : attributes .New (pathKey , pathValue {"a" })},
117- {Addr : "a1" , BalancerAttributes : attributes .New (pathKey , pathValue {"a" })},
118- {Addr : "b0" , BalancerAttributes : nil },
119- {Addr : "b1" , BalancerAttributes : nil },
115+ eps : []resolver.Endpoint {
116+ {Addresses : []resolver. Address {{ Addr : "a0" }}, Attributes : attributes .New (pathKey , pathValue {"a" })},
117+ {Addresses : []resolver. Address {{ Addr : "a1" }}, Attributes : attributes .New (pathKey , pathValue {"a" })},
118+ {Addresses : []resolver. Address {{ Addr : "b0" }}, Attributes : nil },
119+ {Addresses : []resolver. Address {{ Addr : "b1" }}, Attributes : nil },
120120 },
121- want : map [string ][]resolver.Address {
121+ want : map [string ][]resolver.Endpoint {
122122 "a" : {
123- {Addr : "a0" , BalancerAttributes : attributes .New (pathKey , pathValue {})},
124- {Addr : "a1" , BalancerAttributes : attributes .New (pathKey , pathValue {})},
123+ {Addresses : []resolver. Address {{ Addr : "a0" }}, Attributes : attributes .New (pathKey , pathValue {})},
124+ {Addresses : []resolver. Address {{ Addr : "a1" }}, Attributes : attributes .New (pathKey , pathValue {})},
125125 },
126126 },
127127 },
128128 {
129129 // If hierarchy is set to a wrong type (which should never happen),
130- // the address is ignored.
130+ // the endpoint is ignored.
131131 name : "wrong type" ,
132- addrs : []resolver.Address {
133- {Addr : "a0" , BalancerAttributes : attributes .New (pathKey , pathValue {"a" })},
134- {Addr : "a1" , BalancerAttributes : attributes .New (pathKey , pathValue {"a" })},
135- {Addr : "b0" , BalancerAttributes : attributes .New (pathKey , "b" )},
136- {Addr : "b1" , BalancerAttributes : attributes .New (pathKey , 314 )},
132+ eps : []resolver.Endpoint {
133+ {Addresses : []resolver. Address {{ Addr : "a0" }}, Attributes : attributes .New (pathKey , pathValue {"a" })},
134+ {Addresses : []resolver. Address {{ Addr : "a1" }}, Attributes : attributes .New (pathKey , pathValue {"a" })},
135+ {Addresses : []resolver. Address {{ Addr : "b0" }}, Attributes : attributes .New (pathKey , "b" )},
136+ {Addresses : []resolver. Address {{ Addr : "b1" }}, Attributes : attributes .New (pathKey , 314 )},
137137 },
138- want : map [string ][]resolver.Address {
138+ want : map [string ][]resolver.Endpoint {
139139 "a" : {
140- {Addr : "a0" , BalancerAttributes : attributes .New (pathKey , pathValue {})},
141- {Addr : "a1" , BalancerAttributes : attributes .New (pathKey , pathValue {})},
140+ {Addresses : []resolver. Address {{ Addr : "a0" }}, Attributes : attributes .New (pathKey , pathValue {})},
141+ {Addresses : []resolver. Address {{ Addr : "a1" }}, Attributes : attributes .New (pathKey , pathValue {})},
142142 },
143143 },
144144 },
145145 }
146146 for _ , tt := range tests {
147147 t .Run (tt .name , func (t * testing.T ) {
148- if got := Group (tt .addrs ); ! cmp .Equal (got , tt .want , cmp .AllowUnexported (attributes.Attributes {})) {
148+ if got := Group (tt .eps ); ! cmp .Equal (got , tt .want , cmp .AllowUnexported (attributes.Attributes {})) {
149149 t .Errorf ("Group() = %v, want %v" , got , tt .want )
150150 t .Errorf ("diff: %v" , cmp .Diff (got , tt .want , cmp .AllowUnexported (attributes.Attributes {})))
151151 }
@@ -165,28 +165,28 @@ func TestGroupE2E(t *testing.T) {
165165 },
166166 }
167167
168- var addrsWithHierarchy []resolver.Address
168+ var epsWithHierarchy []resolver.Endpoint
169169 for p , wts := range hierarchy {
170170 path1 := pathValue {p }
171171 for wt , addrs := range wts {
172172 path2 := append (pathValue (nil ), path1 ... )
173173 path2 = append (path2 , wt )
174174 for _ , addr := range addrs {
175- a := resolver.Address {
176- Addr : addr ,
177- BalancerAttributes : attributes .New (pathKey , path2 ),
175+ a := resolver.Endpoint {
176+ Addresses : []resolver. Address {{ Addr : addr }} ,
177+ Attributes : attributes .New (pathKey , path2 ),
178178 }
179- addrsWithHierarchy = append (addrsWithHierarchy , a )
179+ epsWithHierarchy = append (epsWithHierarchy , a )
180180 }
181181 }
182182 }
183183
184184 gotHierarchy := make (map [string ]map [string ][]string )
185- for p1 , wts := range Group (addrsWithHierarchy ) {
185+ for p1 , wts := range Group (epsWithHierarchy ) {
186186 gotHierarchy [p1 ] = make (map [string ][]string )
187- for p2 , addrs := range Group (wts ) {
188- for _ , addr := range addrs {
189- gotHierarchy [p1 ][p2 ] = append (gotHierarchy [p1 ][p2 ], addr .Addr )
187+ for p2 , eps := range Group (wts ) {
188+ for _ , ep := range eps {
189+ gotHierarchy [p1 ][p2 ] = append (gotHierarchy [p1 ][p2 ], ep . Addresses [ 0 ] .Addr )
190190 }
191191 }
192192 }
0 commit comments