Skip to content

Commit 978effa

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

File tree

4 files changed

+113
-107
lines changed

4 files changed

+113
-107
lines changed

packages/google-cloud-mediatranslation/samples/generated/v1beta1/snippet_metadata.google.cloud.mediatranslation.v1beta1.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"segments": [
2323
{
2424
"start": 25,
25-
"end": 66,
25+
"end": 69,
2626
"type": "FULL"
2727
}
2828
],

packages/google-cloud-mediatranslation/samples/generated/v1beta1/speech_translation_service.streaming_translate_speech.js

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
function main() {
2424
// [START mediatranslation_v1beta1_generated_SpeechTranslationService_StreamingTranslateSpeech_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-mediatranslation/src/v1beta1/speech_translation_service_client.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ export class SpeechTranslationServiceClient {
246246
const apiCall = this._gaxModule.createApiCall(
247247
callPromise,
248248
this._defaults[methodName],
249-
descriptor
249+
descriptor,
250+
this._opts.fallback
250251
);
251252

252253
this.innerApiCalls[methodName] = apiCall;

packages/google-cloud-mediatranslation/test/gapic_speech_translation_service_v1beta1.ts

+107-105
Original file line numberDiff line numberDiff line change
@@ -51,124 +51,126 @@ function stubBidiStreamingCall<ResponseType>(
5151
}
5252

5353
describe('v1beta1.SpeechTranslationServiceClient', () => {
54-
it('has servicePath', () => {
55-
const servicePath =
56-
speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient
57-
.servicePath;
58-
assert(servicePath);
59-
});
54+
describe('Common methods', () => {
55+
it('has servicePath', () => {
56+
const servicePath =
57+
speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient
58+
.servicePath;
59+
assert(servicePath);
60+
});
6061

61-
it('has apiEndpoint', () => {
62-
const apiEndpoint =
63-
speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient
64-
.apiEndpoint;
65-
assert(apiEndpoint);
66-
});
62+
it('has apiEndpoint', () => {
63+
const apiEndpoint =
64+
speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient
65+
.apiEndpoint;
66+
assert(apiEndpoint);
67+
});
6768

68-
it('has port', () => {
69-
const port =
70-
speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient
71-
.port;
72-
assert(port);
73-
assert(typeof port === 'number');
74-
});
69+
it('has port', () => {
70+
const port =
71+
speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient
72+
.port;
73+
assert(port);
74+
assert(typeof port === 'number');
75+
});
7576

76-
it('should create a client with no option', () => {
77-
const client =
78-
new speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient();
79-
assert(client);
80-
});
77+
it('should create a client with no option', () => {
78+
const client =
79+
new speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient();
80+
assert(client);
81+
});
8182

82-
it('should create a client with gRPC fallback', () => {
83-
const client =
84-
new speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient(
85-
{
86-
fallback: true,
87-
}
88-
);
89-
assert(client);
90-
});
83+
it('should create a client with gRPC fallback', () => {
84+
const client =
85+
new speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient(
86+
{
87+
fallback: true,
88+
}
89+
);
90+
assert(client);
91+
});
9192

92-
it('has initialize method and supports deferred initialization', async () => {
93-
const client =
94-
new speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient(
95-
{
96-
credentials: {client_email: 'bogus', private_key: 'bogus'},
97-
projectId: 'bogus',
98-
}
99-
);
100-
assert.strictEqual(client.speechTranslationServiceStub, undefined);
101-
await client.initialize();
102-
assert(client.speechTranslationServiceStub);
103-
});
93+
it('has initialize method and supports deferred initialization', async () => {
94+
const client =
95+
new speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient(
96+
{
97+
credentials: {client_email: 'bogus', private_key: 'bogus'},
98+
projectId: 'bogus',
99+
}
100+
);
101+
assert.strictEqual(client.speechTranslationServiceStub, undefined);
102+
await client.initialize();
103+
assert(client.speechTranslationServiceStub);
104+
});
104105

105-
it('has close method for the initialized client', done => {
106-
const client =
107-
new speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient(
108-
{
109-
credentials: {client_email: 'bogus', private_key: 'bogus'},
110-
projectId: 'bogus',
111-
}
112-
);
113-
client.initialize();
114-
assert(client.speechTranslationServiceStub);
115-
client.close().then(() => {
116-
done();
106+
it('has close method for the initialized client', done => {
107+
const client =
108+
new speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient(
109+
{
110+
credentials: {client_email: 'bogus', private_key: 'bogus'},
111+
projectId: 'bogus',
112+
}
113+
);
114+
client.initialize();
115+
assert(client.speechTranslationServiceStub);
116+
client.close().then(() => {
117+
done();
118+
});
117119
});
118-
});
119120

120-
it('has close method for the non-initialized client', done => {
121-
const client =
122-
new speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient(
123-
{
124-
credentials: {client_email: 'bogus', private_key: 'bogus'},
125-
projectId: 'bogus',
126-
}
127-
);
128-
assert.strictEqual(client.speechTranslationServiceStub, undefined);
129-
client.close().then(() => {
130-
done();
121+
it('has close method for the non-initialized client', done => {
122+
const client =
123+
new speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient(
124+
{
125+
credentials: {client_email: 'bogus', private_key: 'bogus'},
126+
projectId: 'bogus',
127+
}
128+
);
129+
assert.strictEqual(client.speechTranslationServiceStub, undefined);
130+
client.close().then(() => {
131+
done();
132+
});
131133
});
132-
});
133134

134-
it('has getProjectId method', async () => {
135-
const fakeProjectId = 'fake-project-id';
136-
const client =
137-
new speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient(
138-
{
139-
credentials: {client_email: 'bogus', private_key: 'bogus'},
140-
projectId: 'bogus',
141-
}
142-
);
143-
client.auth.getProjectId = sinon.stub().resolves(fakeProjectId);
144-
const result = await client.getProjectId();
145-
assert.strictEqual(result, fakeProjectId);
146-
assert((client.auth.getProjectId as SinonStub).calledWithExactly());
147-
});
135+
it('has getProjectId method', async () => {
136+
const fakeProjectId = 'fake-project-id';
137+
const client =
138+
new speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient(
139+
{
140+
credentials: {client_email: 'bogus', private_key: 'bogus'},
141+
projectId: 'bogus',
142+
}
143+
);
144+
client.auth.getProjectId = sinon.stub().resolves(fakeProjectId);
145+
const result = await client.getProjectId();
146+
assert.strictEqual(result, fakeProjectId);
147+
assert((client.auth.getProjectId as SinonStub).calledWithExactly());
148+
});
148149

149-
it('has getProjectId method with callback', async () => {
150-
const fakeProjectId = 'fake-project-id';
151-
const client =
152-
new speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient(
153-
{
154-
credentials: {client_email: 'bogus', private_key: 'bogus'},
155-
projectId: 'bogus',
156-
}
157-
);
158-
client.auth.getProjectId = sinon
159-
.stub()
160-
.callsArgWith(0, null, fakeProjectId);
161-
const promise = new Promise((resolve, reject) => {
162-
client.getProjectId((err?: Error | null, projectId?: string | null) => {
163-
if (err) {
164-
reject(err);
165-
} else {
166-
resolve(projectId);
167-
}
150+
it('has getProjectId method with callback', async () => {
151+
const fakeProjectId = 'fake-project-id';
152+
const client =
153+
new speechtranslationserviceModule.v1beta1.SpeechTranslationServiceClient(
154+
{
155+
credentials: {client_email: 'bogus', private_key: 'bogus'},
156+
projectId: 'bogus',
157+
}
158+
);
159+
client.auth.getProjectId = sinon
160+
.stub()
161+
.callsArgWith(0, null, fakeProjectId);
162+
const promise = new Promise((resolve, reject) => {
163+
client.getProjectId((err?: Error | null, projectId?: string | null) => {
164+
if (err) {
165+
reject(err);
166+
} else {
167+
resolve(projectId);
168+
}
169+
});
168170
});
171+
const result = await promise;
172+
assert.strictEqual(result, fakeProjectId);
169173
});
170-
const result = await promise;
171-
assert.strictEqual(result, fakeProjectId);
172174
});
173175

174176
describe('streamingTranslateSpeech', () => {

0 commit comments

Comments
 (0)