Skip to content

Commit 2fd63ac

Browse files
authored
fix: getMetadata for Session (#2124)
fixes: #2123
1 parent 85a9b0f commit 2fd63ac

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

src/session.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -541,11 +541,5 @@ export class Session extends common.GrpcServiceObject {
541541
* that a callback is omitted.
542542
*/
543543
promisifyAll(Session, {
544-
exclude: [
545-
'delete',
546-
'getMetadata',
547-
'partitionedDml',
548-
'snapshot',
549-
'transaction',
550-
],
544+
exclude: ['delete', 'partitionedDml', 'snapshot', 'transaction'],
551545
});

test/session.ts

+29-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const fakePfy = extend({}, pfy, {
3737
promisified = true;
3838
assert.deepStrictEqual(options.exclude, [
3939
'delete',
40-
'getMetadata',
4140
'partitionedDml',
4241
'snapshot',
4342
'transaction',
@@ -285,10 +284,35 @@ describe('Session', () => {
285284
});
286285

287286
describe('getMetadata', () => {
288-
it('should correctly call and return the request', () => {
287+
it('should correctly call and return the request using callback', done => {
289288
const requestReturnValue = {};
290289

291-
function callback() {}
290+
session.request = (config, callback) => {
291+
assert.strictEqual(config.client, 'SpannerClient');
292+
assert.strictEqual(config.method, 'getSession');
293+
assert.deepStrictEqual(config.reqOpts, {
294+
name: session.formattedName_,
295+
});
296+
assert.deepStrictEqual(config.gaxOpts, {});
297+
assert.deepStrictEqual(
298+
config.headers,
299+
Object.assign(
300+
{[LEADER_AWARE_ROUTING_HEADER]: true},
301+
session.resourceHeader_
302+
)
303+
);
304+
callback(null, requestReturnValue);
305+
};
306+
307+
session.getMetadata((err, returnValue) => {
308+
assert.ifError(err);
309+
assert.strictEqual(returnValue, requestReturnValue);
310+
done();
311+
});
312+
});
313+
314+
it('should correctly call and return the request using promise', async () => {
315+
const requestReturnValue = {};
292316

293317
session.request = config => {
294318
assert.strictEqual(config.client, 'SpannerClient');
@@ -304,10 +328,10 @@ describe('Session', () => {
304328
session.resourceHeader_
305329
)
306330
);
307-
return requestReturnValue;
331+
return new Promise(resolve => resolve(requestReturnValue));
308332
};
309333

310-
const returnValue = session.getMetadata(callback);
334+
const returnValue = await session.getMetadata();
311335
assert.strictEqual(returnValue, requestReturnValue);
312336
});
313337

0 commit comments

Comments
 (0)