From 8984236b32c9d91e4118b22c405f7bc60d1a709f Mon Sep 17 00:00:00 2001 From: Alexander Fenster Date: Thu, 5 Mar 2020 15:29:02 -0800 Subject: [PATCH] feat: deferred client initialization --- src/v1/asset_service_client.ts | 92 +++++++++++++++++++-------- src/v1beta1/asset_service_client.ts | 81 +++++++++++++++-------- src/v1p1beta1/asset_service_client.ts | 73 +++++++++++++++------ src/v1p2beta1/asset_service_client.ts | 76 +++++++++++++++------- synth.metadata | 8 +-- test/gapic-asset_service-v1.ts | 44 +++++++++++++ test/gapic-asset_service-v1beta1.ts | 24 +++++++ test/gapic-asset_service-v1p1beta1.ts | 24 +++++++ test/gapic-asset_service-v1p2beta1.ts | 36 +++++++++++ 9 files changed, 358 insertions(+), 100 deletions(-) diff --git a/src/v1/asset_service_client.ts b/src/v1/asset_service_client.ts index 663dbbd6..5efcd8e7 100644 --- a/src/v1/asset_service_client.ts +++ b/src/v1/asset_service_client.ts @@ -42,9 +42,14 @@ export class AssetServiceClient { private _innerApiCalls: {[name: string]: Function}; private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; + private _opts: ClientOptions; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; operationsClient: gax.OperationsClient; - assetServiceStub: Promise<{[name: string]: Function}>; + assetServiceStub?: Promise<{[name: string]: Function}>; /** * Construct an instance of AssetServiceClient. @@ -68,8 +73,6 @@ export class AssetServiceClient { * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. - * @param {function} [options.promise] - Custom promise module to use instead - * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ @@ -99,25 +102,28 @@ export class AssetServiceClient { // If we are in browser, we are already using fallback because of the // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. - const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; + this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = (this.constructor as typeof AssetServiceClient).scopes; - const gaxGrpc = new gaxModule.GrpcClient(opts); + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = gaxGrpc.auth as gax.GoogleAuth; + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Determine the client header string. - const clientHeader = [`gax/${gaxModule.version}`, `gapic/${version}`]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { - clientHeader.push(`gl-web/${gaxModule.version}`); + clientHeader.push(`gl-web/${this._gaxModule.version}`); } if (!opts.fallback) { - clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`); + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); } if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); @@ -133,7 +139,7 @@ export class AssetServiceClient { 'protos', 'protos.json' ); - const protos = gaxGrpc.loadProto( + this._protos = this._gaxGrpc.loadProto( opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath ); @@ -141,13 +147,13 @@ export class AssetServiceClient { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - folderFeedPathTemplate: new gaxModule.PathTemplate( + folderFeedPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/feeds/{feed}' ), - organizationFeedPathTemplate: new gaxModule.PathTemplate( + organizationFeedPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/feeds/{feed}' ), - projectFeedPathTemplate: new gaxModule.PathTemplate( + projectFeedPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/feeds/{feed}' ), }; @@ -156,13 +162,15 @@ export class AssetServiceClient { // an Operation object that allows for tracking of the operation, // rather than holding a request open. const protoFilesRoot = opts.fallback - ? gaxModule.protobuf.Root.fromJSON(require('../../protos/protos.json')) - : gaxModule.protobuf.loadSync(nodejsProtoPath); + ? this._gaxModule.protobuf.Root.fromJSON( + require('../../protos/protos.json') + ) + : this._gaxModule.protobuf.loadSync(nodejsProtoPath); - this.operationsClient = gaxModule + this.operationsClient = this._gaxModule .lro({ auth: this.auth, - grpc: 'grpc' in gaxGrpc ? gaxGrpc.grpc : undefined, + grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined, }) .operationsClient(opts); const exportAssetsResponse = protoFilesRoot.lookup( @@ -173,7 +181,7 @@ export class AssetServiceClient { ) as gax.protobuf.Type; this._descriptors.longrunning = { - exportAssets: new gaxModule.LongrunningDescriptor( + exportAssets: new this._gaxModule.LongrunningDescriptor( this.operationsClient, exportAssetsResponse.decode.bind(exportAssetsResponse), exportAssetsMetadata.decode.bind(exportAssetsMetadata) @@ -181,7 +189,7 @@ export class AssetServiceClient { }; // Put together the default options sent with requests. - const defaults = gaxGrpc.constructSettings( + this._defaults = this._gaxGrpc.constructSettings( 'google.cloud.asset.v1.AssetService', gapicConfig as gax.ClientConfig, opts.clientConfig || {}, @@ -192,17 +200,35 @@ export class AssetServiceClient { // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this._innerApiCalls = {}; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.assetServiceStub) { + return this.assetServiceStub; + } // Put together the "service stub" for // google.cloud.asset.v1.AssetService. - this.assetServiceStub = gaxGrpc.createStub( - opts.fallback - ? (protos as protobuf.Root).lookupService( + this.assetServiceStub = this._gaxGrpc.createStub( + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( 'google.cloud.asset.v1.AssetService' ) : // tslint:disable-next-line no-any - (protos as any).google.cloud.asset.v1.AssetService, - opts + (this._protos as any).google.cloud.asset.v1.AssetService, + this._opts ) as Promise<{[method: string]: Function}>; // Iterate over each of the methods that the service provides @@ -230,9 +256,9 @@ export class AssetServiceClient { } ); - const apiCall = gaxModule.createApiCall( + const apiCall = this._gaxModule.createApiCall( innerCallPromise, - defaults[methodName], + this._defaults[methodName], this._descriptors.page[methodName] || this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] @@ -246,6 +272,8 @@ export class AssetServiceClient { return apiCall(argument, callOptions, callback); }; } + + return this.assetServiceStub; } /** @@ -404,6 +432,7 @@ export class AssetServiceClient { ] = gax.routingHeader.fromParams({ parent: request.parent || '', }); + this.initialize(); return this._innerApiCalls.batchGetAssetsHistory( request, options, @@ -493,6 +522,7 @@ export class AssetServiceClient { ] = gax.routingHeader.fromParams({ parent: request.parent || '', }); + this.initialize(); return this._innerApiCalls.createFeed(request, options, callback); } getFeed( @@ -567,6 +597,7 @@ export class AssetServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.getFeed(request, options, callback); } listFeeds( @@ -640,6 +671,7 @@ export class AssetServiceClient { ] = gax.routingHeader.fromParams({ parent: request.parent || '', }); + this.initialize(); return this._innerApiCalls.listFeeds(request, options, callback); } updateFeed( @@ -719,6 +751,7 @@ export class AssetServiceClient { ] = gax.routingHeader.fromParams({ 'feed.name': request.feed!.name || '', }); + this.initialize(); return this._innerApiCalls.updateFeed(request, options, callback); } deleteFeed( @@ -793,6 +826,7 @@ export class AssetServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.deleteFeed(request, options, callback); } @@ -824,7 +858,7 @@ export class AssetServiceClient { /** * Exports assets with time and resource types to a given Cloud Storage * location. The output format is newline-delimited JSON. - * This API implements the [google.longrunning.Operation][google.longrunning.Operation] API allowing you + * This API implements the {@link google.longrunning.Operation|google.longrunning.Operation} API allowing you * to keep track of the export. * * @param {Object} request @@ -904,6 +938,7 @@ export class AssetServiceClient { ] = gax.routingHeader.fromParams({ parent: request.parent || '', }); + this.initialize(); return this._innerApiCalls.exportAssets(request, options, callback); } // -------------------- @@ -1032,8 +1067,9 @@ export class AssetServiceClient { * The client will no longer be usable and all future behavior is undefined. */ close(): Promise { + this.initialize(); if (!this._terminated) { - return this.assetServiceStub.then(stub => { + return this.assetServiceStub!.then(stub => { this._terminated = true; stub.close(); }); diff --git a/src/v1beta1/asset_service_client.ts b/src/v1beta1/asset_service_client.ts index 0a8ee820..dc6b2d88 100644 --- a/src/v1beta1/asset_service_client.ts +++ b/src/v1beta1/asset_service_client.ts @@ -41,9 +41,14 @@ export class AssetServiceClient { private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; private _innerApiCalls: {[name: string]: Function}; private _terminated = false; + private _opts: ClientOptions; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; operationsClient: gax.OperationsClient; - assetServiceStub: Promise<{[name: string]: Function}>; + assetServiceStub?: Promise<{[name: string]: Function}>; /** * Construct an instance of AssetServiceClient. @@ -67,8 +72,6 @@ export class AssetServiceClient { * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. - * @param {function} [options.promise] - Custom promise module to use instead - * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ @@ -98,25 +101,28 @@ export class AssetServiceClient { // If we are in browser, we are already using fallback because of the // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. - const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; + this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = (this.constructor as typeof AssetServiceClient).scopes; - const gaxGrpc = new gaxModule.GrpcClient(opts); + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = gaxGrpc.auth as gax.GoogleAuth; + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Determine the client header string. - const clientHeader = [`gax/${gaxModule.version}`, `gapic/${version}`]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { - clientHeader.push(`gl-web/${gaxModule.version}`); + clientHeader.push(`gl-web/${this._gaxModule.version}`); } if (!opts.fallback) { - clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`); + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); } if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); @@ -132,7 +138,7 @@ export class AssetServiceClient { 'protos', 'protos.json' ); - const protos = gaxGrpc.loadProto( + this._protos = this._gaxGrpc.loadProto( opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath ); @@ -140,13 +146,15 @@ export class AssetServiceClient { // an Operation object that allows for tracking of the operation, // rather than holding a request open. const protoFilesRoot = opts.fallback - ? gaxModule.protobuf.Root.fromJSON(require('../../protos/protos.json')) - : gaxModule.protobuf.loadSync(nodejsProtoPath); + ? this._gaxModule.protobuf.Root.fromJSON( + require('../../protos/protos.json') + ) + : this._gaxModule.protobuf.loadSync(nodejsProtoPath); - this.operationsClient = gaxModule + this.operationsClient = this._gaxModule .lro({ auth: this.auth, - grpc: 'grpc' in gaxGrpc ? gaxGrpc.grpc : undefined, + grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined, }) .operationsClient(opts); const exportAssetsResponse = protoFilesRoot.lookup( @@ -157,7 +165,7 @@ export class AssetServiceClient { ) as gax.protobuf.Type; this._descriptors.longrunning = { - exportAssets: new gaxModule.LongrunningDescriptor( + exportAssets: new this._gaxModule.LongrunningDescriptor( this.operationsClient, exportAssetsResponse.decode.bind(exportAssetsResponse), exportAssetsMetadata.decode.bind(exportAssetsMetadata) @@ -165,7 +173,7 @@ export class AssetServiceClient { }; // Put together the default options sent with requests. - const defaults = gaxGrpc.constructSettings( + this._defaults = this._gaxGrpc.constructSettings( 'google.cloud.asset.v1beta1.AssetService', gapicConfig as gax.ClientConfig, opts.clientConfig || {}, @@ -176,17 +184,35 @@ export class AssetServiceClient { // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this._innerApiCalls = {}; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.assetServiceStub) { + return this.assetServiceStub; + } // Put together the "service stub" for // google.cloud.asset.v1beta1.AssetService. - this.assetServiceStub = gaxGrpc.createStub( - opts.fallback - ? (protos as protobuf.Root).lookupService( + this.assetServiceStub = this._gaxGrpc.createStub( + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( 'google.cloud.asset.v1beta1.AssetService' ) : // tslint:disable-next-line no-any - (protos as any).google.cloud.asset.v1beta1.AssetService, - opts + (this._protos as any).google.cloud.asset.v1beta1.AssetService, + this._opts ) as Promise<{[method: string]: Function}>; // Iterate over each of the methods that the service provides @@ -206,9 +232,9 @@ export class AssetServiceClient { } ); - const apiCall = gaxModule.createApiCall( + const apiCall = this._gaxModule.createApiCall( innerCallPromise, - defaults[methodName], + this._defaults[methodName], this._descriptors.page[methodName] || this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] @@ -222,6 +248,8 @@ export class AssetServiceClient { return apiCall(argument, callOptions, callback); }; } + + return this.assetServiceStub; } /** @@ -378,6 +406,7 @@ export class AssetServiceClient { ] = gax.routingHeader.fromParams({ parent: request.parent || '', }); + this.initialize(); return this._innerApiCalls.batchGetAssetsHistory( request, options, @@ -414,7 +443,7 @@ export class AssetServiceClient { * Exports assets with time and resource types to a given Cloud Storage * location. The output format is newline-delimited JSON. * This API implements the - * [google.longrunning.Operation][google.longrunning.Operation] API allowing + * {@link google.longrunning.Operation|google.longrunning.Operation} API allowing * you to keep track of the export. * * @param {Object} request @@ -494,6 +523,7 @@ export class AssetServiceClient { ] = gax.routingHeader.fromParams({ parent: request.parent || '', }); + this.initialize(); return this._innerApiCalls.exportAssets(request, options, callback); } @@ -503,8 +533,9 @@ export class AssetServiceClient { * The client will no longer be usable and all future behavior is undefined. */ close(): Promise { + this.initialize(); if (!this._terminated) { - return this.assetServiceStub.then(stub => { + return this.assetServiceStub!.then(stub => { this._terminated = true; stub.close(); }); diff --git a/src/v1p1beta1/asset_service_client.ts b/src/v1p1beta1/asset_service_client.ts index fce13d5f..e53bdfd0 100644 --- a/src/v1p1beta1/asset_service_client.ts +++ b/src/v1p1beta1/asset_service_client.ts @@ -43,8 +43,13 @@ export class AssetServiceClient { private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; private _innerApiCalls: {[name: string]: Function}; private _terminated = false; + private _opts: ClientOptions; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; - assetServiceStub: Promise<{[name: string]: Function}>; + assetServiceStub?: Promise<{[name: string]: Function}>; /** * Construct an instance of AssetServiceClient. @@ -68,8 +73,6 @@ export class AssetServiceClient { * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. - * @param {function} [options.promise] - Custom promise module to use instead - * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ @@ -99,25 +102,28 @@ export class AssetServiceClient { // If we are in browser, we are already using fallback because of the // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. - const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; + this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = (this.constructor as typeof AssetServiceClient).scopes; - const gaxGrpc = new gaxModule.GrpcClient(opts); + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = gaxGrpc.auth as gax.GoogleAuth; + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Determine the client header string. - const clientHeader = [`gax/${gaxModule.version}`, `gapic/${version}`]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { - clientHeader.push(`gl-web/${gaxModule.version}`); + clientHeader.push(`gl-web/${this._gaxModule.version}`); } if (!opts.fallback) { - clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`); + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); } if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); @@ -133,7 +139,7 @@ export class AssetServiceClient { 'protos', 'protos.json' ); - const protos = gaxGrpc.loadProto( + this._protos = this._gaxGrpc.loadProto( opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath ); @@ -141,12 +147,12 @@ export class AssetServiceClient { // (e.g. 50 results at a time, with tokens to get subsequent // pages). Denote the keys used for pagination and results. this._descriptors.page = { - searchAllResources: new gaxModule.PageDescriptor( + searchAllResources: new this._gaxModule.PageDescriptor( 'pageToken', 'nextPageToken', 'results' ), - searchAllIamPolicies: new gaxModule.PageDescriptor( + searchAllIamPolicies: new this._gaxModule.PageDescriptor( 'pageToken', 'nextPageToken', 'results' @@ -154,7 +160,7 @@ export class AssetServiceClient { }; // Put together the default options sent with requests. - const defaults = gaxGrpc.constructSettings( + this._defaults = this._gaxGrpc.constructSettings( 'google.cloud.asset.v1p1beta1.AssetService', gapicConfig as gax.ClientConfig, opts.clientConfig || {}, @@ -165,17 +171,35 @@ export class AssetServiceClient { // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this._innerApiCalls = {}; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.assetServiceStub) { + return this.assetServiceStub; + } // Put together the "service stub" for // google.cloud.asset.v1p1beta1.AssetService. - this.assetServiceStub = gaxGrpc.createStub( - opts.fallback - ? (protos as protobuf.Root).lookupService( + this.assetServiceStub = this._gaxGrpc.createStub( + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( 'google.cloud.asset.v1p1beta1.AssetService' ) : // tslint:disable-next-line no-any - (protos as any).google.cloud.asset.v1p1beta1.AssetService, - opts + (this._protos as any).google.cloud.asset.v1p1beta1.AssetService, + this._opts ) as Promise<{[method: string]: Function}>; // Iterate over each of the methods that the service provides @@ -198,9 +222,9 @@ export class AssetServiceClient { } ); - const apiCall = gaxModule.createApiCall( + const apiCall = this._gaxModule.createApiCall( innerCallPromise, - defaults[methodName], + this._defaults[methodName], this._descriptors.page[methodName] || this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] @@ -214,6 +238,8 @@ export class AssetServiceClient { return apiCall(argument, callOptions, callback); }; } + + return this.assetServiceStub; } /** @@ -372,6 +398,7 @@ export class AssetServiceClient { ] = gax.routingHeader.fromParams({ scope: request.scope || '', }); + this.initialize(); return this._innerApiCalls.searchAllResources(request, options, callback); } @@ -430,6 +457,7 @@ export class AssetServiceClient { scope: request.scope || '', }); const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.searchAllResources.createStream( this._innerApiCalls.searchAllResources as gax.GaxCall, request, @@ -541,6 +569,7 @@ export class AssetServiceClient { ] = gax.routingHeader.fromParams({ scope: request.scope || '', }); + this.initialize(); return this._innerApiCalls.searchAllIamPolicies(request, options, callback); } @@ -599,6 +628,7 @@ export class AssetServiceClient { scope: request.scope || '', }); const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.searchAllIamPolicies.createStream( this._innerApiCalls.searchAllIamPolicies as gax.GaxCall, request, @@ -612,8 +642,9 @@ export class AssetServiceClient { * The client will no longer be usable and all future behavior is undefined. */ close(): Promise { + this.initialize(); if (!this._terminated) { - return this.assetServiceStub.then(stub => { + return this.assetServiceStub!.then(stub => { this._terminated = true; stub.close(); }); diff --git a/src/v1p2beta1/asset_service_client.ts b/src/v1p2beta1/asset_service_client.ts index c3bb3235..00796f3e 100644 --- a/src/v1p2beta1/asset_service_client.ts +++ b/src/v1p2beta1/asset_service_client.ts @@ -41,8 +41,13 @@ export class AssetServiceClient { private _innerApiCalls: {[name: string]: Function}; private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; + private _opts: ClientOptions; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; - assetServiceStub: Promise<{[name: string]: Function}>; + assetServiceStub?: Promise<{[name: string]: Function}>; /** * Construct an instance of AssetServiceClient. @@ -66,8 +71,6 @@ export class AssetServiceClient { * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. - * @param {function} [options.promise] - Custom promise module to use instead - * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ @@ -97,25 +100,28 @@ export class AssetServiceClient { // If we are in browser, we are already using fallback because of the // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. - const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; + this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = (this.constructor as typeof AssetServiceClient).scopes; - const gaxGrpc = new gaxModule.GrpcClient(opts); + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = gaxGrpc.auth as gax.GoogleAuth; + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Determine the client header string. - const clientHeader = [`gax/${gaxModule.version}`, `gapic/${version}`]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { - clientHeader.push(`gl-web/${gaxModule.version}`); + clientHeader.push(`gl-web/${this._gaxModule.version}`); } if (!opts.fallback) { - clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`); + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); } if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); @@ -131,7 +137,7 @@ export class AssetServiceClient { 'protos', 'protos.json' ); - const protos = gaxGrpc.loadProto( + this._protos = this._gaxGrpc.loadProto( opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath ); @@ -139,19 +145,19 @@ export class AssetServiceClient { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - folderFeedPathTemplate: new gaxModule.PathTemplate( + folderFeedPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/feeds/{feed}' ), - organizationFeedPathTemplate: new gaxModule.PathTemplate( + organizationFeedPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/feeds/{feed}' ), - projectFeedPathTemplate: new gaxModule.PathTemplate( + projectFeedPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/feeds/{feed}' ), }; // Put together the default options sent with requests. - const defaults = gaxGrpc.constructSettings( + this._defaults = this._gaxGrpc.constructSettings( 'google.cloud.asset.v1p2beta1.AssetService', gapicConfig as gax.ClientConfig, opts.clientConfig || {}, @@ -162,17 +168,35 @@ export class AssetServiceClient { // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this._innerApiCalls = {}; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.assetServiceStub) { + return this.assetServiceStub; + } // Put together the "service stub" for // google.cloud.asset.v1p2beta1.AssetService. - this.assetServiceStub = gaxGrpc.createStub( - opts.fallback - ? (protos as protobuf.Root).lookupService( + this.assetServiceStub = this._gaxGrpc.createStub( + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( 'google.cloud.asset.v1p2beta1.AssetService' ) : // tslint:disable-next-line no-any - (protos as any).google.cloud.asset.v1p2beta1.AssetService, - opts + (this._protos as any).google.cloud.asset.v1p2beta1.AssetService, + this._opts ) as Promise<{[method: string]: Function}>; // Iterate over each of the methods that the service provides @@ -198,9 +222,9 @@ export class AssetServiceClient { } ); - const apiCall = gaxModule.createApiCall( + const apiCall = this._gaxModule.createApiCall( innerCallPromise, - defaults[methodName], + this._defaults[methodName], this._descriptors.page[methodName] || this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] @@ -214,6 +238,8 @@ export class AssetServiceClient { return apiCall(argument, callOptions, callback); }; } + + return this.assetServiceStub; } /** @@ -350,6 +376,7 @@ export class AssetServiceClient { ] = gax.routingHeader.fromParams({ parent: request.parent || '', }); + this.initialize(); return this._innerApiCalls.createFeed(request, options, callback); } getFeed( @@ -424,6 +451,7 @@ export class AssetServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.getFeed(request, options, callback); } listFeeds( @@ -498,6 +526,7 @@ export class AssetServiceClient { ] = gax.routingHeader.fromParams({ parent: request.parent || '', }); + this.initialize(); return this._innerApiCalls.listFeeds(request, options, callback); } updateFeed( @@ -578,6 +607,7 @@ export class AssetServiceClient { ] = gax.routingHeader.fromParams({ 'feed.name': request.feed!.name || '', }); + this.initialize(); return this._innerApiCalls.updateFeed(request, options, callback); } deleteFeed( @@ -653,6 +683,7 @@ export class AssetServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.deleteFeed(request, options, callback); } @@ -782,8 +813,9 @@ export class AssetServiceClient { * The client will no longer be usable and all future behavior is undefined. */ close(): Promise { + this.initialize(); if (!this._terminated) { - return this.assetServiceStub.then(stub => { + return this.assetServiceStub!.then(stub => { this._terminated = true; stub.close(); }); diff --git a/synth.metadata b/synth.metadata index debdd2c1..93e6a24b 100644 --- a/synth.metadata +++ b/synth.metadata @@ -1,13 +1,13 @@ { - "updateTime": "2020-02-29T12:11:41.085915Z", + "updateTime": "2020-03-05T23:01:19.178450Z", "sources": [ { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "83c6f84035ee0f80eaa44d8b688a010461cc4080", - "internalRef": "297918498", - "log": "83c6f84035ee0f80eaa44d8b688a010461cc4080\nUpdate google/api/auth.proto to make AuthProvider to have JwtLocation\n\nPiperOrigin-RevId: 297918498\n\ne9e90a787703ec5d388902e2cb796aaed3a385b4\nDialogflow weekly v2/v2beta1 library update:\n - adding get validation result\n - adding field mask override control for output audio config\nImportant updates are also posted at:\nhttps://cloud.google.com/dialogflow/docs/release-notes\n\nPiperOrigin-RevId: 297671458\n\n1a2b05cc3541a5f7714529c665aecc3ea042c646\nAdding .yaml and .json config files.\n\nPiperOrigin-RevId: 297570622\n\ndfe1cf7be44dee31d78f78e485d8c95430981d6e\nPublish `QueryOptions` proto.\n\nIntroduced a `query_options` input in `ExecuteSqlRequest`.\n\nPiperOrigin-RevId: 297497710\n\ndafc905f71e5d46f500b41ed715aad585be062c3\npubsub: revert pull init_rpc_timeout & max_rpc_timeout back to 25 seconds and reset multiplier to 1.0\n\nPiperOrigin-RevId: 297486523\n\nf077632ba7fee588922d9e8717ee272039be126d\nfirestore: add update_transform\n\nPiperOrigin-RevId: 297405063\n\n0aba1900ffef672ec5f0da677cf590ee5686e13b\ncluster: use square brace for cross-reference\n\nPiperOrigin-RevId: 297204568\n\n5dac2da18f6325cbaed54603c43f0667ecd50247\nRestore retry params in gapic config because securitycenter has non-standard default retry params.\nRestore a few retry codes for some idempotent methods.\n\nPiperOrigin-RevId: 297196720\n\n1eb61455530252bba8b2c8d4bc9832960e5a56f6\npubsub: v1 replace IAM HTTP rules\n\nPiperOrigin-RevId: 297188590\n\n80b2d25f8d43d9d47024ff06ead7f7166548a7ba\nDialogflow weekly v2/v2beta1 library update:\n - updates to mega agent api\n - adding field mask override control for output audio config\nImportant updates are also posted at:\nhttps://cloud.google.com/dialogflow/docs/release-notes\n\nPiperOrigin-RevId: 297187629\n\n0b1876b35e98f560f9c9ca9797955f020238a092\nUse an older version of protoc-docs-plugin that is compatible with the specified gapic-generator and protobuf versions.\n\nprotoc-docs-plugin >=0.4.0 (see commit https://github.com/googleapis/protoc-docs-plugin/commit/979f03ede6678c487337f3d7e88bae58df5207af) is incompatible with protobuf 3.9.1.\n\nPiperOrigin-RevId: 296986742\n\n1e47e676cddbbd8d93f19ba0665af15b5532417e\nFix: Restore a method signature for UpdateCluster\n\nPiperOrigin-RevId: 296901854\n\n7f910bcc4fc4704947ccfd3ceed015d16b9e00c2\nUpdate Dataproc v1beta2 client.\n\nPiperOrigin-RevId: 296451205\n\nde287524405a3dce124d301634731584fc0432d7\nFix: Reinstate method signatures that had been missed off some RPCs\nFix: Correct resource types for two fields\n\nPiperOrigin-RevId: 296435091\n\ne5bc9566ae057fb4c92f8b7e047f1c8958235b53\nDeprecate the endpoint_uris field, as it is unused.\n\nPiperOrigin-RevId: 296357191\n\n8c12e2b4dca94e12bff9f538bdac29524ff7ef7a\nUpdate Dataproc v1 client.\n\nPiperOrigin-RevId: 296336662\n\n17567c4a1ef0a9b50faa87024d66f8acbb561089\nRemoving erroneous comment, a la https://github.com/googleapis/java-speech/pull/103\n\nPiperOrigin-RevId: 296332968\n\n3eaaaf8626ce5b0c0bc7eee05e143beffa373b01\nAdd BUILD.bazel for v1 secretmanager.googleapis.com\n\nPiperOrigin-RevId: 296274723\n\ne76149c3d992337f85eeb45643106aacae7ede82\nMove securitycenter v1 to use generate from annotations.\n\nPiperOrigin-RevId: 296266862\n\n203740c78ac69ee07c3bf6be7408048751f618f8\nAdd StackdriverLoggingConfig field to Cloud Tasks v2 API.\n\nPiperOrigin-RevId: 296256388\n\ne4117d5e9ed8bbca28da4a60a94947ca51cb2083\nCreate a Bazel BUILD file for the google.actions.type export.\n\nPiperOrigin-RevId: 296212567\n\na9639a0a9854fd6e1be08bba1ac3897f4f16cb2f\nAdd secretmanager.googleapis.com v1 protos\n\nPiperOrigin-RevId: 295983266\n\nce4f4c21d9dd2bfab18873a80449b9d9851efde8\nasset: v1p1beta1 remove SearchResources and SearchIamPolicies\n\nPiperOrigin-RevId: 295861722\n\ncb61d6c2d070b589980c779b68ffca617f789116\nasset: v1p1beta1 remove SearchResources and SearchIamPolicies\n\nPiperOrigin-RevId: 295855449\n\nab2685d8d3a0e191dc8aef83df36773c07cb3d06\nfix: Dataproc v1 - AutoscalingPolicy annotation\n\nThis adds the second resource name pattern to the\nAutoscalingPolicy resource.\n\nCommitter: @lukesneeringer\nPiperOrigin-RevId: 295738415\n\n8a1020bf6828f6e3c84c3014f2c51cb62b739140\nUpdate cloud asset api v1p4beta1.\n\nPiperOrigin-RevId: 295286165\n\n5cfa105206e77670369e4b2225597386aba32985\nAdd service control related proto build rule.\n\nPiperOrigin-RevId: 295262088\n\nee4dddf805072004ab19ac94df2ce669046eec26\nmonitoring v3: Add prefix \"https://cloud.google.com/\" into the link for global access\ncl 295167522, get ride of synth.py hacks\n\nPiperOrigin-RevId: 295238095\n\nd9835e922ea79eed8497db270d2f9f85099a519c\nUpdate some minor docs changes about user event proto\n\nPiperOrigin-RevId: 295185610\n\n5f311e416e69c170243de722023b22f3df89ec1c\nfix: use correct PHP package name in gapic configuration\n\nPiperOrigin-RevId: 295161330\n\n6cdd74dcdb071694da6a6b5a206e3a320b62dd11\npubsub: v1 add client config annotations and retry config\n\nPiperOrigin-RevId: 295158776\n\n5169f46d9f792e2934d9fa25c36d0515b4fd0024\nAdded cloud asset api v1p4beta1.\n\nPiperOrigin-RevId: 295026522\n\n56b55aa8818cd0a532a7d779f6ef337ba809ccbd\nFix: Resource annotations for CreateTimeSeriesRequest and ListTimeSeriesRequest should refer to valid resources. TimeSeries is not a named resource.\n\nPiperOrigin-RevId: 294931650\n\n0646bc775203077226c2c34d3e4d50cc4ec53660\nRemove unnecessary languages from bigquery-related artman configuration files.\n\nPiperOrigin-RevId: 294809380\n\n8b78aa04382e3d4147112ad6d344666771bb1909\nUpdate backend.proto for schemes and protocol\n\nPiperOrigin-RevId: 294788800\n\n80b8f8b3de2359831295e24e5238641a38d8488f\nAdds artman config files for bigquerystorage endpoints v1beta2, v1alpha2, v1\n\nPiperOrigin-RevId: 294763931\n\n" + "sha": "f0b581b5bdf803e45201ecdb3688b60e381628a8", + "internalRef": "299181282", + "log": "f0b581b5bdf803e45201ecdb3688b60e381628a8\nfix: recommendationengine/v1beta1 update some comments\n\nPiperOrigin-RevId: 299181282\n\n10e9a0a833dc85ff8f05b2c67ebe5ac785fe04ff\nbuild: add generated BUILD file for Routes Preferred API\n\nPiperOrigin-RevId: 299164808\n\n86738c956a8238d7c77f729be78b0ed887a6c913\npublish v1p1beta1: update with absolute address in comments\n\nPiperOrigin-RevId: 299152383\n\n73d9f2ad4591de45c2e1f352bc99d70cbd2a6d95\npublish v1: update with absolute address in comments\n\nPiperOrigin-RevId: 299147194\n\nd2158f24cb77b0b0ccfe68af784c6a628705e3c6\npublish v1beta2: update with absolute address in comments\n\nPiperOrigin-RevId: 299147086\n\n7fca61292c11b4cd5b352cee1a50bf88819dd63b\npublish v1p2beta1: update with absolute address in comments\n\nPiperOrigin-RevId: 299146903\n\n583b7321624736e2c490e328f4b1957335779295\npublish v1p3beta1: update with absolute address in comments\n\nPiperOrigin-RevId: 299146674\n\n638253bf86d1ce1c314108a089b7351440c2f0bf\nfix: add java_multiple_files option for automl text_sentiment.proto\n\nPiperOrigin-RevId: 298971070\n\n373d655703bf914fb8b0b1cc4071d772bac0e0d1\nUpdate Recs AI Beta public bazel file\n\nPiperOrigin-RevId: 298961623\n\ndcc5d00fc8a8d8b56f16194d7c682027b2c66a3b\nfix: add java_multiple_files option for automl classification.proto\n\nPiperOrigin-RevId: 298953301\n\na3f791827266f3496a6a5201d58adc4bb265c2a3\nchore: automl/v1 publish annotations and retry config\n\nPiperOrigin-RevId: 298942178\n\n01c681586d8d6dbd60155289b587aee678530bd9\nMark return_immediately in PullRequest deprecated.\n\nPiperOrigin-RevId: 298893281\n\nc9f5e9c4bfed54bbd09227e990e7bded5f90f31c\nRemove out of date documentation for predicate support on the Storage API\n\nPiperOrigin-RevId: 298883309\n\nfd5b3b8238d783b04692a113ffe07c0363f5de0f\ngenerate webrisk v1 proto\n\nPiperOrigin-RevId: 298847934\n\n541b1ded4abadcc38e8178680b0677f65594ea6f\nUpdate cloud asset api v1p4beta1.\n\nPiperOrigin-RevId: 298686266\n\nc0d171acecb4f5b0bfd2c4ca34fc54716574e300\n Updated to include the Notification v1 API.\n\nPiperOrigin-RevId: 298652775\n\n2346a9186c0bff2c9cc439f2459d558068637e05\nAdd Service Directory v1beta1 protos and configs\n\nPiperOrigin-RevId: 298625638\n\na78ed801b82a5c6d9c5368e24b1412212e541bb7\nPublishing v3 protos and configs.\n\nPiperOrigin-RevId: 298607357\n\n4a180bfff8a21645b3a935c2756e8d6ab18a74e0\nautoml/v1beta1 publish proto updates\n\nPiperOrigin-RevId: 298484782\n\n6de6e938b7df1cd62396563a067334abeedb9676\nchore: use the latest gapic-generator and protoc-java-resource-name-plugin in Bazel workspace.\n\nPiperOrigin-RevId: 298474513\n\n244ab2b83a82076a1fa7be63b7e0671af73f5c02\nAdds service config definition for bigqueryreservation v1\n\nPiperOrigin-RevId: 298455048\n\n" } }, { diff --git a/test/gapic-asset_service-v1.ts b/test/gapic-asset_service-v1.ts index f56860b8..d79fd23b 100644 --- a/test/gapic-asset_service-v1.ts +++ b/test/gapic-asset_service-v1.ts @@ -102,12 +102,30 @@ describe('v1.AssetServiceClient', () => { }); assert(client); }); + it('has initialize method and supports deferred initialization', async () => { + const client = new assetserviceModule.v1.AssetServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.assetServiceStub, undefined); + await client.initialize(); + assert(client.assetServiceStub); + }); + it('has close method', () => { + const client = new assetserviceModule.v1.AssetServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.close(); + }); describe('batchGetAssetsHistory', () => { it('invokes batchGetAssetsHistory without error', done => { const client = new assetserviceModule.v1.AssetServiceClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1.IBatchGetAssetsHistoryRequest = {}; request.parent = ''; @@ -131,6 +149,8 @@ describe('v1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1.IBatchGetAssetsHistoryRequest = {}; request.parent = ''; @@ -156,6 +176,8 @@ describe('v1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1.ICreateFeedRequest = {}; request.parent = ''; @@ -179,6 +201,8 @@ describe('v1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1.ICreateFeedRequest = {}; request.parent = ''; @@ -204,6 +228,8 @@ describe('v1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1.IGetFeedRequest = {}; request.name = ''; @@ -227,6 +253,8 @@ describe('v1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1.IGetFeedRequest = {}; request.name = ''; @@ -252,6 +280,8 @@ describe('v1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1.IListFeedsRequest = {}; request.parent = ''; @@ -275,6 +305,8 @@ describe('v1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1.IListFeedsRequest = {}; request.parent = ''; @@ -300,6 +332,8 @@ describe('v1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1.IUpdateFeedRequest = {}; request.feed = {}; @@ -324,6 +358,8 @@ describe('v1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1.IUpdateFeedRequest = {}; request.feed = {}; @@ -350,6 +386,8 @@ describe('v1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1.IDeleteFeedRequest = {}; request.name = ''; @@ -373,6 +411,8 @@ describe('v1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1.IDeleteFeedRequest = {}; request.name = ''; @@ -398,6 +438,8 @@ describe('v1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1.IExportAssetsRequest = {}; request.parent = ''; @@ -428,6 +470,8 @@ describe('v1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1.IExportAssetsRequest = {}; request.parent = ''; diff --git a/test/gapic-asset_service-v1beta1.ts b/test/gapic-asset_service-v1beta1.ts index ad8df628..dfb52b9d 100644 --- a/test/gapic-asset_service-v1beta1.ts +++ b/test/gapic-asset_service-v1beta1.ts @@ -104,12 +104,30 @@ describe('v1beta1.AssetServiceClient', () => { }); assert(client); }); + it('has initialize method and supports deferred initialization', async () => { + const client = new assetserviceModule.v1beta1.AssetServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.assetServiceStub, undefined); + await client.initialize(); + assert(client.assetServiceStub); + }); + it('has close method', () => { + const client = new assetserviceModule.v1beta1.AssetServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.close(); + }); describe('batchGetAssetsHistory', () => { it('invokes batchGetAssetsHistory without error', done => { const client = new assetserviceModule.v1beta1.AssetServiceClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1beta1.IBatchGetAssetsHistoryRequest = {}; request.parent = ''; @@ -133,6 +151,8 @@ describe('v1beta1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1beta1.IBatchGetAssetsHistoryRequest = {}; request.parent = ''; @@ -158,6 +178,8 @@ describe('v1beta1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1beta1.IExportAssetsRequest = {}; request.parent = ''; @@ -188,6 +210,8 @@ describe('v1beta1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1beta1.IExportAssetsRequest = {}; request.parent = ''; diff --git a/test/gapic-asset_service-v1p1beta1.ts b/test/gapic-asset_service-v1p1beta1.ts index 6a09509c..9f1b560b 100644 --- a/test/gapic-asset_service-v1p1beta1.ts +++ b/test/gapic-asset_service-v1p1beta1.ts @@ -67,12 +67,30 @@ describe('v1p1beta1.AssetServiceClient', () => { }); assert(client); }); + it('has initialize method and supports deferred initialization', async () => { + const client = new assetserviceModule.v1p1beta1.AssetServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.assetServiceStub, undefined); + await client.initialize(); + assert(client.assetServiceStub); + }); + it('has close method', () => { + const client = new assetserviceModule.v1p1beta1.AssetServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.close(); + }); describe('searchAllResources', () => { it('invokes searchAllResources without error', done => { const client = new assetserviceModule.v1p1beta1.AssetServiceClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1p1beta1.ISearchAllResourcesRequest = {}; request.scope = ''; @@ -100,6 +118,8 @@ describe('v1p1beta1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1p1beta1.ISearchAllResourcesRequest = {}; request.scope = ''; @@ -132,6 +152,8 @@ describe('v1p1beta1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1p1beta1.ISearchAllIamPoliciesRequest = {}; request.scope = ''; @@ -159,6 +181,8 @@ describe('v1p1beta1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1p1beta1.ISearchAllIamPoliciesRequest = {}; request.scope = ''; diff --git a/test/gapic-asset_service-v1p2beta1.ts b/test/gapic-asset_service-v1p2beta1.ts index 02fd1b88..73678598 100644 --- a/test/gapic-asset_service-v1p2beta1.ts +++ b/test/gapic-asset_service-v1p2beta1.ts @@ -83,12 +83,30 @@ describe('v1p2beta1.AssetServiceClient', () => { }); assert(client); }); + it('has initialize method and supports deferred initialization', async () => { + const client = new assetserviceModule.v1p2beta1.AssetServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.assetServiceStub, undefined); + await client.initialize(); + assert(client.assetServiceStub); + }); + it('has close method', () => { + const client = new assetserviceModule.v1p2beta1.AssetServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.close(); + }); describe('createFeed', () => { it('invokes createFeed without error', done => { const client = new assetserviceModule.v1p2beta1.AssetServiceClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1p2beta1.ICreateFeedRequest = {}; request.parent = ''; @@ -112,6 +130,8 @@ describe('v1p2beta1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1p2beta1.ICreateFeedRequest = {}; request.parent = ''; @@ -137,6 +157,8 @@ describe('v1p2beta1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1p2beta1.IGetFeedRequest = {}; request.name = ''; @@ -160,6 +182,8 @@ describe('v1p2beta1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1p2beta1.IGetFeedRequest = {}; request.name = ''; @@ -185,6 +209,8 @@ describe('v1p2beta1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1p2beta1.IListFeedsRequest = {}; request.parent = ''; @@ -208,6 +234,8 @@ describe('v1p2beta1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1p2beta1.IListFeedsRequest = {}; request.parent = ''; @@ -233,6 +261,8 @@ describe('v1p2beta1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1p2beta1.IUpdateFeedRequest = {}; request.feed = {}; @@ -257,6 +287,8 @@ describe('v1p2beta1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1p2beta1.IUpdateFeedRequest = {}; request.feed = {}; @@ -283,6 +315,8 @@ describe('v1p2beta1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1p2beta1.IDeleteFeedRequest = {}; request.name = ''; @@ -306,6 +340,8 @@ describe('v1p2beta1.AssetServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.asset.v1p2beta1.IDeleteFeedRequest = {}; request.name = '';