Skip to content

Commit 5fc0df4

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

10 files changed

+180
-162
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"segments": [
2323
{
2424
"start": 25,
25-
"end": 56,
25+
"end": 59,
2626
"type": "FULL"
2727
}
2828
],
@@ -62,7 +62,7 @@
6262
"segments": [
6363
{
6464
"start": 25,
65-
"end": 60,
65+
"end": 63,
6666
"type": "FULL"
6767
}
6868
],

packages/google-cloud-texttospeech/samples/generated/v1/text_to_speech.list_voices.js

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
function main() {
2424
// [START texttospeech_v1_generated_TextToSpeech_ListVoices_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-texttospeech/samples/generated/v1/text_to_speech.synthesize_speech.js

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
function main(input, voice, audioConfig) {
2424
// [START texttospeech_v1_generated_TextToSpeech_SynthesizeSpeech_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-texttospeech/samples/generated/v1beta1/snippet_metadata.google.cloud.texttospeech.v1beta1.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"segments": [
2323
{
2424
"start": 25,
25-
"end": 56,
25+
"end": 59,
2626
"type": "FULL"
2727
}
2828
],
@@ -62,7 +62,7 @@
6262
"segments": [
6363
{
6464
"start": 25,
65-
"end": 64,
65+
"end": 67,
6666
"type": "FULL"
6767
}
6868
],

packages/google-cloud-texttospeech/samples/generated/v1beta1/text_to_speech.list_voices.js

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
function main() {
2424
// [START texttospeech_v1beta1_generated_TextToSpeech_ListVoices_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-texttospeech/samples/generated/v1beta1/text_to_speech.synthesize_speech.js

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
function main(input, voice, audioConfig) {
2424
// [START texttospeech_v1beta1_generated_TextToSpeech_SynthesizeSpeech_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-texttospeech/src/v1/text_to_speech_client.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ export class TextToSpeechClient {
228228
const apiCall = this._gaxModule.createApiCall(
229229
callPromise,
230230
this._defaults[methodName],
231-
descriptor
231+
descriptor,
232+
this._opts.fallback
232233
);
233234

234235
this.innerApiCalls[methodName] = apiCall;

packages/google-cloud-texttospeech/src/v1beta1/text_to_speech_client.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ export class TextToSpeechClient {
228228
const apiCall = this._gaxModule.createApiCall(
229229
callPromise,
230230
this._defaults[methodName],
231-
descriptor
231+
descriptor,
232+
this._opts.fallback
232233
);
233234

234235
this.innerApiCalls[methodName] = apiCall;

packages/google-cloud-texttospeech/test/gapic_text_to_speech_v1.ts

+79-77
Original file line numberDiff line numberDiff line change
@@ -50,99 +50,101 @@ function stubSimpleCallWithCallback<ResponseType>(
5050
}
5151

5252
describe('v1.TextToSpeechClient', () => {
53-
it('has servicePath', () => {
54-
const servicePath = texttospeechModule.v1.TextToSpeechClient.servicePath;
55-
assert(servicePath);
56-
});
57-
58-
it('has apiEndpoint', () => {
59-
const apiEndpoint = texttospeechModule.v1.TextToSpeechClient.apiEndpoint;
60-
assert(apiEndpoint);
61-
});
62-
63-
it('has port', () => {
64-
const port = texttospeechModule.v1.TextToSpeechClient.port;
65-
assert(port);
66-
assert(typeof port === 'number');
67-
});
68-
69-
it('should create a client with no option', () => {
70-
const client = new texttospeechModule.v1.TextToSpeechClient();
71-
assert(client);
72-
});
53+
describe('Common methods', () => {
54+
it('has servicePath', () => {
55+
const servicePath = texttospeechModule.v1.TextToSpeechClient.servicePath;
56+
assert(servicePath);
57+
});
7358

74-
it('should create a client with gRPC fallback', () => {
75-
const client = new texttospeechModule.v1.TextToSpeechClient({
76-
fallback: true,
59+
it('has apiEndpoint', () => {
60+
const apiEndpoint = texttospeechModule.v1.TextToSpeechClient.apiEndpoint;
61+
assert(apiEndpoint);
7762
});
78-
assert(client);
79-
});
8063

81-
it('has initialize method and supports deferred initialization', async () => {
82-
const client = new texttospeechModule.v1.TextToSpeechClient({
83-
credentials: {client_email: 'bogus', private_key: 'bogus'},
84-
projectId: 'bogus',
64+
it('has port', () => {
65+
const port = texttospeechModule.v1.TextToSpeechClient.port;
66+
assert(port);
67+
assert(typeof port === 'number');
8568
});
86-
assert.strictEqual(client.textToSpeechStub, undefined);
87-
await client.initialize();
88-
assert(client.textToSpeechStub);
89-
});
9069

91-
it('has close method for the initialized client', done => {
92-
const client = new texttospeechModule.v1.TextToSpeechClient({
93-
credentials: {client_email: 'bogus', private_key: 'bogus'},
94-
projectId: 'bogus',
70+
it('should create a client with no option', () => {
71+
const client = new texttospeechModule.v1.TextToSpeechClient();
72+
assert(client);
9573
});
96-
client.initialize();
97-
assert(client.textToSpeechStub);
98-
client.close().then(() => {
99-
done();
74+
75+
it('should create a client with gRPC fallback', () => {
76+
const client = new texttospeechModule.v1.TextToSpeechClient({
77+
fallback: true,
78+
});
79+
assert(client);
10080
});
101-
});
10281

103-
it('has close method for the non-initialized client', done => {
104-
const client = new texttospeechModule.v1.TextToSpeechClient({
105-
credentials: {client_email: 'bogus', private_key: 'bogus'},
106-
projectId: 'bogus',
82+
it('has initialize method and supports deferred initialization', async () => {
83+
const client = new texttospeechModule.v1.TextToSpeechClient({
84+
credentials: {client_email: 'bogus', private_key: 'bogus'},
85+
projectId: 'bogus',
86+
});
87+
assert.strictEqual(client.textToSpeechStub, undefined);
88+
await client.initialize();
89+
assert(client.textToSpeechStub);
10790
});
108-
assert.strictEqual(client.textToSpeechStub, undefined);
109-
client.close().then(() => {
110-
done();
91+
92+
it('has close method for the initialized client', done => {
93+
const client = new texttospeechModule.v1.TextToSpeechClient({
94+
credentials: {client_email: 'bogus', private_key: 'bogus'},
95+
projectId: 'bogus',
96+
});
97+
client.initialize();
98+
assert(client.textToSpeechStub);
99+
client.close().then(() => {
100+
done();
101+
});
111102
});
112-
});
113103

114-
it('has getProjectId method', async () => {
115-
const fakeProjectId = 'fake-project-id';
116-
const client = new texttospeechModule.v1.TextToSpeechClient({
117-
credentials: {client_email: 'bogus', private_key: 'bogus'},
118-
projectId: 'bogus',
104+
it('has close method for the non-initialized client', done => {
105+
const client = new texttospeechModule.v1.TextToSpeechClient({
106+
credentials: {client_email: 'bogus', private_key: 'bogus'},
107+
projectId: 'bogus',
108+
});
109+
assert.strictEqual(client.textToSpeechStub, undefined);
110+
client.close().then(() => {
111+
done();
112+
});
119113
});
120-
client.auth.getProjectId = sinon.stub().resolves(fakeProjectId);
121-
const result = await client.getProjectId();
122-
assert.strictEqual(result, fakeProjectId);
123-
assert((client.auth.getProjectId as SinonStub).calledWithExactly());
124-
});
125114

126-
it('has getProjectId method with callback', async () => {
127-
const fakeProjectId = 'fake-project-id';
128-
const client = new texttospeechModule.v1.TextToSpeechClient({
129-
credentials: {client_email: 'bogus', private_key: 'bogus'},
130-
projectId: 'bogus',
115+
it('has getProjectId method', async () => {
116+
const fakeProjectId = 'fake-project-id';
117+
const client = new texttospeechModule.v1.TextToSpeechClient({
118+
credentials: {client_email: 'bogus', private_key: 'bogus'},
119+
projectId: 'bogus',
120+
});
121+
client.auth.getProjectId = sinon.stub().resolves(fakeProjectId);
122+
const result = await client.getProjectId();
123+
assert.strictEqual(result, fakeProjectId);
124+
assert((client.auth.getProjectId as SinonStub).calledWithExactly());
131125
});
132-
client.auth.getProjectId = sinon
133-
.stub()
134-
.callsArgWith(0, null, fakeProjectId);
135-
const promise = new Promise((resolve, reject) => {
136-
client.getProjectId((err?: Error | null, projectId?: string | null) => {
137-
if (err) {
138-
reject(err);
139-
} else {
140-
resolve(projectId);
141-
}
126+
127+
it('has getProjectId method with callback', async () => {
128+
const fakeProjectId = 'fake-project-id';
129+
const client = new texttospeechModule.v1.TextToSpeechClient({
130+
credentials: {client_email: 'bogus', private_key: 'bogus'},
131+
projectId: 'bogus',
132+
});
133+
client.auth.getProjectId = sinon
134+
.stub()
135+
.callsArgWith(0, null, fakeProjectId);
136+
const promise = new Promise((resolve, reject) => {
137+
client.getProjectId((err?: Error | null, projectId?: string | null) => {
138+
if (err) {
139+
reject(err);
140+
} else {
141+
resolve(projectId);
142+
}
143+
});
142144
});
145+
const result = await promise;
146+
assert.strictEqual(result, fakeProjectId);
143147
});
144-
const result = await promise;
145-
assert.strictEqual(result, fakeProjectId);
146148
});
147149

148150
describe('listVoices', () => {

0 commit comments

Comments
 (0)