Skip to content

Commit

Permalink
fix: better support for fallback mode (#121)
Browse files Browse the repository at this point in the history
- [ ] Regenerate this pull request now.

PiperOrigin-RevId: 468790263

Source-Link: googleapis/googleapis@873ab45

Source-Link: googleapis/googleapis-gen@cb6f37a
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiY2I2ZjM3YWVmZjJhMzQ3MmU0MGE3YmJhY2U4YzY3ZDc1ZTI0YmVlNSJ9
  • Loading branch information
gcf-owl-bot[bot] authored Aug 23, 2022
1 parent 7909e16 commit 05ccfa9
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
function main(parent, policy) {
// [START orgpolicy_v2_generated_OrgPolicy_CreatePolicy_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
function main(name) {
// [START orgpolicy_v2_generated_OrgPolicy_DeletePolicy_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
function main(name) {
// [START orgpolicy_v2_generated_OrgPolicy_GetEffectivePolicy_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
function main(name) {
// [START orgpolicy_v2_generated_OrgPolicy_GetPolicy_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
function main(parent) {
// [START orgpolicy_v2_generated_OrgPolicy_ListConstraints_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
function main(parent) {
// [START orgpolicy_v2_generated_OrgPolicy_ListPolicies_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
function main(policy) {
// [START orgpolicy_v2_generated_OrgPolicy_UpdatePolicy_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"segments": [
{
"start": 25,
"end": 68,
"end": 71,
"type": "FULL"
}
],
Expand Down Expand Up @@ -70,7 +70,7 @@
"segments": [
{
"start": 25,
"end": 69,
"end": 72,
"type": "FULL"
}
],
Expand Down Expand Up @@ -118,7 +118,7 @@
"segments": [
{
"start": 25,
"end": 50,
"end": 53,
"type": "FULL"
}
],
Expand Down Expand Up @@ -158,7 +158,7 @@
"segments": [
{
"start": 25,
"end": 50,
"end": 53,
"type": "FULL"
}
],
Expand Down Expand Up @@ -198,7 +198,7 @@
"segments": [
{
"start": 25,
"end": 60,
"end": 63,
"type": "FULL"
}
],
Expand Down Expand Up @@ -242,7 +242,7 @@
"segments": [
{
"start": 25,
"end": 50,
"end": 53,
"type": "FULL"
}
],
Expand Down Expand Up @@ -282,7 +282,7 @@
"segments": [
{
"start": 25,
"end": 51,
"end": 54,
"type": "FULL"
}
],
Expand Down
12 changes: 6 additions & 6 deletions packages/google-cloud-orgpolicy/src/v2/org_policy_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
} from 'google-gax';

import {Transform} from 'stream';
import {RequestType} from 'google-gax/build/src/apitypes';
import * as protos from '../../protos/protos';
import jsonProtos = require('../../protos/protos.json');
/**
Expand Down Expand Up @@ -298,7 +297,8 @@ export class OrgPolicyClient {
const apiCall = this._gaxModule.createApiCall(
callPromise,
this._defaults[methodName],
descriptor
descriptor,
this._opts.fallback
);

this.innerApiCalls[methodName] = apiCall;
Expand Down Expand Up @@ -976,7 +976,7 @@ export class OrgPolicyClient {
const callSettings = defaultCallSettings.merge(options);
this.initialize();
return this.descriptors.page.listConstraints.createStream(
this.innerApiCalls.listConstraints as gax.GaxCall,
this.innerApiCalls.listConstraints as GaxCall,
request,
callSettings
);
Expand Down Expand Up @@ -1032,7 +1032,7 @@ export class OrgPolicyClient {
this.initialize();
return this.descriptors.page.listConstraints.asyncIterate(
this.innerApiCalls['listConstraints'] as GaxCall,
request as unknown as RequestType,
request as {},
callSettings
) as AsyncIterable<protos.google.cloud.orgpolicy.v2.IConstraint>;
}
Expand Down Expand Up @@ -1185,7 +1185,7 @@ export class OrgPolicyClient {
const callSettings = defaultCallSettings.merge(options);
this.initialize();
return this.descriptors.page.listPolicies.createStream(
this.innerApiCalls.listPolicies as gax.GaxCall,
this.innerApiCalls.listPolicies as GaxCall,
request,
callSettings
);
Expand Down Expand Up @@ -1242,7 +1242,7 @@ export class OrgPolicyClient {
this.initialize();
return this.descriptors.page.listPolicies.asyncIterate(
this.innerApiCalls['listPolicies'] as GaxCall,
request as unknown as RequestType,
request as {},
callSettings
) as AsyncIterable<protos.google.cloud.orgpolicy.v2.IPolicy>;
}
Expand Down
156 changes: 79 additions & 77 deletions packages/google-cloud-orgpolicy/test/gapic_org_policy_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,99 +113,101 @@ function stubAsyncIterationCall<ResponseType>(
}

describe('v2.OrgPolicyClient', () => {
it('has servicePath', () => {
const servicePath = orgpolicyModule.v2.OrgPolicyClient.servicePath;
assert(servicePath);
});

it('has apiEndpoint', () => {
const apiEndpoint = orgpolicyModule.v2.OrgPolicyClient.apiEndpoint;
assert(apiEndpoint);
});

it('has port', () => {
const port = orgpolicyModule.v2.OrgPolicyClient.port;
assert(port);
assert(typeof port === 'number');
});

it('should create a client with no option', () => {
const client = new orgpolicyModule.v2.OrgPolicyClient();
assert(client);
});
describe('Common methods', () => {
it('has servicePath', () => {
const servicePath = orgpolicyModule.v2.OrgPolicyClient.servicePath;
assert(servicePath);
});

it('should create a client with gRPC fallback', () => {
const client = new orgpolicyModule.v2.OrgPolicyClient({
fallback: true,
it('has apiEndpoint', () => {
const apiEndpoint = orgpolicyModule.v2.OrgPolicyClient.apiEndpoint;
assert(apiEndpoint);
});
assert(client);
});

it('has initialize method and supports deferred initialization', async () => {
const client = new orgpolicyModule.v2.OrgPolicyClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('has port', () => {
const port = orgpolicyModule.v2.OrgPolicyClient.port;
assert(port);
assert(typeof port === 'number');
});
assert.strictEqual(client.orgPolicyStub, undefined);
await client.initialize();
assert(client.orgPolicyStub);
});

it('has close method for the initialized client', done => {
const client = new orgpolicyModule.v2.OrgPolicyClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('should create a client with no option', () => {
const client = new orgpolicyModule.v2.OrgPolicyClient();
assert(client);
});
client.initialize();
assert(client.orgPolicyStub);
client.close().then(() => {
done();

it('should create a client with gRPC fallback', () => {
const client = new orgpolicyModule.v2.OrgPolicyClient({
fallback: true,
});
assert(client);
});
});

it('has close method for the non-initialized client', done => {
const client = new orgpolicyModule.v2.OrgPolicyClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('has initialize method and supports deferred initialization', async () => {
const client = new orgpolicyModule.v2.OrgPolicyClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
assert.strictEqual(client.orgPolicyStub, undefined);
await client.initialize();
assert(client.orgPolicyStub);
});
assert.strictEqual(client.orgPolicyStub, undefined);
client.close().then(() => {
done();

it('has close method for the initialized client', done => {
const client = new orgpolicyModule.v2.OrgPolicyClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
client.initialize();
assert(client.orgPolicyStub);
client.close().then(() => {
done();
});
});
});

it('has getProjectId method', async () => {
const fakeProjectId = 'fake-project-id';
const client = new orgpolicyModule.v2.OrgPolicyClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('has close method for the non-initialized client', done => {
const client = new orgpolicyModule.v2.OrgPolicyClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
assert.strictEqual(client.orgPolicyStub, undefined);
client.close().then(() => {
done();
});
});
client.auth.getProjectId = sinon.stub().resolves(fakeProjectId);
const result = await client.getProjectId();
assert.strictEqual(result, fakeProjectId);
assert((client.auth.getProjectId as SinonStub).calledWithExactly());
});

it('has getProjectId method with callback', async () => {
const fakeProjectId = 'fake-project-id';
const client = new orgpolicyModule.v2.OrgPolicyClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('has getProjectId method', async () => {
const fakeProjectId = 'fake-project-id';
const client = new orgpolicyModule.v2.OrgPolicyClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
client.auth.getProjectId = sinon.stub().resolves(fakeProjectId);
const result = await client.getProjectId();
assert.strictEqual(result, fakeProjectId);
assert((client.auth.getProjectId as SinonStub).calledWithExactly());
});
client.auth.getProjectId = sinon
.stub()
.callsArgWith(0, null, fakeProjectId);
const promise = new Promise((resolve, reject) => {
client.getProjectId((err?: Error | null, projectId?: string | null) => {
if (err) {
reject(err);
} else {
resolve(projectId);
}

it('has getProjectId method with callback', async () => {
const fakeProjectId = 'fake-project-id';
const client = new orgpolicyModule.v2.OrgPolicyClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
client.auth.getProjectId = sinon
.stub()
.callsArgWith(0, null, fakeProjectId);
const promise = new Promise((resolve, reject) => {
client.getProjectId((err?: Error | null, projectId?: string | null) => {
if (err) {
reject(err);
} else {
resolve(projectId);
}
});
});
const result = await promise;
assert.strictEqual(result, fakeProjectId);
});
const result = await promise;
assert.strictEqual(result, fakeProjectId);
});

describe('getPolicy', () => {
Expand Down

0 comments on commit 05ccfa9

Please sign in to comment.