Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
fix: preserve default values in x-goog-request-params header (#627)
Browse files Browse the repository at this point in the history
- [ ] Regenerate this pull request now.

PiperOrigin-RevId: 474338479

Source-Link: googleapis/googleapis@d5d35e0

Source-Link: googleapis/googleapis-gen@efcd3f9
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZWZjZDNmOTM5NjJhMTAzZjY4ZjAwM2UyYTFlZWNkZTZmYTIxNmEyNyJ9
  • Loading branch information
gcf-owl-bot[bot] committed Sep 14, 2022
1 parent df7fc10 commit 26a4f84
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 72 deletions.
51 changes: 15 additions & 36 deletions test/gapic_text_to_speech_v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ import * as texttospeechModule from '../src';

import {protobuf} from 'google-gax';

// Dynamically loaded proto JSON is needed to get the type information
// to fill in default values for request objects
const root = protobuf.Root.fromJSON(
require('../protos/protos.json')
).resolveAll();

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function getTypeDefaultValue(typeName: string, fields: string[]) {
let type = root.lookupType(typeName) as protobuf.Type;
for (const field of fields.slice(0, -1)) {
type = type.fields[field]?.resolvedType as protobuf.Type;
}
return type.fields[fields[fields.length - 1]]?.defaultValue;
}

function generateSampleMessage<T extends object>(instance: T) {
const filledObject = (
instance.constructor as typeof protobuf.Message
Expand Down Expand Up @@ -157,18 +172,12 @@ describe('v1.TextToSpeechClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.texttospeech.v1.ListVoicesRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.texttospeech.v1.ListVoicesResponse()
);
client.innerApiCalls.listVoices = stubSimpleCall(expectedResponse);
const [response] = await client.listVoices(request);
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.listVoices as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions, undefined)
);
});

it('invokes listVoices without error using callback', async () => {
Expand All @@ -180,7 +189,6 @@ describe('v1.TextToSpeechClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.texttospeech.v1.ListVoicesRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.texttospeech.v1.ListVoicesResponse()
);
Expand All @@ -203,11 +211,6 @@ describe('v1.TextToSpeechClient', () => {
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.listVoices as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions /*, callback defined above */)
);
});

it('invokes listVoices with error', async () => {
Expand All @@ -219,18 +222,12 @@ describe('v1.TextToSpeechClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.texttospeech.v1.ListVoicesRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedError = new Error('expected');
client.innerApiCalls.listVoices = stubSimpleCall(
undefined,
expectedError
);
await assert.rejects(client.listVoices(request), expectedError);
assert(
(client.innerApiCalls.listVoices as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions, undefined)
);
});

it('invokes listVoices with closed client', async () => {
Expand Down Expand Up @@ -258,18 +255,12 @@ describe('v1.TextToSpeechClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.texttospeech.v1.SynthesizeSpeechRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.texttospeech.v1.SynthesizeSpeechResponse()
);
client.innerApiCalls.synthesizeSpeech = stubSimpleCall(expectedResponse);
const [response] = await client.synthesizeSpeech(request);
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.synthesizeSpeech as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions, undefined)
);
});

it('invokes synthesizeSpeech without error using callback', async () => {
Expand All @@ -281,7 +272,6 @@ describe('v1.TextToSpeechClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.texttospeech.v1.SynthesizeSpeechRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.texttospeech.v1.SynthesizeSpeechResponse()
);
Expand All @@ -304,11 +294,6 @@ describe('v1.TextToSpeechClient', () => {
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.synthesizeSpeech as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions /*, callback defined above */)
);
});

