Skip to content

Commit

Permalink
fix: getMetadata for Session
Browse files Browse the repository at this point in the history
  • Loading branch information
alkatrivedi committed Sep 27, 2024
1 parent 37e0346 commit d4ba9bd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
8 changes: 1 addition & 7 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,5 @@ export class Session extends common.GrpcServiceObject {
* that a callback is omitted.
*/
promisifyAll(Session, {
exclude: [
'delete',
'getMetadata',
'partitionedDml',
'snapshot',
'transaction',
],
exclude: ['delete', 'partitionedDml', 'snapshot', 'transaction'],
});
34 changes: 29 additions & 5 deletions test/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const fakePfy = extend({}, pfy, {
promisified = true;
assert.deepStrictEqual(options.exclude, [
'delete',
'getMetadata',
'partitionedDml',
'snapshot',
'transaction',
Expand Down Expand Up @@ -285,10 +284,35 @@ describe('Session', () => {
});

describe('getMetadata', () => {
it('should correctly call and return the request', () => {
it('should correctly call and return the request using callback', done => {
const requestReturnValue = {};

function callback() {}
session.request = (config, callback) => {
assert.strictEqual(config.client, 'SpannerClient');
assert.strictEqual(config.method, 'getSession');
assert.deepStrictEqual(config.reqOpts, {
name: session.formattedName_,
});
assert.deepStrictEqual(config.gaxOpts, {});
assert.deepStrictEqual(
config.headers,
Object.assign(
{[LEADER_AWARE_ROUTING_HEADER]: true},
session.resourceHeader_
)
);
callback(null, requestReturnValue);
};

session.getMetadata((err, returnValue) => {
assert.ifError(err);
assert.strictEqual(returnValue, requestReturnValue);
done();
});
});

it('should correctly call and return the request using promise', async () => {
const requestReturnValue = {};

session.request = config => {
assert.strictEqual(config.client, 'SpannerClient');
Expand All @@ -304,10 +328,10 @@ describe('Session', () => {
session.resourceHeader_
)
);
return requestReturnValue;
return new Promise(resolve => resolve(requestReturnValue));
};

const returnValue = session.getMetadata(callback);
const returnValue = await session.getMetadata();
assert.strictEqual(returnValue, requestReturnValue);
});

Expand Down

0 comments on commit d4ba9bd

Please sign in to comment.