Skip to content

Commit

Permalink
fix: better support for fallback mode (#135)
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 1a31a3e commit f381586
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
function main() {
// [START accessapproval_v1_generated_AccessApproval_ApproveApprovalRequest_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() {
// [START accessapproval_v1_generated_AccessApproval_DeleteAccessApprovalSettings_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() {
// [START accessapproval_v1_generated_AccessApproval_DismissApprovalRequest_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() {
// [START accessapproval_v1_generated_AccessApproval_GetAccessApprovalServiceAccount_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() {
// [START accessapproval_v1_generated_AccessApproval_GetAccessApprovalSettings_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() {
// [START accessapproval_v1_generated_AccessApproval_GetApprovalRequest_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() {
// [START accessapproval_v1_generated_AccessApproval_InvalidateApprovalRequest_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() {
// [START accessapproval_v1_generated_AccessApproval_ListApprovalRequests_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() {
// [START accessapproval_v1_generated_AccessApproval_UpdateAccessApprovalSettings_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": 74,
"end": 77,
"type": "FULL"
}
],
Expand Down Expand Up @@ -74,7 +74,7 @@
"segments": [
{
"start": 25,
"end": 51,
"end": 54,
"type": "FULL"
}
],
Expand Down Expand Up @@ -114,7 +114,7 @@
"segments": [
{
"start": 25,
"end": 53,
"end": 56,
"type": "FULL"
}
],
Expand Down Expand Up @@ -158,7 +158,7 @@
"segments": [
{
"start": 25,
"end": 49,
"end": 52,
"type": "FULL"
}
],
Expand Down Expand Up @@ -198,7 +198,7 @@
"segments": [
{
"start": 25,
"end": 49,
"end": 52,
"type": "FULL"
}
],
Expand Down Expand Up @@ -238,7 +238,7 @@
"segments": [
{
"start": 25,
"end": 50,
"end": 53,
"type": "FULL"
}
],
Expand Down Expand Up @@ -278,7 +278,7 @@
"segments": [
{
"start": 25,
"end": 61,
"end": 64,
"type": "FULL"
}
],
Expand Down Expand Up @@ -322,7 +322,7 @@
"segments": [
{
"start": 25,
"end": 49,
"end": 52,
"type": "FULL"
}
],
Expand Down Expand Up @@ -362,7 +362,7 @@
"segments": [
{
"start": 25,
"end": 49,
"end": 52,
"type": "FULL"
}
],
Expand Down
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 @@ -320,7 +319,8 @@ export class AccessApprovalClient {
const apiCall = this._gaxModule.createApiCall(
callPromise,
this._defaults[methodName],
descriptor
descriptor,
this._opts.fallback
);

this.innerApiCalls[methodName] = apiCall;
Expand Down Expand Up @@ -1396,7 +1396,7 @@ export class AccessApprovalClient {
const callSettings = defaultCallSettings.merge(options);
this.initialize();
return this.descriptors.page.listApprovalRequests.createStream(
this.innerApiCalls.listApprovalRequests as gax.GaxCall,
this.innerApiCalls.listApprovalRequests as GaxCall,
request,
callSettings
);
Expand Down Expand Up @@ -1458,7 +1458,7 @@ export class AccessApprovalClient {
this.initialize();
return this.descriptors.page.listApprovalRequests.asyncIterate(
this.innerApiCalls['listApprovalRequests'] as GaxCall,
request as unknown as RequestType,
request as {},
callSettings
) as AsyncIterable<protos.google.cloud.accessapproval.v1.IApprovalRequest>;
}
Expand Down
160 changes: 81 additions & 79 deletions packages/google-cloud-accessapproval/test/gapic_access_approval_v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,101 +113,103 @@ function stubAsyncIterationCall<ResponseType>(
}

describe('v1.AccessApprovalClient', () => {
it('has servicePath', () => {
const servicePath =
accessapprovalModule.v1.AccessApprovalClient.servicePath;
assert(servicePath);
});

it('has apiEndpoint', () => {
const apiEndpoint =
accessapprovalModule.v1.AccessApprovalClient.apiEndpoint;
assert(apiEndpoint);
});

it('has port', () => {
const port = accessapprovalModule.v1.AccessApprovalClient.port;
assert(port);
assert(typeof port === 'number');
});

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

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

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

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

it('should create a client with gRPC fallback', () => {
const client = new accessapprovalModule.v1.AccessApprovalClient({
fallback: true,
});
assert(client);
});
});

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

it('has close method for the initialized client', done => {
const client = new accessapprovalModule.v1.AccessApprovalClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
client.initialize();
assert(client.accessApprovalStub);
client.close().then(() => {
done();
});
});
});

it('has getProjectId method', async () => {
const fakeProjectId = 'fake-project-id';
const client = new accessapprovalModule.v1.AccessApprovalClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('has close method for the non-initialized client', done => {
const client = new accessapprovalModule.v1.AccessApprovalClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
assert.strictEqual(client.accessApprovalStub, 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 accessapprovalModule.v1.AccessApprovalClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('has getProjectId method', async () => {
const fakeProjectId = 'fake-project-id';
const client = new accessapprovalModule.v1.AccessApprovalClient({
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 accessapprovalModule.v1.AccessApprovalClient({
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('getApprovalRequest', () => {
Expand Down

0 comments on commit f381586

Please sign in to comment.