Skip to content

Commit

Permalink
Merge pull request #2542 from murgatroid99/grpc-js-xds_config_parsing…
Browse files Browse the repository at this point in the history
…_tests

grpc-js-xds: Add config parsing tests
  • Loading branch information
murgatroid99 committed Aug 10, 2023
2 parents b979cbd + b2ad73a commit aa905bf
Show file tree
Hide file tree
Showing 5 changed files with 382 additions and 6 deletions.
7 changes: 3 additions & 4 deletions packages/grpc-js-xds/src/load-balancer-cds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ class CdsLoadBalancingConfig implements TypedLoadBalancingConfig {
}

static createFromJson(obj: any): CdsLoadBalancingConfig {
if ('cluster' in obj) {
return new CdsLoadBalancingConfig(obj.cluster);
} else {
throw new Error('Missing "cluster" in cds load balancing config');
if (!('cluster' in obj && typeof obj.cluster === 'string')) {
throw new Error('cds config must have a string field cluster');
}
return new CdsLoadBalancingConfig(obj.cluster);
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/grpc-js-xds/src/load-balancer-lrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class LrsLoadBalancingConfig implements TypedLoadBalancingConfig {
[TYPE_NAME]: {
cluster_name: this.clusterName,
eds_service_name: this.edsServiceName,
lrs_load_reporting_server_name: this.lrsLoadReportingServer,
lrs_load_reporting_server: this.lrsLoadReportingServer,
locality: this.locality,
child_policy: [this.childPolicy.toJsonObject()]
}
Expand Down Expand Up @@ -97,6 +97,9 @@ class LrsLoadBalancingConfig implements TypedLoadBalancingConfig {
if (!('child_policy' in obj && Array.isArray(obj.child_policy))) {
throw new Error('lrs config must have a child_policy array');
}
if (!('lrs_load_reporting_server' in obj && obj.lrs_load_reporting_server !== null && typeof obj.lrs_load_reporting_server === 'object')) {
throw new Error('lrs config must have an object field lrs_load_reporting_server');
}
const childConfig = selectLbConfigFromList(obj.child_policy);
if (!childConfig) {
throw new Error('lrs config child_policy parsing failed');
Expand Down
3 changes: 2 additions & 1 deletion packages/grpc-js-xds/src/load-balancer-priority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class PriorityLoadBalancingConfig implements TypedLoadBalancingConfig {
const childrenField: {[key: string]: object} = {}
for (const [childName, childValue] of this.children.entries()) {
childrenField[childName] = {
config: [childValue.config.toJsonObject()]
config: [childValue.config.toJsonObject()],
ignore_reresolution_requests: childValue.ignore_reresolution_requests
};
}
return {
Expand Down
3 changes: 3 additions & 0 deletions packages/grpc-js-xds/src/xds-bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ const SUPPORTED_CHANNEL_CREDS_TYPES = [
];

export function validateXdsServerConfig(obj: any): XdsServerConfig {
if (!(typeof obj === 'object' && obj !== null)) {
throw new Error('xDS server config must be an object');
}
if (!('server_uri' in obj)) {
throw new Error('server_uri field missing in xds_servers element');
}
Expand Down
Loading

0 comments on commit aa905bf

Please sign in to comment.