diff --git a/samples/generated/v1/snippet_metadata.google.cloud.videointelligence.v1.json b/samples/generated/v1/snippet_metadata.google.cloud.videointelligence.v1.json index 431bda45..255e1112 100644 --- a/samples/generated/v1/snippet_metadata.google.cloud.videointelligence.v1.json +++ b/samples/generated/v1/snippet_metadata.google.cloud.videointelligence.v1.json @@ -22,7 +22,7 @@ "segments": [ { "start": 25, - "end": 92, + "end": 95, "type": "FULL" } ], diff --git a/samples/generated/v1/video_intelligence_service.annotate_video.js b/samples/generated/v1/video_intelligence_service.annotate_video.js index caac0742..5200ada4 100644 --- a/samples/generated/v1/video_intelligence_service.annotate_video.js +++ b/samples/generated/v1/video_intelligence_service.annotate_video.js @@ -23,6 +23,9 @@ function main(features) { // [START videointelligence_v1_generated_VideoIntelligenceService_AnnotateVideo_async] /** + * This snippet has been automatically generated and should be regarded as a code template only. + * It will require modifications to work. + * It may require correct/in-range values for request initialization. * TODO(developer): Uncomment these variables before running the sample. */ /** diff --git a/samples/generated/v1beta2/snippet_metadata.google.cloud.videointelligence.v1beta2.json b/samples/generated/v1beta2/snippet_metadata.google.cloud.videointelligence.v1beta2.json index 38860f45..e0d7951d 100644 --- a/samples/generated/v1beta2/snippet_metadata.google.cloud.videointelligence.v1beta2.json +++ b/samples/generated/v1beta2/snippet_metadata.google.cloud.videointelligence.v1beta2.json @@ -22,7 +22,7 @@ "segments": [ { "start": 25, - "end": 91, + "end": 94, "type": "FULL" } ], diff --git a/samples/generated/v1beta2/video_intelligence_service.annotate_video.js b/samples/generated/v1beta2/video_intelligence_service.annotate_video.js index 6c39d8b5..505d4d0c 100644 --- a/samples/generated/v1beta2/video_intelligence_service.annotate_video.js +++ b/samples/generated/v1beta2/video_intelligence_service.annotate_video.js @@ -23,6 +23,9 @@ function main(features) { // [START videointelligence_v1beta2_generated_VideoIntelligenceService_AnnotateVideo_async] /** + * This snippet has been automatically generated and should be regarded as a code template only. + * It will require modifications to work. + * It may require correct/in-range values for request initialization. * TODO(developer): Uncomment these variables before running the sample. */ /** diff --git a/samples/generated/v1p1beta1/snippet_metadata.google.cloud.videointelligence.v1p1beta1.json b/samples/generated/v1p1beta1/snippet_metadata.google.cloud.videointelligence.v1p1beta1.json index 7c6eedbf..01af454e 100644 --- a/samples/generated/v1p1beta1/snippet_metadata.google.cloud.videointelligence.v1p1beta1.json +++ b/samples/generated/v1p1beta1/snippet_metadata.google.cloud.videointelligence.v1p1beta1.json @@ -22,7 +22,7 @@ "segments": [ { "start": 25, - "end": 91, + "end": 94, "type": "FULL" } ], diff --git a/samples/generated/v1p1beta1/video_intelligence_service.annotate_video.js b/samples/generated/v1p1beta1/video_intelligence_service.annotate_video.js index ccf9f33c..afa38678 100644 --- a/samples/generated/v1p1beta1/video_intelligence_service.annotate_video.js +++ b/samples/generated/v1p1beta1/video_intelligence_service.annotate_video.js @@ -23,6 +23,9 @@ function main(features) { // [START videointelligence_v1p1beta1_generated_VideoIntelligenceService_AnnotateVideo_async] /** + * This snippet has been automatically generated and should be regarded as a code template only. + * It will require modifications to work. + * It may require correct/in-range values for request initialization. * TODO(developer): Uncomment these variables before running the sample. */ /** diff --git a/samples/generated/v1p2beta1/snippet_metadata.google.cloud.videointelligence.v1p2beta1.json b/samples/generated/v1p2beta1/snippet_metadata.google.cloud.videointelligence.v1p2beta1.json index 5dbc6e71..d138c675 100644 --- a/samples/generated/v1p2beta1/snippet_metadata.google.cloud.videointelligence.v1p2beta1.json +++ b/samples/generated/v1p2beta1/snippet_metadata.google.cloud.videointelligence.v1p2beta1.json @@ -22,7 +22,7 @@ "segments": [ { "start": 25, - "end": 89, + "end": 92, "type": "FULL" } ], diff --git a/samples/generated/v1p2beta1/video_intelligence_service.annotate_video.js b/samples/generated/v1p2beta1/video_intelligence_service.annotate_video.js index f4e003e8..5f47ef9b 100644 --- a/samples/generated/v1p2beta1/video_intelligence_service.annotate_video.js +++ b/samples/generated/v1p2beta1/video_intelligence_service.annotate_video.js @@ -23,6 +23,9 @@ function main(features) { // [START videointelligence_v1p2beta1_generated_VideoIntelligenceService_AnnotateVideo_async] /** + * This snippet has been automatically generated and should be regarded as a code template only. + * It will require modifications to work. + * It may require correct/in-range values for request initialization. * TODO(developer): Uncomment these variables before running the sample. */ /** diff --git a/samples/generated/v1p3beta1/snippet_metadata.google.cloud.videointelligence.v1p3beta1.json b/samples/generated/v1p3beta1/snippet_metadata.google.cloud.videointelligence.v1p3beta1.json index 774afbfe..c368e203 100644 --- a/samples/generated/v1p3beta1/snippet_metadata.google.cloud.videointelligence.v1p3beta1.json +++ b/samples/generated/v1p3beta1/snippet_metadata.google.cloud.videointelligence.v1p3beta1.json @@ -22,7 +22,7 @@ "segments": [ { "start": 25, - "end": 65, + "end": 68, "type": "FULL" } ], @@ -66,7 +66,7 @@ "segments": [ { "start": 25, - "end": 92, + "end": 95, "type": "FULL" } ], diff --git a/samples/generated/v1p3beta1/streaming_video_intelligence_service.streaming_annotate_video.js b/samples/generated/v1p3beta1/streaming_video_intelligence_service.streaming_annotate_video.js index 2236cb17..e2460b12 100644 --- a/samples/generated/v1p3beta1/streaming_video_intelligence_service.streaming_annotate_video.js +++ b/samples/generated/v1p3beta1/streaming_video_intelligence_service.streaming_annotate_video.js @@ -23,6 +23,9 @@ function main() { // [START videointelligence_v1p3beta1_generated_StreamingVideoIntelligenceService_StreamingAnnotateVideo_async] /** + * This snippet has been automatically generated and should be regarded as a code template only. + * It will require modifications to work. + * It may require correct/in-range values for request initialization. * TODO(developer): Uncomment these variables before running the sample. */ /** diff --git a/samples/generated/v1p3beta1/video_intelligence_service.annotate_video.js b/samples/generated/v1p3beta1/video_intelligence_service.annotate_video.js index 4f56a02a..8323e6c2 100644 --- a/samples/generated/v1p3beta1/video_intelligence_service.annotate_video.js +++ b/samples/generated/v1p3beta1/video_intelligence_service.annotate_video.js @@ -23,6 +23,9 @@ function main(features) { // [START videointelligence_v1p3beta1_generated_VideoIntelligenceService_AnnotateVideo_async] /** + * This snippet has been automatically generated and should be regarded as a code template only. + * It will require modifications to work. + * It may require correct/in-range values for request initialization. * TODO(developer): Uncomment these variables before running the sample. */ /** diff --git a/src/v1/video_intelligence_service_client.ts b/src/v1/video_intelligence_service_client.ts index 392839d0..9f529c15 100644 --- a/src/v1/video_intelligence_service_client.ts +++ b/src/v1/video_intelligence_service_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, @@ -35,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 './video_intelligence_service_client_config.json'; -import {operationsProtos} from 'google-gax'; const version = require('../../../package.json').version; /** @@ -95,8 +94,18 @@ export class VideoIntelligenceServiceClient { * 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 VideoIntelligenceServiceClient({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 VideoIntelligenceServiceClient; @@ -117,8 +126,13 @@ export class VideoIntelligenceServiceClient { 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); @@ -234,7 +248,7 @@ export class VideoIntelligenceServiceClient { 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; } /** @@ -290,7 +304,8 @@ export class VideoIntelligenceServiceClient { const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], - descriptor + descriptor, + this._opts.fallback ); this.innerApiCalls[methodName] = apiCall; @@ -506,14 +521,15 @@ export class VideoIntelligenceServiceClient { protos.google.cloud.videointelligence.v1.AnnotateVideoProgress > > { - const request = new operationsProtos.google.longrunning.GetOperationRequest( - {name} - ); + const request = + new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest( + {name} + ); const [operation] = await this.operationsClient.getOperation(request); - const decodeOperation = new gax.Operation( + const decodeOperation = new this._gaxModule.Operation( operation, this.descriptors.longrunning.annotateVideo, - gax.createDefaultBackoffSettings() + this._gaxModule.createDefaultBackoffSettings() ); return decodeOperation as LROperation< protos.google.cloud.videointelligence.v1.AnnotateVideoResponse, diff --git a/src/v1beta2/video_intelligence_service_client.ts b/src/v1beta2/video_intelligence_service_client.ts index 5c31f108..33a3dcd8 100644 --- a/src/v1beta2/video_intelligence_service_client.ts +++ b/src/v1beta2/video_intelligence_service_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, @@ -35,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 './video_intelligence_service_client_config.json'; -import {operationsProtos} from 'google-gax'; const version = require('../../../package.json').version; /** @@ -95,8 +94,18 @@ export class VideoIntelligenceServiceClient { * 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 VideoIntelligenceServiceClient({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 VideoIntelligenceServiceClient; @@ -117,8 +126,13 @@ export class VideoIntelligenceServiceClient { 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); @@ -236,7 +250,7 @@ export class VideoIntelligenceServiceClient { 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; } /** @@ -292,7 +306,8 @@ export class VideoIntelligenceServiceClient { const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], - descriptor + descriptor, + this._opts.fallback ); this.innerApiCalls[methodName] = apiCall; @@ -507,14 +522,15 @@ export class VideoIntelligenceServiceClient { protos.google.cloud.videointelligence.v1beta2.AnnotateVideoProgress > > { - const request = new operationsProtos.google.longrunning.GetOperationRequest( - {name} - ); + const request = + new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest( + {name} + ); const [operation] = await this.operationsClient.getOperation(request); - const decodeOperation = new gax.Operation( + const decodeOperation = new this._gaxModule.Operation( operation, this.descriptors.longrunning.annotateVideo, - gax.createDefaultBackoffSettings() + this._gaxModule.createDefaultBackoffSettings() ); return decodeOperation as LROperation< protos.google.cloud.videointelligence.v1beta2.AnnotateVideoResponse, diff --git a/src/v1p1beta1/video_intelligence_service_client.ts b/src/v1p1beta1/video_intelligence_service_client.ts index c4547443..ed8e8a4e 100644 --- a/src/v1p1beta1/video_intelligence_service_client.ts +++ b/src/v1p1beta1/video_intelligence_service_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, @@ -35,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 './video_intelligence_service_client_config.json'; -import {operationsProtos} from 'google-gax'; const version = require('../../../package.json').version; /** @@ -95,8 +94,18 @@ export class VideoIntelligenceServiceClient { * 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 VideoIntelligenceServiceClient({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 VideoIntelligenceServiceClient; @@ -117,8 +126,13 @@ export class VideoIntelligenceServiceClient { 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); @@ -236,7 +250,7 @@ export class VideoIntelligenceServiceClient { 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; } /** @@ -292,7 +306,8 @@ export class VideoIntelligenceServiceClient { const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], - descriptor + descriptor, + this._opts.fallback ); this.innerApiCalls[methodName] = apiCall; @@ -507,14 +522,15 @@ export class VideoIntelligenceServiceClient { protos.google.cloud.videointelligence.v1p1beta1.AnnotateVideoProgress > > { - const request = new operationsProtos.google.longrunning.GetOperationRequest( - {name} - ); + const request = + new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest( + {name} + ); const [operation] = await this.operationsClient.getOperation(request); - const decodeOperation = new gax.Operation( + const decodeOperation = new this._gaxModule.Operation( operation, this.descriptors.longrunning.annotateVideo, - gax.createDefaultBackoffSettings() + this._gaxModule.createDefaultBackoffSettings() ); return decodeOperation as LROperation< protos.google.cloud.videointelligence.v1p1beta1.AnnotateVideoResponse, diff --git a/src/v1p2beta1/video_intelligence_service_client.ts b/src/v1p2beta1/video_intelligence_service_client.ts index 6a7d3777..d14f83c2 100644 --- a/src/v1p2beta1/video_intelligence_service_client.ts +++ b/src/v1p2beta1/video_intelligence_service_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, @@ -35,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 './video_intelligence_service_client_config.json'; -import {operationsProtos} from 'google-gax'; const version = require('../../../package.json').version; /** @@ -95,8 +94,18 @@ export class VideoIntelligenceServiceClient { * 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 VideoIntelligenceServiceClient({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 VideoIntelligenceServiceClient; @@ -117,8 +126,13 @@ export class VideoIntelligenceServiceClient { 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); @@ -236,7 +250,7 @@ export class VideoIntelligenceServiceClient { 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; } /** @@ -292,7 +306,8 @@ export class VideoIntelligenceServiceClient { const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], - descriptor + descriptor, + this._opts.fallback ); this.innerApiCalls[methodName] = apiCall; @@ -505,14 +520,15 @@ export class VideoIntelligenceServiceClient { protos.google.cloud.videointelligence.v1p2beta1.AnnotateVideoProgress > > { - const request = new operationsProtos.google.longrunning.GetOperationRequest( - {name} - ); + const request = + new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest( + {name} + ); const [operation] = await this.operationsClient.getOperation(request); - const decodeOperation = new gax.Operation( + const decodeOperation = new this._gaxModule.Operation( operation, this.descriptors.longrunning.annotateVideo, - gax.createDefaultBackoffSettings() + this._gaxModule.createDefaultBackoffSettings() ); return decodeOperation as LROperation< protos.google.cloud.videointelligence.v1p2beta1.AnnotateVideoResponse, diff --git a/src/v1p3beta1/streaming_video_intelligence_service_client.ts b/src/v1p3beta1/streaming_video_intelligence_service_client.ts index 3e21b7fd..fa26e48e 100644 --- a/src/v1p3beta1/streaming_video_intelligence_service_client.ts +++ b/src/v1p3beta1/streaming_video_intelligence_service_client.ts @@ -17,15 +17,13 @@ // ** 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, ClientOptions, - GoogleError, } from 'google-gax'; - import {PassThrough} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); @@ -35,7 +33,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 './streaming_video_intelligence_service_client_config.json'; - const version = require('../../../package.json').version; /** @@ -94,8 +91,18 @@ export class StreamingVideoIntelligenceServiceClient { * 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 StreamingVideoIntelligenceServiceClient({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 StreamingVideoIntelligenceServiceClient; @@ -116,8 +123,13 @@ export class StreamingVideoIntelligenceServiceClient { 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); @@ -161,7 +173,7 @@ export class StreamingVideoIntelligenceServiceClient { // Provide descriptors for these. this.descriptors.stream = { streamingAnnotateVideo: new this._gaxModule.StreamDescriptor( - gax.StreamType.BIDI_STREAMING, + this._gaxModule.StreamType.BIDI_STREAMING, opts.fallback === 'rest' ), }; @@ -180,7 +192,7 @@ export class StreamingVideoIntelligenceServiceClient { 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; } /** @@ -229,7 +241,9 @@ export class StreamingVideoIntelligenceServiceClient { setImmediate(() => { stream.emit( 'error', - new GoogleError('The client has already been closed.') + new this._gaxModule.GoogleError( + 'The client has already been closed.' + ) ); }); return stream; @@ -248,7 +262,8 @@ export class StreamingVideoIntelligenceServiceClient { const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], - descriptor + descriptor, + this._opts.fallback ); this.innerApiCalls[methodName] = apiCall; diff --git a/src/v1p3beta1/video_intelligence_service_client.ts b/src/v1p3beta1/video_intelligence_service_client.ts index 61a566e7..bf1dbc95 100644 --- a/src/v1p3beta1/video_intelligence_service_client.ts +++ b/src/v1p3beta1/video_intelligence_service_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, @@ -35,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 './video_intelligence_service_client_config.json'; -import {operationsProtos} from 'google-gax'; const version = require('../../../package.json').version; /** @@ -95,8 +94,18 @@ export class VideoIntelligenceServiceClient { * 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 VideoIntelligenceServiceClient({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 VideoIntelligenceServiceClient; @@ -117,8 +126,13 @@ export class VideoIntelligenceServiceClient { 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); @@ -236,7 +250,7 @@ export class VideoIntelligenceServiceClient { 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; } /** @@ -292,7 +306,8 @@ export class VideoIntelligenceServiceClient { const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], - descriptor + descriptor, + this._opts.fallback ); this.innerApiCalls[methodName] = apiCall; @@ -508,14 +523,15 @@ export class VideoIntelligenceServiceClient { protos.google.cloud.videointelligence.v1p3beta1.AnnotateVideoProgress > > { - const request = new operationsProtos.google.longrunning.GetOperationRequest( - {name} - ); + const request = + new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest( + {name} + ); const [operation] = await this.operationsClient.getOperation(request); - const decodeOperation = new gax.Operation( + const decodeOperation = new this._gaxModule.Operation( operation, this.descriptors.longrunning.annotateVideo, - gax.createDefaultBackoffSettings() + this._gaxModule.createDefaultBackoffSettings() ); return decodeOperation as LROperation< protos.google.cloud.videointelligence.v1p3beta1.AnnotateVideoResponse, diff --git a/test/gapic_streaming_video_intelligence_service_v1p3beta1.ts b/test/gapic_streaming_video_intelligence_service_v1p3beta1.ts index b23bc9b0..a318a050 100644 --- a/test/gapic_streaming_video_intelligence_service_v1p3beta1.ts +++ b/test/gapic_streaming_video_intelligence_service_v1p3beta1.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 @@ -51,124 +66,132 @@ function stubBidiStreamingCall( } describe('v1p3beta1.StreamingVideoIntelligenceServiceClient', () => { - it('has servicePath', () => { - const servicePath = - streamingvideointelligenceserviceModule.v1p3beta1 - .StreamingVideoIntelligenceServiceClient.servicePath; - assert(servicePath); - }); + describe('Common methods', () => { + it('has servicePath', () => { + const servicePath = + streamingvideointelligenceserviceModule.v1p3beta1 + .StreamingVideoIntelligenceServiceClient.servicePath; + assert(servicePath); + }); - it('has apiEndpoint', () => { - const apiEndpoint = - streamingvideointelligenceserviceModule.v1p3beta1 - .StreamingVideoIntelligenceServiceClient.apiEndpoint; - assert(apiEndpoint); - }); + it('has apiEndpoint', () => { + const apiEndpoint = + streamingvideointelligenceserviceModule.v1p3beta1 + .StreamingVideoIntelligenceServiceClient.apiEndpoint; + assert(apiEndpoint); + }); - it('has port', () => { - const port = - streamingvideointelligenceserviceModule.v1p3beta1 - .StreamingVideoIntelligenceServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); + it('has port', () => { + const port = + streamingvideointelligenceserviceModule.v1p3beta1 + .StreamingVideoIntelligenceServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); - it('should create a client with no option', () => { - const client = - new streamingvideointelligenceserviceModule.v1p3beta1.StreamingVideoIntelligenceServiceClient(); - assert(client); - }); + it('should create a client with no option', () => { + const client = + new streamingvideointelligenceserviceModule.v1p3beta1.StreamingVideoIntelligenceServiceClient(); + assert(client); + }); - it('should create a client with gRPC fallback', () => { - const client = - new streamingvideointelligenceserviceModule.v1p3beta1.StreamingVideoIntelligenceServiceClient( - { - fallback: true, - } - ); - assert(client); - }); + it('should create a client with gRPC fallback', () => { + const client = + new streamingvideointelligenceserviceModule.v1p3beta1.StreamingVideoIntelligenceServiceClient( + { + fallback: true, + } + ); + assert(client); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = - new streamingvideointelligenceserviceModule.v1p3beta1.StreamingVideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } + it('has initialize method and supports deferred initialization', async () => { + const client = + new streamingvideointelligenceserviceModule.v1p3beta1.StreamingVideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + assert.strictEqual( + client.streamingVideoIntelligenceServiceStub, + undefined ); - assert.strictEqual(client.streamingVideoIntelligenceServiceStub, undefined); - await client.initialize(); - assert(client.streamingVideoIntelligenceServiceStub); - }); + await client.initialize(); + assert(client.streamingVideoIntelligenceServiceStub); + }); - it('has close method for the initialized client', done => { - const client = - new streamingvideointelligenceserviceModule.v1p3beta1.StreamingVideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.initialize(); - assert(client.streamingVideoIntelligenceServiceStub); - client.close().then(() => { - done(); + it('has close method for the initialized client', done => { + const client = + new streamingvideointelligenceserviceModule.v1p3beta1.StreamingVideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + assert(client.streamingVideoIntelligenceServiceStub); + client.close().then(() => { + done(); + }); }); - }); - it('has close method for the non-initialized client', done => { - const client = - new streamingvideointelligenceserviceModule.v1p3beta1.StreamingVideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } + it('has close method for the non-initialized client', done => { + const client = + new streamingvideointelligenceserviceModule.v1p3beta1.StreamingVideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + assert.strictEqual( + client.streamingVideoIntelligenceServiceStub, + undefined ); - assert.strictEqual(client.streamingVideoIntelligenceServiceStub, undefined); - client.close().then(() => { - done(); + client.close().then(() => { + done(); + }); }); - }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = - new streamingvideointelligenceserviceModule.v1p3beta1.StreamingVideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); - const result = await client.getProjectId(); - assert.strictEqual(result, fakeProjectId); - assert((client.auth.getProjectId as SinonStub).calledWithExactly()); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new streamingvideointelligenceserviceModule.v1p3beta1.StreamingVideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = - new streamingvideointelligenceserviceModule.v1p3beta1.StreamingVideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.auth.getProjectId = sinon - .stub() - .callsArgWith(0, null, fakeProjectId); - const promise = new Promise((resolve, reject) => { - client.getProjectId((err?: Error | null, projectId?: string | null) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new streamingvideointelligenceserviceModule.v1p3beta1.StreamingVideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); }); - const result = await promise; - assert.strictEqual(result, fakeProjectId); }); describe('streamingAnnotateVideo', () => { @@ -184,6 +207,7 @@ describe('v1p3beta1.StreamingVideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1p3beta1.StreamingAnnotateVideoRequest() ); + const expectedResponse = generateSampleMessage( new protos.google.cloud.videointelligence.v1p3beta1.StreamingAnnotateVideoResponse() ); diff --git a/test/gapic_video_intelligence_service_v1.ts b/test/gapic_video_intelligence_service_v1.ts index 6064d743..24ff4ee2 100644 --- a/test/gapic_video_intelligence_service_v1.ts +++ b/test/gapic_video_intelligence_service_v1.ts @@ -25,6 +25,21 @@ import * as videointelligenceserviceModule from '../src'; import {protobuf, LROperation, operationsProtos} from 'google-gax'; +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON( + require('../protos/protos.json') +).resolveAll(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type.fields[field]?.resolvedType as protobuf.Type; + } + return type.fields[fields[fields.length - 1]]?.defaultValue; +} + function generateSampleMessage(instance: T) { const filledObject = ( instance.constructor as typeof protobuf.Message @@ -73,111 +88,113 @@ function stubLongRunningCallWithCallback( } describe('v1.VideoIntelligenceServiceClient', () => { - it('has servicePath', () => { - const servicePath = - videointelligenceserviceModule.v1.VideoIntelligenceServiceClient - .servicePath; - assert(servicePath); - }); + describe('Common methods', () => { + it('has servicePath', () => { + const servicePath = + videointelligenceserviceModule.v1.VideoIntelligenceServiceClient + .servicePath; + assert(servicePath); + }); - it('has apiEndpoint', () => { - const apiEndpoint = - videointelligenceserviceModule.v1.VideoIntelligenceServiceClient - .apiEndpoint; - assert(apiEndpoint); - }); + it('has apiEndpoint', () => { + const apiEndpoint = + videointelligenceserviceModule.v1.VideoIntelligenceServiceClient + .apiEndpoint; + assert(apiEndpoint); + }); - it('has port', () => { - const port = - videointelligenceserviceModule.v1.VideoIntelligenceServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); + it('has port', () => { + const port = + videointelligenceserviceModule.v1.VideoIntelligenceServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); - it('should create a client with no option', () => { - const client = - new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient(); - assert(client); - }); + it('should create a client with no option', () => { + const client = + new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient(); + assert(client); + }); - it('should create a client with gRPC fallback', () => { - const client = - new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - fallback: true, - }); - assert(client); - }); + it('should create a client with gRPC fallback', () => { + const client = + new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ + fallback: true, + }); + assert(client); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = - new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.videoIntelligenceServiceStub, undefined); - await client.initialize(); - assert(client.videoIntelligenceServiceStub); - }); + it('has initialize method and supports deferred initialization', async () => { + const client = + new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.videoIntelligenceServiceStub, undefined); + await client.initialize(); + assert(client.videoIntelligenceServiceStub); + }); - it('has close method for the initialized client', done => { - const client = - new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('has close method for the initialized client', done => { + const client = + new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + assert(client.videoIntelligenceServiceStub); + client.close().then(() => { + done(); }); - client.initialize(); - assert(client.videoIntelligenceServiceStub); - client.close().then(() => { - done(); }); - }); - it('has close method for the non-initialized client', done => { - const client = - new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('has close method for the non-initialized client', done => { + const client = + new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.videoIntelligenceServiceStub, undefined); + client.close().then(() => { + done(); }); - assert.strictEqual(client.videoIntelligenceServiceStub, undefined); - client.close().then(() => { - done(); }); - }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = - new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); - const result = await client.getProjectId(); - assert.strictEqual(result, fakeProjectId); - assert((client.auth.getProjectId as SinonStub).calledWithExactly()); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = - new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.auth.getProjectId = sinon - .stub() - .callsArgWith(0, null, fakeProjectId); - const promise = new Promise((resolve, reject) => { - client.getProjectId((err?: Error | null, projectId?: string | null) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); }); - const result = await promise; - assert.strictEqual(result, fakeProjectId); }); describe('annotateVideo', () => { @@ -191,7 +208,6 @@ describe('v1.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -200,11 +216,6 @@ describe('v1.VideoIntelligenceServiceClient', () => { const [operation] = await client.annotateVideo(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes annotateVideo without error using callback', async () => { @@ -217,7 +228,6 @@ describe('v1.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -247,11 +257,6 @@ describe('v1.VideoIntelligenceServiceClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); }); it('invokes annotateVideo with call error', async () => { @@ -264,18 +269,12 @@ describe('v1.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedError = new Error('expected'); client.innerApiCalls.annotateVideo = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.annotateVideo(request), expectedError); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes annotateVideo with LRO error', async () => { @@ -288,7 +287,6 @@ describe('v1.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedError = new Error('expected'); client.innerApiCalls.annotateVideo = stubLongRunningCall( undefined, @@ -297,11 +295,6 @@ describe('v1.VideoIntelligenceServiceClient', () => { ); const [operation] = await client.annotateVideo(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes checkAnnotateVideoProgress without error', async () => { diff --git a/test/gapic_video_intelligence_service_v1beta2.ts b/test/gapic_video_intelligence_service_v1beta2.ts index baa17d45..c01bbfa1 100644 --- a/test/gapic_video_intelligence_service_v1beta2.ts +++ b/test/gapic_video_intelligence_service_v1beta2.ts @@ -25,6 +25,21 @@ import * as videointelligenceserviceModule from '../src'; import {protobuf, LROperation, operationsProtos} from 'google-gax'; +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON( + require('../protos/protos.json') +).resolveAll(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type.fields[field]?.resolvedType as protobuf.Type; + } + return type.fields[fields[fields.length - 1]]?.defaultValue; +} + function generateSampleMessage(instance: T) { const filledObject = ( instance.constructor as typeof protobuf.Message @@ -73,124 +88,126 @@ function stubLongRunningCallWithCallback( } describe('v1beta2.VideoIntelligenceServiceClient', () => { - it('has servicePath', () => { - const servicePath = - videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient - .servicePath; - assert(servicePath); - }); + describe('Common methods', () => { + it('has servicePath', () => { + const servicePath = + videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient + .servicePath; + assert(servicePath); + }); - it('has apiEndpoint', () => { - const apiEndpoint = - videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient - .apiEndpoint; - assert(apiEndpoint); - }); + it('has apiEndpoint', () => { + const apiEndpoint = + videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient + .apiEndpoint; + assert(apiEndpoint); + }); - it('has port', () => { - const port = - videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient - .port; - assert(port); - assert(typeof port === 'number'); - }); + it('has port', () => { + const port = + videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient + .port; + assert(port); + assert(typeof port === 'number'); + }); - it('should create a client with no option', () => { - const client = - new videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient(); - assert(client); - }); + it('should create a client with no option', () => { + const client = + new videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient(); + assert(client); + }); - it('should create a client with gRPC fallback', () => { - const client = - new videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient( - { - fallback: true, - } - ); - assert(client); - }); + it('should create a client with gRPC fallback', () => { + const client = + new videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient( + { + fallback: true, + } + ); + assert(client); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = - new videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - assert.strictEqual(client.videoIntelligenceServiceStub, undefined); - await client.initialize(); - assert(client.videoIntelligenceServiceStub); - }); + it('has initialize method and supports deferred initialization', async () => { + const client = + new videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + assert.strictEqual(client.videoIntelligenceServiceStub, undefined); + await client.initialize(); + assert(client.videoIntelligenceServiceStub); + }); - it('has close method for the initialized client', done => { - const client = - new videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.initialize(); - assert(client.videoIntelligenceServiceStub); - client.close().then(() => { - done(); + it('has close method for the initialized client', done => { + const client = + new videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + assert(client.videoIntelligenceServiceStub); + client.close().then(() => { + done(); + }); }); - }); - it('has close method for the non-initialized client', done => { - const client = - new videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - assert.strictEqual(client.videoIntelligenceServiceStub, undefined); - client.close().then(() => { - done(); + it('has close method for the non-initialized client', done => { + const client = + new videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + assert.strictEqual(client.videoIntelligenceServiceStub, undefined); + client.close().then(() => { + done(); + }); }); - }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = - new videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); - const result = await client.getProjectId(); - assert.strictEqual(result, fakeProjectId); - assert((client.auth.getProjectId as SinonStub).calledWithExactly()); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = - new videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.auth.getProjectId = sinon - .stub() - .callsArgWith(0, null, fakeProjectId); - const promise = new Promise((resolve, reject) => { - client.getProjectId((err?: Error | null, projectId?: string | null) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new videointelligenceserviceModule.v1beta2.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); }); - const result = await promise; - assert.strictEqual(result, fakeProjectId); }); describe('annotateVideo', () => { @@ -206,7 +223,6 @@ describe('v1beta2.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1beta2.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -215,11 +231,6 @@ describe('v1beta2.VideoIntelligenceServiceClient', () => { const [operation] = await client.annotateVideo(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes annotateVideo without error using callback', async () => { @@ -234,7 +245,6 @@ describe('v1beta2.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1beta2.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -264,11 +274,6 @@ describe('v1beta2.VideoIntelligenceServiceClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); }); it('invokes annotateVideo with call error', async () => { @@ -283,18 +288,12 @@ describe('v1beta2.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1beta2.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedError = new Error('expected'); client.innerApiCalls.annotateVideo = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.annotateVideo(request), expectedError); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes annotateVideo with LRO error', async () => { @@ -309,7 +308,6 @@ describe('v1beta2.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1beta2.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedError = new Error('expected'); client.innerApiCalls.annotateVideo = stubLongRunningCall( undefined, @@ -318,11 +316,6 @@ describe('v1beta2.VideoIntelligenceServiceClient', () => { ); const [operation] = await client.annotateVideo(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes checkAnnotateVideoProgress without error', async () => { diff --git a/test/gapic_video_intelligence_service_v1p1beta1.ts b/test/gapic_video_intelligence_service_v1p1beta1.ts index 81159b34..2908e4f5 100644 --- a/test/gapic_video_intelligence_service_v1p1beta1.ts +++ b/test/gapic_video_intelligence_service_v1p1beta1.ts @@ -25,6 +25,21 @@ import * as videointelligenceserviceModule from '../src'; import {protobuf, LROperation, operationsProtos} from 'google-gax'; +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON( + require('../protos/protos.json') +).resolveAll(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type.fields[field]?.resolvedType as protobuf.Type; + } + return type.fields[fields[fields.length - 1]]?.defaultValue; +} + function generateSampleMessage(instance: T) { const filledObject = ( instance.constructor as typeof protobuf.Message @@ -73,124 +88,126 @@ function stubLongRunningCallWithCallback( } describe('v1p1beta1.VideoIntelligenceServiceClient', () => { - it('has servicePath', () => { - const servicePath = - videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient - .servicePath; - assert(servicePath); - }); + describe('Common methods', () => { + it('has servicePath', () => { + const servicePath = + videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient + .servicePath; + assert(servicePath); + }); - it('has apiEndpoint', () => { - const apiEndpoint = - videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient - .apiEndpoint; - assert(apiEndpoint); - }); + it('has apiEndpoint', () => { + const apiEndpoint = + videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient + .apiEndpoint; + assert(apiEndpoint); + }); - it('has port', () => { - const port = - videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient - .port; - assert(port); - assert(typeof port === 'number'); - }); + it('has port', () => { + const port = + videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient + .port; + assert(port); + assert(typeof port === 'number'); + }); - it('should create a client with no option', () => { - const client = - new videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient(); - assert(client); - }); + it('should create a client with no option', () => { + const client = + new videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient(); + assert(client); + }); - it('should create a client with gRPC fallback', () => { - const client = - new videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient( - { - fallback: true, - } - ); - assert(client); - }); + it('should create a client with gRPC fallback', () => { + const client = + new videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient( + { + fallback: true, + } + ); + assert(client); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = - new videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - assert.strictEqual(client.videoIntelligenceServiceStub, undefined); - await client.initialize(); - assert(client.videoIntelligenceServiceStub); - }); + it('has initialize method and supports deferred initialization', async () => { + const client = + new videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + assert.strictEqual(client.videoIntelligenceServiceStub, undefined); + await client.initialize(); + assert(client.videoIntelligenceServiceStub); + }); - it('has close method for the initialized client', done => { - const client = - new videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.initialize(); - assert(client.videoIntelligenceServiceStub); - client.close().then(() => { - done(); + it('has close method for the initialized client', done => { + const client = + new videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + assert(client.videoIntelligenceServiceStub); + client.close().then(() => { + done(); + }); }); - }); - it('has close method for the non-initialized client', done => { - const client = - new videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - assert.strictEqual(client.videoIntelligenceServiceStub, undefined); - client.close().then(() => { - done(); + it('has close method for the non-initialized client', done => { + const client = + new videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + assert.strictEqual(client.videoIntelligenceServiceStub, undefined); + client.close().then(() => { + done(); + }); }); - }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = - new videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); - const result = await client.getProjectId(); - assert.strictEqual(result, fakeProjectId); - assert((client.auth.getProjectId as SinonStub).calledWithExactly()); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = - new videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.auth.getProjectId = sinon - .stub() - .callsArgWith(0, null, fakeProjectId); - const promise = new Promise((resolve, reject) => { - client.getProjectId((err?: Error | null, projectId?: string | null) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new videointelligenceserviceModule.v1p1beta1.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); }); - const result = await promise; - assert.strictEqual(result, fakeProjectId); }); describe('annotateVideo', () => { @@ -206,7 +223,6 @@ describe('v1p1beta1.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1p1beta1.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -215,11 +231,6 @@ describe('v1p1beta1.VideoIntelligenceServiceClient', () => { const [operation] = await client.annotateVideo(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes annotateVideo without error using callback', async () => { @@ -234,7 +245,6 @@ describe('v1p1beta1.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1p1beta1.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -264,11 +274,6 @@ describe('v1p1beta1.VideoIntelligenceServiceClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); }); it('invokes annotateVideo with call error', async () => { @@ -283,18 +288,12 @@ describe('v1p1beta1.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1p1beta1.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedError = new Error('expected'); client.innerApiCalls.annotateVideo = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.annotateVideo(request), expectedError); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes annotateVideo with LRO error', async () => { @@ -309,7 +308,6 @@ describe('v1p1beta1.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1p1beta1.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedError = new Error('expected'); client.innerApiCalls.annotateVideo = stubLongRunningCall( undefined, @@ -318,11 +316,6 @@ describe('v1p1beta1.VideoIntelligenceServiceClient', () => { ); const [operation] = await client.annotateVideo(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes checkAnnotateVideoProgress without error', async () => { diff --git a/test/gapic_video_intelligence_service_v1p2beta1.ts b/test/gapic_video_intelligence_service_v1p2beta1.ts index bb6b63b1..451fa85b 100644 --- a/test/gapic_video_intelligence_service_v1p2beta1.ts +++ b/test/gapic_video_intelligence_service_v1p2beta1.ts @@ -25,6 +25,21 @@ import * as videointelligenceserviceModule from '../src'; import {protobuf, LROperation, operationsProtos} from 'google-gax'; +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON( + require('../protos/protos.json') +).resolveAll(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type.fields[field]?.resolvedType as protobuf.Type; + } + return type.fields[fields[fields.length - 1]]?.defaultValue; +} + function generateSampleMessage(instance: T) { const filledObject = ( instance.constructor as typeof protobuf.Message @@ -73,124 +88,126 @@ function stubLongRunningCallWithCallback( } describe('v1p2beta1.VideoIntelligenceServiceClient', () => { - it('has servicePath', () => { - const servicePath = - videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient - .servicePath; - assert(servicePath); - }); + describe('Common methods', () => { + it('has servicePath', () => { + const servicePath = + videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient + .servicePath; + assert(servicePath); + }); - it('has apiEndpoint', () => { - const apiEndpoint = - videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient - .apiEndpoint; - assert(apiEndpoint); - }); + it('has apiEndpoint', () => { + const apiEndpoint = + videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient + .apiEndpoint; + assert(apiEndpoint); + }); - it('has port', () => { - const port = - videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient - .port; - assert(port); - assert(typeof port === 'number'); - }); + it('has port', () => { + const port = + videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient + .port; + assert(port); + assert(typeof port === 'number'); + }); - it('should create a client with no option', () => { - const client = - new videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient(); - assert(client); - }); + it('should create a client with no option', () => { + const client = + new videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient(); + assert(client); + }); - it('should create a client with gRPC fallback', () => { - const client = - new videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient( - { - fallback: true, - } - ); - assert(client); - }); + it('should create a client with gRPC fallback', () => { + const client = + new videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient( + { + fallback: true, + } + ); + assert(client); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = - new videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - assert.strictEqual(client.videoIntelligenceServiceStub, undefined); - await client.initialize(); - assert(client.videoIntelligenceServiceStub); - }); + it('has initialize method and supports deferred initialization', async () => { + const client = + new videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + assert.strictEqual(client.videoIntelligenceServiceStub, undefined); + await client.initialize(); + assert(client.videoIntelligenceServiceStub); + }); - it('has close method for the initialized client', done => { - const client = - new videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.initialize(); - assert(client.videoIntelligenceServiceStub); - client.close().then(() => { - done(); + it('has close method for the initialized client', done => { + const client = + new videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + assert(client.videoIntelligenceServiceStub); + client.close().then(() => { + done(); + }); }); - }); - it('has close method for the non-initialized client', done => { - const client = - new videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - assert.strictEqual(client.videoIntelligenceServiceStub, undefined); - client.close().then(() => { - done(); + it('has close method for the non-initialized client', done => { + const client = + new videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + assert.strictEqual(client.videoIntelligenceServiceStub, undefined); + client.close().then(() => { + done(); + }); }); - }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = - new videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); - const result = await client.getProjectId(); - assert.strictEqual(result, fakeProjectId); - assert((client.auth.getProjectId as SinonStub).calledWithExactly()); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = - new videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.auth.getProjectId = sinon - .stub() - .callsArgWith(0, null, fakeProjectId); - const promise = new Promise((resolve, reject) => { - client.getProjectId((err?: Error | null, projectId?: string | null) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new videointelligenceserviceModule.v1p2beta1.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); }); - const result = await promise; - assert.strictEqual(result, fakeProjectId); }); describe('annotateVideo', () => { @@ -206,7 +223,6 @@ describe('v1p2beta1.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1p2beta1.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -215,11 +231,6 @@ describe('v1p2beta1.VideoIntelligenceServiceClient', () => { const [operation] = await client.annotateVideo(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes annotateVideo without error using callback', async () => { @@ -234,7 +245,6 @@ describe('v1p2beta1.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1p2beta1.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -264,11 +274,6 @@ describe('v1p2beta1.VideoIntelligenceServiceClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); }); it('invokes annotateVideo with call error', async () => { @@ -283,18 +288,12 @@ describe('v1p2beta1.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1p2beta1.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedError = new Error('expected'); client.innerApiCalls.annotateVideo = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.annotateVideo(request), expectedError); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes annotateVideo with LRO error', async () => { @@ -309,7 +308,6 @@ describe('v1p2beta1.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1p2beta1.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedError = new Error('expected'); client.innerApiCalls.annotateVideo = stubLongRunningCall( undefined, @@ -318,11 +316,6 @@ describe('v1p2beta1.VideoIntelligenceServiceClient', () => { ); const [operation] = await client.annotateVideo(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes checkAnnotateVideoProgress without error', async () => { diff --git a/test/gapic_video_intelligence_service_v1p3beta1.ts b/test/gapic_video_intelligence_service_v1p3beta1.ts index 879c799a..f3b36991 100644 --- a/test/gapic_video_intelligence_service_v1p3beta1.ts +++ b/test/gapic_video_intelligence_service_v1p3beta1.ts @@ -25,6 +25,21 @@ import * as videointelligenceserviceModule from '../src'; import {protobuf, LROperation, operationsProtos} from 'google-gax'; +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON( + require('../protos/protos.json') +).resolveAll(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type.fields[field]?.resolvedType as protobuf.Type; + } + return type.fields[fields[fields.length - 1]]?.defaultValue; +} + function generateSampleMessage(instance: T) { const filledObject = ( instance.constructor as typeof protobuf.Message @@ -73,124 +88,126 @@ function stubLongRunningCallWithCallback( } describe('v1p3beta1.VideoIntelligenceServiceClient', () => { - it('has servicePath', () => { - const servicePath = - videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient - .servicePath; - assert(servicePath); - }); + describe('Common methods', () => { + it('has servicePath', () => { + const servicePath = + videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient + .servicePath; + assert(servicePath); + }); - it('has apiEndpoint', () => { - const apiEndpoint = - videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient - .apiEndpoint; - assert(apiEndpoint); - }); + it('has apiEndpoint', () => { + const apiEndpoint = + videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient + .apiEndpoint; + assert(apiEndpoint); + }); - it('has port', () => { - const port = - videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient - .port; - assert(port); - assert(typeof port === 'number'); - }); + it('has port', () => { + const port = + videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient + .port; + assert(port); + assert(typeof port === 'number'); + }); - it('should create a client with no option', () => { - const client = - new videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient(); - assert(client); - }); + it('should create a client with no option', () => { + const client = + new videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient(); + assert(client); + }); - it('should create a client with gRPC fallback', () => { - const client = - new videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient( - { - fallback: true, - } - ); - assert(client); - }); + it('should create a client with gRPC fallback', () => { + const client = + new videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient( + { + fallback: true, + } + ); + assert(client); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = - new videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - assert.strictEqual(client.videoIntelligenceServiceStub, undefined); - await client.initialize(); - assert(client.videoIntelligenceServiceStub); - }); + it('has initialize method and supports deferred initialization', async () => { + const client = + new videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + assert.strictEqual(client.videoIntelligenceServiceStub, undefined); + await client.initialize(); + assert(client.videoIntelligenceServiceStub); + }); - it('has close method for the initialized client', done => { - const client = - new videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.initialize(); - assert(client.videoIntelligenceServiceStub); - client.close().then(() => { - done(); + it('has close method for the initialized client', done => { + const client = + new videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + assert(client.videoIntelligenceServiceStub); + client.close().then(() => { + done(); + }); }); - }); - it('has close method for the non-initialized client', done => { - const client = - new videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - assert.strictEqual(client.videoIntelligenceServiceStub, undefined); - client.close().then(() => { - done(); + it('has close method for the non-initialized client', done => { + const client = + new videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + assert.strictEqual(client.videoIntelligenceServiceStub, undefined); + client.close().then(() => { + done(); + }); }); - }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = - new videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); - const result = await client.getProjectId(); - assert.strictEqual(result, fakeProjectId); - assert((client.auth.getProjectId as SinonStub).calledWithExactly()); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = - new videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.auth.getProjectId = sinon - .stub() - .callsArgWith(0, null, fakeProjectId); - const promise = new Promise((resolve, reject) => { - client.getProjectId((err?: Error | null, projectId?: string | null) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new videointelligenceserviceModule.v1p3beta1.VideoIntelligenceServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); }); - const result = await promise; - assert.strictEqual(result, fakeProjectId); }); describe('annotateVideo', () => { @@ -206,7 +223,6 @@ describe('v1p3beta1.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1p3beta1.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -215,11 +231,6 @@ describe('v1p3beta1.VideoIntelligenceServiceClient', () => { const [operation] = await client.annotateVideo(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes annotateVideo without error using callback', async () => { @@ -234,7 +245,6 @@ describe('v1p3beta1.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1p3beta1.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -264,11 +274,6 @@ describe('v1p3beta1.VideoIntelligenceServiceClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); }); it('invokes annotateVideo with call error', async () => { @@ -283,18 +288,12 @@ describe('v1p3beta1.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1p3beta1.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedError = new Error('expected'); client.innerApiCalls.annotateVideo = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.annotateVideo(request), expectedError); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes annotateVideo with LRO error', async () => { @@ -309,7 +308,6 @@ describe('v1p3beta1.VideoIntelligenceServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.videointelligence.v1p3beta1.AnnotateVideoRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedError = new Error('expected'); client.innerApiCalls.annotateVideo = stubLongRunningCall( undefined, @@ -318,11 +316,6 @@ describe('v1p3beta1.VideoIntelligenceServiceClient', () => { ); const [operation] = await client.annotateVideo(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.annotateVideo as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes checkAnnotateVideoProgress without error', async () => {