it('invokes synthesizeSpeech with error', async () => {
Expand All @@ -320,18 +305,12 @@ describe('v1.TextToSpeechClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.texttospeech.v1.SynthesizeSpeechRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedError = new Error('expected');
client.innerApiCalls.synthesizeSpeech = stubSimpleCall(
undefined,
expectedError
);
await assert.rejects(client.synthesizeSpeech(request), expectedError);
assert(
(client.innerApiCalls.synthesizeSpeech as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions, undefined)
);
});

it('invokes synthesizeSpeech with closed client', async () => {
Expand Down
51 changes: 15 additions & 36 deletions test/gapic_text_to_speech_v1beta1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ import * as texttospeechModule from '../src';

import {protobuf} from 'google-gax';

// Dynamically loaded proto JSON is needed to get the type information
// to fill in default values for request objects
const root = protobuf.Root.fromJSON(
require('../protos/protos.json')
).resolveAll();

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function getTypeDefaultValue(typeName: string, fields: string[]) {
let type = root.lookupType(typeName) as protobuf.Type;
for (const field of fields.slice(0, -1)) {
type = type.fields[field]?.resolvedType as protobuf.Type;
}
return type.fields[fields[fields.length - 1]]?.defaultValue;
}

function generateSampleMessage<T extends object>(instance: T) {
const filledObject = (
instance.constructor as typeof protobuf.Message
Expand Down Expand Up @@ -159,18 +174,12 @@ describe('v1beta1.TextToSpeechClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.texttospeech.v1beta1.ListVoicesRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.texttospeech.v1beta1.ListVoicesResponse()
);
client.innerApiCalls.listVoices = stubSimpleCall(expectedResponse);
const [response] = await client.listVoices(request);
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.listVoices as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions, undefined)
);
});

it('invokes listVoices without error using callback', async () => {
Expand All @@ -182,7 +191,6 @@ describe('v1beta1.TextToSpeechClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.texttospeech.v1beta1.ListVoicesRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.texttospeech.v1beta1.ListVoicesResponse()
);
Expand All @@ -205,11 +213,6 @@ describe('v1beta1.TextToSpeechClient', () => {
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.listVoices as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions /*, callback defined above */)
);
});

it('invokes listVoices with error', async () => {
Expand All @@ -221,18 +224,12 @@ describe('v1beta1.TextToSpeechClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.texttospeech.v1beta1.ListVoicesRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedError = new Error('expected');
client.innerApiCalls.listVoices = stubSimpleCall(
undefined,
expectedError
);
await assert.rejects(client.listVoices(request), expectedError);
assert(
(client.innerApiCalls.listVoices as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions, undefined)
);
});

it('invokes listVoices with closed client', async () => {
Expand Down Expand Up @@ -260,18 +257,12 @@ describe('v1beta1.TextToSpeechClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.texttospeech.v1beta1.SynthesizeSpeechRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.texttospeech.v1beta1.SynthesizeSpeechResponse()
);
client.innerApiCalls.synthesizeSpeech = stubSimpleCall(expectedResponse);
const [response] = await client.synthesizeSpeech(request);
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.synthesizeSpeech as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions, undefined)
);
});

it('invokes synthesizeSpeech without error using callback', async () => {
Expand All @@ -283,7 +274,6 @@ describe('v1beta1.TextToSpeechClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.texttospeech.v1beta1.SynthesizeSpeechRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.texttospeech.v1beta1.SynthesizeSpeechResponse()
);
Expand All @@ -306,11 +296,6 @@ describe('v1beta1.TextToSpeechClient', () => {
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.synthesizeSpeech as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions /*, callback defined above */)
);
});

it('invokes synthesizeSpeech with error', async () => {
Expand All @@ -322,18 +307,12 @@ describe('v1beta1.TextToSpeechClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.texttospeech.v1beta1.SynthesizeSpeechRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedError = new Error('expected');
client.innerApiCalls.synthesizeSpeech = stubSimpleCall(
undefined,
expectedError
);
await assert.rejects(client.synthesizeSpeech(request), expectedError);
assert(
(client.innerApiCalls.synthesizeSpeech as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions, undefined)
);
});

it('invokes synthesizeSpeech with closed client', async () => {
Expand Down

0 comments on commit 26a4f84

Please sign in to comment.