From 608cdbdefdb6ef4ee3fdeba160eead1ca72356b8 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Wed, 14 Sep 2022 22:34:29 +0000 Subject: [PATCH] fix: preserve default values in x-goog-request-params header (#627) - [ ] Regenerate this pull request now. PiperOrigin-RevId: 474338479 Source-Link: https://github.com/googleapis/googleapis/commit/d5d35e0353b59719e8917103b1bc7df2782bf6ba Source-Link: https://github.com/googleapis/googleapis-gen/commit/efcd3f93962a103f68f003e2a1eecde6fa216a27 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZWZjZDNmOTM5NjJhMTAzZjY4ZjAwM2UyYTFlZWNkZTZmYTIxNmEyNyJ9 --- .../test/gapic_text_to_speech_v1.ts | 51 ++++++------------- .../test/gapic_text_to_speech_v1beta1.ts | 51 ++++++------------- 2 files changed, 30 insertions(+), 72 deletions(-) diff --git a/packages/google-cloud-texttospeech/test/gapic_text_to_speech_v1.ts b/packages/google-cloud-texttospeech/test/gapic_text_to_speech_v1.ts index 4e913f3f233..424a08cdd8c 100644 --- a/packages/google-cloud-texttospeech/test/gapic_text_to_speech_v1.ts +++ b/packages/google-cloud-texttospeech/test/gapic_text_to_speech_v1.ts @@ -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(instance: T) { const filledObject = ( instance.constructor as typeof protobuf.Message @@ -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 () => { @@ -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() ); @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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() ); @@ -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 () => { @@ -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 () => { diff --git a/packages/google-cloud-texttospeech/test/gapic_text_to_speech_v1beta1.ts b/packages/google-cloud-texttospeech/test/gapic_text_to_speech_v1beta1.ts index 8d4fab2d66b..e58c196dc7f 100644 --- a/packages/google-cloud-texttospeech/test/gapic_text_to_speech_v1beta1.ts +++ b/packages/google-cloud-texttospeech/test/gapic_text_to_speech_v1beta1.ts @@ -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(instance: T) { const filledObject = ( instance.constructor as typeof protobuf.Message @@ -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 () => { @@ -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() ); @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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() ); @@ -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 () => { @@ -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 () => {