Skip to content

Commit f168eb3

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

8 files changed

+105
-88
lines changed

packages/google-monitoring-dashboard/samples/generated/v1/dashboards_service.create_dashboard.js

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
function main(parent, dashboard) {
2424
// [START monitoring_v1_generated_DashboardsService_CreateDashboard_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-monitoring-dashboard/samples/generated/v1/dashboards_service.delete_dashboard.js

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
function main(name) {
2424
// [START monitoring_v1_generated_DashboardsService_DeleteDashboard_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-monitoring-dashboard/samples/generated/v1/dashboards_service.get_dashboard.js

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
function main(name) {
2424
// [START monitoring_v1_generated_DashboardsService_GetDashboard_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-monitoring-dashboard/samples/generated/v1/dashboards_service.list_dashboards.js

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
function main(parent) {
2424
// [START monitoring_v1_generated_DashboardsService_ListDashboards_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-monitoring-dashboard/samples/generated/v1/dashboards_service.update_dashboard.js

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
function main(dashboard) {
2424
// [START monitoring_v1_generated_DashboardsService_UpdateDashboard_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-monitoring-dashboard/samples/generated/v1/snippet_metadata.google.monitoring.dashboard.v1.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"segments": [
2323
{
2424
"start": 25,
25-
"end": 62,
25+
"end": 65,
2626
"type": "FULL"
2727
}
2828
],
@@ -70,7 +70,7 @@
7070
"segments": [
7171
{
7272
"start": 25,
73-
"end": 64,
73+
"end": 67,
7474
"type": "FULL"
7575
}
7676
],
@@ -118,7 +118,7 @@
118118
"segments": [
119119
{
120120
"start": 25,
121-
"end": 53,
121+
"end": 56,
122122
"type": "FULL"
123123
}
124124
],
@@ -158,7 +158,7 @@
158158
"segments": [
159159
{
160160
"start": 25,
161-
"end": 51,
161+
"end": 54,
162162
"type": "FULL"
163163
}
164164
],
@@ -198,7 +198,7 @@
198198
"segments": [
199199
{
200200
"start": 25,
201-
"end": 55,
201+
"end": 58,
202202
"type": "FULL"
203203
}
204204
],

packages/google-monitoring-dashboard/src/v1/dashboards_service_client.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
} from 'google-gax';
2929

3030
import {Transform} from 'stream';
31-
import {RequestType} from 'google-gax/build/src/apitypes';
3231
import * as protos from '../../protos/protos';
3332
import jsonProtos = require('../../protos/protos.json');
3433
/**
@@ -262,7 +261,8 @@ export class DashboardsServiceClient {
262261
const apiCall = this._gaxModule.createApiCall(
263262
callPromise,
264263
this._defaults[methodName],
265-
descriptor
264+
descriptor,
265+
this._opts.fallback
266266
);
267267

268268
this.innerApiCalls[methodName] = apiCall;
@@ -876,7 +876,7 @@ export class DashboardsServiceClient {
876876
const callSettings = defaultCallSettings.merge(options);
877877
this.initialize();
878878
return this.descriptors.page.listDashboards.createStream(
879-
this.innerApiCalls.listDashboards as gax.GaxCall,
879+
this.innerApiCalls.listDashboards as GaxCall,
880880
request,
881881
callSettings
882882
);
@@ -929,7 +929,7 @@ export class DashboardsServiceClient {
929929
this.initialize();
930930
return this.descriptors.page.listDashboards.asyncIterate(
931931
this.innerApiCalls['listDashboards'] as GaxCall,
932-
request as unknown as RequestType,
932+
request as {},
933933
callSettings
934934
) as AsyncIterable<protos.google.monitoring.dashboard.v1.IDashboard>;
935935
}

packages/google-monitoring-dashboard/test/gapic_dashboards_service_v1.ts

+81-79
Original file line numberDiff line numberDiff line change
@@ -113,101 +113,103 @@ function stubAsyncIterationCall<ResponseType>(
113113
}
114114

115115
describe('v1.DashboardsServiceClient', () => {
116-
it('has servicePath', () => {
117-
const servicePath =
118-
dashboardsserviceModule.v1.DashboardsServiceClient.servicePath;
119-
assert(servicePath);
120-
});
121-
122-
it('has apiEndpoint', () => {
123-
const apiEndpoint =
124-
dashboardsserviceModule.v1.DashboardsServiceClient.apiEndpoint;
125-
assert(apiEndpoint);
126-
});
127-
128-
it('has port', () => {
129-
const port = dashboardsserviceModule.v1.DashboardsServiceClient.port;
130-
assert(port);
131-
assert(typeof port === 'number');
132-
});
133-
134-
it('should create a client with no option', () => {
135-
const client = new dashboardsserviceModule.v1.DashboardsServiceClient();
136-
assert(client);
137-
});
116+
describe('Common methods', () => {
117+
it('has servicePath', () => {
118+
const servicePath =
119+
dashboardsserviceModule.v1.DashboardsServiceClient.servicePath;
120+
assert(servicePath);
121+
});
138122

139-
it('should create a client with gRPC fallback', () => {
140-
const client = new dashboardsserviceModule.v1.DashboardsServiceClient({
141-
fallback: true,
123+
it('has apiEndpoint', () => {
124+
const apiEndpoint =
125+
dashboardsserviceModule.v1.DashboardsServiceClient.apiEndpoint;
126+
assert(apiEndpoint);
142127
});
143-
assert(client);
144-
});
145128

146-
it('has initialize method and supports deferred initialization', async () => {
147-
const client = new dashboardsserviceModule.v1.DashboardsServiceClient({
148-
credentials: {client_email: 'bogus', private_key: 'bogus'},
149-
projectId: 'bogus',
129+
it('has port', () => {
130+
const port = dashboardsserviceModule.v1.DashboardsServiceClient.port;
131+
assert(port);
132+
assert(typeof port === 'number');
150133
});
151-
assert.strictEqual(client.dashboardsServiceStub, undefined);
152-
await client.initialize();
153-
assert(client.dashboardsServiceStub);
154-
});
155134

156-
it('has close method for the initialized client', done => {
157-
const client = new dashboardsserviceModule.v1.DashboardsServiceClient({
158-
credentials: {client_email: 'bogus', private_key: 'bogus'},
159-
projectId: 'bogus',
135+
it('should create a client with no option', () => {
136+
const client = new dashboardsserviceModule.v1.DashboardsServiceClient();
137+
assert(client);
160138
});
161-
client.initialize();
162-
assert(client.dashboardsServiceStub);
163-
client.close().then(() => {
164-
done();
139+
140+
it('should create a client with gRPC fallback', () => {
141+
const client = new dashboardsserviceModule.v1.DashboardsServiceClient({
142+
fallback: true,
143+
});
144+
assert(client);
165145
});
166-
});
167146

168-
it('has close method for the non-initialized client', done => {
169-
const client = new dashboardsserviceModule.v1.DashboardsServiceClient({
170-
credentials: {client_email: 'bogus', private_key: 'bogus'},
171-
projectId: 'bogus',
147+
it('has initialize method and supports deferred initialization', async () => {
148+
const client = new dashboardsserviceModule.v1.DashboardsServiceClient({
149+
credentials: {client_email: 'bogus', private_key: 'bogus'},
150+
projectId: 'bogus',
151+
});
152+
assert.strictEqual(client.dashboardsServiceStub, undefined);
153+
await client.initialize();
154+
assert(client.dashboardsServiceStub);
172155
});
173-
assert.strictEqual(client.dashboardsServiceStub, undefined);
174-
client.close().then(() => {
175-
done();
156+
157+
it('has close method for the initialized client', done => {
158+
const client = new dashboardsserviceModule.v1.DashboardsServiceClient({
159+
credentials: {client_email: 'bogus', private_key: 'bogus'},
160+
projectId: 'bogus',
161+
});
162+
client.initialize();
163+
assert(client.dashboardsServiceStub);
164+
client.close().then(() => {
165+
done();
166+
});
176167
});
177-
});
178168

179-
it('has getProjectId method', async () => {
180-
const fakeProjectId = 'fake-project-id';
181-
const client = new dashboardsserviceModule.v1.DashboardsServiceClient({
182-
credentials: {client_email: 'bogus', private_key: 'bogus'},
183-
projectId: 'bogus',
169+
it('has close method for the non-initialized client', done => {
170+
const client = new dashboardsserviceModule.v1.DashboardsServiceClient({
171+
credentials: {client_email: 'bogus', private_key: 'bogus'},
172+
projectId: 'bogus',
173+
});
174+
assert.strictEqual(client.dashboardsServiceStub, undefined);
175+
client.close().then(() => {
176+
done();
177+
});
184178
});
185-
client.auth.getProjectId = sinon.stub().resolves(fakeProjectId);
186-
const result = await client.getProjectId();
187-
assert.strictEqual(result, fakeProjectId);
188-
assert((client.auth.getProjectId as SinonStub).calledWithExactly());
189-
});
190179

191-
it('has getProjectId method with callback', async () => {
192-
const fakeProjectId = 'fake-project-id';
193-
const client = new dashboardsserviceModule.v1.DashboardsServiceClient({
194-
credentials: {client_email: 'bogus', private_key: 'bogus'},
195-
projectId: 'bogus',
180+
it('has getProjectId method', async () => {
181+
const fakeProjectId = 'fake-project-id';
182+
const client = new dashboardsserviceModule.v1.DashboardsServiceClient({
183+
credentials: {client_email: 'bogus', private_key: 'bogus'},
184+
projectId: 'bogus',
185+
});
186+
client.auth.getProjectId = sinon.stub().resolves(fakeProjectId);
187+
const result = await client.getProjectId();
188+
assert.strictEqual(result, fakeProjectId);
189+
assert((client.auth.getProjectId as SinonStub).calledWithExactly());
196190
});
197-
client.auth.getProjectId = sinon
198-
.stub()
199-
.callsArgWith(0, null, fakeProjectId);
200-
const promise = new Promise((resolve, reject) => {
201-
client.getProjectId((err?: Error | null, projectId?: string | null) => {
202-
if (err) {
203-
reject(err);
204-
} else {
205-
resolve(projectId);
206-
}
191+
192+
it('has getProjectId method with callback', async () => {
193+
const fakeProjectId = 'fake-project-id';
194+
const client = new dashboardsserviceModule.v1.DashboardsServiceClient({
195+
credentials: {client_email: 'bogus', private_key: 'bogus'},
196+
projectId: 'bogus',
197+
});
198+
client.auth.getProjectId = sinon
199+
.stub()
200+
.callsArgWith(0, null, fakeProjectId);
201+
const promise = new Promise((resolve, reject) => {
202+
client.getProjectId((err?: Error | null, projectId?: string | null) => {
203+
if (err) {
204+
reject(err);
205+
} else {
206+
resolve(projectId);
207+
}
208+
});
207209
});
210+
const result = await promise;
211+
assert.strictEqual(result, fakeProjectId);
208212
});
209-
const result = await promise;
210-
assert.strictEqual(result, fakeProjectId);
211213
});
212214

213215
describe('createDashboard', () => {

0 commit comments

Comments
 (0)