@@ -134,6 +134,114 @@ func TestEndpointsForUpstreamOrderDoesntMatter(t *testing.T) {
134
134
135
135
}
136
136
137
+ func TestEndpointsForUpstreamWithDiscoveredUpstream (t * testing.T ) {
138
+ g := gomega .NewWithT (t )
139
+
140
+ us := UpstreamWrapper {
141
+ Inner : & gloov1.Upstream {
142
+ Metadata : & core.Metadata {Name : "name" , Namespace : "ns" },
143
+ UpstreamType : & gloov1.Upstream_Kube {
144
+ Kube : & kubernetes.UpstreamSpec {
145
+ ServiceName : "svc" ,
146
+ ServiceNamespace : "ns" ,
147
+ ServicePort : 8080 ,
148
+ },
149
+ },
150
+ },
151
+ }
152
+ usd := UpstreamWrapper {
153
+ Inner : & gloov1.Upstream {
154
+ Metadata : & core.Metadata {Name : "discovered-name" , Namespace : "ns" },
155
+ UpstreamType : & gloov1.Upstream_Kube {
156
+ Kube : & kubernetes.UpstreamSpec {
157
+ ServiceName : "svc" ,
158
+ ServiceNamespace : "ns" ,
159
+ ServicePort : 8080 ,
160
+ },
161
+ },
162
+ },
163
+ }
164
+ // input
165
+ emd1 := EndpointWithMd {
166
+ LbEndpoint : & endpointv3.LbEndpoint {
167
+ HostIdentifier : & endpointv3.LbEndpoint_Endpoint {
168
+ Endpoint : & endpointv3.Endpoint {
169
+ Address : & envoy_config_core_v3.Address {
170
+ Address : & envoy_config_core_v3.Address_SocketAddress {
171
+ SocketAddress : & envoy_config_core_v3.SocketAddress {
172
+ Address : "1.2.3.4" ,
173
+ PortSpecifier : & envoy_config_core_v3.SocketAddress_PortValue {
174
+ PortValue : 8080 ,
175
+ },
176
+ },
177
+ },
178
+ },
179
+ },
180
+ },
181
+ },
182
+ EndpointMd : EndpointMetadata {
183
+ Labels : map [string ]string {
184
+ corev1 .LabelTopologyRegion : "region" ,
185
+ corev1 .LabelTopologyZone : "zone" ,
186
+ },
187
+ },
188
+ }
189
+ emd2 := EndpointWithMd {
190
+ LbEndpoint : & endpointv3.LbEndpoint {
191
+ HostIdentifier : & endpointv3.LbEndpoint_Endpoint {
192
+ Endpoint : & endpointv3.Endpoint {
193
+ Address : & envoy_config_core_v3.Address {
194
+ Address : & envoy_config_core_v3.Address_SocketAddress {
195
+ SocketAddress : & envoy_config_core_v3.SocketAddress {
196
+ Address : "1.2.3.5" ,
197
+ PortSpecifier : & envoy_config_core_v3.SocketAddress_PortValue {
198
+ PortValue : 8080 ,
199
+ },
200
+ },
201
+ },
202
+ },
203
+ },
204
+ },
205
+ },
206
+ EndpointMd : EndpointMetadata {
207
+ Labels : map [string ]string {
208
+ corev1 .LabelTopologyRegion : "region" ,
209
+ corev1 .LabelTopologyZone : "zone" ,
210
+ },
211
+ },
212
+ }
213
+
214
+ result1 := NewEndpointsForUpstream (us , nil )
215
+ result1 .Add (PodLocality {
216
+ Region : "region" ,
217
+ Zone : "zone" ,
218
+ }, emd1 )
219
+
220
+ result2 := NewEndpointsForUpstream (usd , nil )
221
+ result2 .Add (PodLocality {
222
+ Region : "region" ,
223
+ Zone : "zone" ,
224
+ }, emd1 )
225
+
226
+ result3 := NewEndpointsForUpstream (us , nil )
227
+ result3 .Add (PodLocality {
228
+ Region : "region" ,
229
+ Zone : "zone" ,
230
+ }, emd2 )
231
+
232
+ result4 := NewEndpointsForUpstream (usd , nil )
233
+ result4 .Add (PodLocality {
234
+ Region : "region" ,
235
+ Zone : "zone" ,
236
+ }, emd2 )
237
+
238
+ h1 := result1 .LbEpsEqualityHash ^ result2 .LbEpsEqualityHash
239
+ h2 := result3 .LbEpsEqualityHash ^ result4 .LbEpsEqualityHash
240
+
241
+ g .Expect (h1 ).NotTo (Equal (h2 ), "not expected %v, got %v" , h1 , h2 )
242
+
243
+ }
244
+
137
245
func TestEndpoints (t * testing.T ) {
138
246
testCases := []struct {
139
247
name string
0 commit comments