From 51e82fd484752113c48efba4ff42ac838b961056 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 22 Sep 2022 12:31:57 -0700 Subject: [PATCH] feat: accept google-gax instance as a parameter (#433) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: accept google-gax instance as a parameter Please see the documentation of the client constructor for details. PiperOrigin-RevId: 470332808 Source-Link: https://github.com/googleapis/googleapis/commit/d4a23675457cd8f0b44080e0594ec72de1291b89 Source-Link: https://github.com/googleapis/googleapis-gen/commit/e97a1ac204ead4fe7341f91e72db7c6ac6016341 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZTk3YTFhYzIwNGVhZDRmZTczNDFmOTFlNzJkYjdjNmFjNjAxNjM0MSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fix: use _gaxModule when accessing gax for bundling PiperOrigin-RevId: 470911839 Source-Link: https://github.com/googleapis/googleapis/commit/352756699ebc5b2144c252867c265ea44448712e Source-Link: https://github.com/googleapis/googleapis-gen/commit/f16a1d224f00a630ea43d6a9a1a31f566f45cdea Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZjE2YTFkMjI0ZjAwYTYzMGVhNDNkNmE5YTFhMzFmNTY2ZjQ1Y2RlYSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: use gapic-generator-typescript v2.17.0 PiperOrigin-RevId: 474338479 Source-Link: https://github.com/googleapis/googleapis/commit/d5d35e0353b59719e8917103b1bc7df2782bf6ba Source-Link: https://github.com/googleapis/googleapis-gen/commit/efcd3f93962a103f68f003e2a1eecde6fa216a27 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZWZjZDNmOTM5NjJhMTAzZjY4ZjAwM2UyYTFlZWNkZTZmYTIxNmEyNyJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * test: use fully qualified request type name in tests PiperOrigin-RevId: 475685359 Source-Link: https://github.com/googleapis/googleapis/commit/7a129736313ceb1f277c3b7f7e16d2e04cc901dd Source-Link: https://github.com/googleapis/googleapis-gen/commit/370c729e2ba062a167449c27882ba5f379c5c34d Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMzcwYzcyOWUyYmEwNjJhMTY3NDQ5YzI3ODgyYmE1ZjM3OWM1YzM0ZCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fix: owlbot post-processing for grafeas * fix: add Grafeas import back Co-authored-by: Owl Bot Co-authored-by: Alexander Fenster --- owlbot.py | 4 +- src/v1/container_analysis_client.ts | 47 +- .../container_analysis_v1_beta1_client.ts | 59 +- src/v1beta1/grafeas_v1_beta1_client.ts | 111 +- test/gapic_container_analysis_v1.ts | 375 ++-- ...pic_container_analysis_v1_beta1_v1beta1.ts | 625 ++++--- test/gapic_grafeas_v1_beta1_v1beta1.ts | 1571 +++++++++-------- 7 files changed, 1525 insertions(+), 1267 deletions(-) diff --git a/owlbot.py b/owlbot.py index e88755b..9137671 100644 --- a/owlbot.py +++ b/owlbot.py @@ -30,8 +30,8 @@ def patch(library: pathlib.Path): # perform surgery inserting the Grafeas client. s.replace(library / "src/v1/container_analysis_client.ts", - """import \* as gax from \'google-gax\';""", - """import * as gax from 'google-gax'; + """import type \* as gax from \'google-gax\';""", + """import type * as gax from 'google-gax'; import {GrafeasClient} from '@google-cloud/grafeas';""") s.replace(library / "src/v1/container_analysis_client.ts", "^}", r""" diff --git a/src/v1/container_analysis_client.ts b/src/v1/container_analysis_client.ts index 476705a..12e1b4b 100644 --- a/src/v1/container_analysis_client.ts +++ b/src/v1/container_analysis_client.ts @@ -17,9 +17,14 @@ // ** All changes to this file may be overwritten. ** /* global window */ -import * as gax from 'google-gax'; +import type * as gax from 'google-gax'; import {GrafeasClient} from '@google-cloud/grafeas'; -import {Callback, CallOptions, Descriptors, ClientOptions} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); @@ -29,7 +34,6 @@ import jsonProtos = require('../../protos/protos.json'); * This file defines retry strategy and timeouts for all API methods in this library. */ import * as gapicConfig from './container_analysis_client_config.json'; - const version = require('../../../package.json').version; /** @@ -101,8 +105,18 @@ export class ContainerAnalysisClient { * Pass "rest" to use HTTP/1.1 REST API instead of gRPC. * For more information, please check the * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}. + * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you + * need to avoid loading the default gRPC version and want to use the fallback + * HTTP implementation. Load only fallback version and pass it to the constructor: + * ``` + * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC + * const client = new ContainerAnalysisClient({fallback: 'rest'}, gax); + * ``` */ - constructor(opts?: ClientOptions) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof ContainerAnalysisClient; const servicePath = @@ -122,8 +136,13 @@ export class ContainerAnalysisClient { opts['scopes'] = staticMembers.scopes; } + // Load google-gax module synchronously if needed + if (!gaxInstance) { + gaxInstance = require('google-gax') as typeof gax; + } + // Choose either gRPC or proto-over-HTTP implementation of google-gax. - this._gaxModule = opts.fallback ? gax.fallback : gax; + this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance; // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. this._gaxGrpc = new this._gaxModule.GrpcClient(opts); @@ -192,7 +211,7 @@ export class ContainerAnalysisClient { this.innerApiCalls = {}; // Add a warn function to the client constructor so it can be easily tested. - this.warn = gax.warn; + this.warn = this._gaxModule.warn; } /** @@ -412,8 +431,8 @@ export class ContainerAnalysisClient { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - resource: request.resource || '', + this._gaxModule.routingHeader.fromParams({ + resource: request.resource ?? '', }); this.initialize(); return this.innerApiCalls.setIamPolicy(request, options, callback); @@ -506,8 +525,8 @@ export class ContainerAnalysisClient { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - resource: request.resource || '', + this._gaxModule.routingHeader.fromParams({ + resource: request.resource ?? '', }); this.initialize(); return this.innerApiCalls.getIamPolicy(request, options, callback); @@ -601,8 +620,8 @@ export class ContainerAnalysisClient { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - resource: request.resource || '', + this._gaxModule.routingHeader.fromParams({ + resource: request.resource ?? '', }); this.initialize(); return this.innerApiCalls.testIamPermissions(request, options, callback); @@ -701,8 +720,8 @@ export class ContainerAnalysisClient { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - parent: request.parent || '', + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.getVulnerabilityOccurrencesSummary( diff --git a/src/v1beta1/container_analysis_v1_beta1_client.ts b/src/v1beta1/container_analysis_v1_beta1_client.ts index 613d2bb..e3f8d4c 100644 --- a/src/v1beta1/container_analysis_v1_beta1_client.ts +++ b/src/v1beta1/container_analysis_v1_beta1_client.ts @@ -17,8 +17,8 @@ // ** All changes to this file may be overwritten. ** /* global window */ -import * as gax from 'google-gax'; -import { +import type * as gax from 'google-gax'; +import type { Callback, CallOptions, Descriptors, @@ -26,7 +26,6 @@ import { PaginationCallback, GaxCall, } from 'google-gax'; - import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); @@ -36,7 +35,6 @@ import jsonProtos = require('../../protos/protos.json'); * This file defines retry strategy and timeouts for all API methods in this library. */ import * as gapicConfig from './container_analysis_v1_beta1_client_config.json'; - const version = require('../../../package.json').version; /** @@ -108,8 +106,18 @@ export class ContainerAnalysisV1Beta1Client { * Pass "rest" to use HTTP/1.1 REST API instead of gRPC. * For more information, please check the * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}. + * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you + * need to avoid loading the default gRPC version and want to use the fallback + * HTTP implementation. Load only fallback version and pass it to the constructor: + * ``` + * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC + * const client = new ContainerAnalysisV1Beta1Client({fallback: 'rest'}, gax); + * ``` */ - constructor(opts?: ClientOptions) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback + ) { // Ensure that options include all the required fields. const staticMembers = this .constructor as typeof ContainerAnalysisV1Beta1Client; @@ -130,8 +138,13 @@ export class ContainerAnalysisV1Beta1Client { opts['scopes'] = staticMembers.scopes; } + // Load google-gax module synchronously if needed + if (!gaxInstance) { + gaxInstance = require('google-gax') as typeof gax; + } + // Choose either gRPC or proto-over-HTTP implementation of google-gax. - this._gaxModule = opts.fallback ? gax.fallback : gax; + this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance; // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. this._gaxGrpc = new this._gaxModule.GrpcClient(opts); @@ -208,7 +221,7 @@ export class ContainerAnalysisV1Beta1Client { this.innerApiCalls = {}; // Add a warn function to the client constructor so it can be easily tested. - this.warn = gax.warn; + this.warn = this._gaxModule.warn; } /** @@ -430,8 +443,8 @@ export class ContainerAnalysisV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - resource: request.resource || '', + this._gaxModule.routingHeader.fromParams({ + resource: request.resource ?? '', }); this.initialize(); return this.innerApiCalls.setIamPolicy(request, options, callback); @@ -524,8 +537,8 @@ export class ContainerAnalysisV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - resource: request.resource || '', + this._gaxModule.routingHeader.fromParams({ + resource: request.resource ?? '', }); this.initialize(); return this.innerApiCalls.getIamPolicy(request, options, callback); @@ -619,8 +632,8 @@ export class ContainerAnalysisV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - resource: request.resource || '', + this._gaxModule.routingHeader.fromParams({ + resource: request.resource ?? '', }); this.initialize(); return this.innerApiCalls.testIamPermissions(request, options, callback); @@ -717,8 +730,8 @@ export class ContainerAnalysisV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - name: request.name || '', + this._gaxModule.routingHeader.fromParams({ + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.getScanConfig(request, options, callback); @@ -817,8 +830,8 @@ export class ContainerAnalysisV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - name: request.name || '', + this._gaxModule.routingHeader.fromParams({ + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.updateScanConfig(request, options, callback); @@ -919,8 +932,8 @@ export class ContainerAnalysisV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - parent: request.parent || '', + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.listScanConfigs(request, options, callback); @@ -960,8 +973,8 @@ export class ContainerAnalysisV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - parent: request.parent || '', + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', }); const defaultCallSettings = this._defaults['listScanConfigs']; const callSettings = defaultCallSettings.merge(options); @@ -1010,8 +1023,8 @@ export class ContainerAnalysisV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - parent: request.parent || '', + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', }); const defaultCallSettings = this._defaults['listScanConfigs']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v1beta1/grafeas_v1_beta1_client.ts b/src/v1beta1/grafeas_v1_beta1_client.ts index 83b7044..612a126 100644 --- a/src/v1beta1/grafeas_v1_beta1_client.ts +++ b/src/v1beta1/grafeas_v1_beta1_client.ts @@ -17,8 +17,8 @@ // ** All changes to this file may be overwritten. ** /* global window */ -import * as gax from 'google-gax'; -import { +import type * as gax from 'google-gax'; +import type { Callback, CallOptions, Descriptors, @@ -26,7 +26,6 @@ import { PaginationCallback, GaxCall, } from 'google-gax'; - import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); @@ -36,7 +35,6 @@ import jsonProtos = require('../../protos/protos.json'); * This file defines retry strategy and timeouts for all API methods in this library. */ import * as gapicConfig from './grafeas_v1_beta1_client_config.json'; - const version = require('../../../package.json').version; /** @@ -109,8 +107,18 @@ export class GrafeasV1Beta1Client { * Pass "rest" to use HTTP/1.1 REST API instead of gRPC. * For more information, please check the * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}. + * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you + * need to avoid loading the default gRPC version and want to use the fallback + * HTTP implementation. Load only fallback version and pass it to the constructor: + * ``` + * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC + * const client = new GrafeasV1Beta1Client({fallback: 'rest'}, gax); + * ``` */ - constructor(opts?: ClientOptions) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof GrafeasV1Beta1Client; const servicePath = @@ -130,8 +138,13 @@ export class GrafeasV1Beta1Client { opts['scopes'] = staticMembers.scopes; } + // Load google-gax module synchronously if needed + if (!gaxInstance) { + gaxInstance = require('google-gax') as typeof gax; + } + // Choose either gRPC or proto-over-HTTP implementation of google-gax. - this._gaxModule = opts.fallback ? gax.fallback : gax; + this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance; // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. this._gaxGrpc = new this._gaxModule.GrpcClient(opts); @@ -215,7 +228,7 @@ export class GrafeasV1Beta1Client { this.innerApiCalls = {}; // Add a warn function to the client constructor so it can be easily tested. - this.warn = gax.warn; + this.warn = this._gaxModule.warn; } /** @@ -427,8 +440,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - name: request.name || '', + this._gaxModule.routingHeader.fromParams({ + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.getOccurrence(request, options, callback); @@ -513,8 +526,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - name: request.name || '', + this._gaxModule.routingHeader.fromParams({ + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.deleteOccurrence(request, options, callback); @@ -599,8 +612,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - parent: request.parent || '', + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.createOccurrence(request, options, callback); @@ -687,8 +700,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - parent: request.parent || '', + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.batchCreateOccurrences( @@ -779,8 +792,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - name: request.name || '', + this._gaxModule.routingHeader.fromParams({ + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.updateOccurrence(request, options, callback); @@ -864,8 +877,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - name: request.name || '', + this._gaxModule.routingHeader.fromParams({ + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.getOccurrenceNote(request, options, callback); @@ -948,8 +961,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - name: request.name || '', + this._gaxModule.routingHeader.fromParams({ + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.getNote(request, options, callback); @@ -1032,8 +1045,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - name: request.name || '', + this._gaxModule.routingHeader.fromParams({ + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.deleteNote(request, options, callback); @@ -1120,8 +1133,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - parent: request.parent || '', + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.createNote(request, options, callback); @@ -1206,8 +1219,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - parent: request.parent || '', + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.batchCreateNotes(request, options, callback); @@ -1294,8 +1307,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - name: request.name || '', + this._gaxModule.routingHeader.fromParams({ + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.updateNote(request, options, callback); @@ -1394,8 +1407,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - parent: request.parent || '', + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.getVulnerabilityOccurrencesSummary( @@ -1492,8 +1505,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - parent: request.parent || '', + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.listOccurrences(request, options, callback); @@ -1533,8 +1546,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - parent: request.parent || '', + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', }); const defaultCallSettings = this._defaults['listOccurrences']; const callSettings = defaultCallSettings.merge(options); @@ -1583,8 +1596,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - parent: request.parent || '', + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', }); const defaultCallSettings = this._defaults['listOccurrences']; const callSettings = defaultCallSettings.merge(options); @@ -1682,8 +1695,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - parent: request.parent || '', + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.listNotes(request, options, callback); @@ -1723,8 +1736,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - parent: request.parent || '', + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', }); const defaultCallSettings = this._defaults['listNotes']; const callSettings = defaultCallSettings.merge(options); @@ -1773,8 +1786,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - parent: request.parent || '', + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', }); const defaultCallSettings = this._defaults['listNotes']; const callSettings = defaultCallSettings.merge(options); @@ -1876,8 +1889,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - name: request.name || '', + this._gaxModule.routingHeader.fromParams({ + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.listNoteOccurrences(request, options, callback); @@ -1917,8 +1930,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - name: request.name || '', + this._gaxModule.routingHeader.fromParams({ + name: request.name ?? '', }); const defaultCallSettings = this._defaults['listNoteOccurrences']; const callSettings = defaultCallSettings.merge(options); @@ -1967,8 +1980,8 @@ export class GrafeasV1Beta1Client { options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = - gax.routingHeader.fromParams({ - name: request.name || '', + this._gaxModule.routingHeader.fromParams({ + name: request.name ?? '', }); const defaultCallSettings = this._defaults['listNoteOccurrences']; const callSettings = defaultCallSettings.merge(options); diff --git a/test/gapic_container_analysis_v1.ts b/test/gapic_container_analysis_v1.ts index e8af12c..9ef9604 100644 --- a/test/gapic_container_analysis_v1.ts +++ b/test/gapic_container_analysis_v1.ts @@ -25,6 +25,21 @@ import * as containeranalysisModule from '../src'; 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 @@ -159,26 +174,26 @@ describe('v1.ContainerAnalysisClient', () => { const request = generateSampleMessage( new protos.google.iam.v1.SetIamPolicyRequest() ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.SetIamPolicyRequest', + ['resource'] + ); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.iam.v1.Policy() ); client.innerApiCalls.setIamPolicy = stubSimpleCall(expectedResponse); const [response] = await client.setIamPolicy(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.setIamPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.setIamPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.setIamPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes setIamPolicy without error using callback', async () => { @@ -190,15 +205,12 @@ describe('v1.ContainerAnalysisClient', () => { const request = generateSampleMessage( new protos.google.iam.v1.SetIamPolicyRequest() ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.SetIamPolicyRequest', + ['resource'] + ); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.iam.v1.Policy() ); @@ -221,11 +233,14 @@ describe('v1.ContainerAnalysisClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.setIamPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.setIamPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.setIamPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes setIamPolicy with error', async () => { @@ -237,26 +252,26 @@ describe('v1.ContainerAnalysisClient', () => { const request = generateSampleMessage( new protos.google.iam.v1.SetIamPolicyRequest() ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.SetIamPolicyRequest', + ['resource'] + ); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.setIamPolicy = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.setIamPolicy(request), expectedError); - assert( - (client.innerApiCalls.setIamPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.setIamPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.setIamPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes setIamPolicy with closed client', async () => { @@ -268,7 +283,11 @@ describe('v1.ContainerAnalysisClient', () => { const request = generateSampleMessage( new protos.google.iam.v1.SetIamPolicyRequest() ); - request.resource = ''; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.SetIamPolicyRequest', + ['resource'] + ); + request.resource = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.setIamPolicy(request), expectedError); @@ -285,26 +304,26 @@ describe('v1.ContainerAnalysisClient', () => { const request = generateSampleMessage( new protos.google.iam.v1.GetIamPolicyRequest() ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.GetIamPolicyRequest', + ['resource'] + ); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.iam.v1.Policy() ); client.innerApiCalls.getIamPolicy = stubSimpleCall(expectedResponse); const [response] = await client.getIamPolicy(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getIamPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getIamPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getIamPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getIamPolicy without error using callback', async () => { @@ -316,15 +335,12 @@ describe('v1.ContainerAnalysisClient', () => { const request = generateSampleMessage( new protos.google.iam.v1.GetIamPolicyRequest() ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.GetIamPolicyRequest', + ['resource'] + ); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.iam.v1.Policy() ); @@ -347,11 +363,14 @@ describe('v1.ContainerAnalysisClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getIamPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getIamPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getIamPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getIamPolicy with error', async () => { @@ -363,26 +382,26 @@ describe('v1.ContainerAnalysisClient', () => { const request = generateSampleMessage( new protos.google.iam.v1.GetIamPolicyRequest() ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.GetIamPolicyRequest', + ['resource'] + ); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getIamPolicy = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getIamPolicy(request), expectedError); - assert( - (client.innerApiCalls.getIamPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getIamPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getIamPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getIamPolicy with closed client', async () => { @@ -394,7 +413,11 @@ describe('v1.ContainerAnalysisClient', () => { const request = generateSampleMessage( new protos.google.iam.v1.GetIamPolicyRequest() ); - request.resource = ''; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.GetIamPolicyRequest', + ['resource'] + ); + request.resource = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getIamPolicy(request), expectedError); @@ -411,15 +434,12 @@ describe('v1.ContainerAnalysisClient', () => { const request = generateSampleMessage( new protos.google.iam.v1.TestIamPermissionsRequest() ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.TestIamPermissionsRequest', + ['resource'] + ); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.iam.v1.TestIamPermissionsResponse() ); @@ -427,11 +447,14 @@ describe('v1.ContainerAnalysisClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.testIamPermissions(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.testIamPermissions as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.testIamPermissions as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.testIamPermissions as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes testIamPermissions without error using callback', async () => { @@ -443,15 +466,12 @@ describe('v1.ContainerAnalysisClient', () => { const request = generateSampleMessage( new protos.google.iam.v1.TestIamPermissionsRequest() ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.TestIamPermissionsRequest', + ['resource'] + ); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.iam.v1.TestIamPermissionsResponse() ); @@ -474,11 +494,14 @@ describe('v1.ContainerAnalysisClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.testIamPermissions as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.testIamPermissions as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.testIamPermissions as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes testIamPermissions with error', async () => { @@ -490,26 +513,26 @@ describe('v1.ContainerAnalysisClient', () => { const request = generateSampleMessage( new protos.google.iam.v1.TestIamPermissionsRequest() ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.TestIamPermissionsRequest', + ['resource'] + ); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.testIamPermissions = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.testIamPermissions(request), expectedError); - assert( - (client.innerApiCalls.testIamPermissions as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.testIamPermissions as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.testIamPermissions as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes testIamPermissions with closed client', async () => { @@ -521,7 +544,11 @@ describe('v1.ContainerAnalysisClient', () => { const request = generateSampleMessage( new protos.google.iam.v1.TestIamPermissionsRequest() ); - request.resource = ''; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.TestIamPermissionsRequest', + ['resource'] + ); + request.resource = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.testIamPermissions(request), expectedError); @@ -538,15 +565,12 @@ describe('v1.ContainerAnalysisClient', () => { const request = generateSampleMessage( new protos.google.devtools.containeranalysis.v1.GetVulnerabilityOccurrencesSummaryRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.devtools.containeranalysis.v1.GetVulnerabilityOccurrencesSummaryRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.devtools.containeranalysis.v1.VulnerabilityOccurrencesSummary() ); @@ -556,11 +580,14 @@ describe('v1.ContainerAnalysisClient', () => { request ); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getVulnerabilityOccurrencesSummary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getVulnerabilityOccurrencesSummary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getVulnerabilityOccurrencesSummary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getVulnerabilityOccurrencesSummary without error using callback', async () => { @@ -572,15 +599,12 @@ describe('v1.ContainerAnalysisClient', () => { const request = generateSampleMessage( new protos.google.devtools.containeranalysis.v1.GetVulnerabilityOccurrencesSummaryRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.devtools.containeranalysis.v1.GetVulnerabilityOccurrencesSummaryRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.devtools.containeranalysis.v1.VulnerabilityOccurrencesSummary() ); @@ -603,11 +627,14 @@ describe('v1.ContainerAnalysisClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getVulnerabilityOccurrencesSummary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getVulnerabilityOccurrencesSummary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getVulnerabilityOccurrencesSummary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getVulnerabilityOccurrencesSummary with error', async () => { @@ -619,15 +646,12 @@ describe('v1.ContainerAnalysisClient', () => { const request = generateSampleMessage( new protos.google.devtools.containeranalysis.v1.GetVulnerabilityOccurrencesSummaryRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.devtools.containeranalysis.v1.GetVulnerabilityOccurrencesSummaryRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getVulnerabilityOccurrencesSummary = stubSimpleCall( undefined, @@ -637,11 +661,14 @@ describe('v1.ContainerAnalysisClient', () => { client.getVulnerabilityOccurrencesSummary(request), expectedError ); - assert( - (client.innerApiCalls.getVulnerabilityOccurrencesSummary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getVulnerabilityOccurrencesSummary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getVulnerabilityOccurrencesSummary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getVulnerabilityOccurrencesSummary with closed client', async () => { @@ -653,7 +680,11 @@ describe('v1.ContainerAnalysisClient', () => { const request = generateSampleMessage( new protos.google.devtools.containeranalysis.v1.GetVulnerabilityOccurrencesSummaryRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + '.google.devtools.containeranalysis.v1.GetVulnerabilityOccurrencesSummaryRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( diff --git a/test/gapic_container_analysis_v1_beta1_v1beta1.ts b/test/gapic_container_analysis_v1_beta1_v1beta1.ts index 8f6ad66..3debd24 100644 --- a/test/gapic_container_analysis_v1_beta1_v1beta1.ts +++ b/test/gapic_container_analysis_v1_beta1_v1beta1.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 @@ -248,26 +263,26 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.iam.v1.SetIamPolicyRequest() ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.SetIamPolicyRequest', + ['resource'] + ); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.iam.v1.Policy() ); client.innerApiCalls.setIamPolicy = stubSimpleCall(expectedResponse); const [response] = await client.setIamPolicy(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.setIamPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.setIamPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.setIamPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes setIamPolicy without error using callback', async () => { @@ -282,15 +297,12 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.iam.v1.SetIamPolicyRequest() ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.SetIamPolicyRequest', + ['resource'] + ); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.iam.v1.Policy() ); @@ -313,11 +325,14 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.setIamPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.setIamPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.setIamPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes setIamPolicy with error', async () => { @@ -332,26 +347,26 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.iam.v1.SetIamPolicyRequest() ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.SetIamPolicyRequest', + ['resource'] + ); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.setIamPolicy = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.setIamPolicy(request), expectedError); - assert( - (client.innerApiCalls.setIamPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.setIamPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.setIamPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes setIamPolicy with closed client', async () => { @@ -366,7 +381,11 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.iam.v1.SetIamPolicyRequest() ); - request.resource = ''; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.SetIamPolicyRequest', + ['resource'] + ); + request.resource = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.setIamPolicy(request), expectedError); @@ -386,26 +405,26 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.iam.v1.GetIamPolicyRequest() ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.GetIamPolicyRequest', + ['resource'] + ); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.iam.v1.Policy() ); client.innerApiCalls.getIamPolicy = stubSimpleCall(expectedResponse); const [response] = await client.getIamPolicy(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getIamPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getIamPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getIamPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getIamPolicy without error using callback', async () => { @@ -420,15 +439,12 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.iam.v1.GetIamPolicyRequest() ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.GetIamPolicyRequest', + ['resource'] + ); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.iam.v1.Policy() ); @@ -451,11 +467,14 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getIamPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getIamPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getIamPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getIamPolicy with error', async () => { @@ -470,26 +489,26 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.iam.v1.GetIamPolicyRequest() ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.GetIamPolicyRequest', + ['resource'] + ); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getIamPolicy = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getIamPolicy(request), expectedError); - assert( - (client.innerApiCalls.getIamPolicy as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getIamPolicy as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getIamPolicy as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getIamPolicy with closed client', async () => { @@ -504,7 +523,11 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.iam.v1.GetIamPolicyRequest() ); - request.resource = ''; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.GetIamPolicyRequest', + ['resource'] + ); + request.resource = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getIamPolicy(request), expectedError); @@ -524,15 +547,12 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.iam.v1.TestIamPermissionsRequest() ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.TestIamPermissionsRequest', + ['resource'] + ); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.iam.v1.TestIamPermissionsResponse() ); @@ -540,11 +560,14 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { stubSimpleCall(expectedResponse); const [response] = await client.testIamPermissions(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.testIamPermissions as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.testIamPermissions as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.testIamPermissions as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes testIamPermissions without error using callback', async () => { @@ -559,15 +582,12 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.iam.v1.TestIamPermissionsRequest() ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.TestIamPermissionsRequest', + ['resource'] + ); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.iam.v1.TestIamPermissionsResponse() ); @@ -590,11 +610,14 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.testIamPermissions as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.testIamPermissions as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.testIamPermissions as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes testIamPermissions with error', async () => { @@ -609,26 +632,26 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.iam.v1.TestIamPermissionsRequest() ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.TestIamPermissionsRequest', + ['resource'] + ); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.testIamPermissions = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.testIamPermissions(request), expectedError); - assert( - (client.innerApiCalls.testIamPermissions as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.testIamPermissions as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.testIamPermissions as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes testIamPermissions with closed client', async () => { @@ -643,7 +666,11 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.iam.v1.TestIamPermissionsRequest() ); - request.resource = ''; + const defaultValue1 = getTypeDefaultValue( + '.google.iam.v1.TestIamPermissionsRequest', + ['resource'] + ); + request.resource = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.testIamPermissions(request), expectedError); @@ -663,26 +690,26 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.GetScanConfigRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.devtools.containeranalysis.v1beta1.GetScanConfigRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.ScanConfig() ); client.innerApiCalls.getScanConfig = stubSimpleCall(expectedResponse); const [response] = await client.getScanConfig(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getScanConfig as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getScanConfig as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getScanConfig as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getScanConfig without error using callback', async () => { @@ -697,15 +724,12 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.GetScanConfigRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.devtools.containeranalysis.v1beta1.GetScanConfigRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.ScanConfig() ); @@ -728,11 +752,14 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getScanConfig as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getScanConfig as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getScanConfig as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getScanConfig with error', async () => { @@ -747,26 +774,26 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.GetScanConfigRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.devtools.containeranalysis.v1beta1.GetScanConfigRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getScanConfig = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getScanConfig(request), expectedError); - assert( - (client.innerApiCalls.getScanConfig as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getScanConfig as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getScanConfig as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getScanConfig with closed client', async () => { @@ -781,7 +808,11 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.GetScanConfigRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + '.google.devtools.containeranalysis.v1beta1.GetScanConfigRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getScanConfig(request), expectedError); @@ -801,26 +832,26 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.UpdateScanConfigRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.devtools.containeranalysis.v1beta1.UpdateScanConfigRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.ScanConfig() ); client.innerApiCalls.updateScanConfig = stubSimpleCall(expectedResponse); const [response] = await client.updateScanConfig(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateScanConfig as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateScanConfig as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateScanConfig as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateScanConfig without error using callback', async () => { @@ -835,15 +866,12 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.UpdateScanConfigRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.devtools.containeranalysis.v1beta1.UpdateScanConfigRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.ScanConfig() ); @@ -866,11 +894,14 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateScanConfig as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateScanConfig as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateScanConfig as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateScanConfig with error', async () => { @@ -885,26 +916,26 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.UpdateScanConfigRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.devtools.containeranalysis.v1beta1.UpdateScanConfigRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateScanConfig = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateScanConfig(request), expectedError); - assert( - (client.innerApiCalls.updateScanConfig as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateScanConfig as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateScanConfig as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateScanConfig with closed client', async () => { @@ -919,7 +950,11 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.UpdateScanConfigRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + '.google.devtools.containeranalysis.v1beta1.UpdateScanConfigRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateScanConfig(request), expectedError); @@ -939,15 +974,12 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.ListScanConfigsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.devtools.containeranalysis.v1beta1.ListScanConfigsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.ScanConfig() @@ -962,11 +994,14 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { client.innerApiCalls.listScanConfigs = stubSimpleCall(expectedResponse); const [response] = await client.listScanConfigs(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listScanConfigs as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listScanConfigs as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listScanConfigs as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listScanConfigs without error using callback', async () => { @@ -981,15 +1016,12 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.ListScanConfigsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.devtools.containeranalysis.v1beta1.ListScanConfigsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.ScanConfig() @@ -1022,11 +1054,14 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listScanConfigs as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listScanConfigs as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listScanConfigs as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listScanConfigs with error', async () => { @@ -1041,26 +1076,26 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.ListScanConfigsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.devtools.containeranalysis.v1beta1.ListScanConfigsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listScanConfigs = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listScanConfigs(request), expectedError); - assert( - (client.innerApiCalls.listScanConfigs as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listScanConfigs as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listScanConfigs as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listScanConfigsStream without error', async () => { @@ -1075,8 +1110,12 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.ListScanConfigsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.google.devtools.containeranalysis.v1beta1.ListScanConfigsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.ScanConfig() @@ -1116,11 +1155,12 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { .getCall(0) .calledWith(client.innerApiCalls.listScanConfigs, request) ); - assert.strictEqual( - ( - client.descriptors.page.listScanConfigs.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listScanConfigs.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1136,8 +1176,12 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.ListScanConfigsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.google.devtools.containeranalysis.v1beta1.ListScanConfigsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listScanConfigs.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1166,11 +1210,12 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { .getCall(0) .calledWith(client.innerApiCalls.listScanConfigs, request) ); - assert.strictEqual( - ( - client.descriptors.page.listScanConfigs.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listScanConfigs.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1186,8 +1231,12 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.ListScanConfigsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.google.devtools.containeranalysis.v1beta1.ListScanConfigsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.ScanConfig() @@ -1214,11 +1263,12 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listScanConfigs.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listScanConfigs.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1234,8 +1284,12 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { const request = generateSampleMessage( new protos.google.devtools.containeranalysis.v1beta1.ListScanConfigsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.google.devtools.containeranalysis.v1beta1.ListScanConfigsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listScanConfigs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1253,11 +1307,12 @@ describe('v1beta1.ContainerAnalysisV1Beta1Client', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listScanConfigs.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listScanConfigs.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_grafeas_v1_beta1_v1beta1.ts b/test/gapic_grafeas_v1_beta1_v1beta1.ts index c2502bb..570c27a 100644 --- a/test/gapic_grafeas_v1_beta1_v1beta1.ts +++ b/test/gapic_grafeas_v1_beta1_v1beta1.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 @@ -222,26 +237,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.GetOccurrenceRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.GetOccurrenceRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.Occurrence() ); client.innerApiCalls.getOccurrence = stubSimpleCall(expectedResponse); const [response] = await client.getOccurrence(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getOccurrence as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getOccurrence as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getOccurrence as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getOccurrence without error using callback', async () => { @@ -253,15 +268,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.GetOccurrenceRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.GetOccurrenceRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.Occurrence() ); @@ -284,11 +296,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getOccurrence as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getOccurrence as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getOccurrence as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getOccurrence with error', async () => { @@ -300,26 +315,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.GetOccurrenceRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.GetOccurrenceRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getOccurrence = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getOccurrence(request), expectedError); - assert( - (client.innerApiCalls.getOccurrence as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getOccurrence as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getOccurrence as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getOccurrence with closed client', async () => { @@ -331,7 +346,11 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.GetOccurrenceRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.GetOccurrenceRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getOccurrence(request), expectedError); @@ -348,26 +367,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.DeleteOccurrenceRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.DeleteOccurrenceRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteOccurrence = stubSimpleCall(expectedResponse); const [response] = await client.deleteOccurrence(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteOccurrence as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteOccurrence as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteOccurrence as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteOccurrence without error using callback', async () => { @@ -379,15 +398,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.DeleteOccurrenceRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.DeleteOccurrenceRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -410,11 +426,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteOccurrence as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteOccurrence as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteOccurrence as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteOccurrence with error', async () => { @@ -426,26 +445,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.DeleteOccurrenceRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.DeleteOccurrenceRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteOccurrence = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteOccurrence(request), expectedError); - assert( - (client.innerApiCalls.deleteOccurrence as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteOccurrence as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteOccurrence as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteOccurrence with closed client', async () => { @@ -457,7 +476,11 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.DeleteOccurrenceRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.DeleteOccurrenceRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteOccurrence(request), expectedError); @@ -474,26 +497,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.CreateOccurrenceRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.CreateOccurrenceRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.Occurrence() ); client.innerApiCalls.createOccurrence = stubSimpleCall(expectedResponse); const [response] = await client.createOccurrence(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createOccurrence as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createOccurrence as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createOccurrence as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createOccurrence without error using callback', async () => { @@ -505,15 +528,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.CreateOccurrenceRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.CreateOccurrenceRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.Occurrence() ); @@ -536,11 +556,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createOccurrence as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createOccurrence as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createOccurrence as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createOccurrence with error', async () => { @@ -552,26 +575,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.CreateOccurrenceRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.CreateOccurrenceRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createOccurrence = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createOccurrence(request), expectedError); - assert( - (client.innerApiCalls.createOccurrence as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createOccurrence as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createOccurrence as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createOccurrence with closed client', async () => { @@ -583,7 +606,11 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.CreateOccurrenceRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.CreateOccurrenceRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createOccurrence(request), expectedError); @@ -600,15 +627,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.BatchCreateOccurrencesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.BatchCreateOccurrencesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.BatchCreateOccurrencesResponse() ); @@ -616,11 +640,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { stubSimpleCall(expectedResponse); const [response] = await client.batchCreateOccurrences(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchCreateOccurrences as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchCreateOccurrences as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchCreateOccurrences as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchCreateOccurrences without error using callback', async () => { @@ -632,15 +659,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.BatchCreateOccurrencesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.BatchCreateOccurrencesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.BatchCreateOccurrencesResponse() ); @@ -663,11 +687,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchCreateOccurrences as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.batchCreateOccurrences as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchCreateOccurrences as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchCreateOccurrences with error', async () => { @@ -679,15 +706,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.BatchCreateOccurrencesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.BatchCreateOccurrencesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.batchCreateOccurrences = stubSimpleCall( undefined, @@ -697,11 +721,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { client.batchCreateOccurrences(request), expectedError ); - assert( - (client.innerApiCalls.batchCreateOccurrences as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchCreateOccurrences as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchCreateOccurrences as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchCreateOccurrences with closed client', async () => { @@ -713,7 +740,11 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.BatchCreateOccurrencesRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.BatchCreateOccurrencesRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -733,26 +764,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.UpdateOccurrenceRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.UpdateOccurrenceRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.Occurrence() ); client.innerApiCalls.updateOccurrence = stubSimpleCall(expectedResponse); const [response] = await client.updateOccurrence(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateOccurrence as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateOccurrence as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateOccurrence as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateOccurrence without error using callback', async () => { @@ -764,15 +795,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.UpdateOccurrenceRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.UpdateOccurrenceRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.Occurrence() ); @@ -795,11 +823,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateOccurrence as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateOccurrence as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateOccurrence as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateOccurrence with error', async () => { @@ -811,26 +842,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.UpdateOccurrenceRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.UpdateOccurrenceRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateOccurrence = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateOccurrence(request), expectedError); - assert( - (client.innerApiCalls.updateOccurrence as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateOccurrence as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateOccurrence as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateOccurrence with closed client', async () => { @@ -842,7 +873,11 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.UpdateOccurrenceRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.UpdateOccurrenceRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateOccurrence(request), expectedError); @@ -859,26 +894,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.GetOccurrenceNoteRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.GetOccurrenceNoteRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.Note() ); client.innerApiCalls.getOccurrenceNote = stubSimpleCall(expectedResponse); const [response] = await client.getOccurrenceNote(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getOccurrenceNote as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getOccurrenceNote as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getOccurrenceNote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getOccurrenceNote without error using callback', async () => { @@ -890,15 +925,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.GetOccurrenceNoteRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.GetOccurrenceNoteRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.Note() ); @@ -921,11 +953,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getOccurrenceNote as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getOccurrenceNote as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getOccurrenceNote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getOccurrenceNote with error', async () => { @@ -937,26 +972,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.GetOccurrenceNoteRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.GetOccurrenceNoteRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getOccurrenceNote = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getOccurrenceNote(request), expectedError); - assert( - (client.innerApiCalls.getOccurrenceNote as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getOccurrenceNote as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getOccurrenceNote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getOccurrenceNote with closed client', async () => { @@ -968,7 +1003,11 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.GetOccurrenceNoteRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.GetOccurrenceNoteRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getOccurrenceNote(request), expectedError); @@ -985,26 +1024,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.GetNoteRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.GetNoteRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.Note() ); client.innerApiCalls.getNote = stubSimpleCall(expectedResponse); const [response] = await client.getNote(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getNote as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = (client.innerApiCalls.getNote as SinonStub).getCall( + 0 + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getNote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getNote without error using callback', async () => { @@ -1016,15 +1055,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.GetNoteRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.GetNoteRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.Note() ); @@ -1047,11 +1083,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getNote as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = (client.innerApiCalls.getNote as SinonStub).getCall( + 0 + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getNote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getNote with error', async () => { @@ -1063,23 +1102,23 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.GetNoteRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.GetNoteRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getNote = stubSimpleCall(undefined, expectedError); await assert.rejects(client.getNote(request), expectedError); - assert( - (client.innerApiCalls.getNote as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = (client.innerApiCalls.getNote as SinonStub).getCall( + 0 + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getNote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getNote with closed client', async () => { @@ -1091,7 +1130,11 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.GetNoteRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.GetNoteRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getNote(request), expectedError); @@ -1108,26 +1151,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.DeleteNoteRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.DeleteNoteRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteNote = stubSimpleCall(expectedResponse); const [response] = await client.deleteNote(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteNote as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteNote as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteNote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteNote without error using callback', async () => { @@ -1139,15 +1182,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.DeleteNoteRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.DeleteNoteRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -1170,11 +1210,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteNote as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteNote as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteNote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteNote with error', async () => { @@ -1186,26 +1229,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.DeleteNoteRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.DeleteNoteRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteNote = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteNote(request), expectedError); - assert( - (client.innerApiCalls.deleteNote as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteNote as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteNote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteNote with closed client', async () => { @@ -1217,7 +1260,11 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.DeleteNoteRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.DeleteNoteRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteNote(request), expectedError); @@ -1234,26 +1281,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.CreateNoteRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.CreateNoteRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.Note() ); client.innerApiCalls.createNote = stubSimpleCall(expectedResponse); const [response] = await client.createNote(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createNote as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createNote as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createNote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createNote without error using callback', async () => { @@ -1265,15 +1312,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.CreateNoteRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.CreateNoteRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.Note() ); @@ -1296,11 +1340,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createNote as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createNote as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createNote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createNote with error', async () => { @@ -1312,26 +1359,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.CreateNoteRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.CreateNoteRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createNote = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createNote(request), expectedError); - assert( - (client.innerApiCalls.createNote as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createNote as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createNote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createNote with closed client', async () => { @@ -1343,7 +1390,11 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.CreateNoteRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.CreateNoteRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createNote(request), expectedError); @@ -1360,26 +1411,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.BatchCreateNotesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.BatchCreateNotesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.BatchCreateNotesResponse() ); client.innerApiCalls.batchCreateNotes = stubSimpleCall(expectedResponse); const [response] = await client.batchCreateNotes(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchCreateNotes as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchCreateNotes as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchCreateNotes as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchCreateNotes without error using callback', async () => { @@ -1391,15 +1442,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.BatchCreateNotesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.BatchCreateNotesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.BatchCreateNotesResponse() ); @@ -1422,11 +1470,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchCreateNotes as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.batchCreateNotes as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchCreateNotes as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchCreateNotes with error', async () => { @@ -1438,26 +1489,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.BatchCreateNotesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.BatchCreateNotesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.batchCreateNotes = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.batchCreateNotes(request), expectedError); - assert( - (client.innerApiCalls.batchCreateNotes as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchCreateNotes as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchCreateNotes as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchCreateNotes with closed client', async () => { @@ -1469,7 +1520,11 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.BatchCreateNotesRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.BatchCreateNotesRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.batchCreateNotes(request), expectedError); @@ -1486,26 +1541,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.UpdateNoteRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.UpdateNoteRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.Note() ); client.innerApiCalls.updateNote = stubSimpleCall(expectedResponse); const [response] = await client.updateNote(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateNote as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateNote as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateNote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateNote without error using callback', async () => { @@ -1517,15 +1572,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.UpdateNoteRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.UpdateNoteRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.Note() ); @@ -1548,11 +1600,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateNote as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateNote as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateNote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateNote with error', async () => { @@ -1564,26 +1619,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.UpdateNoteRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.UpdateNoteRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateNote = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateNote(request), expectedError); - assert( - (client.innerApiCalls.updateNote as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateNote as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateNote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateNote with closed client', async () => { @@ -1595,7 +1650,11 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.UpdateNoteRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.UpdateNoteRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateNote(request), expectedError); @@ -1612,15 +1671,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.GetVulnerabilityOccurrencesSummaryRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.GetVulnerabilityOccurrencesSummaryRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.VulnerabilityOccurrencesSummary() ); @@ -1630,11 +1686,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { request ); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getVulnerabilityOccurrencesSummary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getVulnerabilityOccurrencesSummary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getVulnerabilityOccurrencesSummary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getVulnerabilityOccurrencesSummary without error using callback', async () => { @@ -1646,15 +1705,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.GetVulnerabilityOccurrencesSummaryRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.GetVulnerabilityOccurrencesSummaryRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.grafeas.v1beta1.VulnerabilityOccurrencesSummary() ); @@ -1677,11 +1733,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getVulnerabilityOccurrencesSummary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getVulnerabilityOccurrencesSummary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getVulnerabilityOccurrencesSummary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getVulnerabilityOccurrencesSummary with error', async () => { @@ -1693,15 +1752,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.GetVulnerabilityOccurrencesSummaryRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.GetVulnerabilityOccurrencesSummaryRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getVulnerabilityOccurrencesSummary = stubSimpleCall( undefined, @@ -1711,11 +1767,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { client.getVulnerabilityOccurrencesSummary(request), expectedError ); - assert( - (client.innerApiCalls.getVulnerabilityOccurrencesSummary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getVulnerabilityOccurrencesSummary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getVulnerabilityOccurrencesSummary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getVulnerabilityOccurrencesSummary with closed client', async () => { @@ -1727,7 +1786,11 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.GetVulnerabilityOccurrencesSummaryRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.GetVulnerabilityOccurrencesSummaryRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -1747,15 +1810,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListOccurrencesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListOccurrencesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.grafeas.v1beta1.Occurrence()), generateSampleMessage(new protos.grafeas.v1beta1.Occurrence()), @@ -1764,11 +1824,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { client.innerApiCalls.listOccurrences = stubSimpleCall(expectedResponse); const [response] = await client.listOccurrences(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listOccurrences as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listOccurrences as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listOccurrences as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listOccurrences without error using callback', async () => { @@ -1780,15 +1843,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListOccurrencesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListOccurrencesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.grafeas.v1beta1.Occurrence()), generateSampleMessage(new protos.grafeas.v1beta1.Occurrence()), @@ -1813,11 +1873,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listOccurrences as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listOccurrences as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listOccurrences as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listOccurrences with error', async () => { @@ -1829,26 +1892,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListOccurrencesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListOccurrencesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listOccurrences = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listOccurrences(request), expectedError); - assert( - (client.innerApiCalls.listOccurrences as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listOccurrences as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listOccurrences as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listOccurrencesStream without error', async () => { @@ -1860,8 +1923,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListOccurrencesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListOccurrencesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.grafeas.v1beta1.Occurrence()), generateSampleMessage(new protos.grafeas.v1beta1.Occurrence()), @@ -1889,11 +1956,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { .getCall(0) .calledWith(client.innerApiCalls.listOccurrences, request) ); - assert.strictEqual( - ( - client.descriptors.page.listOccurrences.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listOccurrences.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1906,8 +1974,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListOccurrencesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListOccurrencesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listOccurrences.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1930,11 +2002,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { .getCall(0) .calledWith(client.innerApiCalls.listOccurrences, request) ); - assert.strictEqual( - ( - client.descriptors.page.listOccurrences.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listOccurrences.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1947,8 +2020,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListOccurrencesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListOccurrencesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.grafeas.v1beta1.Occurrence()), generateSampleMessage(new protos.grafeas.v1beta1.Occurrence()), @@ -1968,11 +2045,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listOccurrences.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listOccurrences.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1985,8 +2063,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListOccurrencesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListOccurrencesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listOccurrences.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -2003,11 +2085,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listOccurrences.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listOccurrences.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -2022,15 +2105,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListNotesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListNotesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.grafeas.v1beta1.Note()), generateSampleMessage(new protos.grafeas.v1beta1.Note()), @@ -2039,11 +2119,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { client.innerApiCalls.listNotes = stubSimpleCall(expectedResponse); const [response] = await client.listNotes(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listNotes as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listNotes as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listNotes as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listNotes without error using callback', async () => { @@ -2055,15 +2138,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListNotesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListNotesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.grafeas.v1beta1.Note()), generateSampleMessage(new protos.grafeas.v1beta1.Note()), @@ -2088,11 +2168,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listNotes as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listNotes as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listNotes as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listNotes with error', async () => { @@ -2104,23 +2187,23 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListNotesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListNotesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listNotes = stubSimpleCall(undefined, expectedError); await assert.rejects(client.listNotes(request), expectedError); - assert( - (client.innerApiCalls.listNotes as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listNotes as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listNotes as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listNotesStream without error', async () => { @@ -2132,8 +2215,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListNotesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListNotesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.grafeas.v1beta1.Note()), generateSampleMessage(new protos.grafeas.v1beta1.Note()), @@ -2161,10 +2248,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { .getCall(0) .calledWith(client.innerApiCalls.listNotes, request) ); - assert.strictEqual( - (client.descriptors.page.listNotes.createStream as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listNotes.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2177,8 +2266,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListNotesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListNotesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listNotes.createStream = stubPageStreamingCall( undefined, @@ -2203,10 +2296,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { .getCall(0) .calledWith(client.innerApiCalls.listNotes, request) ); - assert.strictEqual( - (client.descriptors.page.listNotes.createStream as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listNotes.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2219,8 +2314,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListNotesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListNotesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.grafeas.v1beta1.Note()), generateSampleMessage(new protos.grafeas.v1beta1.Note()), @@ -2239,10 +2338,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { .args[1], request ); - assert.strictEqual( - (client.descriptors.page.listNotes.asyncIterate as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listNotes.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2255,8 +2356,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListNotesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListNotesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listNotes.asyncIterate = stubAsyncIterationCall( undefined, @@ -2274,10 +2379,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { .args[1], request ); - assert.strictEqual( - (client.descriptors.page.listNotes.asyncIterate as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listNotes.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -2292,15 +2399,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListNoteOccurrencesRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListNoteOccurrencesRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.grafeas.v1beta1.Occurrence()), generateSampleMessage(new protos.grafeas.v1beta1.Occurrence()), @@ -2310,11 +2414,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { stubSimpleCall(expectedResponse); const [response] = await client.listNoteOccurrences(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listNoteOccurrences as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listNoteOccurrences as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listNoteOccurrences as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listNoteOccurrences without error using callback', async () => { @@ -2326,15 +2433,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListNoteOccurrencesRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListNoteOccurrencesRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.grafeas.v1beta1.Occurrence()), generateSampleMessage(new protos.grafeas.v1beta1.Occurrence()), @@ -2359,11 +2463,14 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listNoteOccurrences as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listNoteOccurrences as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listNoteOccurrences as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listNoteOccurrences with error', async () => { @@ -2375,26 +2482,26 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListNoteOccurrencesRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListNoteOccurrencesRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listNoteOccurrences = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listNoteOccurrences(request), expectedError); - assert( - (client.innerApiCalls.listNoteOccurrences as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listNoteOccurrences as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listNoteOccurrences as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listNoteOccurrencesStream without error', async () => { @@ -2406,8 +2513,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListNoteOccurrencesRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListNoteOccurrencesRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.grafeas.v1beta1.Occurrence()), generateSampleMessage(new protos.grafeas.v1beta1.Occurrence()), @@ -2435,11 +2546,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { .getCall(0) .calledWith(client.innerApiCalls.listNoteOccurrences, request) ); - assert.strictEqual( - ( - client.descriptors.page.listNoteOccurrences.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listNoteOccurrences.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2452,8 +2564,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListNoteOccurrencesRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListNoteOccurrencesRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listNoteOccurrences.createStream = stubPageStreamingCall(undefined, expectedError); @@ -2476,11 +2592,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { .getCall(0) .calledWith(client.innerApiCalls.listNoteOccurrences, request) ); - assert.strictEqual( - ( - client.descriptors.page.listNoteOccurrences.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listNoteOccurrences.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2493,8 +2610,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListNoteOccurrencesRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListNoteOccurrencesRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.grafeas.v1beta1.Occurrence()), generateSampleMessage(new protos.grafeas.v1beta1.Occurrence()), @@ -2514,11 +2635,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listNoteOccurrences.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listNoteOccurrences.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2531,8 +2653,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { const request = generateSampleMessage( new protos.grafeas.v1beta1.ListNoteOccurrencesRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; + const defaultValue1 = getTypeDefaultValue( + '.grafeas.v1beta1.ListNoteOccurrencesRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listNoteOccurrences.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -2549,11 +2675,12 @@ describe('v1beta1.GrafeasV1Beta1Client', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listNoteOccurrences.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listNoteOccurrences.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); });