From f3815860f750520b97e5d6c1e02f8e315d4452a0 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 23 Aug 2022 00:12:11 +0000 Subject: [PATCH] fix: better support for fallback mode (#135) - [ ] Regenerate this pull request now. PiperOrigin-RevId: 468790263 Source-Link: https://github.com/googleapis/googleapis/commit/873ab456273d105245df0fb82a6c17a814553b80 Source-Link: https://github.com/googleapis/googleapis-gen/commit/cb6f37aeff2a3472e40a7bbace8c67d75e24bee5 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiY2I2ZjM3YWVmZjJhMzQ3MmU0MGE3YmJhY2U4YzY3ZDc1ZTI0YmVlNSJ9 --- ...ccess_approval.approve_approval_request.js | 3 + ...pproval.delete_access_approval_settings.js | 3 + ...ccess_approval.dismiss_approval_request.js | 3 + ...val.get_access_approval_service_account.js | 3 + ...s_approval.get_access_approval_settings.js | 3 + .../access_approval.get_approval_request.js | 3 + ...ss_approval.invalidate_approval_request.js | 3 + .../access_approval.list_approval_requests.js | 3 + ...pproval.update_access_approval_settings.js | 3 + ...tadata.google.cloud.accessapproval.v1.json | 18 +- .../src/v1/access_approval_client.ts | 8 +- .../test/gapic_access_approval_v1.ts | 160 +++++++++--------- 12 files changed, 121 insertions(+), 92 deletions(-) diff --git a/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.approve_approval_request.js b/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.approve_approval_request.js index ae557eadda8..e5f856d73c9 100644 --- a/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.approve_approval_request.js +++ b/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.approve_approval_request.js @@ -23,6 +23,9 @@ function main() { // [START accessapproval_v1_generated_AccessApproval_ApproveApprovalRequest_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/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.delete_access_approval_settings.js b/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.delete_access_approval_settings.js index fafa039301d..2d7ea73ed64 100644 --- a/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.delete_access_approval_settings.js +++ b/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.delete_access_approval_settings.js @@ -23,6 +23,9 @@ function main() { // [START accessapproval_v1_generated_AccessApproval_DeleteAccessApprovalSettings_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/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.dismiss_approval_request.js b/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.dismiss_approval_request.js index e3f361adc02..9f5fb671b82 100644 --- a/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.dismiss_approval_request.js +++ b/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.dismiss_approval_request.js @@ -23,6 +23,9 @@ function main() { // [START accessapproval_v1_generated_AccessApproval_DismissApprovalRequest_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/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.get_access_approval_service_account.js b/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.get_access_approval_service_account.js index 086f7560af2..e1d5497b64c 100644 --- a/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.get_access_approval_service_account.js +++ b/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.get_access_approval_service_account.js @@ -23,6 +23,9 @@ function main() { // [START accessapproval_v1_generated_AccessApproval_GetAccessApprovalServiceAccount_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/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.get_access_approval_settings.js b/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.get_access_approval_settings.js index fbe0cf4b7c4..bf569fc29f5 100644 --- a/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.get_access_approval_settings.js +++ b/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.get_access_approval_settings.js @@ -23,6 +23,9 @@ function main() { // [START accessapproval_v1_generated_AccessApproval_GetAccessApprovalSettings_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/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.get_approval_request.js b/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.get_approval_request.js index 76cbe89bd59..8be1b3eebe7 100644 --- a/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.get_approval_request.js +++ b/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.get_approval_request.js @@ -23,6 +23,9 @@ function main() { // [START accessapproval_v1_generated_AccessApproval_GetApprovalRequest_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/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.invalidate_approval_request.js b/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.invalidate_approval_request.js index c08b38e5ad2..e4cb948fe04 100644 --- a/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.invalidate_approval_request.js +++ b/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.invalidate_approval_request.js @@ -23,6 +23,9 @@ function main() { // [START accessapproval_v1_generated_AccessApproval_InvalidateApprovalRequest_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/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.list_approval_requests.js b/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.list_approval_requests.js index ccac649af6f..efb48a2b4b1 100644 --- a/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.list_approval_requests.js +++ b/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.list_approval_requests.js @@ -23,6 +23,9 @@ function main() { // [START accessapproval_v1_generated_AccessApproval_ListApprovalRequests_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/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.update_access_approval_settings.js b/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.update_access_approval_settings.js index 14142045829..3f87fd9cee1 100644 --- a/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.update_access_approval_settings.js +++ b/packages/google-cloud-accessapproval/samples/generated/v1/access_approval.update_access_approval_settings.js @@ -23,6 +23,9 @@ function main() { // [START accessapproval_v1_generated_AccessApproval_UpdateAccessApprovalSettings_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/packages/google-cloud-accessapproval/samples/generated/v1/snippet_metadata.google.cloud.accessapproval.v1.json b/packages/google-cloud-accessapproval/samples/generated/v1/snippet_metadata.google.cloud.accessapproval.v1.json index df58d7faa18..08954f6dbdd 100644 --- a/packages/google-cloud-accessapproval/samples/generated/v1/snippet_metadata.google.cloud.accessapproval.v1.json +++ b/packages/google-cloud-accessapproval/samples/generated/v1/snippet_metadata.google.cloud.accessapproval.v1.json @@ -22,7 +22,7 @@ "segments": [ { "start": 25, - "end": 74, + "end": 77, "type": "FULL" } ], @@ -74,7 +74,7 @@ "segments": [ { "start": 25, - "end": 51, + "end": 54, "type": "FULL" } ], @@ -114,7 +114,7 @@ "segments": [ { "start": 25, - "end": 53, + "end": 56, "type": "FULL" } ], @@ -158,7 +158,7 @@ "segments": [ { "start": 25, - "end": 49, + "end": 52, "type": "FULL" } ], @@ -198,7 +198,7 @@ "segments": [ { "start": 25, - "end": 49, + "end": 52, "type": "FULL" } ], @@ -238,7 +238,7 @@ "segments": [ { "start": 25, - "end": 50, + "end": 53, "type": "FULL" } ], @@ -278,7 +278,7 @@ "segments": [ { "start": 25, - "end": 61, + "end": 64, "type": "FULL" } ], @@ -322,7 +322,7 @@ "segments": [ { "start": 25, - "end": 49, + "end": 52, "type": "FULL" } ], @@ -362,7 +362,7 @@ "segments": [ { "start": 25, - "end": 49, + "end": 52, "type": "FULL" } ], diff --git a/packages/google-cloud-accessapproval/src/v1/access_approval_client.ts b/packages/google-cloud-accessapproval/src/v1/access_approval_client.ts index 365a18c88fd..922896bb204 100644 --- a/packages/google-cloud-accessapproval/src/v1/access_approval_client.ts +++ b/packages/google-cloud-accessapproval/src/v1/access_approval_client.ts @@ -28,7 +28,6 @@ import { } from 'google-gax'; import {Transform} from 'stream'; -import {RequestType} from 'google-gax/build/src/apitypes'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); /** @@ -320,7 +319,8 @@ export class AccessApprovalClient { const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], - descriptor + descriptor, + this._opts.fallback ); this.innerApiCalls[methodName] = apiCall; @@ -1396,7 +1396,7 @@ export class AccessApprovalClient { const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.listApprovalRequests.createStream( - this.innerApiCalls.listApprovalRequests as gax.GaxCall, + this.innerApiCalls.listApprovalRequests as GaxCall, request, callSettings ); @@ -1458,7 +1458,7 @@ export class AccessApprovalClient { this.initialize(); return this.descriptors.page.listApprovalRequests.asyncIterate( this.innerApiCalls['listApprovalRequests'] as GaxCall, - request as unknown as RequestType, + request as {}, callSettings ) as AsyncIterable; } diff --git a/packages/google-cloud-accessapproval/test/gapic_access_approval_v1.ts b/packages/google-cloud-accessapproval/test/gapic_access_approval_v1.ts index 6de073a7147..fa6678f190c 100644 --- a/packages/google-cloud-accessapproval/test/gapic_access_approval_v1.ts +++ b/packages/google-cloud-accessapproval/test/gapic_access_approval_v1.ts @@ -113,101 +113,103 @@ function stubAsyncIterationCall( } describe('v1.AccessApprovalClient', () => { - it('has servicePath', () => { - const servicePath = - accessapprovalModule.v1.AccessApprovalClient.servicePath; - assert(servicePath); - }); - - it('has apiEndpoint', () => { - const apiEndpoint = - accessapprovalModule.v1.AccessApprovalClient.apiEndpoint; - assert(apiEndpoint); - }); - - it('has port', () => { - const port = accessapprovalModule.v1.AccessApprovalClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new accessapprovalModule.v1.AccessApprovalClient(); - assert(client); - }); + describe('Common methods', () => { + it('has servicePath', () => { + const servicePath = + accessapprovalModule.v1.AccessApprovalClient.servicePath; + assert(servicePath); + }); - it('should create a client with gRPC fallback', () => { - const client = new accessapprovalModule.v1.AccessApprovalClient({ - fallback: true, + it('has apiEndpoint', () => { + const apiEndpoint = + accessapprovalModule.v1.AccessApprovalClient.apiEndpoint; + assert(apiEndpoint); }); - assert(client); - }); - it('has initialize method and supports deferred initialization', async () => { - const client = new accessapprovalModule.v1.AccessApprovalClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('has port', () => { + const port = accessapprovalModule.v1.AccessApprovalClient.port; + assert(port); + assert(typeof port === 'number'); }); - assert.strictEqual(client.accessApprovalStub, undefined); - await client.initialize(); - assert(client.accessApprovalStub); - }); - it('has close method for the initialized client', done => { - const client = new accessapprovalModule.v1.AccessApprovalClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('should create a client with no option', () => { + const client = new accessapprovalModule.v1.AccessApprovalClient(); + assert(client); }); - client.initialize(); - assert(client.accessApprovalStub); - client.close().then(() => { - done(); + + it('should create a client with gRPC fallback', () => { + const client = new accessapprovalModule.v1.AccessApprovalClient({ + fallback: true, + }); + assert(client); }); - }); - it('has close method for the non-initialized client', done => { - const client = new accessapprovalModule.v1.AccessApprovalClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('has initialize method and supports deferred initialization', async () => { + const client = new accessapprovalModule.v1.AccessApprovalClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.accessApprovalStub, undefined); + await client.initialize(); + assert(client.accessApprovalStub); }); - assert.strictEqual(client.accessApprovalStub, undefined); - client.close().then(() => { - done(); + + it('has close method for the initialized client', done => { + const client = new accessapprovalModule.v1.AccessApprovalClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + assert(client.accessApprovalStub); + client.close().then(() => { + done(); + }); }); - }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new accessapprovalModule.v1.AccessApprovalClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('has close method for the non-initialized client', done => { + const client = new accessapprovalModule.v1.AccessApprovalClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.accessApprovalStub, undefined); + client.close().then(() => { + done(); + }); }); - 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 accessapprovalModule.v1.AccessApprovalClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new accessapprovalModule.v1.AccessApprovalClient({ + 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()); }); - 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 accessapprovalModule.v1.AccessApprovalClient({ + 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('getApprovalRequest', () => {