Skip to content

Commit

Permalink
fix: better support for fallback mode (#226)
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 6d1100b commit ab5e1bc
Show file tree
Hide file tree
Showing 14 changed files with 219 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
function main() {
// [START analyticsdata_v1alpha_generated_AlphaAnalyticsData_RunFunnelReport_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": 120,
"end": 123,
"type": "FULL"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
function main() {
// [START analyticsdata_v1beta_generated_BetaAnalyticsData_BatchRunPivotReports_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 analyticsdata_v1beta_generated_BetaAnalyticsData_BatchRunReports_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 analyticsdata_v1beta_generated_BetaAnalyticsData_CheckCompatibility_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 analyticsdata_v1beta_generated_BetaAnalyticsData_GetMetadata_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 analyticsdata_v1beta_generated_BetaAnalyticsData_RunPivotReport_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 analyticsdata_v1beta_generated_BetaAnalyticsData_RunRealtimeReport_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 analyticsdata_v1beta_generated_BetaAnalyticsData_RunReport_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": 136,
"end": 139,
"type": "FULL"
}
],
Expand Down Expand Up @@ -114,7 +114,7 @@
"segments": [
{
"start": 25,
"end": 113,
"end": 116,
"type": "FULL"
}
],
Expand Down Expand Up @@ -194,7 +194,7 @@
"segments": [
{
"start": 25,
"end": 61,
"end": 64,
"type": "FULL"
}
],
Expand Down Expand Up @@ -238,7 +238,7 @@
"segments": [
{
"start": 25,
"end": 61,
"end": 64,
"type": "FULL"
}
],
Expand Down Expand Up @@ -282,7 +282,7 @@
"segments": [
{
"start": 25,
"end": 58,
"end": 61,
"type": "FULL"
}
],
Expand Down Expand Up @@ -322,7 +322,7 @@
"segments": [
{
"start": 25,
"end": 105,
"end": 108,
"type": "FULL"
}
],
Expand Down Expand Up @@ -398,7 +398,7 @@
"segments": [
{
"start": 25,
"end": 82,
"end": 85,
"type": "FULL"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ export class AlphaAnalyticsDataClient {
const apiCall = this._gaxModule.createApiCall(
callPromise,
this._defaults[methodName],
descriptor
descriptor,
this._opts.fallback
);

this.innerApiCalls[methodName] = apiCall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ export class BetaAnalyticsDataClient {
const apiCall = this._gaxModule.createApiCall(
callPromise,
this._defaults[methodName],
descriptor
descriptor,
this._opts.fallback
);

this.innerApiCalls[methodName] = apiCall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,108 +50,111 @@ function stubSimpleCallWithCallback<ResponseType>(
}

describe('v1alpha.AlphaAnalyticsDataClient', () => {
it('has servicePath', () => {
const servicePath =
alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient.servicePath;
assert(servicePath);
});
describe('Common methods', () => {
it('has servicePath', () => {
const servicePath =
alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient.servicePath;
assert(servicePath);
});

it('has apiEndpoint', () => {
const apiEndpoint =
alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient.apiEndpoint;
assert(apiEndpoint);
});
it('has apiEndpoint', () => {
const apiEndpoint =
alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient.apiEndpoint;
assert(apiEndpoint);
});

it('has port', () => {
const port = alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient.port;
assert(port);
assert(typeof port === 'number');
});
it('has port', () => {
const port =
alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient.port;
assert(port);
assert(typeof port === 'number');
});

it('should create a client with no option', () => {
const client =
new alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient();
assert(client);
});
it('should create a client with no option', () => {
const client =
new alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient();
assert(client);
});

it('should create a client with gRPC fallback', () => {
const client =
new alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient({
fallback: true,
});
assert(client);
});
it('should create a client with gRPC fallback', () => {
const client =
new alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient({
fallback: true,
});
assert(client);
});

it('has initialize method and supports deferred initialization', async () => {
const client =
new alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
assert.strictEqual(client.alphaAnalyticsDataStub, undefined);
await client.initialize();
assert(client.alphaAnalyticsDataStub);
});
it('has initialize method and supports deferred initialization', async () => {
const client =
new alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
assert.strictEqual(client.alphaAnalyticsDataStub, undefined);
await client.initialize();
assert(client.alphaAnalyticsDataStub);
});

it('has close method for the initialized client', done => {
const client =
new alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('has close method for the initialized client', done => {
const client =
new alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
client.initialize();
assert(client.alphaAnalyticsDataStub);
client.close().then(() => {
done();
});
client.initialize();
assert(client.alphaAnalyticsDataStub);
client.close().then(() => {
done();
});
});

it('has close method for the non-initialized client', done => {
const client =
new alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('has close method for the non-initialized client', done => {
const client =
new alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
assert.strictEqual(client.alphaAnalyticsDataStub, undefined);
client.close().then(() => {
done();
});
assert.strictEqual(client.alphaAnalyticsDataStub, undefined);
client.close().then(() => {
done();
});
});

it('has getProjectId method', async () => {
const fakeProjectId = 'fake-project-id';
const client =
new alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient({
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());
});
it('has getProjectId method', async () => {
const fakeProjectId = 'fake-project-id';
const client =
new alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient({
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());
});

it('has getProjectId method with callback', async () => {
const fakeProjectId = 'fake-project-id';
const client =
new alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient({
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);
}
it('has getProjectId method with callback', async () => {
const fakeProjectId = 'fake-project-id';
const client =
new alphaanalyticsdataModule.v1alpha.AlphaAnalyticsDataClient({
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('runFunnelReport', () => {
Expand Down
Loading

0 comments on commit ab5e1bc

Please sign in to comment.