Skip to content

Commit

Permalink
fix: preserve default values in x-goog-request-params header (#142)
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 Sep 14, 2022
1 parent b000110 commit a3a6e6d
Showing 1 changed file with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ import * as iamcheckerModule 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,19 +172,13 @@ describe('v1.IamCheckerClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.policytroubleshooter.v1.TroubleshootIamPolicyRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.policytroubleshooter.v1.TroubleshootIamPolicyResponse()
);
client.innerApiCalls.troubleshootIamPolicy =
stubSimpleCall(expectedResponse);
const [response] = await client.troubleshootIamPolicy(request);
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.troubleshootIamPolicy as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions, undefined)
);
});

it('invokes troubleshootIamPolicy without error using callback', async () => {
Expand All @@ -181,7 +190,6 @@ describe('v1.IamCheckerClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.policytroubleshooter.v1.TroubleshootIamPolicyRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedResponse = generateSampleMessage(
new protos.google.cloud.policytroubleshooter.v1.TroubleshootIamPolicyResponse()
);
Expand All @@ -204,11 +212,6 @@ describe('v1.IamCheckerClient', () => {
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.troubleshootIamPolicy as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions /*, callback defined above */)
);
});

it('invokes troubleshootIamPolicy with error', async () => {
Expand All @@ -220,7 +223,6 @@ describe('v1.IamCheckerClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.policytroubleshooter.v1.TroubleshootIamPolicyRequest()
);
const expectedOptions = {otherArgs: {headers: {}}};
const expectedError = new Error('expected');
client.innerApiCalls.troubleshootIamPolicy = stubSimpleCall(
undefined,
Expand All @@ -230,11 +232,6 @@ describe('v1.IamCheckerClient', () => {
client.troubleshootIamPolicy(request),
expectedError
);
assert(
(client.innerApiCalls.troubleshootIamPolicy as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions, undefined)
);
});

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

0 comments on commit a3a6e6d

Please sign in to comment.