diff --git a/src/v1/autoscaling_policy_service_client.ts b/src/v1/autoscaling_policy_service_client.ts index 1024baee..03a2347f 100644 --- a/src/v1/autoscaling_policy_service_client.ts +++ b/src/v1/autoscaling_policy_service_client.ts @@ -457,7 +457,7 @@ export class AutoscalingPolicyServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.createAutoscalingPolicy( @@ -561,7 +561,7 @@ export class AutoscalingPolicyServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'policy.name': request.policy!.name || '', + 'policy.name': request.policy!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateAutoscalingPolicy( @@ -665,7 +665,7 @@ export class AutoscalingPolicyServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - name: request.name || '', + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.getAutoscalingPolicy(request, options, callback); @@ -772,7 +772,7 @@ export class AutoscalingPolicyServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - name: request.name || '', + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.deleteAutoscalingPolicy( @@ -886,7 +886,7 @@ export class AutoscalingPolicyServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.listAutoscalingPolicies( @@ -939,7 +939,7 @@ export class AutoscalingPolicyServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); const defaultCallSettings = this._defaults['listAutoscalingPolicies']; const callSettings = defaultCallSettings.merge(options); @@ -997,7 +997,7 @@ export class AutoscalingPolicyServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); const defaultCallSettings = this._defaults['listAutoscalingPolicies']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v1/batch_controller_client.ts b/src/v1/batch_controller_client.ts index 128497f5..8e8f33fb 100644 --- a/src/v1/batch_controller_client.ts +++ b/src/v1/batch_controller_client.ts @@ -574,7 +574,7 @@ export class BatchControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - name: request.name || '', + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.getBatch(request, options, callback); @@ -660,7 +660,7 @@ export class BatchControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - name: request.name || '', + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.deleteBatch(request, options, callback); @@ -784,7 +784,7 @@ export class BatchControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.createBatch(request, options, callback); @@ -914,7 +914,7 @@ export class BatchControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.listBatches(request, options, callback); @@ -955,7 +955,7 @@ export class BatchControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); const defaultCallSettings = this._defaults['listBatches']; const callSettings = defaultCallSettings.merge(options); @@ -1005,7 +1005,7 @@ export class BatchControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); const defaultCallSettings = this._defaults['listBatches']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v1/cluster_controller_client.ts b/src/v1/cluster_controller_client.ts index ea90d4b4..9403ad69 100644 --- a/src/v1/cluster_controller_client.ts +++ b/src/v1/cluster_controller_client.ts @@ -636,9 +636,9 @@ export class ClusterControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - project_id: request.projectId || '', - region: request.region || '', - cluster_name: request.clusterName || '', + project_id: request.projectId ?? '', + region: request.region ?? '', + cluster_name: request.clusterName ?? '', }); this.initialize(); return this.innerApiCalls.getCluster(request, options, callback); @@ -763,8 +763,8 @@ export class ClusterControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - project_id: request.projectId || '', - region: request.region || '', + project_id: request.projectId ?? '', + region: request.region ?? '', }); this.initialize(); return this.innerApiCalls.createCluster(request, options, callback); @@ -988,9 +988,9 @@ export class ClusterControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - project_id: request.projectId || '', - region: request.region || '', - cluster_name: request.clusterName || '', + project_id: request.projectId ?? '', + region: request.region ?? '', + cluster_name: request.clusterName ?? '', }); this.initialize(); return this.innerApiCalls.updateCluster(request, options, callback); @@ -1149,9 +1149,9 @@ export class ClusterControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - project_id: request.projectId || '', - region: request.region || '', - cluster_name: request.clusterName || '', + project_id: request.projectId ?? '', + region: request.region ?? '', + cluster_name: request.clusterName ?? '', }); this.initialize(); return this.innerApiCalls.stopCluster(request, options, callback); @@ -1310,9 +1310,9 @@ export class ClusterControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - project_id: request.projectId || '', - region: request.region || '', - cluster_name: request.clusterName || '', + project_id: request.projectId ?? '', + region: request.region ?? '', + cluster_name: request.clusterName ?? '', }); this.initialize(); return this.innerApiCalls.startCluster(request, options, callback); @@ -1473,9 +1473,9 @@ export class ClusterControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - project_id: request.projectId || '', - region: request.region || '', - cluster_name: request.clusterName || '', + project_id: request.projectId ?? '', + region: request.region ?? '', + cluster_name: request.clusterName ?? '', }); this.initialize(); return this.innerApiCalls.deleteCluster(request, options, callback); @@ -1624,9 +1624,9 @@ export class ClusterControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - project_id: request.projectId || '', - region: request.region || '', - cluster_name: request.clusterName || '', + project_id: request.projectId ?? '', + region: request.region ?? '', + cluster_name: request.clusterName ?? '', }); this.initialize(); return this.innerApiCalls.diagnoseCluster(request, options, callback); @@ -1776,8 +1776,8 @@ export class ClusterControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - project_id: request.projectId || '', - region: request.region || '', + project_id: request.projectId ?? '', + region: request.region ?? '', }); this.initialize(); return this.innerApiCalls.listClusters(request, options, callback); @@ -1838,8 +1838,8 @@ export class ClusterControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - project_id: request.projectId || '', - region: request.region || '', + project_id: request.projectId ?? '', + region: request.region ?? '', }); const defaultCallSettings = this._defaults['listClusters']; const callSettings = defaultCallSettings.merge(options); @@ -1909,8 +1909,8 @@ export class ClusterControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - project_id: request.projectId || '', - region: request.region || '', + project_id: request.projectId ?? '', + region: request.region ?? '', }); const defaultCallSettings = this._defaults['listClusters']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v1/job_controller_client.ts b/src/v1/job_controller_client.ts index a9dd5743..c1eb5ddf 100644 --- a/src/v1/job_controller_client.ts +++ b/src/v1/job_controller_client.ts @@ -589,8 +589,8 @@ export class JobControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - project_id: request.projectId || '', - region: request.region || '', + project_id: request.projectId ?? '', + region: request.region ?? '', }); this.initialize(); return this.innerApiCalls.submitJob(request, options, callback); @@ -678,9 +678,9 @@ export class JobControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - project_id: request.projectId || '', - region: request.region || '', - job_id: request.jobId || '', + project_id: request.projectId ?? '', + region: request.region ?? '', + job_id: request.jobId ?? '', }); this.initialize(); return this.innerApiCalls.getJob(request, options, callback); @@ -777,9 +777,9 @@ export class JobControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - project_id: request.projectId || '', - region: request.region || '', - job_id: request.jobId || '', + project_id: request.projectId ?? '', + region: request.region ?? '', + job_id: request.jobId ?? '', }); this.initialize(); return this.innerApiCalls.updateJob(request, options, callback); @@ -871,9 +871,9 @@ export class JobControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - project_id: request.projectId || '', - region: request.region || '', - job_id: request.jobId || '', + project_id: request.projectId ?? '', + region: request.region ?? '', + job_id: request.jobId ?? '', }); this.initialize(); return this.innerApiCalls.cancelJob(request, options, callback); @@ -962,9 +962,9 @@ export class JobControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - project_id: request.projectId || '', - region: request.region || '', - job_id: request.jobId || '', + project_id: request.projectId ?? '', + region: request.region ?? '', + job_id: request.jobId ?? '', }); this.initialize(); return this.innerApiCalls.deleteJob(request, options, callback); @@ -1086,8 +1086,8 @@ export class JobControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - project_id: request.projectId || '', - region: request.region || '', + project_id: request.projectId ?? '', + region: request.region ?? '', }); this.initialize(); return this.innerApiCalls.submitJobAsOperation(request, options, callback); @@ -1239,8 +1239,8 @@ export class JobControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - project_id: request.projectId || '', - region: request.region || '', + project_id: request.projectId ?? '', + region: request.region ?? '', }); this.initialize(); return this.innerApiCalls.listJobs(request, options, callback); @@ -1305,8 +1305,8 @@ export class JobControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - project_id: request.projectId || '', - region: request.region || '', + project_id: request.projectId ?? '', + region: request.region ?? '', }); const defaultCallSettings = this._defaults['listJobs']; const callSettings = defaultCallSettings.merge(options); @@ -1380,8 +1380,8 @@ export class JobControllerClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - project_id: request.projectId || '', - region: request.region || '', + project_id: request.projectId ?? '', + region: request.region ?? '', }); const defaultCallSettings = this._defaults['listJobs']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v1/workflow_template_service_client.ts b/src/v1/workflow_template_service_client.ts index b79af6dd..3dac9762 100644 --- a/src/v1/workflow_template_service_client.ts +++ b/src/v1/workflow_template_service_client.ts @@ -625,7 +625,7 @@ export class WorkflowTemplateServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.createWorkflowTemplate( @@ -737,7 +737,7 @@ export class WorkflowTemplateServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - name: request.name || '', + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.getWorkflowTemplate(request, options, callback); @@ -837,7 +837,7 @@ export class WorkflowTemplateServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'template.name': request.template!.name || '', + 'template.name': request.template!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateWorkflowTemplate( @@ -951,7 +951,7 @@ export class WorkflowTemplateServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - name: request.name || '', + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.deleteWorkflowTemplate( @@ -1107,7 +1107,7 @@ export class WorkflowTemplateServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - name: request.name || '', + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.instantiateWorkflowTemplate( @@ -1293,7 +1293,7 @@ export class WorkflowTemplateServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.instantiateInlineWorkflowTemplate( @@ -1440,7 +1440,7 @@ export class WorkflowTemplateServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.listWorkflowTemplates(request, options, callback); @@ -1488,7 +1488,7 @@ export class WorkflowTemplateServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); const defaultCallSettings = this._defaults['listWorkflowTemplates']; const callSettings = defaultCallSettings.merge(options); @@ -1545,7 +1545,7 @@ export class WorkflowTemplateServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); const defaultCallSettings = this._defaults['listWorkflowTemplates']; const callSettings = defaultCallSettings.merge(options); diff --git a/test/gapic_autoscaling_policy_service_v1.ts b/test/gapic_autoscaling_policy_service_v1.ts index 746a32f8..93ce32d8 100644 --- a/test/gapic_autoscaling_policy_service_v1.ts +++ b/test/gapic_autoscaling_policy_service_v1.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf} from 'google-gax'; +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON( + require('../protos/protos.json') +).resolveAll(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type.fields[field]?.resolvedType as protobuf.Type; + } + return type.fields[fields[fields.length - 1]]?.defaultValue; +} + function generateSampleMessage(instance: T) { const filledObject = ( instance.constructor as typeof protobuf.Message @@ -233,15 +248,12 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CreateAutoscalingPolicyRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateAutoscalingPolicyRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.AutoscalingPolicy() ); @@ -249,11 +261,14 @@ describe('v1.AutoscalingPolicyServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.createAutoscalingPolicy(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createAutoscalingPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createAutoscalingPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createAutoscalingPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createAutoscalingPolicy without error using callback', async () => { @@ -266,15 +281,12 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CreateAutoscalingPolicyRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateAutoscalingPolicyRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.AutoscalingPolicy() ); @@ -297,11 +309,14 @@ describe('v1.AutoscalingPolicyServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createAutoscalingPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createAutoscalingPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createAutoscalingPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createAutoscalingPolicy with error', async () => { @@ -314,15 +329,12 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CreateAutoscalingPolicyRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateAutoscalingPolicyRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createAutoscalingPolicy = stubSimpleCall( undefined, @@ -332,11 +344,14 @@ describe('v1.AutoscalingPolicyServiceClient', () => { client.createAutoscalingPolicy(request), expectedError ); - assert( - (client.innerApiCalls.createAutoscalingPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createAutoscalingPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createAutoscalingPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createAutoscalingPolicy with closed client', async () => { @@ -349,7 +364,11 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CreateAutoscalingPolicyRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + 'CreateAutoscalingPolicyRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -370,16 +389,13 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.UpdateAutoscalingPolicyRequest() ); - request.policy = {}; - request.policy.name = ''; - const expectedHeaderRequestParams = 'policy.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.policy ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateAutoscalingPolicyRequest', + ['policy', 'name'] + ); + request.policy.name = defaultValue1; + const expectedHeaderRequestParams = `policy.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.AutoscalingPolicy() ); @@ -387,11 +403,14 @@ describe('v1.AutoscalingPolicyServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.updateAutoscalingPolicy(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateAutoscalingPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateAutoscalingPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateAutoscalingPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateAutoscalingPolicy without error using callback', async () => { @@ -404,16 +423,13 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.UpdateAutoscalingPolicyRequest() ); - request.policy = {}; - request.policy.name = ''; - const expectedHeaderRequestParams = 'policy.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.policy ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateAutoscalingPolicyRequest', + ['policy', 'name'] + ); + request.policy.name = defaultValue1; + const expectedHeaderRequestParams = `policy.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.AutoscalingPolicy() ); @@ -436,11 +452,14 @@ describe('v1.AutoscalingPolicyServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateAutoscalingPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateAutoscalingPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateAutoscalingPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateAutoscalingPolicy with error', async () => { @@ -453,16 +472,13 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.UpdateAutoscalingPolicyRequest() ); - request.policy = {}; - request.policy.name = ''; - const expectedHeaderRequestParams = 'policy.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.policy ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateAutoscalingPolicyRequest', + ['policy', 'name'] + ); + request.policy.name = defaultValue1; + const expectedHeaderRequestParams = `policy.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateAutoscalingPolicy = stubSimpleCall( undefined, @@ -472,11 +488,14 @@ describe('v1.AutoscalingPolicyServiceClient', () => { client.updateAutoscalingPolicy(request), expectedError ); - assert( - (client.innerApiCalls.updateAutoscalingPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateAutoscalingPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateAutoscalingPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateAutoscalingPolicy with closed client', async () => { @@ -489,8 +508,12 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.UpdateAutoscalingPolicyRequest() ); - request.policy = {}; - request.policy.name = ''; + request.policy ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateAutoscalingPolicyRequest', + ['policy', 'name'] + ); + request.policy.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -511,15 +534,11 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetAutoscalingPolicyRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetAutoscalingPolicyRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.AutoscalingPolicy() ); @@ -527,11 +546,14 @@ describe('v1.AutoscalingPolicyServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.getAutoscalingPolicy(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getAutoscalingPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getAutoscalingPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getAutoscalingPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getAutoscalingPolicy without error using callback', async () => { @@ -544,15 +566,11 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetAutoscalingPolicyRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetAutoscalingPolicyRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.AutoscalingPolicy() ); @@ -575,11 +593,14 @@ describe('v1.AutoscalingPolicyServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getAutoscalingPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getAutoscalingPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getAutoscalingPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getAutoscalingPolicy with error', async () => { @@ -592,26 +613,25 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetAutoscalingPolicyRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetAutoscalingPolicyRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getAutoscalingPolicy = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getAutoscalingPolicy(request), expectedError); - assert( - (client.innerApiCalls.getAutoscalingPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getAutoscalingPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getAutoscalingPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getAutoscalingPolicy with closed client', async () => { @@ -624,7 +644,10 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetAutoscalingPolicyRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetAutoscalingPolicyRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getAutoscalingPolicy(request), expectedError); @@ -642,15 +665,12 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteAutoscalingPolicyRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteAutoscalingPolicyRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -658,11 +678,14 @@ describe('v1.AutoscalingPolicyServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.deleteAutoscalingPolicy(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteAutoscalingPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteAutoscalingPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteAutoscalingPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteAutoscalingPolicy without error using callback', async () => { @@ -675,15 +698,12 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteAutoscalingPolicyRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteAutoscalingPolicyRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -706,11 +726,14 @@ describe('v1.AutoscalingPolicyServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteAutoscalingPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteAutoscalingPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteAutoscalingPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteAutoscalingPolicy with error', async () => { @@ -723,15 +746,12 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteAutoscalingPolicyRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteAutoscalingPolicyRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteAutoscalingPolicy = stubSimpleCall( undefined, @@ -741,11 +761,14 @@ describe('v1.AutoscalingPolicyServiceClient', () => { client.deleteAutoscalingPolicy(request), expectedError ); - assert( - (client.innerApiCalls.deleteAutoscalingPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteAutoscalingPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteAutoscalingPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteAutoscalingPolicy with closed client', async () => { @@ -758,7 +781,11 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteAutoscalingPolicyRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + 'DeleteAutoscalingPolicyRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -779,15 +806,12 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListAutoscalingPoliciesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListAutoscalingPoliciesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dataproc.v1.AutoscalingPolicy() @@ -803,11 +827,14 @@ describe('v1.AutoscalingPolicyServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.listAutoscalingPolicies(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listAutoscalingPolicies as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listAutoscalingPolicies as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listAutoscalingPolicies as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listAutoscalingPolicies without error using callback', async () => { @@ -820,15 +847,12 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListAutoscalingPoliciesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListAutoscalingPoliciesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dataproc.v1.AutoscalingPolicy() @@ -859,11 +883,14 @@ describe('v1.AutoscalingPolicyServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listAutoscalingPolicies as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listAutoscalingPolicies as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listAutoscalingPolicies as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listAutoscalingPolicies with error', async () => { @@ -876,15 +903,12 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListAutoscalingPoliciesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListAutoscalingPoliciesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listAutoscalingPolicies = stubSimpleCall( undefined, @@ -894,11 +918,14 @@ describe('v1.AutoscalingPolicyServiceClient', () => { client.listAutoscalingPolicies(request), expectedError ); - assert( - (client.innerApiCalls.listAutoscalingPolicies as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listAutoscalingPolicies as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listAutoscalingPolicies as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listAutoscalingPoliciesStream without error', async () => { @@ -911,8 +938,12 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListAutoscalingPoliciesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListAutoscalingPoliciesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dataproc.v1.AutoscalingPolicy() @@ -953,12 +984,15 @@ describe('v1.AutoscalingPolicyServiceClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listAutoscalingPolicies, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.listAutoscalingPolicies .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -972,8 +1006,12 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListAutoscalingPoliciesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListAutoscalingPoliciesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listAutoscalingPolicies.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1003,12 +1041,15 @@ describe('v1.AutoscalingPolicyServiceClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listAutoscalingPolicies, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.listAutoscalingPolicies .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1022,8 +1063,12 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListAutoscalingPoliciesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListAutoscalingPoliciesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dataproc.v1.AutoscalingPolicy() @@ -1051,12 +1096,15 @@ describe('v1.AutoscalingPolicyServiceClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.listAutoscalingPolicies .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1070,8 +1118,12 @@ describe('v1.AutoscalingPolicyServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListAutoscalingPoliciesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListAutoscalingPoliciesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listAutoscalingPolicies.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1090,12 +1142,15 @@ describe('v1.AutoscalingPolicyServiceClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.listAutoscalingPolicies .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_batch_controller_v1.ts b/test/gapic_batch_controller_v1.ts index f42db7ce..b5610269 100644 --- a/test/gapic_batch_controller_v1.ts +++ b/test/gapic_batch_controller_v1.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, LROperation, operationsProtos} from 'google-gax'; +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON( + require('../protos/protos.json') +).resolveAll(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type.fields[field]?.resolvedType as protobuf.Type; + } + return type.fields[fields[fields.length - 1]]?.defaultValue; +} + function generateSampleMessage(instance: T) { const filledObject = ( instance.constructor as typeof protobuf.Message @@ -254,26 +269,23 @@ describe('v1.BatchControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetBatchRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetBatchRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.Batch() ); client.innerApiCalls.getBatch = stubSimpleCall(expectedResponse); const [response] = await client.getBatch(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getBatch as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getBatch as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getBatch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getBatch without error using callback', async () => { @@ -285,15 +297,9 @@ describe('v1.BatchControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetBatchRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetBatchRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.Batch() ); @@ -316,11 +322,14 @@ describe('v1.BatchControllerClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getBatch as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getBatch as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getBatch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getBatch with error', async () => { @@ -332,23 +341,20 @@ describe('v1.BatchControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetBatchRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetBatchRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getBatch = stubSimpleCall(undefined, expectedError); await assert.rejects(client.getBatch(request), expectedError); - assert( - (client.innerApiCalls.getBatch as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getBatch as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getBatch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getBatch with closed client', async () => { @@ -360,7 +366,8 @@ describe('v1.BatchControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetBatchRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetBatchRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getBatch(request), expectedError); @@ -377,26 +384,23 @@ describe('v1.BatchControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteBatchRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteBatchRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteBatch = stubSimpleCall(expectedResponse); const [response] = await client.deleteBatch(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteBatch as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteBatch as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteBatch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteBatch without error using callback', async () => { @@ -408,15 +412,9 @@ describe('v1.BatchControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteBatchRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteBatchRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -439,11 +437,14 @@ describe('v1.BatchControllerClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteBatch as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteBatch as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteBatch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteBatch with error', async () => { @@ -455,26 +456,23 @@ describe('v1.BatchControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteBatchRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteBatchRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteBatch = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteBatch(request), expectedError); - assert( - (client.innerApiCalls.deleteBatch as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteBatch as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteBatch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteBatch with closed client', async () => { @@ -486,7 +484,8 @@ describe('v1.BatchControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteBatchRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeleteBatchRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteBatch(request), expectedError); @@ -503,15 +502,11 @@ describe('v1.BatchControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CreateBatchRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateBatchRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -519,11 +514,14 @@ describe('v1.BatchControllerClient', () => { const [operation] = await client.createBatch(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createBatch as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createBatch as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createBatch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createBatch without error using callback', async () => { @@ -535,15 +533,11 @@ describe('v1.BatchControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CreateBatchRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateBatchRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -573,11 +567,14 @@ describe('v1.BatchControllerClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createBatch as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createBatch as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createBatch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createBatch with call error', async () => { @@ -589,26 +586,25 @@ describe('v1.BatchControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CreateBatchRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateBatchRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createBatch = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.createBatch(request), expectedError); - assert( - (client.innerApiCalls.createBatch as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createBatch as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createBatch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createBatch with LRO error', async () => { @@ -620,15 +616,11 @@ describe('v1.BatchControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CreateBatchRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateBatchRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createBatch = stubLongRunningCall( undefined, @@ -637,11 +629,14 @@ describe('v1.BatchControllerClient', () => { ); const [operation] = await client.createBatch(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.createBatch as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createBatch as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createBatch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkCreateBatchProgress without error', async () => { @@ -693,15 +688,11 @@ describe('v1.BatchControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListBatchesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListBatchesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dataproc.v1.Batch()), generateSampleMessage(new protos.google.cloud.dataproc.v1.Batch()), @@ -710,11 +701,14 @@ describe('v1.BatchControllerClient', () => { client.innerApiCalls.listBatches = stubSimpleCall(expectedResponse); const [response] = await client.listBatches(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listBatches as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listBatches as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listBatches as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listBatches without error using callback', async () => { @@ -726,15 +720,11 @@ describe('v1.BatchControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListBatchesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListBatchesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dataproc.v1.Batch()), generateSampleMessage(new protos.google.cloud.dataproc.v1.Batch()), @@ -759,11 +749,14 @@ describe('v1.BatchControllerClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listBatches as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listBatches as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listBatches as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listBatches with error', async () => { @@ -775,26 +768,25 @@ describe('v1.BatchControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListBatchesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListBatchesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listBatches = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listBatches(request), expectedError); - assert( - (client.innerApiCalls.listBatches as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listBatches as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listBatches as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listBatchesStream without error', async () => { @@ -806,8 +798,11 @@ describe('v1.BatchControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListBatchesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListBatchesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dataproc.v1.Batch()), generateSampleMessage(new protos.google.cloud.dataproc.v1.Batch()), @@ -835,11 +830,12 @@ describe('v1.BatchControllerClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listBatches, request) ); - assert.strictEqual( - (client.descriptors.page.listBatches.createStream as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listBatches.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -852,8 +848,11 @@ describe('v1.BatchControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListBatchesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListBatchesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listBatches.createStream = stubPageStreamingCall( undefined, @@ -878,11 +877,12 @@ describe('v1.BatchControllerClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listBatches, request) ); - assert.strictEqual( - (client.descriptors.page.listBatches.createStream as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listBatches.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -895,8 +895,11 @@ describe('v1.BatchControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListBatchesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListBatchesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dataproc.v1.Batch()), generateSampleMessage(new protos.google.cloud.dataproc.v1.Batch()), @@ -916,11 +919,12 @@ describe('v1.BatchControllerClient', () => { ).args[1], request ); - assert.strictEqual( - (client.descriptors.page.listBatches.asyncIterate as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listBatches.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -933,8 +937,11 @@ describe('v1.BatchControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListBatchesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListBatchesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listBatches.asyncIterate = stubAsyncIterationCall( undefined, @@ -953,11 +960,12 @@ describe('v1.BatchControllerClient', () => { ).args[1], request ); - assert.strictEqual( - (client.descriptors.page.listBatches.asyncIterate as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listBatches.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_cluster_controller_v1.ts b/test/gapic_cluster_controller_v1.ts index 65041098..aa841892 100644 --- a/test/gapic_cluster_controller_v1.ts +++ b/test/gapic_cluster_controller_v1.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, LROperation, operationsProtos} from 'google-gax'; +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON( + require('../protos/protos.json') +).resolveAll(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type.fields[field]?.resolvedType as protobuf.Type; + } + return type.fields[fields[fields.length - 1]]?.defaultValue; +} + function generateSampleMessage(instance: T) { const filledObject = ( instance.constructor as typeof protobuf.Message @@ -254,28 +269,33 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('GetClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('GetClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.Cluster() ); client.innerApiCalls.getCluster = stubSimpleCall(expectedResponse); const [response] = await client.getCluster(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getCluster without error using callback', async () => { @@ -287,17 +307,19 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('GetClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('GetClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.Cluster() ); @@ -320,11 +342,14 @@ describe('v1.ClusterControllerClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getCluster with error', async () => { @@ -336,28 +361,33 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('GetClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('GetClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedError = new Error('expected'); client.innerApiCalls.getCluster = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getCluster(request), expectedError); - assert( - (client.innerApiCalls.getCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getCluster with closed client', async () => { @@ -369,9 +399,18 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; + const defaultValue1 = getTypeDefaultValue('GetClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('GetClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('GetClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getCluster(request), expectedError); @@ -388,16 +427,15 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CreateClusterRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('CreateClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -406,11 +444,14 @@ describe('v1.ClusterControllerClient', () => { const [operation] = await client.createCluster(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createCluster without error using callback', async () => { @@ -422,16 +463,15 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CreateClusterRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('CreateClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -461,11 +501,14 @@ describe('v1.ClusterControllerClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createCluster with call error', async () => { @@ -477,27 +520,29 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CreateClusterRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('CreateClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedError = new Error('expected'); client.innerApiCalls.createCluster = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.createCluster(request), expectedError); - assert( - (client.innerApiCalls.createCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createCluster with LRO error', async () => { @@ -509,16 +554,15 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CreateClusterRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('CreateClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedError = new Error('expected'); client.innerApiCalls.createCluster = stubLongRunningCall( undefined, @@ -527,11 +571,14 @@ describe('v1.ClusterControllerClient', () => { ); const [operation] = await client.createCluster(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.createCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkCreateClusterProgress without error', async () => { @@ -586,17 +633,19 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.UpdateClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('UpdateClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('UpdateClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('UpdateClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -605,11 +654,14 @@ describe('v1.ClusterControllerClient', () => { const [operation] = await client.updateCluster(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateCluster without error using callback', async () => { @@ -621,17 +673,19 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.UpdateClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('UpdateClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('UpdateClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('UpdateClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -661,11 +715,14 @@ describe('v1.ClusterControllerClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateCluster with call error', async () => { @@ -677,28 +734,33 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.UpdateClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('UpdateClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('UpdateClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('UpdateClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedError = new Error('expected'); client.innerApiCalls.updateCluster = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.updateCluster(request), expectedError); - assert( - (client.innerApiCalls.updateCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateCluster with LRO error', async () => { @@ -710,17 +772,19 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.UpdateClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('UpdateClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('UpdateClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('UpdateClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedError = new Error('expected'); client.innerApiCalls.updateCluster = stubLongRunningCall( undefined, @@ -729,11 +793,14 @@ describe('v1.ClusterControllerClient', () => { ); const [operation] = await client.updateCluster(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.updateCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkUpdateClusterProgress without error', async () => { @@ -788,17 +855,19 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.StopClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StopClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('StopClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('StopClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -806,11 +875,14 @@ describe('v1.ClusterControllerClient', () => { const [operation] = await client.stopCluster(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.stopCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.stopCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.stopCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes stopCluster without error using callback', async () => { @@ -822,17 +894,19 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.StopClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StopClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('StopClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('StopClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -862,11 +936,14 @@ describe('v1.ClusterControllerClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.stopCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.stopCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.stopCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes stopCluster with call error', async () => { @@ -878,28 +955,33 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.StopClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StopClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('StopClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('StopClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedError = new Error('expected'); client.innerApiCalls.stopCluster = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.stopCluster(request), expectedError); - assert( - (client.innerApiCalls.stopCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.stopCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.stopCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes stopCluster with LRO error', async () => { @@ -911,17 +993,19 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.StopClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StopClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('StopClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('StopClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedError = new Error('expected'); client.innerApiCalls.stopCluster = stubLongRunningCall( undefined, @@ -930,11 +1014,14 @@ describe('v1.ClusterControllerClient', () => { ); const [operation] = await client.stopCluster(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.stopCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.stopCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.stopCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkStopClusterProgress without error', async () => { @@ -986,17 +1073,19 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.StartClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StartClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('StartClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('StartClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1004,11 +1093,14 @@ describe('v1.ClusterControllerClient', () => { const [operation] = await client.startCluster(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.startCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.startCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes startCluster without error using callback', async () => { @@ -1020,17 +1112,19 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.StartClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StartClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('StartClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('StartClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1060,11 +1154,14 @@ describe('v1.ClusterControllerClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.startCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.startCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes startCluster with call error', async () => { @@ -1076,28 +1173,33 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.StartClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StartClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('StartClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('StartClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedError = new Error('expected'); client.innerApiCalls.startCluster = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.startCluster(request), expectedError); - assert( - (client.innerApiCalls.startCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.startCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes startCluster with LRO error', async () => { @@ -1109,17 +1211,19 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.StartClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StartClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('StartClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('StartClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedError = new Error('expected'); client.innerApiCalls.startCluster = stubLongRunningCall( undefined, @@ -1128,11 +1232,14 @@ describe('v1.ClusterControllerClient', () => { ); const [operation] = await client.startCluster(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.startCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.startCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkStartClusterProgress without error', async () => { @@ -1184,17 +1291,19 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('DeleteClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('DeleteClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1203,11 +1312,14 @@ describe('v1.ClusterControllerClient', () => { const [operation] = await client.deleteCluster(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteCluster without error using callback', async () => { @@ -1219,17 +1331,19 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('DeleteClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('DeleteClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1259,11 +1373,14 @@ describe('v1.ClusterControllerClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteCluster with call error', async () => { @@ -1275,28 +1392,33 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('DeleteClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('DeleteClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteCluster = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.deleteCluster(request), expectedError); - assert( - (client.innerApiCalls.deleteCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteCluster with LRO error', async () => { @@ -1308,17 +1430,19 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('DeleteClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('DeleteClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteCluster = stubLongRunningCall( undefined, @@ -1327,11 +1451,14 @@ describe('v1.ClusterControllerClient', () => { ); const [operation] = await client.deleteCluster(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.deleteCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkDeleteClusterProgress without error', async () => { @@ -1386,17 +1513,19 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DiagnoseClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DiagnoseClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('DiagnoseClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('DiagnoseClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1405,11 +1534,14 @@ describe('v1.ClusterControllerClient', () => { const [operation] = await client.diagnoseCluster(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.diagnoseCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.diagnoseCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.diagnoseCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes diagnoseCluster without error using callback', async () => { @@ -1421,17 +1553,19 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DiagnoseClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DiagnoseClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('DiagnoseClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('DiagnoseClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1461,11 +1595,14 @@ describe('v1.ClusterControllerClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.diagnoseCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.diagnoseCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.diagnoseCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes diagnoseCluster with call error', async () => { @@ -1477,28 +1614,33 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DiagnoseClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DiagnoseClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('DiagnoseClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('DiagnoseClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedError = new Error('expected'); client.innerApiCalls.diagnoseCluster = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.diagnoseCluster(request), expectedError); - assert( - (client.innerApiCalls.diagnoseCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.diagnoseCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.diagnoseCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes diagnoseCluster with LRO error', async () => { @@ -1510,17 +1652,19 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DiagnoseClusterRequest() ); - request.projectId = ''; - request.region = ''; - request.clusterName = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&cluster_name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DiagnoseClusterRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('DiagnoseClusterRequest', [ + 'region', + ]); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('DiagnoseClusterRequest', [ + 'clusterName', + ]); + request.clusterName = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&cluster_name=${defaultValue3}`; const expectedError = new Error('expected'); client.innerApiCalls.diagnoseCluster = stubLongRunningCall( undefined, @@ -1529,11 +1673,14 @@ describe('v1.ClusterControllerClient', () => { ); const [operation] = await client.diagnoseCluster(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.diagnoseCluster as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.diagnoseCluster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.diagnoseCluster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkDiagnoseClusterProgress without error', async () => { @@ -1588,16 +1735,15 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListClustersRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListClustersRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('ListClustersRequest', [ + 'region', + ]); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dataproc.v1.Cluster()), generateSampleMessage(new protos.google.cloud.dataproc.v1.Cluster()), @@ -1606,11 +1752,14 @@ describe('v1.ClusterControllerClient', () => { client.innerApiCalls.listClusters = stubSimpleCall(expectedResponse); const [response] = await client.listClusters(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listClusters as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listClusters as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listClusters as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listClusters without error using callback', async () => { @@ -1622,16 +1771,15 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListClustersRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListClustersRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('ListClustersRequest', [ + 'region', + ]); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dataproc.v1.Cluster()), generateSampleMessage(new protos.google.cloud.dataproc.v1.Cluster()), @@ -1656,11 +1804,14 @@ describe('v1.ClusterControllerClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listClusters as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listClusters as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listClusters as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listClusters with error', async () => { @@ -1672,27 +1823,29 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListClustersRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListClustersRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('ListClustersRequest', [ + 'region', + ]); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedError = new Error('expected'); client.innerApiCalls.listClusters = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listClusters(request), expectedError); - assert( - (client.innerApiCalls.listClusters as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listClusters as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listClusters as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listClustersStream without error', async () => { @@ -1704,9 +1857,15 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListClustersRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; + const defaultValue1 = getTypeDefaultValue('ListClustersRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('ListClustersRequest', [ + 'region', + ]); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dataproc.v1.Cluster()), generateSampleMessage(new protos.google.cloud.dataproc.v1.Cluster()), @@ -1737,11 +1896,12 @@ describe('v1.ClusterControllerClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listClusters, request) ); - assert.strictEqual( - ( - client.descriptors.page.listClusters.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listClusters.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1754,9 +1914,15 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListClustersRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; + const defaultValue1 = getTypeDefaultValue('ListClustersRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('ListClustersRequest', [ + 'region', + ]); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedError = new Error('expected'); client.descriptors.page.listClusters.createStream = stubPageStreamingCall( undefined, @@ -1784,11 +1950,12 @@ describe('v1.ClusterControllerClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listClusters, request) ); - assert.strictEqual( - ( - client.descriptors.page.listClusters.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listClusters.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1801,9 +1968,15 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListClustersRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; + const defaultValue1 = getTypeDefaultValue('ListClustersRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('ListClustersRequest', [ + 'region', + ]); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dataproc.v1.Cluster()), generateSampleMessage(new protos.google.cloud.dataproc.v1.Cluster()), @@ -1823,11 +1996,12 @@ describe('v1.ClusterControllerClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listClusters.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listClusters.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1840,9 +2014,15 @@ describe('v1.ClusterControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListClustersRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; + const defaultValue1 = getTypeDefaultValue('ListClustersRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('ListClustersRequest', [ + 'region', + ]); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedError = new Error('expected'); client.descriptors.page.listClusters.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1859,11 +2039,12 @@ describe('v1.ClusterControllerClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listClusters.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listClusters.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_job_controller_v1.ts b/test/gapic_job_controller_v1.ts index e9f29aec..3756dd08 100644 --- a/test/gapic_job_controller_v1.ts +++ b/test/gapic_job_controller_v1.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, LROperation, operationsProtos} from 'google-gax'; +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON( + require('../protos/protos.json') +).resolveAll(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type.fields[field]?.resolvedType as protobuf.Type; + } + return type.fields[fields[fields.length - 1]]?.defaultValue; +} + function generateSampleMessage(instance: T) { const filledObject = ( instance.constructor as typeof protobuf.Message @@ -254,27 +269,27 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.SubmitJobRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('SubmitJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('SubmitJobRequest', ['region']); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.Job() ); client.innerApiCalls.submitJob = stubSimpleCall(expectedResponse); const [response] = await client.submitJob(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.submitJob as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.submitJob as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.submitJob as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes submitJob without error using callback', async () => { @@ -286,16 +301,13 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.SubmitJobRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('SubmitJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('SubmitJobRequest', ['region']); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.Job() ); @@ -318,11 +330,14 @@ describe('v1.JobControllerClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.submitJob as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.submitJob as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.submitJob as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes submitJob with error', async () => { @@ -334,24 +349,24 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.SubmitJobRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('SubmitJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('SubmitJobRequest', ['region']); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedError = new Error('expected'); client.innerApiCalls.submitJob = stubSimpleCall(undefined, expectedError); await assert.rejects(client.submitJob(request), expectedError); - assert( - (client.innerApiCalls.submitJob as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.submitJob as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.submitJob as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes submitJob with closed client', async () => { @@ -363,8 +378,12 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.SubmitJobRequest() ); - request.projectId = ''; - request.region = ''; + const defaultValue1 = getTypeDefaultValue('SubmitJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('SubmitJobRequest', ['region']); + request.region = defaultValue2; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.submitJob(request), expectedError); @@ -381,28 +400,27 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetJobRequest() ); - request.projectId = ''; - request.region = ''; - request.jobId = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&job_id='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetJobRequest', ['projectId']); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('GetJobRequest', ['region']); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('GetJobRequest', ['jobId']); + request.jobId = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&job_id=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.Job() ); client.innerApiCalls.getJob = stubSimpleCall(expectedResponse); const [response] = await client.getJob(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getJob as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = (client.innerApiCalls.getJob as SinonStub).getCall( + 0 + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getJob as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getJob without error using callback', async () => { @@ -414,17 +432,13 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetJobRequest() ); - request.projectId = ''; - request.region = ''; - request.jobId = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&job_id='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetJobRequest', ['projectId']); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('GetJobRequest', ['region']); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('GetJobRequest', ['jobId']); + request.jobId = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&job_id=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.Job() ); @@ -447,11 +461,14 @@ describe('v1.JobControllerClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getJob as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = (client.innerApiCalls.getJob as SinonStub).getCall( + 0 + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getJob as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getJob with error', async () => { @@ -463,25 +480,24 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetJobRequest() ); - request.projectId = ''; - request.region = ''; - request.jobId = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&job_id='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetJobRequest', ['projectId']); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('GetJobRequest', ['region']); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('GetJobRequest', ['jobId']); + request.jobId = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&job_id=${defaultValue3}`; const expectedError = new Error('expected'); client.innerApiCalls.getJob = stubSimpleCall(undefined, expectedError); await assert.rejects(client.getJob(request), expectedError); - assert( - (client.innerApiCalls.getJob as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = (client.innerApiCalls.getJob as SinonStub).getCall( + 0 + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getJob as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getJob with closed client', async () => { @@ -493,9 +509,12 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetJobRequest() ); - request.projectId = ''; - request.region = ''; - request.jobId = ''; + const defaultValue1 = getTypeDefaultValue('GetJobRequest', ['projectId']); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('GetJobRequest', ['region']); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('GetJobRequest', ['jobId']); + request.jobId = defaultValue3; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getJob(request), expectedError); @@ -512,28 +531,29 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.UpdateJobRequest() ); - request.projectId = ''; - request.region = ''; - request.jobId = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&job_id='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('UpdateJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('UpdateJobRequest', ['region']); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('UpdateJobRequest', ['jobId']); + request.jobId = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&job_id=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.Job() ); client.innerApiCalls.updateJob = stubSimpleCall(expectedResponse); const [response] = await client.updateJob(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateJob as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateJob as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateJob as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateJob without error using callback', async () => { @@ -545,17 +565,15 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.UpdateJobRequest() ); - request.projectId = ''; - request.region = ''; - request.jobId = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&job_id='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('UpdateJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('UpdateJobRequest', ['region']); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('UpdateJobRequest', ['jobId']); + request.jobId = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&job_id=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.Job() ); @@ -578,11 +596,14 @@ describe('v1.JobControllerClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateJob as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateJob as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateJob as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateJob with error', async () => { @@ -594,25 +615,26 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.UpdateJobRequest() ); - request.projectId = ''; - request.region = ''; - request.jobId = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&job_id='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('UpdateJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('UpdateJobRequest', ['region']); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('UpdateJobRequest', ['jobId']); + request.jobId = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&job_id=${defaultValue3}`; const expectedError = new Error('expected'); client.innerApiCalls.updateJob = stubSimpleCall(undefined, expectedError); await assert.rejects(client.updateJob(request), expectedError); - assert( - (client.innerApiCalls.updateJob as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateJob as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateJob as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateJob with closed client', async () => { @@ -624,9 +646,14 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.UpdateJobRequest() ); - request.projectId = ''; - request.region = ''; - request.jobId = ''; + const defaultValue1 = getTypeDefaultValue('UpdateJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('UpdateJobRequest', ['region']); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('UpdateJobRequest', ['jobId']); + request.jobId = defaultValue3; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateJob(request), expectedError); @@ -643,28 +670,29 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CancelJobRequest() ); - request.projectId = ''; - request.region = ''; - request.jobId = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&job_id='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CancelJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('CancelJobRequest', ['region']); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('CancelJobRequest', ['jobId']); + request.jobId = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&job_id=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.Job() ); client.innerApiCalls.cancelJob = stubSimpleCall(expectedResponse); const [response] = await client.cancelJob(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.cancelJob as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.cancelJob as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.cancelJob as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes cancelJob without error using callback', async () => { @@ -676,17 +704,15 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CancelJobRequest() ); - request.projectId = ''; - request.region = ''; - request.jobId = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&job_id='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CancelJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('CancelJobRequest', ['region']); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('CancelJobRequest', ['jobId']); + request.jobId = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&job_id=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.Job() ); @@ -709,11 +735,14 @@ describe('v1.JobControllerClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.cancelJob as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.cancelJob as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.cancelJob as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes cancelJob with error', async () => { @@ -725,25 +754,26 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CancelJobRequest() ); - request.projectId = ''; - request.region = ''; - request.jobId = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&job_id='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CancelJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('CancelJobRequest', ['region']); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('CancelJobRequest', ['jobId']); + request.jobId = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&job_id=${defaultValue3}`; const expectedError = new Error('expected'); client.innerApiCalls.cancelJob = stubSimpleCall(undefined, expectedError); await assert.rejects(client.cancelJob(request), expectedError); - assert( - (client.innerApiCalls.cancelJob as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.cancelJob as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.cancelJob as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes cancelJob with closed client', async () => { @@ -755,9 +785,14 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CancelJobRequest() ); - request.projectId = ''; - request.region = ''; - request.jobId = ''; + const defaultValue1 = getTypeDefaultValue('CancelJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('CancelJobRequest', ['region']); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('CancelJobRequest', ['jobId']); + request.jobId = defaultValue3; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.cancelJob(request), expectedError); @@ -774,28 +809,29 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteJobRequest() ); - request.projectId = ''; - request.region = ''; - request.jobId = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&job_id='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('DeleteJobRequest', ['region']); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('DeleteJobRequest', ['jobId']); + request.jobId = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&job_id=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteJob = stubSimpleCall(expectedResponse); const [response] = await client.deleteJob(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteJob as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteJob as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteJob as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteJob without error using callback', async () => { @@ -807,17 +843,15 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteJobRequest() ); - request.projectId = ''; - request.region = ''; - request.jobId = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&job_id='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('DeleteJobRequest', ['region']); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('DeleteJobRequest', ['jobId']); + request.jobId = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&job_id=${defaultValue3}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -840,11 +874,14 @@ describe('v1.JobControllerClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteJob as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteJob as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteJob as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteJob with error', async () => { @@ -856,25 +893,26 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteJobRequest() ); - request.projectId = ''; - request.region = ''; - request.jobId = ''; - const expectedHeaderRequestParams = 'project_id=®ion=&job_id='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('DeleteJobRequest', ['region']); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('DeleteJobRequest', ['jobId']); + request.jobId = defaultValue3; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}&job_id=${defaultValue3}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteJob = stubSimpleCall(undefined, expectedError); await assert.rejects(client.deleteJob(request), expectedError); - assert( - (client.innerApiCalls.deleteJob as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteJob as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteJob as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteJob with closed client', async () => { @@ -886,9 +924,14 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteJobRequest() ); - request.projectId = ''; - request.region = ''; - request.jobId = ''; + const defaultValue1 = getTypeDefaultValue('DeleteJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('DeleteJobRequest', ['region']); + request.region = defaultValue2; + const defaultValue3 = getTypeDefaultValue('DeleteJobRequest', ['jobId']); + request.jobId = defaultValue3; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteJob(request), expectedError); @@ -905,16 +948,13 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.SubmitJobRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('SubmitJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('SubmitJobRequest', ['region']); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -923,11 +963,14 @@ describe('v1.JobControllerClient', () => { const [operation] = await client.submitJobAsOperation(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.submitJobAsOperation as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.submitJobAsOperation as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.submitJobAsOperation as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes submitJobAsOperation without error using callback', async () => { @@ -939,16 +982,13 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.SubmitJobRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('SubmitJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('SubmitJobRequest', ['region']); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -978,11 +1018,14 @@ describe('v1.JobControllerClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.submitJobAsOperation as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.submitJobAsOperation as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.submitJobAsOperation as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes submitJobAsOperation with call error', async () => { @@ -994,27 +1037,27 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.SubmitJobRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('SubmitJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('SubmitJobRequest', ['region']); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedError = new Error('expected'); client.innerApiCalls.submitJobAsOperation = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.submitJobAsOperation(request), expectedError); - assert( - (client.innerApiCalls.submitJobAsOperation as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.submitJobAsOperation as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.submitJobAsOperation as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes submitJobAsOperation with LRO error', async () => { @@ -1026,16 +1069,13 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.SubmitJobRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('SubmitJobRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('SubmitJobRequest', ['region']); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedError = new Error('expected'); client.innerApiCalls.submitJobAsOperation = stubLongRunningCall( undefined, @@ -1044,11 +1084,14 @@ describe('v1.JobControllerClient', () => { ); const [operation] = await client.submitJobAsOperation(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.submitJobAsOperation as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.submitJobAsOperation as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.submitJobAsOperation as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkSubmitJobAsOperationProgress without error', async () => { @@ -1103,16 +1146,13 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListJobsRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListJobsRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('ListJobsRequest', ['region']); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dataproc.v1.Job()), generateSampleMessage(new protos.google.cloud.dataproc.v1.Job()), @@ -1121,11 +1161,14 @@ describe('v1.JobControllerClient', () => { client.innerApiCalls.listJobs = stubSimpleCall(expectedResponse); const [response] = await client.listJobs(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listJobs as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listJobs as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listJobs as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listJobs without error using callback', async () => { @@ -1137,16 +1180,13 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListJobsRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListJobsRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('ListJobsRequest', ['region']); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dataproc.v1.Job()), generateSampleMessage(new protos.google.cloud.dataproc.v1.Job()), @@ -1171,11 +1211,14 @@ describe('v1.JobControllerClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listJobs as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listJobs as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listJobs as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listJobs with error', async () => { @@ -1187,24 +1230,24 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListJobsRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListJobsRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('ListJobsRequest', ['region']); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedError = new Error('expected'); client.innerApiCalls.listJobs = stubSimpleCall(undefined, expectedError); await assert.rejects(client.listJobs(request), expectedError); - assert( - (client.innerApiCalls.listJobs as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listJobs as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listJobs as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listJobsStream without error', async () => { @@ -1216,9 +1259,13 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListJobsRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; + const defaultValue1 = getTypeDefaultValue('ListJobsRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('ListJobsRequest', ['region']); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dataproc.v1.Job()), generateSampleMessage(new protos.google.cloud.dataproc.v1.Job()), @@ -1246,10 +1293,12 @@ describe('v1.JobControllerClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listJobs, request) ); - assert.strictEqual( - (client.descriptors.page.listJobs.createStream as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listJobs.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1262,9 +1311,13 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListJobsRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; + const defaultValue1 = getTypeDefaultValue('ListJobsRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('ListJobsRequest', ['region']); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedError = new Error('expected'); client.descriptors.page.listJobs.createStream = stubPageStreamingCall( undefined, @@ -1289,10 +1342,12 @@ describe('v1.JobControllerClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listJobs, request) ); - assert.strictEqual( - (client.descriptors.page.listJobs.createStream as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listJobs.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1305,9 +1360,13 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListJobsRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; + const defaultValue1 = getTypeDefaultValue('ListJobsRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('ListJobsRequest', ['region']); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dataproc.v1.Job()), generateSampleMessage(new protos.google.cloud.dataproc.v1.Job()), @@ -1326,10 +1385,12 @@ describe('v1.JobControllerClient', () => { .args[1], request ); - assert.strictEqual( - (client.descriptors.page.listJobs.asyncIterate as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listJobs.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1342,9 +1403,13 @@ describe('v1.JobControllerClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListJobsRequest() ); - request.projectId = ''; - request.region = ''; - const expectedHeaderRequestParams = 'project_id=®ion='; + const defaultValue1 = getTypeDefaultValue('ListJobsRequest', [ + 'projectId', + ]); + request.projectId = defaultValue1; + const defaultValue2 = getTypeDefaultValue('ListJobsRequest', ['region']); + request.region = defaultValue2; + const expectedHeaderRequestParams = `project_id=${defaultValue1}®ion=${defaultValue2}`; const expectedError = new Error('expected'); client.descriptors.page.listJobs.asyncIterate = stubAsyncIterationCall( undefined, @@ -1362,10 +1427,12 @@ describe('v1.JobControllerClient', () => { .args[1], request ); - assert.strictEqual( - (client.descriptors.page.listJobs.asyncIterate as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listJobs.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_workflow_template_service_v1.ts b/test/gapic_workflow_template_service_v1.ts index 2b0325ff..e74e68a6 100644 --- a/test/gapic_workflow_template_service_v1.ts +++ b/test/gapic_workflow_template_service_v1.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, LROperation, operationsProtos} from 'google-gax'; +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON( + require('../protos/protos.json') +).resolveAll(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type.fields[field]?.resolvedType as protobuf.Type; + } + return type.fields[fields[fields.length - 1]]?.defaultValue; +} + function generateSampleMessage(instance: T) { const filledObject = ( instance.constructor as typeof protobuf.Message @@ -265,15 +280,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CreateWorkflowTemplateRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateWorkflowTemplateRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.WorkflowTemplate() ); @@ -281,11 +293,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.createWorkflowTemplate(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createWorkflowTemplate without error using callback', async () => { @@ -298,15 +313,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CreateWorkflowTemplateRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateWorkflowTemplateRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.WorkflowTemplate() ); @@ -329,11 +341,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createWorkflowTemplate with error', async () => { @@ -346,15 +361,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CreateWorkflowTemplateRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateWorkflowTemplateRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createWorkflowTemplate = stubSimpleCall( undefined, @@ -364,11 +376,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { client.createWorkflowTemplate(request), expectedError ); - assert( - (client.innerApiCalls.createWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createWorkflowTemplate with closed client', async () => { @@ -381,7 +396,11 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.CreateWorkflowTemplateRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + 'CreateWorkflowTemplateRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -402,15 +421,11 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetWorkflowTemplateRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetWorkflowTemplateRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.WorkflowTemplate() ); @@ -418,11 +433,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.getWorkflowTemplate(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getWorkflowTemplate without error using callback', async () => { @@ -435,15 +453,11 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetWorkflowTemplateRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetWorkflowTemplateRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.WorkflowTemplate() ); @@ -466,11 +480,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getWorkflowTemplate with error', async () => { @@ -483,26 +500,25 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetWorkflowTemplateRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetWorkflowTemplateRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getWorkflowTemplate = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getWorkflowTemplate(request), expectedError); - assert( - (client.innerApiCalls.getWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getWorkflowTemplate with closed client', async () => { @@ -515,7 +531,10 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.GetWorkflowTemplateRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetWorkflowTemplateRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getWorkflowTemplate(request), expectedError); @@ -533,16 +552,13 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.UpdateWorkflowTemplateRequest() ); - request.template = {}; - request.template.name = ''; - const expectedHeaderRequestParams = 'template.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.template ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateWorkflowTemplateRequest', + ['template', 'name'] + ); + request.template.name = defaultValue1; + const expectedHeaderRequestParams = `template.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.WorkflowTemplate() ); @@ -550,11 +566,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.updateWorkflowTemplate(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateWorkflowTemplate without error using callback', async () => { @@ -567,16 +586,13 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.UpdateWorkflowTemplateRequest() ); - request.template = {}; - request.template.name = ''; - const expectedHeaderRequestParams = 'template.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.template ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateWorkflowTemplateRequest', + ['template', 'name'] + ); + request.template.name = defaultValue1; + const expectedHeaderRequestParams = `template.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dataproc.v1.WorkflowTemplate() ); @@ -599,11 +615,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateWorkflowTemplate with error', async () => { @@ -616,16 +635,13 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.UpdateWorkflowTemplateRequest() ); - request.template = {}; - request.template.name = ''; - const expectedHeaderRequestParams = 'template.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.template ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateWorkflowTemplateRequest', + ['template', 'name'] + ); + request.template.name = defaultValue1; + const expectedHeaderRequestParams = `template.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateWorkflowTemplate = stubSimpleCall( undefined, @@ -635,11 +651,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { client.updateWorkflowTemplate(request), expectedError ); - assert( - (client.innerApiCalls.updateWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateWorkflowTemplate with closed client', async () => { @@ -652,8 +671,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.UpdateWorkflowTemplateRequest() ); - request.template = {}; - request.template.name = ''; + request.template ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateWorkflowTemplateRequest', + ['template', 'name'] + ); + request.template.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -674,15 +697,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteWorkflowTemplateRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteWorkflowTemplateRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -690,11 +710,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.deleteWorkflowTemplate(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteWorkflowTemplate without error using callback', async () => { @@ -707,15 +730,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteWorkflowTemplateRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteWorkflowTemplateRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -738,11 +758,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteWorkflowTemplate with error', async () => { @@ -755,15 +778,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteWorkflowTemplateRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteWorkflowTemplateRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteWorkflowTemplate = stubSimpleCall( undefined, @@ -773,11 +793,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { client.deleteWorkflowTemplate(request), expectedError ); - assert( - (client.innerApiCalls.deleteWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteWorkflowTemplate with closed client', async () => { @@ -790,7 +813,11 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.DeleteWorkflowTemplateRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + 'DeleteWorkflowTemplateRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -811,15 +838,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.InstantiateWorkflowTemplateRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'InstantiateWorkflowTemplateRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -828,11 +852,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { const [operation] = await client.instantiateWorkflowTemplate(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.instantiateWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.instantiateWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.instantiateWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes instantiateWorkflowTemplate without error using callback', async () => { @@ -845,15 +872,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.InstantiateWorkflowTemplateRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'InstantiateWorkflowTemplateRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -883,11 +907,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.instantiateWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.instantiateWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.instantiateWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes instantiateWorkflowTemplate with call error', async () => { @@ -900,15 +927,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.InstantiateWorkflowTemplateRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'InstantiateWorkflowTemplateRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.instantiateWorkflowTemplate = stubLongRunningCall( undefined, @@ -918,11 +942,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { client.instantiateWorkflowTemplate(request), expectedError ); - assert( - (client.innerApiCalls.instantiateWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.instantiateWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.instantiateWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes instantiateWorkflowTemplate with LRO error', async () => { @@ -935,15 +962,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.InstantiateWorkflowTemplateRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'InstantiateWorkflowTemplateRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.instantiateWorkflowTemplate = stubLongRunningCall( undefined, @@ -952,11 +976,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { ); const [operation] = await client.instantiateWorkflowTemplate(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.instantiateWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.instantiateWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.instantiateWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkInstantiateWorkflowTemplateProgress without error', async () => { @@ -1015,15 +1042,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.InstantiateInlineWorkflowTemplateRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'InstantiateInlineWorkflowTemplateRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1034,11 +1058,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { ); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.instantiateInlineWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.instantiateInlineWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.instantiateInlineWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes instantiateInlineWorkflowTemplate without error using callback', async () => { @@ -1051,15 +1078,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.InstantiateInlineWorkflowTemplateRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'InstantiateInlineWorkflowTemplateRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1089,11 +1113,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.instantiateInlineWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.instantiateInlineWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.instantiateInlineWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes instantiateInlineWorkflowTemplate with call error', async () => { @@ -1106,15 +1133,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.InstantiateInlineWorkflowTemplateRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'InstantiateInlineWorkflowTemplateRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.instantiateInlineWorkflowTemplate = stubLongRunningCall(undefined, expectedError); @@ -1122,11 +1146,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { client.instantiateInlineWorkflowTemplate(request), expectedError ); - assert( - (client.innerApiCalls.instantiateInlineWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.instantiateInlineWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.instantiateInlineWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes instantiateInlineWorkflowTemplate with LRO error', async () => { @@ -1139,15 +1166,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.InstantiateInlineWorkflowTemplateRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'InstantiateInlineWorkflowTemplateRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.instantiateInlineWorkflowTemplate = stubLongRunningCall(undefined, undefined, expectedError); @@ -1155,11 +1179,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { request ); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.instantiateInlineWorkflowTemplate as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.instantiateInlineWorkflowTemplate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.instantiateInlineWorkflowTemplate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkInstantiateInlineWorkflowTemplateProgress without error', async () => { @@ -1218,15 +1245,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListWorkflowTemplatesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListWorkflowTemplatesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dataproc.v1.WorkflowTemplate() @@ -1242,11 +1266,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.listWorkflowTemplates(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listWorkflowTemplates as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listWorkflowTemplates as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listWorkflowTemplates as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listWorkflowTemplates without error using callback', async () => { @@ -1259,15 +1286,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListWorkflowTemplatesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListWorkflowTemplatesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dataproc.v1.WorkflowTemplate() @@ -1298,11 +1322,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listWorkflowTemplates as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listWorkflowTemplates as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listWorkflowTemplates as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listWorkflowTemplates with error', async () => { @@ -1315,15 +1342,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListWorkflowTemplatesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListWorkflowTemplatesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listWorkflowTemplates = stubSimpleCall( undefined, @@ -1333,11 +1357,14 @@ describe('v1.WorkflowTemplateServiceClient', () => { client.listWorkflowTemplates(request), expectedError ); - assert( - (client.innerApiCalls.listWorkflowTemplates as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listWorkflowTemplates as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listWorkflowTemplates as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listWorkflowTemplatesStream without error', async () => { @@ -1350,8 +1377,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListWorkflowTemplatesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListWorkflowTemplatesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dataproc.v1.WorkflowTemplate() @@ -1392,12 +1423,15 @@ describe('v1.WorkflowTemplateServiceClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listWorkflowTemplates, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.listWorkflowTemplates .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1411,8 +1445,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListWorkflowTemplatesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListWorkflowTemplatesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listWorkflowTemplates.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1442,12 +1480,15 @@ describe('v1.WorkflowTemplateServiceClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listWorkflowTemplates, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.listWorkflowTemplates .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1461,8 +1502,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListWorkflowTemplatesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListWorkflowTemplatesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dataproc.v1.WorkflowTemplate() @@ -1489,12 +1534,15 @@ describe('v1.WorkflowTemplateServiceClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.listWorkflowTemplates .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1508,8 +1556,12 @@ describe('v1.WorkflowTemplateServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dataproc.v1.ListWorkflowTemplatesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListWorkflowTemplatesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listWorkflowTemplates.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1528,12 +1580,15 @@ describe('v1.WorkflowTemplateServiceClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.listWorkflowTemplates .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); });