Skip to content

Commit

Permalink
fix: better support for fallback mode (#105)
Browse files Browse the repository at this point in the history
- [ ] Regenerate this pull request now.

PiperOrigin-RevId: 468790263

Source-Link: googleapis/googleapis@873ab45

Source-Link: googleapis/googleapis-gen@cb6f37a
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiY2I2ZjM3YWVmZjJhMzQ3MmU0MGE3YmJhY2U4YzY3ZDc1ZTI0YmVlNSJ9
  • Loading branch information
gcf-owl-bot[bot] committed Aug 23, 2022
1 parent 2c55ebe commit eccee7d
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
function main(parent) {
// [START essentialcontacts_v1_generated_EssentialContactsService_ComputeContacts_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.
*/
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
function main(parent, contact) {
// [START essentialcontacts_v1_generated_EssentialContactsService_CreateContact_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.
*/
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
function main(name) {
// [START essentialcontacts_v1_generated_EssentialContactsService_DeleteContact_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.
*/
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
function main(name) {
// [START essentialcontacts_v1_generated_EssentialContactsService_GetContact_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.
*/
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
function main(parent) {
// [START essentialcontacts_v1_generated_EssentialContactsService_ListContacts_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.
*/
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
function main(contacts, resource, notificationCategory) {
// [START essentialcontacts_v1_generated_EssentialContactsService_SendTestMessage_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.
*/
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
function main(contact) {
// [START essentialcontacts_v1_generated_EssentialContactsService_UpdateContact_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.
*/
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"segments": [
{
"start": 25,
"end": 58,
"end": 61,
"type": "FULL"
}
],
Expand Down Expand Up @@ -66,7 +66,7 @@
"segments": [
{
"start": 25,
"end": 57,
"end": 60,
"type": "FULL"
}
],
Expand Down Expand Up @@ -110,7 +110,7 @@
"segments": [
{
"start": 25,
"end": 68,
"end": 71,
"type": "FULL"
}
],
Expand Down Expand Up @@ -158,7 +158,7 @@
"segments": [
{
"start": 25,
"end": 53,
"end": 56,
"type": "FULL"
}
],
Expand Down Expand Up @@ -198,7 +198,7 @@
"segments": [
{
"start": 25,
"end": 53,
"end": 56,
"type": "FULL"
}
],
Expand Down Expand Up @@ -238,7 +238,7 @@
"segments": [
{
"start": 25,
"end": 74,
"end": 77,
"type": "FULL"
}
],
Expand Down Expand Up @@ -290,7 +290,7 @@
"segments": [
{
"start": 25,
"end": 68,
"end": 71,
"type": "FULL"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
/**
Expand Down Expand Up @@ -272,7 +271,8 @@ export class EssentialContactsServiceClient {
const apiCall = this._gaxModule.createApiCall(
callPromise,
this._defaults[methodName],
descriptor
descriptor,
this._opts.fallback
);

this.innerApiCalls[methodName] = apiCall;
Expand Down Expand Up @@ -997,7 +997,7 @@ export class EssentialContactsServiceClient {
const callSettings = defaultCallSettings.merge(options);
this.initialize();
return this.descriptors.page.listContacts.createStream(
this.innerApiCalls.listContacts as gax.GaxCall,
this.innerApiCalls.listContacts as GaxCall,
request,
callSettings
);
Expand Down Expand Up @@ -1053,7 +1053,7 @@ export class EssentialContactsServiceClient {
this.initialize();
return this.descriptors.page.listContacts.asyncIterate(
this.innerApiCalls['listContacts'] as GaxCall,
request as unknown as RequestType,
request as {},
callSettings
) as AsyncIterable<protos.google.cloud.essentialcontacts.v1.IContact>;
}
Expand Down Expand Up @@ -1220,7 +1220,7 @@ export class EssentialContactsServiceClient {
const callSettings = defaultCallSettings.merge(options);
this.initialize();
return this.descriptors.page.computeContacts.createStream(
this.innerApiCalls.computeContacts as gax.GaxCall,
this.innerApiCalls.computeContacts as GaxCall,
request,
callSettings
);
Expand Down Expand Up @@ -1280,7 +1280,7 @@ export class EssentialContactsServiceClient {
this.initialize();
return this.descriptors.page.computeContacts.asyncIterate(
this.innerApiCalls['computeContacts'] as GaxCall,
request as unknown as RequestType,
request as {},
callSettings
) as AsyncIterable<protos.google.cloud.essentialcontacts.v1.IContact>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,111 +113,113 @@ function stubAsyncIterationCall<ResponseType>(
}

describe('v1.EssentialContactsServiceClient', () => {
it('has servicePath', () => {
const servicePath =
essentialcontactsserviceModule.v1.EssentialContactsServiceClient
.servicePath;
assert(servicePath);
});
describe('Common methods', () => {
it('has servicePath', () => {
const servicePath =
essentialcontactsserviceModule.v1.EssentialContactsServiceClient
.servicePath;
assert(servicePath);
});

it('has apiEndpoint', () => {
const apiEndpoint =
essentialcontactsserviceModule.v1.EssentialContactsServiceClient
.apiEndpoint;
assert(apiEndpoint);
});
it('has apiEndpoint', () => {
const apiEndpoint =
essentialcontactsserviceModule.v1.EssentialContactsServiceClient
.apiEndpoint;
assert(apiEndpoint);
});

it('has port', () => {
const port =
essentialcontactsserviceModule.v1.EssentialContactsServiceClient.port;
assert(port);
assert(typeof port === 'number');
});
it('has port', () => {
const port =
essentialcontactsserviceModule.v1.EssentialContactsServiceClient.port;
assert(port);
assert(typeof port === 'number');
});

it('should create a client with no option', () => {
const client =
new essentialcontactsserviceModule.v1.EssentialContactsServiceClient();
assert(client);
});
it('should create a client with no option', () => {
const client =
new essentialcontactsserviceModule.v1.EssentialContactsServiceClient();
assert(client);
});

it('should create a client with gRPC fallback', () => {
const client =
new essentialcontactsserviceModule.v1.EssentialContactsServiceClient({
fallback: true,
});
assert(client);
});
it('should create a client with gRPC fallback', () => {
const client =
new essentialcontactsserviceModule.v1.EssentialContactsServiceClient({
fallback: true,
});
assert(client);
});

it('has initialize method and supports deferred initialization', async () => {
const client =
new essentialcontactsserviceModule.v1.EssentialContactsServiceClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
assert.strictEqual(client.essentialContactsServiceStub, undefined);
await client.initialize();
assert(client.essentialContactsServiceStub);
});
it('has initialize method and supports deferred initialization', async () => {
const client =
new essentialcontactsserviceModule.v1.EssentialContactsServiceClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
assert.strictEqual(client.essentialContactsServiceStub, undefined);
await client.initialize();
assert(client.essentialContactsServiceStub);
});

it('has close method for the initialized client', done => {
const client =
new essentialcontactsserviceModule.v1.EssentialContactsServiceClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('has close method for the initialized client', done => {
const client =
new essentialcontactsserviceModule.v1.EssentialContactsServiceClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
client.initialize();
assert(client.essentialContactsServiceStub);
client.close().then(() => {
done();
});
client.initialize();
assert(client.essentialContactsServiceStub);
client.close().then(() => {
done();
});
});

it('has close method for the non-initialized client', done => {
const client =
new essentialcontactsserviceModule.v1.EssentialContactsServiceClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('has close method for the non-initialized client', done => {
const client =
new essentialcontactsserviceModule.v1.EssentialContactsServiceClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
assert.strictEqual(client.essentialContactsServiceStub, undefined);
client.close().then(() => {
done();
});
assert.strictEqual(client.essentialContactsServiceStub, undefined);
client.close().then(() => {
done();
});
});

it('has getProjectId method', async () => {
const fakeProjectId = 'fake-project-id';
const client =
new essentialcontactsserviceModule.v1.EssentialContactsServiceClient({
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 essentialcontactsserviceModule.v1.EssentialContactsServiceClient({
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 essentialcontactsserviceModule.v1.EssentialContactsServiceClient({
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 essentialcontactsserviceModule.v1.EssentialContactsServiceClient({
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('createContact', () => {
Expand Down

0 comments on commit eccee7d

Please sign in to comment.