Skip to content

Commit 53e0d3d

Browse files
fix: better support for fallback mode (#49)
- [ ] Regenerate this pull request now. PiperOrigin-RevId: 468790263 Source-Link: googleapis/googleapis@873ab45 Source-Link: googleapis/googleapis-gen@cb6f37a Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiY2I2ZjM3YWVmZjJhMzQ3MmU0MGE3YmJhY2U4YzY3ZDc1ZTI0YmVlNSJ9
1 parent bb3bd07 commit 53e0d3d

File tree

7 files changed

+101
-87
lines changed

7 files changed

+101
-87
lines changed

packages/google-cloud-ids/samples/generated/v1/i_d_s.create_endpoint.js

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
function main(parent, endpointId, endpoint) {
2424
// [START ids_v1_generated_IDS_CreateEndpoint_async]
2525
/**
26+
* This snippet has been automatically generated and should be regarded as a code template only.
27+
* It will require modifications to work.
28+
* It may require correct/in-range values for request initialization.
2629
* TODO(developer): Uncomment these variables before running the sample.
2730
*/
2831
/**

packages/google-cloud-ids/samples/generated/v1/i_d_s.delete_endpoint.js

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
function main(name) {
2424
// [START ids_v1_generated_IDS_DeleteEndpoint_async]
2525
/**
26+
* This snippet has been automatically generated and should be regarded as a code template only.
27+
* It will require modifications to work.
28+
* It may require correct/in-range values for request initialization.
2629
* TODO(developer): Uncomment these variables before running the sample.
2730
*/
2831
/**

packages/google-cloud-ids/samples/generated/v1/i_d_s.get_endpoint.js

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
function main(name) {
2424
// [START ids_v1_generated_IDS_GetEndpoint_async]
2525
/**
26+
* This snippet has been automatically generated and should be regarded as a code template only.
27+
* It will require modifications to work.
28+
* It may require correct/in-range values for request initialization.
2629
* TODO(developer): Uncomment these variables before running the sample.
2730
*/
2831
/**

packages/google-cloud-ids/samples/generated/v1/i_d_s.list_endpoints.js

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
function main(parent) {
2424
// [START ids_v1_generated_IDS_ListEndpoints_async]
2525
/**
26+
* This snippet has been automatically generated and should be regarded as a code template only.
27+
* It will require modifications to work.
28+
* It may require correct/in-range values for request initialization.
2629
* TODO(developer): Uncomment these variables before running the sample.
2730
*/
2831
/**

packages/google-cloud-ids/samples/generated/v1/snippet_metadata.google.cloud.ids.v1.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"segments": [
2323
{
2424
"start": 25,
25-
"end": 74,
25+
"end": 77,
2626
"type": "FULL"
2727
}
2828
],
@@ -78,7 +78,7 @@
7878
"segments": [
7979
{
8080
"start": 25,
81-
"end": 51,
81+
"end": 54,
8282
"type": "FULL"
8383
}
8484
],
@@ -118,7 +118,7 @@
118118
"segments": [
119119
{
120120
"start": 25,
121-
"end": 80,
121+
"end": 83,
122122
"type": "FULL"
123123
}
124124
],
@@ -170,7 +170,7 @@
170170
"segments": [
171171
{
172172
"start": 25,
173-
"end": 65,
173+
"end": 68,
174174
"type": "FULL"
175175
}
176176
],

packages/google-cloud-ids/src/v1/i_d_s_client.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {
3030
} from 'google-gax';
3131

3232
import {Transform} from 'stream';
33-
import {RequestType} from 'google-gax/build/src/apitypes';
3433
import * as protos from '../../protos/protos';
3534
import jsonProtos = require('../../protos/protos.json');
3635
/**
@@ -346,7 +345,8 @@ export class IDSClient {
346345
const apiCall = this._gaxModule.createApiCall(
347346
callPromise,
348347
this._defaults[methodName],
349-
descriptor
348+
descriptor,
349+
this._opts.fallback
350350
);
351351

352352
this.innerApiCalls[methodName] = apiCall;
@@ -646,7 +646,7 @@ export class IDSClient {
646646
const decodeOperation = new gax.Operation(
647647
operation,
648648
this.descriptors.longrunning.createEndpoint,
649-
gax.createDefaultBackoffSettings()
649+
this._gaxModule.createDefaultBackoffSettings()
650650
);
651651
return decodeOperation as LROperation<
652652
protos.google.cloud.ids.v1.Endpoint,
@@ -797,7 +797,7 @@ export class IDSClient {
797797
const decodeOperation = new gax.Operation(
798798
operation,
799799
this.descriptors.longrunning.deleteEndpoint,
800-
gax.createDefaultBackoffSettings()
800+
this._gaxModule.createDefaultBackoffSettings()
801801
);
802802
return decodeOperation as LROperation<
803803
protos.google.protobuf.Empty,
@@ -955,7 +955,7 @@ export class IDSClient {
955955
const callSettings = defaultCallSettings.merge(options);
956956
this.initialize();
957957
return this.descriptors.page.listEndpoints.createStream(
958-
this.innerApiCalls.listEndpoints as gax.GaxCall,
958+
this.innerApiCalls.listEndpoints as GaxCall,
959959
request,
960960
callSettings
961961
);
@@ -1014,7 +1014,7 @@ export class IDSClient {
10141014
this.initialize();
10151015
return this.descriptors.page.listEndpoints.asyncIterate(
10161016
this.innerApiCalls['listEndpoints'] as GaxCall,
1017-
request as unknown as RequestType,
1017+
request as {},
10181018
callSettings
10191019
) as AsyncIterable<protos.google.cloud.ids.v1.IEndpoint>;
10201020
}

packages/google-cloud-ids/test/gapic_i_d_s_v1.ts

+79-77
Original file line numberDiff line numberDiff line change
@@ -145,99 +145,101 @@ function stubAsyncIterationCall<ResponseType>(
145145
}
146146

147147
describe('v1.IDSClient', () => {
148-
it('has servicePath', () => {
149-
const servicePath = idsModule.v1.IDSClient.servicePath;
150-
assert(servicePath);
151-
});
152-
153-
it('has apiEndpoint', () => {
154-
const apiEndpoint = idsModule.v1.IDSClient.apiEndpoint;
155-
assert(apiEndpoint);
156-
});
157-
158-
it('has port', () => {
159-
const port = idsModule.v1.IDSClient.port;
160-
assert(port);
161-
assert(typeof port === 'number');
162-
});
163-
164-
it('should create a client with no option', () => {
165-
const client = new idsModule.v1.IDSClient();
166-
assert(client);
167-
});
148+
describe('Common methods', () => {
149+
it('has servicePath', () => {
150+
const servicePath = idsModule.v1.IDSClient.servicePath;
151+
assert(servicePath);
152+
});
168153

169-
it('should create a client with gRPC fallback', () => {
170-
const client = new idsModule.v1.IDSClient({
171-
fallback: true,
154+
it('has apiEndpoint', () => {
155+
const apiEndpoint = idsModule.v1.IDSClient.apiEndpoint;
156+
assert(apiEndpoint);
172157
});
173-
assert(client);
174-
});
175158

176-
it('has initialize method and supports deferred initialization', async () => {
177-
const client = new idsModule.v1.IDSClient({
178-
credentials: {client_email: 'bogus', private_key: 'bogus'},
179-
projectId: 'bogus',
159+
it('has port', () => {
160+
const port = idsModule.v1.IDSClient.port;
161+
assert(port);
162+
assert(typeof port === 'number');
180163
});
181-
assert.strictEqual(client.iDSStub, undefined);
182-
await client.initialize();
183-
assert(client.iDSStub);
184-
});
185164

186-
it('has close method for the initialized client', done => {
187-
const client = new idsModule.v1.IDSClient({
188-
credentials: {client_email: 'bogus', private_key: 'bogus'},
189-
projectId: 'bogus',
165+
it('should create a client with no option', () => {
166+
const client = new idsModule.v1.IDSClient();
167+
assert(client);
190168
});
191-
client.initialize();
192-
assert(client.iDSStub);
193-
client.close().then(() => {
194-
done();
169+
170+
it('should create a client with gRPC fallback', () => {
171+
const client = new idsModule.v1.IDSClient({
172+
fallback: true,
173+
});
174+
assert(client);
195175
});
196-
});
197176

198-
it('has close method for the non-initialized client', done => {
199-
const client = new idsModule.v1.IDSClient({
200-
credentials: {client_email: 'bogus', private_key: 'bogus'},
201-
projectId: 'bogus',
177+
it('has initialize method and supports deferred initialization', async () => {
178+
const client = new idsModule.v1.IDSClient({
179+
credentials: {client_email: 'bogus', private_key: 'bogus'},
180+
projectId: 'bogus',
181+
});
182+
assert.strictEqual(client.iDSStub, undefined);
183+
await client.initialize();
184+
assert(client.iDSStub);
202185
});
203-
assert.strictEqual(client.iDSStub, undefined);
204-
client.close().then(() => {
205-
done();
186+
187+
it('has close method for the initialized client', done => {
188+
const client = new idsModule.v1.IDSClient({
189+
credentials: {client_email: 'bogus', private_key: 'bogus'},
190+
projectId: 'bogus',
191+
});
192+
client.initialize();
193+
assert(client.iDSStub);
194+
client.close().then(() => {
195+
done();
196+
});
206197
});
207-
});
208198

209-
it('has getProjectId method', async () => {
210-
const fakeProjectId = 'fake-project-id';
211-
const client = new idsModule.v1.IDSClient({
212-
credentials: {client_email: 'bogus', private_key: 'bogus'},
213-
projectId: 'bogus',
199+
it('has close method for the non-initialized client', done => {
200+
const client = new idsModule.v1.IDSClient({
201+
credentials: {client_email: 'bogus', private_key: 'bogus'},
202+
projectId: 'bogus',
203+
});
204+
assert.strictEqual(client.iDSStub, undefined);
205+
client.close().then(() => {
206+
done();
207+
});
214208
});
215-
client.auth.getProjectId = sinon.stub().resolves(fakeProjectId);
216-
const result = await client.getProjectId();
217-
assert.strictEqual(result, fakeProjectId);
218-
assert((client.auth.getProjectId as SinonStub).calledWithExactly());
219-
});
220209

221-
it('has getProjectId method with callback', async () => {
222-
const fakeProjectId = 'fake-project-id';
223-
const client = new idsModule.v1.IDSClient({
224-
credentials: {client_email: 'bogus', private_key: 'bogus'},
225-
projectId: 'bogus',
210+
it('has getProjectId method', async () => {
211+
const fakeProjectId = 'fake-project-id';
212+
const client = new idsModule.v1.IDSClient({
213+
credentials: {client_email: 'bogus', private_key: 'bogus'},
214+
projectId: 'bogus',
215+
});
216+
client.auth.getProjectId = sinon.stub().resolves(fakeProjectId);
217+
const result = await client.getProjectId();
218+
assert.strictEqual(result, fakeProjectId);
219+
assert((client.auth.getProjectId as SinonStub).calledWithExactly());
226220
});
227-
client.auth.getProjectId = sinon
228-
.stub()
229-
.callsArgWith(0, null, fakeProjectId);
230-
const promise = new Promise((resolve, reject) => {
231-
client.getProjectId((err?: Error | null, projectId?: string | null) => {
232-
if (err) {
233-
reject(err);
234-
} else {
235-
resolve(projectId);
236-
}
221+
222+
it('has getProjectId method with callback', async () => {
223+
const fakeProjectId = 'fake-project-id';
224+
const client = new idsModule.v1.IDSClient({
225+
credentials: {client_email: 'bogus', private_key: 'bogus'},
226+
projectId: 'bogus',
227+
});
228+
client.auth.getProjectId = sinon
229+
.stub()
230+
.callsArgWith(0, null, fakeProjectId);
231+
const promise = new Promise((resolve, reject) => {
232+
client.getProjectId((err?: Error | null, projectId?: string | null) => {
233+
if (err) {
234+
reject(err);
235+
} else {
236+
resolve(projectId);
237+
}
238+
});
237239
});
240+
const result = await promise;
241+
assert.strictEqual(result, fakeProjectId);
238242
});
239-
const result = await promise;
240-
assert.strictEqual(result, fakeProjectId);
241243
});
242244

243245
describe('getEndpoint', () => {

0 commit comments

Comments
 (0)