Skip to content

Commit

Permalink
fix: getMetadata for Session (#2124)
Browse files Browse the repository at this point in the history
fixes: #2123
  • Loading branch information
alkatrivedi authored Oct 3, 2024
1 parent 85a9b0f commit 2fd63ac
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 2fd63ac

Please sign in to comment.