Skip to content

Commit

Permalink
feat: decode LRO metadata & response for users (#420)
Browse files Browse the repository at this point in the history
* add decode interface for all LROs

* test decodeLRO method

* add unit test for decodeLRO

* add decodeLRO interface & unit-test

* add tests in application for decodeLRO

* comments for decode method

* use gax develop branch

* add code samples

* add decodeLRO unit test with error

* update return type for decode function

* use latest gax

* update baseline dependency

* use next gax dependency

* change function name to check*Progress

* typo

* update baseline tests

* update baseline

* change function name to PascalCase

* test application for ts/js

* add timeout in js-test-application

* update comments

* update baseline

* feedback

* @example

* shorten reject assertion in test

* tests all green

* yes latest google-gax

* update interface

* update template and unit test

* update comment

* update dependency

* use gax ^2.3.1
  • Loading branch information
xiaozhenliu-gg5 committed Apr 24, 2020
1 parent cd93a5f commit 1fb42f2
Show file tree
Hide file tree
Showing 49 changed files with 1,110 additions and 328 deletions.
2 changes: 1 addition & 1 deletion baselines/bigquery-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"test": "c8 mocha build/test"
},
"dependencies": {
"google-gax": "^2.3.0"
"google-gax": "^2.3.1"
},
"devDependencies": {
"@types/mocha": "^5.2.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ describe('v1beta1.BigQueryStorageClient', () => {
};
const expectedError = new Error('expected');
client.innerApiCalls.createReadSession = stubSimpleCall(undefined, expectedError);
await assert.rejects(async () => { await client.createReadSession(request); }, expectedError);
await assert.rejects(client.createReadSession(request), expectedError);
assert((client.innerApiCalls.createReadSession as SinonStub)
.getCall(0).calledWith(request, expectedOptions, undefined));
});
Expand Down Expand Up @@ -306,7 +306,7 @@ describe('v1beta1.BigQueryStorageClient', () => {
};
const expectedError = new Error('expected');
client.innerApiCalls.batchCreateReadSessionStreams = stubSimpleCall(undefined, expectedError);
await assert.rejects(async () => { await client.batchCreateReadSessionStreams(request); }, expectedError);
await assert.rejects(client.batchCreateReadSessionStreams(request), expectedError);
assert((client.innerApiCalls.batchCreateReadSessionStreams as SinonStub)
.getCall(0).calledWith(request, expectedOptions, undefined));
});
Expand Down Expand Up @@ -393,7 +393,7 @@ describe('v1beta1.BigQueryStorageClient', () => {
};
const expectedError = new Error('expected');
client.innerApiCalls.finalizeStream = stubSimpleCall(undefined, expectedError);
await assert.rejects(async () => { await client.finalizeStream(request); }, expectedError);
await assert.rejects(client.finalizeStream(request), expectedError);
assert((client.innerApiCalls.finalizeStream as SinonStub)
.getCall(0).calledWith(request, expectedOptions, undefined));
});
Expand Down Expand Up @@ -480,7 +480,7 @@ describe('v1beta1.BigQueryStorageClient', () => {
};
const expectedError = new Error('expected');
client.innerApiCalls.splitReadStream = stubSimpleCall(undefined, expectedError);
await assert.rejects(async () => { await client.splitReadStream(request); }, expectedError);
await assert.rejects(client.splitReadStream(request), expectedError);
assert((client.innerApiCalls.splitReadStream as SinonStub)
.getCall(0).calledWith(request, expectedOptions, undefined));
});
Expand Down Expand Up @@ -551,7 +551,7 @@ describe('v1beta1.BigQueryStorageClient', () => {
reject(err);
});
});
await assert.rejects(async () => { await promise; }, expectedError);
await assert.rejects(promise, expectedError);
assert((client.innerApiCalls.readRows as SinonStub)
.getCall(0).calledWith(request, expectedOptions));
});
Expand Down
2 changes: 1 addition & 1 deletion baselines/disable-packing-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"test": "c8 mocha build/test"
},
"dependencies": {
"google-gax": "^2.3.0"
"google-gax": "^2.3.1"
},
"devDependencies": {
"@types/mocha": "^5.2.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Transform } from 'stream';
import { RequestType } from 'google-gax/build/src/apitypes';
import * as protos from '../../protos/protos';
import * as gapicConfig from './echo_client_config.json';

import { operationsProtos } from 'google-gax';
const version = require('../../../package.json').version;

/**
Expand Down Expand Up @@ -607,6 +607,26 @@ export class EchoClient {
this.initialize();
return this.innerApiCalls.wait(request, options, callback);
}
/**
* Check the status of the long running operation returned by the wait() method.
* @param {String} name
* The operation name that will be passed.
* @returns {Promise} - The promise which resolves to an object.
* The decoded operation object has result and metadata field to get information from.
*
* @example:
* const decodedOperation = await checkWaitProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkWaitProgress(name: string): Promise<LROperation<protos.google.showcase.v1beta1.WaitResponse, protos.google.showcase.v1beta1.WaitMetadata>>{
const request = new operationsProtos.google.longrunning.GetOperationRequest({name});
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(operation, this.descriptors.longrunning.wait, gax.createDefaultBackoffSettings());
return decodeOperation as LROperation<protos.google.showcase.v1beta1.WaitResponse, protos.google.showcase.v1beta1.WaitMetadata>;
}
pagedExpand(
request: protos.google.showcase.v1beta1.IPagedExpandRequest,
options?: gax.CallOptions):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Transform } from 'stream';
import { RequestType } from 'google-gax/build/src/apitypes';
import * as protos from '../../protos/protos';
import * as gapicConfig from './messaging_client_config.json';

import { operationsProtos } from 'google-gax';
const version = require('../../../package.json').version;

/**
Expand Down Expand Up @@ -1042,6 +1042,26 @@ export class MessagingClient {
this.initialize();
return this.innerApiCalls.searchBlurbs(request, options, callback);
}
/**
* Check the status of the long running operation returned by the searchBlurbs() method.
* @param {String} name
* The operation name that will be passed.
* @returns {Promise} - The promise which resolves to an object.
* The decoded operation object has result and metadata field to get information from.
*
* @example:
* const decodedOperation = await checkSearchBlurbsProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkSearchBlurbsProgress(name: string): Promise<LROperation<protos.google.showcase.v1beta1.SearchBlurbsResponse, protos.google.showcase.v1beta1.SearchBlurbsMetadata>>{
const request = new operationsProtos.google.longrunning.GetOperationRequest({name});
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(operation, this.descriptors.longrunning.searchBlurbs, gax.createDefaultBackoffSettings());
return decodeOperation as LROperation<protos.google.showcase.v1beta1.SearchBlurbsResponse, protos.google.showcase.v1beta1.SearchBlurbsMetadata>;
}
listRooms(
request: protos.google.showcase.v1beta1.IListRoomsRequest,
options?: gax.CallOptions):
Expand Down
52 changes: 42 additions & 10 deletions baselines/disable-packing-test/test/gapic_echo_v1beta1.ts.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import * as echoModule from '../src';

import {PassThrough} from 'stream';

import {protobuf, LROperation} from 'google-gax';
import {protobuf, LROperation, operationsProtos} from 'google-gax';

function generateSampleMessage<T extends object>(instance: T) {
const filledObject = (instance.constructor as typeof protobuf.Message)
Expand Down Expand Up @@ -268,7 +268,7 @@ describe('v1beta1.EchoClient', () => {
const expectedOptions = {};
const expectedError = new Error('expected');
client.innerApiCalls.echo = stubSimpleCall(undefined, expectedError);
await assert.rejects(async () => { await client.echo(request); }, expectedError);
await assert.rejects(client.echo(request), expectedError);
assert((client.innerApiCalls.echo as SinonStub)
.getCall(0).calledWith(request, expectedOptions, undefined));
});
Expand Down Expand Up @@ -328,7 +328,7 @@ describe('v1beta1.EchoClient', () => {
const expectedOptions = {};
const expectedError = new Error('expected');
client.innerApiCalls.block = stubSimpleCall(undefined, expectedError);
await assert.rejects(async () => { await client.block(request); }, expectedError);
await assert.rejects(client.block(request), expectedError);
assert((client.innerApiCalls.block as SinonStub)
.getCall(0).calledWith(request, expectedOptions, undefined));
});
Expand Down Expand Up @@ -392,7 +392,7 @@ describe('v1beta1.EchoClient', () => {
const expectedOptions = {};
const expectedError = new Error('expected');
client.innerApiCalls.wait = stubLongRunningCall(undefined, expectedError);
await assert.rejects(async () => { await client.wait(request); }, expectedError);
await assert.rejects(client.wait(request), expectedError);
assert((client.innerApiCalls.wait as SinonStub)
.getCall(0).calledWith(request, expectedOptions, undefined));
});
Expand All @@ -408,10 +408,42 @@ describe('v1beta1.EchoClient', () => {
const expectedError = new Error('expected');
client.innerApiCalls.wait = stubLongRunningCall(undefined, undefined, expectedError);
const [operation] = await client.wait(request);
await assert.rejects(async () => { await operation.promise(); }, expectedError);
await assert.rejects(operation.promise(), expectedError);
assert((client.innerApiCalls.wait as SinonStub)
.getCall(0).calledWith(request, expectedOptions, undefined));
});

it('invokes checkWaitProgress without error', async () => {
const client = new echoModule.v1beta1.EchoClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
client.initialize();
const expectedResponse = generateSampleMessage(new operationsProtos.google.longrunning.Operation());
expectedResponse.name = 'test';
expectedResponse.response = {type_url: 'url', value: Buffer.from('')};
expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')}

client.operationsClient.getOperation = stubSimpleCall(expectedResponse);
const decodedOperation = await client.checkWaitProgress(expectedResponse.name);
assert.deepStrictEqual(decodedOperation.name, expectedResponse.name);
assert(decodedOperation.metadata);
assert((client.operationsClient.getOperation as SinonStub).getCall(0));
});

it('invokes checkWaitProgress with error', async () => {
const client = new echoModule.v1beta1.EchoClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
client.initialize();
const expectedError = new Error('expected');

client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError);
await assert.rejects(client.checkWaitProgress(''), expectedError);
assert((client.operationsClient.getOperation as SinonStub)
.getCall(0));
});
});

describe('expand', () => {
Expand Down Expand Up @@ -459,7 +491,7 @@ describe('v1beta1.EchoClient', () => {
reject(err);
});
});
await assert.rejects(async () => { await promise; }, expectedError);
await assert.rejects(promise, expectedError);
assert((client.innerApiCalls.expand as SinonStub)
.getCall(0).calledWith(request, expectedOptions));
});
Expand Down Expand Up @@ -513,7 +545,7 @@ describe('v1beta1.EchoClient', () => {
stream.write(request);
stream.end();
});
await assert.rejects(async () => { await promise; }, expectedError);
await assert.rejects(promise, expectedError);
assert((client.innerApiCalls.chat as SinonStub)
.getCall(0).calledWithExactly(undefined));
assert.deepStrictEqual(((stream as unknown as PassThrough)
Expand Down Expand Up @@ -573,7 +605,7 @@ describe('v1beta1.EchoClient', () => {
stream.write(request);
stream.end();
});
await assert.rejects(async () => { await promise; }, expectedError);
await assert.rejects(promise, expectedError);
assert((client.innerApiCalls.collect as SinonStub)
.getCall(0).calledWith(null, {} /*, callback defined above */));
});
Expand Down Expand Up @@ -641,7 +673,7 @@ describe('v1beta1.EchoClient', () => {
const expectedOptions = {};
const expectedError = new Error('expected');
client.innerApiCalls.pagedExpand = stubSimpleCall(undefined, expectedError);
await assert.rejects(async () => { await client.pagedExpand(request); }, expectedError);
await assert.rejects(client.pagedExpand(request), expectedError);
assert((client.innerApiCalls.pagedExpand as SinonStub)
.getCall(0).calledWith(request, expectedOptions, undefined));
});
Expand Down Expand Up @@ -700,7 +732,7 @@ describe('v1beta1.EchoClient', () => {
reject(err);
});
});
await assert.rejects(async () => { await promise; }, expectedError);
await assert.rejects(promise, expectedError);
assert((client.descriptors.page.pagedExpand.createStream as SinonStub)
.getCall(0).calledWith(client.innerApiCalls.pagedExpand, request));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ describe('v1beta1.IdentityClient', () => {
const expectedOptions = {};
const expectedError = new Error('expected');
client.innerApiCalls.createUser = stubSimpleCall(undefined, expectedError);
await assert.rejects(async () => { await client.createUser(request); }, expectedError);
await assert.rejects(client.createUser(request), expectedError);
assert((client.innerApiCalls.createUser as SinonStub)
.getCall(0).calledWith(request, expectedOptions, undefined));
});
Expand Down Expand Up @@ -303,7 +303,7 @@ describe('v1beta1.IdentityClient', () => {
};
const expectedError = new Error('expected');
client.innerApiCalls.getUser = stubSimpleCall(undefined, expectedError);
await assert.rejects(async () => { await client.getUser(request); }, expectedError);
await assert.rejects(client.getUser(request), expectedError);
assert((client.innerApiCalls.getUser as SinonStub)
.getCall(0).calledWith(request, expectedOptions, undefined));
});
Expand Down Expand Up @@ -390,7 +390,7 @@ describe('v1beta1.IdentityClient', () => {
};
const expectedError = new Error('expected');
client.innerApiCalls.updateUser = stubSimpleCall(undefined, expectedError);
await assert.rejects(async () => { await client.updateUser(request); }, expectedError);
await assert.rejects(client.updateUser(request), expectedError);
assert((client.innerApiCalls.updateUser as SinonStub)
.getCall(0).calledWith(request, expectedOptions, undefined));
});
Expand Down Expand Up @@ -474,7 +474,7 @@ describe('v1beta1.IdentityClient', () => {
};
const expectedError = new Error('expected');
client.innerApiCalls.deleteUser = stubSimpleCall(undefined, expectedError);
await assert.rejects(async () => { await client.deleteUser(request); }, expectedError);
await assert.rejects(client.deleteUser(request), expectedError);
assert((client.innerApiCalls.deleteUser as SinonStub)
.getCall(0).calledWith(request, expectedOptions, undefined));
});
Expand Down Expand Up @@ -542,7 +542,7 @@ describe('v1beta1.IdentityClient', () => {
const expectedOptions = {};
const expectedError = new Error('expected');
client.innerApiCalls.listUsers = stubSimpleCall(undefined, expectedError);
await assert.rejects(async () => { await client.listUsers(request); }, expectedError);
await assert.rejects(client.listUsers(request), expectedError);
assert((client.innerApiCalls.listUsers as SinonStub)
.getCall(0).calledWith(request, expectedOptions, undefined));
});
Expand Down Expand Up @@ -601,7 +601,7 @@ describe('v1beta1.IdentityClient', () => {
reject(err);
});
});
await assert.rejects(async () => { await promise; }, expectedError);
await assert.rejects(promise, expectedError);
assert((client.descriptors.page.listUsers.createStream as SinonStub)
.getCall(0).calledWith(client.innerApiCalls.listUsers, request));
});
Expand Down

0 comments on commit 1fb42f2

Please sign in to comment.