@@ -17,6 +17,7 @@ import (
1717 cswrrv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/load_balancing_policies/client_side_weighted_round_robin/v3"
1818 override_hostv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/load_balancing_policies/override_host/v3"
1919 wrr_localityv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/load_balancing_policies/wrr_locality/v3"
20+ httpv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/upstreams/http/v3"
2021 "github.com/google/go-cmp/cmp"
2122 "github.com/stretchr/testify/require"
2223 "google.golang.org/protobuf/encoding/protojson"
@@ -295,6 +296,53 @@ func TestBuildClusterWithBackendUtilization(t *testing.T) {
295296 require .Equal (t , "type.googleapis.com/envoy.extensions.load_balancing_policies.client_side_weighted_round_robin.v3.ClientSideWeightedRoundRobin" , policy .TypedExtensionConfig .TypedConfig .TypeUrl )
296297}
297298
299+ func TestBuildXdsClusterWithClusterLevelHashPolicy (t * testing.T ) {
300+ sourceIP := true
301+ args := & xdsClusterArgs {
302+ name : "test-cluster-consistent-hash" ,
303+ endpointType : EndpointTypeStatic ,
304+ settings : []* ir.DestinationSetting {{
305+ Endpoints : []* ir.DestinationEndpoint {{Host : "127.0.0.1" , Port : 8080 }},
306+ }},
307+ loadBalancer : & ir.LoadBalancer {
308+ ConsistentHash : & ir.ConsistentHash {
309+ SourceIP : & sourceIP ,
310+ },
311+ },
312+ }
313+
314+ result , err := buildXdsCluster (args )
315+ require .NoError (t , err )
316+
317+ options := & httpv3.HttpProtocolOptions {}
318+ require .NotNil (t , result .cluster .TypedExtensionProtocolOptions )
319+ require .NoError (t , result .cluster .TypedExtensionProtocolOptions [extensionOptionsKey ].UnmarshalTo (options ))
320+ require .Len (t , options .HashPolicy , 1 )
321+ require .True (t , options .HashPolicy [0 ].GetConnectionProperties ().GetSourceIp ())
322+ }
323+
324+ func TestBuildXdsRouteClusterWithoutClusterLevelHashPolicy (t * testing.T ) {
325+ sourceIP := true
326+ args := & xdsClusterArgs {
327+ name : "test-route-cluster-consistent-hash" ,
328+ endpointType : EndpointTypeStatic ,
329+ settings : []* ir.DestinationSetting {{
330+ Endpoints : []* ir.DestinationEndpoint {{Host : "127.0.0.1" , Port : 8080 }},
331+ }},
332+ loadBalancer : & ir.LoadBalancer {
333+ ConsistentHash : & ir.ConsistentHash {
334+ SourceIP : & sourceIP ,
335+ },
336+ },
337+ isRoute : true ,
338+ }
339+
340+ result , err := buildXdsCluster (args )
341+ require .NoError (t , err )
342+
343+ require .Nil (t , result .cluster .TypedExtensionProtocolOptions )
344+ }
345+
298346func TestBuildClusterWithBackendUtilizationSlowStart (t * testing.T ) {
299347 window := 5 * time .Second
300348 args := & xdsClusterArgs {
0 commit comments