From fc5459502718a0fc4f9d71bc8d43bebbe5b7be06 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:10:15 +0000 Subject: [PATCH] fix: better support for fallback mode (#402) - [ ] 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 --- ...ection_service_v1_beta1.report_phishing.js | 3 + ...ogle.cloud.phishingprotection.v1beta1.json | 2 +- ...hing_protection_service_v1_beta1_client.ts | 3 +- ...ing_protection_service_v1_beta1_v1beta1.ts | 214 +++++++++--------- 4 files changed, 117 insertions(+), 105 deletions(-) diff --git a/packages/google-cloud-phishingprotection/samples/generated/v1beta1/phishing_protection_service_v1_beta1.report_phishing.js b/packages/google-cloud-phishingprotection/samples/generated/v1beta1/phishing_protection_service_v1_beta1.report_phishing.js index 6dd97666b29..85e4b74ff33 100644 --- a/packages/google-cloud-phishingprotection/samples/generated/v1beta1/phishing_protection_service_v1_beta1.report_phishing.js +++ b/packages/google-cloud-phishingprotection/samples/generated/v1beta1/phishing_protection_service_v1_beta1.report_phishing.js @@ -23,6 +23,9 @@ function main(parent, uri) { // [START phishingprotection_v1beta1_generated_PhishingProtectionServiceV1Beta1_ReportPhishing_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-phishingprotection/samples/generated/v1beta1/snippet_metadata.google.cloud.phishingprotection.v1beta1.json b/packages/google-cloud-phishingprotection/samples/generated/v1beta1/snippet_metadata.google.cloud.phishingprotection.v1beta1.json index cecb4793d1a..08a6166ed84 100644 --- a/packages/google-cloud-phishingprotection/samples/generated/v1beta1/snippet_metadata.google.cloud.phishingprotection.v1beta1.json +++ b/packages/google-cloud-phishingprotection/samples/generated/v1beta1/snippet_metadata.google.cloud.phishingprotection.v1beta1.json @@ -22,7 +22,7 @@ "segments": [ { "start": 25, - "end": 56, + "end": 59, "type": "FULL" } ], diff --git a/packages/google-cloud-phishingprotection/src/v1beta1/phishing_protection_service_v1_beta1_client.ts b/packages/google-cloud-phishingprotection/src/v1beta1/phishing_protection_service_v1_beta1_client.ts index 61f9c67a48d..3d9c6975cc7 100644 --- a/packages/google-cloud-phishingprotection/src/v1beta1/phishing_protection_service_v1_beta1_client.ts +++ b/packages/google-cloud-phishingprotection/src/v1beta1/phishing_protection_service_v1_beta1_client.ts @@ -230,7 +230,8 @@ export class PhishingProtectionServiceV1Beta1Client { const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], - descriptor + descriptor, + this._opts.fallback ); this.innerApiCalls[methodName] = apiCall; diff --git a/packages/google-cloud-phishingprotection/test/gapic_phishing_protection_service_v1_beta1_v1beta1.ts b/packages/google-cloud-phishingprotection/test/gapic_phishing_protection_service_v1_beta1_v1beta1.ts index 9346b081758..ccadd4a2bab 100644 --- a/packages/google-cloud-phishingprotection/test/gapic_phishing_protection_service_v1_beta1_v1beta1.ts +++ b/packages/google-cloud-phishingprotection/test/gapic_phishing_protection_service_v1_beta1_v1beta1.ts @@ -50,124 +50,132 @@ function stubSimpleCallWithCallback( } describe('v1beta1.PhishingProtectionServiceV1Beta1Client', () => { - it('has servicePath', () => { - const servicePath = - phishingprotectionservicev1beta1Module.v1beta1 - .PhishingProtectionServiceV1Beta1Client.servicePath; - assert(servicePath); - }); + describe('Common methods', () => { + it('has servicePath', () => { + const servicePath = + phishingprotectionservicev1beta1Module.v1beta1 + .PhishingProtectionServiceV1Beta1Client.servicePath; + assert(servicePath); + }); - it('has apiEndpoint', () => { - const apiEndpoint = - phishingprotectionservicev1beta1Module.v1beta1 - .PhishingProtectionServiceV1Beta1Client.apiEndpoint; - assert(apiEndpoint); - }); + it('has apiEndpoint', () => { + const apiEndpoint = + phishingprotectionservicev1beta1Module.v1beta1 + .PhishingProtectionServiceV1Beta1Client.apiEndpoint; + assert(apiEndpoint); + }); - it('has port', () => { - const port = - phishingprotectionservicev1beta1Module.v1beta1 - .PhishingProtectionServiceV1Beta1Client.port; - assert(port); - assert(typeof port === 'number'); - }); + it('has port', () => { + const port = + phishingprotectionservicev1beta1Module.v1beta1 + .PhishingProtectionServiceV1Beta1Client.port; + assert(port); + assert(typeof port === 'number'); + }); - it('should create a client with no option', () => { - const client = - new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client(); - assert(client); - }); + it('should create a client with no option', () => { + const client = + new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client(); + assert(client); + }); - it('should create a client with gRPC fallback', () => { - const client = - new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client( - { - fallback: true, - } - ); - assert(client); - }); + it('should create a client with gRPC fallback', () => { + const client = + new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client( + { + fallback: true, + } + ); + assert(client); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = - new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } + it('has initialize method and supports deferred initialization', async () => { + const client = + new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + assert.strictEqual( + client.phishingProtectionServiceV1Beta1Stub, + undefined ); - assert.strictEqual(client.phishingProtectionServiceV1Beta1Stub, undefined); - await client.initialize(); - assert(client.phishingProtectionServiceV1Beta1Stub); - }); + await client.initialize(); + assert(client.phishingProtectionServiceV1Beta1Stub); + }); - it('has close method for the initialized client', done => { - const client = - new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.initialize(); - assert(client.phishingProtectionServiceV1Beta1Stub); - client.close().then(() => { - done(); + it('has close method for the initialized client', done => { + const client = + new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + assert(client.phishingProtectionServiceV1Beta1Stub); + client.close().then(() => { + done(); + }); }); - }); - it('has close method for the non-initialized client', done => { - const client = - new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } + it('has close method for the non-initialized client', done => { + const client = + new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + assert.strictEqual( + client.phishingProtectionServiceV1Beta1Stub, + undefined ); - assert.strictEqual(client.phishingProtectionServiceV1Beta1Stub, undefined); - client.close().then(() => { - done(); + client.close().then(() => { + done(); + }); }); - }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = - new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); - const result = await client.getProjectId(); - assert.strictEqual(result, fakeProjectId); - assert((client.auth.getProjectId as SinonStub).calledWithExactly()); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = - new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.auth.getProjectId = sinon - .stub() - .callsArgWith(0, null, fakeProjectId); - const promise = new Promise((resolve, reject) => { - client.getProjectId((err?: Error | null, projectId?: string | null) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client( + { + 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('reportPhishing', () => {