Skip to content

Commit aa905bf

Browse files
authored
Merge pull request #2542 from murgatroid99/grpc-js-xds_config_parsing_tests
grpc-js-xds: Add config parsing tests
2 parents b979cbd + b2ad73a commit aa905bf

File tree

5 files changed

+382
-6
lines changed

5 files changed

+382
-6
lines changed

packages/grpc-js-xds/src/load-balancer-cds.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,10 @@ class CdsLoadBalancingConfig implements TypedLoadBalancingConfig {
6565
}
6666

6767
static createFromJson(obj: any): CdsLoadBalancingConfig {
68-
if ('cluster' in obj) {
69-
return new CdsLoadBalancingConfig(obj.cluster);
70-
} else {
71-
throw new Error('Missing "cluster" in cds load balancing config');
68+
if (!('cluster' in obj && typeof obj.cluster === 'string')) {
69+
throw new Error('cds config must have a string field cluster');
7270
}
71+
return new CdsLoadBalancingConfig(obj.cluster);
7372
}
7473
}
7574

packages/grpc-js-xds/src/load-balancer-lrs.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class LrsLoadBalancingConfig implements TypedLoadBalancingConfig {
4646
[TYPE_NAME]: {
4747
cluster_name: this.clusterName,
4848
eds_service_name: this.edsServiceName,
49-
lrs_load_reporting_server_name: this.lrsLoadReportingServer,
49+
lrs_load_reporting_server: this.lrsLoadReportingServer,
5050
locality: this.locality,
5151
child_policy: [this.childPolicy.toJsonObject()]
5252
}
@@ -97,6 +97,9 @@ class LrsLoadBalancingConfig implements TypedLoadBalancingConfig {
9797
if (!('child_policy' in obj && Array.isArray(obj.child_policy))) {
9898
throw new Error('lrs config must have a child_policy array');
9999
}
100+
if (!('lrs_load_reporting_server' in obj && obj.lrs_load_reporting_server !== null && typeof obj.lrs_load_reporting_server === 'object')) {
101+
throw new Error('lrs config must have an object field lrs_load_reporting_server');
102+
}
100103
const childConfig = selectLbConfigFromList(obj.child_policy);
101104
if (!childConfig) {
102105
throw new Error('lrs config child_policy parsing failed');

packages/grpc-js-xds/src/load-balancer-priority.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ class PriorityLoadBalancingConfig implements TypedLoadBalancingConfig {
8181
const childrenField: {[key: string]: object} = {}
8282
for (const [childName, childValue] of this.children.entries()) {
8383
childrenField[childName] = {
84-
config: [childValue.config.toJsonObject()]
84+
config: [childValue.config.toJsonObject()],
85+
ignore_reresolution_requests: childValue.ignore_reresolution_requests
8586
};
8687
}
8788
return {

packages/grpc-js-xds/src/xds-bootstrap.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ const SUPPORTED_CHANNEL_CREDS_TYPES = [
112112
];
113113

114114
export function validateXdsServerConfig(obj: any): XdsServerConfig {
115+
if (!(typeof obj === 'object' && obj !== null)) {
116+
throw new Error('xDS server config must be an object');
117+
}
115118
if (!('server_uri' in obj)) {
116119
throw new Error('server_uri field missing in xds_servers element');
117120
}

0 commit comments

Comments
 (0)