diff --git a/packages/google-cloud-policytroubleshooter/samples/generated/v1/iam_checker.troubleshoot_iam_policy.js b/packages/google-cloud-policytroubleshooter/samples/generated/v1/iam_checker.troubleshoot_iam_policy.js index 82676c5b5c6..6206ea3e548 100644 --- a/packages/google-cloud-policytroubleshooter/samples/generated/v1/iam_checker.troubleshoot_iam_policy.js +++ b/packages/google-cloud-policytroubleshooter/samples/generated/v1/iam_checker.troubleshoot_iam_policy.js @@ -1,16 +1,21 @@ -// Copyright 2021 Google LLC +// Copyright 2022 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + 'use strict'; diff --git a/packages/google-cloud-policytroubleshooter/samples/generated/v1/snippet_metadata.google.cloud.policytroubleshooter.v1.json b/packages/google-cloud-policytroubleshooter/samples/generated/v1/snippet_metadata.google.cloud.policytroubleshooter.v1.json new file mode 100644 index 00000000000..4f4183725eb --- /dev/null +++ b/packages/google-cloud-policytroubleshooter/samples/generated/v1/snippet_metadata.google.cloud.policytroubleshooter.v1.json @@ -0,0 +1,55 @@ +{ + "clientLibrary": { + "name": "nodejs-policytroubleshooter", + "version": "0.1.0", + "language": "TYPESCRIPT", + "apis": [ + { + "id": "google.cloud.policytroubleshooter.v1", + "version": "v1" + } + ] + }, + "snippets": [ + { + "regionTag": "policytroubleshooter_v1_generated_IamChecker_TroubleshootIamPolicy_async", + "title": "IamChecker troubleshootIamPolicy Sample", + "origin": "API_DEFINITION", + "description": " Checks whether a member has a specific permission for a specific resource, and explains why the member does or does not have that permission.", + "canonical": true, + "file": "iam_checker.troubleshoot_iam_policy.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 50, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "TroubleshootIamPolicy", + "fullName": "google.cloud.policytroubleshooter.v1.IamChecker.TroubleshootIamPolicy", + "async": true, + "parameters": [ + { + "name": "access_tuple", + "type": ".google.cloud.policytroubleshooter.v1.AccessTuple" + } + ], + "resultType": ".google.cloud.policytroubleshooter.v1.TroubleshootIamPolicyResponse", + "client": { + "shortName": "IamCheckerClient", + "fullName": "google.cloud.policytroubleshooter.v1.IamCheckerClient" + }, + "method": { + "shortName": "TroubleshootIamPolicy", + "fullName": "google.cloud.policytroubleshooter.v1.IamChecker.TroubleshootIamPolicy", + "service": { + "shortName": "IamChecker", + "fullName": "google.cloud.policytroubleshooter.v1.IamChecker" + } + } + } + } + ] +} diff --git a/packages/google-cloud-policytroubleshooter/src/v1/iam_checker_client.ts b/packages/google-cloud-policytroubleshooter/src/v1/iam_checker_client.ts index 6df1fdd1996..6623db13b1d 100644 --- a/packages/google-cloud-policytroubleshooter/src/v1/iam_checker_client.ts +++ b/packages/google-cloud-policytroubleshooter/src/v1/iam_checker_client.ts @@ -386,9 +386,8 @@ export class IamCheckerClient { * @returns {Promise} A promise that resolves when the client is closed. */ close(): Promise { - this.initialize(); - if (!this._terminated) { - return this.iamCheckerStub!.then(stub => { + if (this.iamCheckerStub && !this._terminated) { + return this.iamCheckerStub.then(stub => { this._terminated = true; stub.close(); }); diff --git a/packages/google-cloud-policytroubleshooter/test/gapic_iam_checker_v1.ts b/packages/google-cloud-policytroubleshooter/test/gapic_iam_checker_v1.ts index fbd7f64d1eb..884da56d4fb 100644 --- a/packages/google-cloud-policytroubleshooter/test/gapic_iam_checker_v1.ts +++ b/packages/google-cloud-policytroubleshooter/test/gapic_iam_checker_v1.ts @@ -88,12 +88,27 @@ describe('v1.IamCheckerClient', () => { assert(client.iamCheckerStub); }); - it('has close method', () => { + it('has close method for the initialized client', done => { const client = new iamcheckerModule.v1.IamCheckerClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); - client.close(); + client.initialize(); + assert(client.iamCheckerStub); + client.close().then(() => { + done(); + }); + }); + + it('has close method for the non-initialized client', done => { + const client = new iamcheckerModule.v1.IamCheckerClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.iamCheckerStub, undefined); + client.close().then(() => { + done(); + }); }); it('has getProjectId method', async () => { @@ -219,5 +234,22 @@ describe('v1.IamCheckerClient', () => { .calledWith(request, expectedOptions, undefined) ); }); + + it('invokes troubleshootIamPolicy with closed client', async () => { + const client = new iamcheckerModule.v1.IamCheckerClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.policytroubleshooter.v1.TroubleshootIamPolicyRequest() + ); + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects( + client.troubleshootIamPolicy(request), + expectedError + ); + }); }); });