From 8c57c42db41131496817fd986e71483620d91d28 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:08:31 +0000 Subject: [PATCH] fix: better support for fallback mode (#95) - [ ] 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 --- ...et_metadata.google.cloud.vpcaccess.v1.json | 8 +- .../v1/vpc_access_service.create_connector.js | 3 + .../v1/vpc_access_service.delete_connector.js | 3 + .../v1/vpc_access_service.get_connector.js | 3 + .../v1/vpc_access_service.list_connectors.js | 3 + .../src/v1/vpc_access_service_client.ts | 12 +- .../test/gapic_vpc_access_service_v1.ts | 160 +++++++++--------- 7 files changed, 103 insertions(+), 89 deletions(-) diff --git a/packages/google-cloud-vpc-access/samples/generated/v1/snippet_metadata.google.cloud.vpcaccess.v1.json b/packages/google-cloud-vpc-access/samples/generated/v1/snippet_metadata.google.cloud.vpcaccess.v1.json index bf77658776a..cdb161d48b1 100644 --- a/packages/google-cloud-vpc-access/samples/generated/v1/snippet_metadata.google.cloud.vpcaccess.v1.json +++ b/packages/google-cloud-vpc-access/samples/generated/v1/snippet_metadata.google.cloud.vpcaccess.v1.json @@ -22,7 +22,7 @@ "segments": [ { "start": 25, - "end": 62, + "end": 65, "type": "FULL" } ], @@ -70,7 +70,7 @@ "segments": [ { "start": 25, - "end": 50, + "end": 53, "type": "FULL" } ], @@ -110,7 +110,7 @@ "segments": [ { "start": 25, - "end": 60, + "end": 63, "type": "FULL" } ], @@ -158,7 +158,7 @@ "segments": [ { "start": 25, - "end": 51, + "end": 54, "type": "FULL" } ], diff --git a/packages/google-cloud-vpc-access/samples/generated/v1/vpc_access_service.create_connector.js b/packages/google-cloud-vpc-access/samples/generated/v1/vpc_access_service.create_connector.js index afbec8cbb02..79bb068f2b9 100644 --- a/packages/google-cloud-vpc-access/samples/generated/v1/vpc_access_service.create_connector.js +++ b/packages/google-cloud-vpc-access/samples/generated/v1/vpc_access_service.create_connector.js @@ -23,6 +23,9 @@ function main(parent, connectorId, connector) { // [START vpcaccess_v1_generated_VpcAccessService_CreateConnector_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-vpc-access/samples/generated/v1/vpc_access_service.delete_connector.js b/packages/google-cloud-vpc-access/samples/generated/v1/vpc_access_service.delete_connector.js index 22c5838ff26..8a4efc5b1c6 100644 --- a/packages/google-cloud-vpc-access/samples/generated/v1/vpc_access_service.delete_connector.js +++ b/packages/google-cloud-vpc-access/samples/generated/v1/vpc_access_service.delete_connector.js @@ -23,6 +23,9 @@ function main(name) { // [START vpcaccess_v1_generated_VpcAccessService_DeleteConnector_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-vpc-access/samples/generated/v1/vpc_access_service.get_connector.js b/packages/google-cloud-vpc-access/samples/generated/v1/vpc_access_service.get_connector.js index 2de96e4dca3..c917e7c64d2 100644 --- a/packages/google-cloud-vpc-access/samples/generated/v1/vpc_access_service.get_connector.js +++ b/packages/google-cloud-vpc-access/samples/generated/v1/vpc_access_service.get_connector.js @@ -23,6 +23,9 @@ function main(name) { // [START vpcaccess_v1_generated_VpcAccessService_GetConnector_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-vpc-access/samples/generated/v1/vpc_access_service.list_connectors.js b/packages/google-cloud-vpc-access/samples/generated/v1/vpc_access_service.list_connectors.js index f03cfb55716..cbcab146b43 100644 --- a/packages/google-cloud-vpc-access/samples/generated/v1/vpc_access_service.list_connectors.js +++ b/packages/google-cloud-vpc-access/samples/generated/v1/vpc_access_service.list_connectors.js @@ -23,6 +23,9 @@ function main(parent) { // [START vpcaccess_v1_generated_VpcAccessService_ListConnectors_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-vpc-access/src/v1/vpc_access_service_client.ts b/packages/google-cloud-vpc-access/src/v1/vpc_access_service_client.ts index 045e9ccf81c..0a49de2234b 100644 --- a/packages/google-cloud-vpc-access/src/v1/vpc_access_service_client.ts +++ b/packages/google-cloud-vpc-access/src/v1/vpc_access_service_client.ts @@ -30,7 +30,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'); /** @@ -318,7 +317,8 @@ export class VpcAccessServiceClient { const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], - descriptor + descriptor, + this._opts.fallback ); this.innerApiCalls[methodName] = apiCall; @@ -602,7 +602,7 @@ export class VpcAccessServiceClient { const decodeOperation = new gax.Operation( operation, this.descriptors.longrunning.createConnector, - gax.createDefaultBackoffSettings() + this._gaxModule.createDefaultBackoffSettings() ); return decodeOperation as LROperation< protos.google.cloud.vpcaccess.v1.Connector, @@ -740,7 +740,7 @@ export class VpcAccessServiceClient { const decodeOperation = new gax.Operation( operation, this.descriptors.longrunning.deleteConnector, - gax.createDefaultBackoffSettings() + this._gaxModule.createDefaultBackoffSettings() ); return decodeOperation as LROperation< protos.google.protobuf.Empty, @@ -884,7 +884,7 @@ export class VpcAccessServiceClient { const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.listConnectors.createStream( - this.innerApiCalls.listConnectors as gax.GaxCall, + this.innerApiCalls.listConnectors as GaxCall, request, callSettings ); @@ -932,7 +932,7 @@ export class VpcAccessServiceClient { this.initialize(); return this.descriptors.page.listConnectors.asyncIterate( this.innerApiCalls['listConnectors'] as GaxCall, - request as unknown as RequestType, + request as {}, callSettings ) as AsyncIterable; } diff --git a/packages/google-cloud-vpc-access/test/gapic_vpc_access_service_v1.ts b/packages/google-cloud-vpc-access/test/gapic_vpc_access_service_v1.ts index 301b227dced..adf4d8affec 100644 --- a/packages/google-cloud-vpc-access/test/gapic_vpc_access_service_v1.ts +++ b/packages/google-cloud-vpc-access/test/gapic_vpc_access_service_v1.ts @@ -145,101 +145,103 @@ function stubAsyncIterationCall( } describe('v1.VpcAccessServiceClient', () => { - it('has servicePath', () => { - const servicePath = - vpcaccessserviceModule.v1.VpcAccessServiceClient.servicePath; - assert(servicePath); - }); - - it('has apiEndpoint', () => { - const apiEndpoint = - vpcaccessserviceModule.v1.VpcAccessServiceClient.apiEndpoint; - assert(apiEndpoint); - }); - - it('has port', () => { - const port = vpcaccessserviceModule.v1.VpcAccessServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new vpcaccessserviceModule.v1.VpcAccessServiceClient(); - assert(client); - }); + describe('Common methods', () => { + it('has servicePath', () => { + const servicePath = + vpcaccessserviceModule.v1.VpcAccessServiceClient.servicePath; + assert(servicePath); + }); - it('should create a client with gRPC fallback', () => { - const client = new vpcaccessserviceModule.v1.VpcAccessServiceClient({ - fallback: true, + it('has apiEndpoint', () => { + const apiEndpoint = + vpcaccessserviceModule.v1.VpcAccessServiceClient.apiEndpoint; + assert(apiEndpoint); }); - assert(client); - }); - it('has initialize method and supports deferred initialization', async () => { - const client = new vpcaccessserviceModule.v1.VpcAccessServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('has port', () => { + const port = vpcaccessserviceModule.v1.VpcAccessServiceClient.port; + assert(port); + assert(typeof port === 'number'); }); - assert.strictEqual(client.vpcAccessServiceStub, undefined); - await client.initialize(); - assert(client.vpcAccessServiceStub); - }); - it('has close method for the initialized client', done => { - const client = new vpcaccessserviceModule.v1.VpcAccessServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('should create a client with no option', () => { + const client = new vpcaccessserviceModule.v1.VpcAccessServiceClient(); + assert(client); }); - client.initialize(); - assert(client.vpcAccessServiceStub); - client.close().then(() => { - done(); + + it('should create a client with gRPC fallback', () => { + const client = new vpcaccessserviceModule.v1.VpcAccessServiceClient({ + fallback: true, + }); + assert(client); }); - }); - it('has close method for the non-initialized client', done => { - const client = new vpcaccessserviceModule.v1.VpcAccessServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('has initialize method and supports deferred initialization', async () => { + const client = new vpcaccessserviceModule.v1.VpcAccessServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.vpcAccessServiceStub, undefined); + await client.initialize(); + assert(client.vpcAccessServiceStub); }); - assert.strictEqual(client.vpcAccessServiceStub, undefined); - client.close().then(() => { - done(); + + it('has close method for the initialized client', done => { + const client = new vpcaccessserviceModule.v1.VpcAccessServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + assert(client.vpcAccessServiceStub); + client.close().then(() => { + done(); + }); }); - }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new vpcaccessserviceModule.v1.VpcAccessServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('has close method for the non-initialized client', done => { + const client = new vpcaccessserviceModule.v1.VpcAccessServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.vpcAccessServiceStub, 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 vpcaccessserviceModule.v1.VpcAccessServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new vpcaccessserviceModule.v1.VpcAccessServiceClient({ + 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 vpcaccessserviceModule.v1.VpcAccessServiceClient({ + 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('getConnector', () => {