Skip to content

Commit 9de879e

Browse files
committed
xds: assert error messages in TestValidateCluster_Failure
1 parent b891dc6 commit 9de879e

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

internal/xds/xdsclient/xdsresource/unmarshal_cds_test.go

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (s) TestValidateCluster_Failure(t *testing.T) {
5959
tests := []struct {
6060
name string
6161
cluster *v3clusterpb.Cluster
62-
wantErr bool
62+
wantErr string
6363
}{
6464
{
6565
name: "non-supported-cluster-type-static",
@@ -74,7 +74,7 @@ func (s) TestValidateCluster_Failure(t *testing.T) {
7474
},
7575
LbPolicy: v3clusterpb.Cluster_LEAST_REQUEST,
7676
},
77-
wantErr: true,
77+
wantErr: "unsupported cluster type",
7878
},
7979
{
8080
name: "non-supported-cluster-type-original-dst",
@@ -89,15 +89,15 @@ func (s) TestValidateCluster_Failure(t *testing.T) {
8989
},
9090
LbPolicy: v3clusterpb.Cluster_LEAST_REQUEST,
9191
},
92-
wantErr: true,
92+
wantErr: "unsupported cluster type",
9393
},
9494
{
9595
name: "no-eds-config",
9696
cluster: &v3clusterpb.Cluster{
9797
ClusterDiscoveryType: &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_EDS},
9898
LbPolicy: v3clusterpb.Cluster_ROUND_ROBIN,
9999
},
100-
wantErr: true,
100+
wantErr: "CDS's EDS config source is not ADS or Self",
101101
},
102102
{
103103
name: "no-ads-config-source",
@@ -106,7 +106,7 @@ func (s) TestValidateCluster_Failure(t *testing.T) {
106106
EdsClusterConfig: &v3clusterpb.Cluster_EdsClusterConfig{},
107107
LbPolicy: v3clusterpb.Cluster_ROUND_ROBIN,
108108
},
109-
wantErr: true,
109+
wantErr: "CDS's EDS config source is not ADS or Self",
110110
},
111111
{
112112
name: "unsupported-lb-policy",
@@ -121,7 +121,7 @@ func (s) TestValidateCluster_Failure(t *testing.T) {
121121
},
122122
LbPolicy: v3clusterpb.Cluster_MAGLEV,
123123
},
124-
wantErr: true,
124+
wantErr: "unexpected lbPolicy MAGLEV",
125125
},
126126
{
127127
name: "logical-dns-multiple-localities",
@@ -137,7 +137,7 @@ func (s) TestValidateCluster_Failure(t *testing.T) {
137137
},
138138
},
139139
},
140-
wantErr: true,
140+
wantErr: "load_assignment for LOGICAL_DNS cluster must have exactly one locality",
141141
},
142142
{
143143
name: "ring-hash-hash-function-not-xx-hash",
@@ -149,19 +149,19 @@ func (s) TestValidateCluster_Failure(t *testing.T) {
149149
},
150150
},
151151
},
152-
wantErr: true,
152+
wantErr: "unsupported ring_hash hash function MURMUR_HASH_2",
153153
},
154154
{
155155
name: "least-request-choice-count-less-than-two",
156156
cluster: &v3clusterpb.Cluster{
157-
LbPolicy: v3clusterpb.Cluster_RING_HASH,
157+
LbPolicy: v3clusterpb.Cluster_LEAST_REQUEST,
158158
LbConfig: &v3clusterpb.Cluster_LeastRequestLbConfig_{
159159
LeastRequestLbConfig: &v3clusterpb.Cluster_LeastRequestLbConfig{
160160
ChoiceCount: wrapperspb.UInt32(1),
161161
},
162162
},
163163
},
164-
wantErr: true,
164+
wantErr: "Cluster_LeastRequestLbConfig.ChoiceCount must be >= 2",
165165
},
166166
{
167167
name: "ring-hash-max-bound-greater-than-upper-bound",
@@ -183,7 +183,7 @@ func (s) TestValidateCluster_Failure(t *testing.T) {
183183
},
184184
},
185185
},
186-
wantErr: true,
186+
wantErr: "ring_hash_lb_config.maximum_ring_size 8388609 is greater than upper bound 8388608",
187187
},
188188
{
189189
name: "ring-hash-min-greater-than-max",
@@ -206,7 +206,7 @@ func (s) TestValidateCluster_Failure(t *testing.T) {
206206
},
207207
},
208208
},
209-
wantErr: true,
209+
wantErr: "ring_hash_lb_config.minimum_ring_size 5000 is greater than maximum_ring_size 100",
210210
},
211211
{
212212
name: "ring-hash-max-bound-greater-than-upper-bound-load-balancing-policy",
@@ -235,7 +235,7 @@ func (s) TestValidateCluster_Failure(t *testing.T) {
235235
},
236236
},
237237
},
238-
wantErr: true,
238+
wantErr: "error converting LoadBalancingPolicy",
239239
},
240240
{
241241
name: "least-request-unsupported-in-converter-since-env-var-unset",
@@ -260,7 +260,7 @@ func (s) TestValidateCluster_Failure(t *testing.T) {
260260
},
261261
},
262262
},
263-
wantErr: true,
263+
wantErr: "no supported policy found in policy list",
264264
},
265265
{
266266
name: "aggregate-nil-clusters",
@@ -274,7 +274,7 @@ func (s) TestValidateCluster_Failure(t *testing.T) {
274274
},
275275
LbPolicy: v3clusterpb.Cluster_ROUND_ROBIN,
276276
},
277-
wantErr: true,
277+
wantErr: "aggregate cluster has empty clusters field",
278278
},
279279
{
280280
name: "aggregate-empty-clusters",
@@ -290,14 +290,18 @@ func (s) TestValidateCluster_Failure(t *testing.T) {
290290
},
291291
LbPolicy: v3clusterpb.Cluster_ROUND_ROBIN,
292292
},
293-
wantErr: true,
293+
wantErr: "aggregate cluster has empty clusters field",
294294
},
295295
}
296296

297297
for _, test := range tests {
298298
t.Run(test.name, func(t *testing.T) {
299-
if update, err := validateClusterAndConstructClusterUpdate(test.cluster, nil); err == nil {
300-
t.Errorf("validateClusterAndConstructClusterUpdate(%+v) = %v, wanted error", test.cluster, update)
299+
update, err := validateClusterAndConstructClusterUpdate(test.cluster, nil)
300+
if err == nil {
301+
t.Fatalf("validateClusterAndConstructClusterUpdate(%+v) = %v, wanted error containing %q", test.cluster, update, test.wantErr)
302+
}
303+
if !strings.Contains(err.Error(), test.wantErr) {
304+
t.Fatalf("validateClusterAndConstructClusterUpdate(%+v) returned err: %v, wanted error containing %q", test.cluster, err, test.wantErr)
301305
}
302306
})
303307
}

0 commit comments

Comments
 (0)