Skip to content

Commit

Permalink
fix: preserve default values in x-goog-request-params header (#691)
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] authored and sofisl committed Oct 13, 2022
1 parent 8567b4a commit e62b990
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 216 deletions.
123 changes: 15 additions & 108 deletions packages/google-cloud-language/test/gapic_language_service_v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ import * as languageserviceModule 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('v1.LanguageServiceClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.language.v1.AnalyzeSentimentRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.language.v1.AnalyzeSentimentResponse()
);
client.innerApiCalls.analyzeSentiment = stubSimpleCall(expectedResponse);
const [response] = await client.analyzeSentiment(request);
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.analyzeSentiment as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions, undefined)
);
});

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

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

it('invokes analyzeSentiment with closed client', async () => {
Expand Down Expand Up @@ -260,18 +257,12 @@ describe('v1.LanguageServiceClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.language.v1.AnalyzeEntitiesRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.language.v1.AnalyzeEntitiesResponse()
);
client.innerApiCalls.analyzeEntities = stubSimpleCall(expectedResponse);
const [response] = await client.analyzeEntities(request);
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.analyzeEntities as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions, undefined)
);
});

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

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

it('invokes analyzeEntities with closed client', async () => {
Expand Down Expand Up @@ -361,19 +340,13 @@ describe('v1.LanguageServiceClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.language.v1.AnalyzeEntitySentimentRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.language.v1.AnalyzeEntitySentimentResponse()
);
client.innerApiCalls.analyzeEntitySentiment =
stubSimpleCall(expectedResponse);
const [response] = await client.analyzeEntitySentiment(request);
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.analyzeEntitySentiment as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions, undefined)
);
});

it('invokes analyzeEntitySentiment without error using callback', async () => {
Expand All @@ -385,7 +358,6 @@ describe('v1.LanguageServiceClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.language.v1.AnalyzeEntitySentimentRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.language.v1.AnalyzeEntitySentimentResponse()
);
Expand All @@ -408,11 +380,6 @@ describe('v1.LanguageServiceClient', () => {
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.analyzeEntitySentiment as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions /*, callback defined above */)
);
});

it('invokes analyzeEntitySentiment with error', async () => {
Expand All @@ -424,7 +391,6 @@ describe('v1.LanguageServiceClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.language.v1.AnalyzeEntitySentimentRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedError = new Error('expected');
client.innerApiCalls.analyzeEntitySentiment = stubSimpleCall(
undefined,
Expand All @@ -434,11 +400,6 @@ describe('v1.LanguageServiceClient', () => {
client.analyzeEntitySentiment(request),
expectedError
);
assert(
(client.innerApiCalls.analyzeEntitySentiment as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions, undefined)
);
});

it('invokes analyzeEntitySentiment with closed client', async () => {
Expand Down Expand Up @@ -469,18 +430,12 @@ describe('v1.LanguageServiceClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.language.v1.AnalyzeSyntaxRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.language.v1.AnalyzeSyntaxResponse()
);
client.innerApiCalls.analyzeSyntax = stubSimpleCall(expectedResponse);
const [response] = await client.analyzeSyntax(request);
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.analyzeSyntax as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions, undefined)
);
});

it('invokes analyzeSyntax without error using callback', async () => {
Expand All @@ -492,7 +447,6 @@ describe('v1.LanguageServiceClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.language.v1.AnalyzeSyntaxRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.language.v1.AnalyzeSyntaxResponse()
);
Expand All @@ -515,11 +469,6 @@ describe('v1.LanguageServiceClient', () => {
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.analyzeSyntax as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions /*, callback defined above */)
);
});

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

it('invokes analyzeSyntax with closed client', async () => {
Expand Down Expand Up @@ -570,18 +513,12 @@ describe('v1.LanguageServiceClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.language.v1.ClassifyTextRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.language.v1.ClassifyTextResponse()
);
client.innerApiCalls.classifyText = stubSimpleCall(expectedResponse);
const [response] = await client.classifyText(request);
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.classifyText as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions, undefined)
);
});

it('invokes classifyText without error using callback', async () => {
Expand All @@ -593,7 +530,6 @@ describe('v1.LanguageServiceClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.language.v1.ClassifyTextRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.language.v1.ClassifyTextResponse()
);
Expand All @@ -616,11 +552,6 @@ describe('v1.LanguageServiceClient', () => {
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.classifyText as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions /*, callback defined above */)
);
});

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

it('invokes classifyText with closed client', async () => {
Expand Down Expand Up @@ -671,18 +596,12 @@ describe('v1.LanguageServiceClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.language.v1.AnnotateTextRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.language.v1.AnnotateTextResponse()
);
client.innerApiCalls.annotateText = stubSimpleCall(expectedResponse);
const [response] = await client.annotateText(request);
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.annotateText as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions, undefined)
);
});

it('invokes annotateText without error using callback', async () => {
Expand All @@ -694,7 +613,6 @@ describe('v1.LanguageServiceClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.language.v1.AnnotateTextRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.language.v1.AnnotateTextResponse()
);
Expand All @@ -717,11 +635,6 @@ describe('v1.LanguageServiceClient', () => {
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.annotateText as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions /*, callback defined above */)
);
});

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

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

0 comments on commit e62b990

Please sign in to comment.