@@ -26,18 +26,20 @@ import (
2626 "github.com/google/go-cmp/cmp"
2727 "github.com/google/go-cmp/cmp/cmpopts"
2828 "google.golang.org/grpc/balancer/leastrequest"
29- _ "google.golang.org/grpc/balancer/roundrobin" // To register round_robin load balancer.
3029 "google.golang.org/grpc/internal/balancer/stub"
3130 "google.golang.org/grpc/internal/envconfig"
3231 "google.golang.org/grpc/internal/grpctest"
3332 iserviceconfig "google.golang.org/grpc/internal/serviceconfig"
3433 "google.golang.org/grpc/internal/testutils"
3534 "google.golang.org/grpc/internal/testutils/xds/e2e"
3635 "google.golang.org/grpc/serviceconfig"
37- _ "google.golang.org/grpc/xds" // Register the xDS LB Registry Converters.
3836 "google.golang.org/grpc/xds/internal/balancer/ringhash"
3937 "google.golang.org/grpc/xds/internal/balancer/wrrlocality"
38+ "google.golang.org/grpc/xds/internal/xdsclient/bootstrap"
4039 "google.golang.org/grpc/xds/internal/xdsclient/xdsresource"
40+ "google.golang.org/protobuf/proto"
41+ "google.golang.org/protobuf/types/known/anypb"
42+ "google.golang.org/protobuf/types/known/structpb"
4143 "google.golang.org/protobuf/types/known/wrapperspb"
4244
4345 v3xdsxdstypepb "github.com/cncf/xds/go/xds/type/v3"
@@ -48,9 +50,9 @@ import (
4850 v3ringhashpb "github.com/envoyproxy/go-control-plane/envoy/extensions/load_balancing_policies/ring_hash/v3"
4951 v3roundrobinpb "github.com/envoyproxy/go-control-plane/envoy/extensions/load_balancing_policies/round_robin/v3"
5052 v3wrrlocalitypb "github.com/envoyproxy/go-control-plane/envoy/extensions/load_balancing_policies/wrr_locality/v3"
51- "google.golang.org/protobuf/proto"
52- "google.golang.org/protobuf/types/known/anypb"
53- "google.golang.org/protobuf/types/known/structpb"
53+
54+ _ "google.golang.org/grpc/balancer/roundrobin" // To register round_robin load balancer.
55+ _ "google.golang.org/grpc/xds" // Register the xDS LB Registry Converters.
5456)
5557
5658type s struct {
@@ -66,8 +68,6 @@ const (
6668 serviceName = "service"
6769)
6870
69- var emptyUpdate = xdsresource.ClusterUpdate {ClusterName : clusterName , LRSServerConfig : xdsresource .ClusterLRSOff }
70-
7171func wrrLocality (t * testing.T , m proto.Message ) * v3wrrlocalitypb.WrrLocality {
7272 return & v3wrrlocalitypb.WrrLocality {
7373 EndpointPickingPolicy : & v3clusterpb.LoadBalancingPolicy {
@@ -105,6 +105,7 @@ func (s) TestValidateCluster_Success(t *testing.T) {
105105 tests := []struct {
106106 name string
107107 cluster * v3clusterpb.Cluster
108+ serverCfg * bootstrap.ServerConfig
108109 wantUpdate xdsresource.ClusterUpdate
109110 wantLBConfig * iserviceconfig.BalancerConfig
110111 }{
@@ -164,7 +165,8 @@ func (s) TestValidateCluster_Success(t *testing.T) {
164165 LbPolicy : v3clusterpb .Cluster_ROUND_ROBIN ,
165166 },
166167 wantUpdate : xdsresource.ClusterUpdate {
167- ClusterName : clusterName , LRSServerConfig : xdsresource .ClusterLRSOff , ClusterType : xdsresource .ClusterTypeAggregate ,
168+ ClusterName : clusterName ,
169+ ClusterType : xdsresource .ClusterTypeAggregate ,
168170 PrioritizedClusterNames : []string {"a" , "b" , "c" },
169171 },
170172 wantLBConfig : & iserviceconfig.BalancerConfig {
@@ -179,7 +181,7 @@ func (s) TestValidateCluster_Success(t *testing.T) {
179181 {
180182 name : "happy-case-no-service-name-no-lrs" ,
181183 cluster : e2e .DefaultCluster (clusterName , "" , e2e .SecurityLevelNone ),
182- wantUpdate : emptyUpdate ,
184+ wantUpdate : xdsresource. ClusterUpdate { ClusterName : clusterName } ,
183185 wantLBConfig : & iserviceconfig.BalancerConfig {
184186 Name : wrrlocality .Name ,
185187 Config : & wrrlocality.LBConfig {
@@ -206,16 +208,17 @@ func (s) TestValidateCluster_Success(t *testing.T) {
206208 },
207209 },
208210 {
209- name : "happiest-case" ,
211+ name : "happiest-case-with-lrs " ,
210212 cluster : e2e .ClusterResourceWithOptions (e2e.ClusterOptions {
211213 ClusterName : clusterName ,
212214 ServiceName : serviceName ,
213215 EnableLRS : true ,
214216 }),
217+ serverCfg : & bootstrap.ServerConfig {ServerURI : "test-server-uri" },
215218 wantUpdate : xdsresource.ClusterUpdate {
216219 ClusterName : clusterName ,
217220 EDSServiceName : serviceName ,
218- LRSServerConfig : xdsresource . ClusterLRSServerSelf ,
221+ LRSServerConfig : & bootstrap. ServerConfig { ServerURI : "test-server-uri" } ,
219222 },
220223 wantLBConfig : & iserviceconfig.BalancerConfig {
221224 Name : wrrlocality .Name ,
@@ -248,10 +251,11 @@ func (s) TestValidateCluster_Success(t *testing.T) {
248251 }
249252 return c
250253 }(),
254+ serverCfg : & bootstrap.ServerConfig {ServerURI : "test-server-uri" },
251255 wantUpdate : xdsresource.ClusterUpdate {
252256 ClusterName : clusterName ,
253257 EDSServiceName : serviceName ,
254- LRSServerConfig : xdsresource . ClusterLRSServerSelf ,
258+ LRSServerConfig : & bootstrap. ServerConfig { ServerURI : "test-server-uri" } ,
255259 MaxRequests : func () * uint32 { i := uint32 (512 ); return & i }(),
256260 },
257261 wantLBConfig : & iserviceconfig.BalancerConfig {
@@ -298,7 +302,8 @@ func (s) TestValidateCluster_Success(t *testing.T) {
298302 LbPolicy : v3clusterpb .Cluster_LEAST_REQUEST ,
299303 },
300304 wantUpdate : xdsresource.ClusterUpdate {
301- ClusterName : clusterName , EDSServiceName : serviceName ,
305+ ClusterName : clusterName ,
306+ EDSServiceName : serviceName ,
302307 },
303308 wantLBConfig : & iserviceconfig.BalancerConfig {
304309 Name : "least_request_experimental" ,
@@ -353,7 +358,8 @@ func (s) TestValidateCluster_Success(t *testing.T) {
353358 },
354359 },
355360 wantUpdate : xdsresource.ClusterUpdate {
356- ClusterName : clusterName , EDSServiceName : serviceName ,
361+ ClusterName : clusterName ,
362+ EDSServiceName : serviceName ,
357363 },
358364 wantLBConfig : & iserviceconfig.BalancerConfig {
359365 Name : "least_request_experimental" ,
@@ -527,7 +533,7 @@ func (s) TestValidateCluster_Success(t *testing.T) {
527533
528534 for _ , test := range tests {
529535 t .Run (test .name , func (t * testing.T ) {
530- update , err := xdsresource .ValidateClusterAndConstructClusterUpdateForTesting (test .cluster )
536+ update , err := xdsresource .ValidateClusterAndConstructClusterUpdateForTesting (test .cluster , test . serverCfg )
531537 if err != nil {
532538 t .Errorf ("validateClusterAndConstructClusterUpdate(%+v) failed: %v" , test .cluster , err )
533539 }
0 commit comments