Skip to content

Commit fc93cbd

Browse files
committed
Fix helper tests
1 parent d082248 commit fc93cbd

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

packages/shell-api/src/helpers.spec.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import sinon from 'ts-sinon';
1919
import chai, { expect } from 'chai';
2020
import { EventEmitter } from 'events';
2121
import sinonChai from 'sinon-chai';
22+
import { stub } from 'sinon';
2223
chai.use(sinonChai);
2324

2425
const fakeConfigDb = makeFakeConfigDatabase(
@@ -129,6 +130,7 @@ describe('getPrintableShardStatus', function () {
129130
const testServer = startSharedTestServer();
130131

131132
let mongo: Mongo;
133+
let db: Database;
132134
let configDatabase: Database;
133135
let serviceProvider: ServiceProvider;
134136
let inBalancerRound = false;
@@ -150,6 +152,11 @@ describe('getPrintableShardStatus', function () {
150152
configDatabase = new Database(mongo, 'config_test');
151153
expect(configDatabase.getName()).to.equal('config_test');
152154

155+
db = {
156+
_maybeCachedHello: stub().returns({ msg: 'isdbgrid' }),
157+
getSiblingDB: stub().withArgs('config').returns(configDatabase),
158+
} as unknown as Database;
159+
153160
const origRunCommandWithCheck = serviceProvider.runCommandWithCheck;
154161
serviceProvider.runCommandWithCheck = async (db, cmd) => {
155162
if (cmd.hello) {
@@ -186,7 +193,7 @@ describe('getPrintableShardStatus', function () {
186193
});
187194

188195
it('returns an object with sharding information', async function () {
189-
const status = await getPrintableShardStatus(configDatabase, false);
196+
const status = await getPrintableShardStatus(db, false);
190197
expect(status.shardingVersion.clusterId).to.be.instanceOf(bson.ObjectId);
191198
expect(status.shards.map(({ host }: { host: string }) => host)).to.include(
192199
'shard01/localhost:27018,localhost:27019,localhost:27020'
@@ -213,7 +220,7 @@ describe('getPrintableShardStatus', function () {
213220
'upgradeState',
214221
]) {
215222
it(`does not show ${hiddenField} in shardingVersion`, async function () {
216-
const status = await getPrintableShardStatus(configDatabase, false);
223+
const status = await getPrintableShardStatus(db, false);
217224
expect((status.shardingVersion as any)[hiddenField]).to.equal(
218225
undefined
219226
);
@@ -224,19 +231,19 @@ describe('getPrintableShardStatus', function () {
224231
it('returns whether the balancer is currently running', async function () {
225232
{
226233
inBalancerRound = true;
227-
const status = await getPrintableShardStatus(configDatabase, true);
234+
const status = await getPrintableShardStatus(db, true);
228235
expect(status.balancer['Currently running']).to.equal('yes');
229236
}
230237

231238
{
232239
inBalancerRound = false;
233-
const status = await getPrintableShardStatus(configDatabase, true);
240+
const status = await getPrintableShardStatus(db, true);
234241
expect(status.balancer['Currently running']).to.equal('no');
235242
}
236243
});
237244

238245
it('returns an object with verbose sharding information if requested', async function () {
239-
const status = await getPrintableShardStatus(configDatabase, true);
246+
const status = await getPrintableShardStatus(db, true);
240247
expect((status['most recently active mongoses'][0] as any).up).to.be.a(
241248
'number'
242249
);
@@ -250,7 +257,7 @@ describe('getPrintableShardStatus', function () {
250257
_id: 'balancer',
251258
activeWindow: { start: '00:00', stop: '23:59' },
252259
});
253-
const status = await getPrintableShardStatus(configDatabase, false);
260+
const status = await getPrintableShardStatus(db, false);
254261
expect(status.balancer['Balancer active window is set between']).to.equal(
255262
'00:00 and 23:59 server local time'
256263
);
@@ -266,7 +273,7 @@ describe('getPrintableShardStatus', function () {
266273
what: 'balancer.round',
267274
ns: '',
268275
});
269-
const status = await getPrintableShardStatus(configDatabase, false);
276+
const status = await getPrintableShardStatus(db, false);
270277
expect(
271278
status.balancer['Failed balancer rounds in last 5 attempts']
272279
).to.equal(1);
@@ -280,7 +287,7 @@ describe('getPrintableShardStatus', function () {
280287
ts: new bson.ObjectId('5fce116c579db766a198a176'),
281288
when: new Date('2020-12-07T11:26:36.803Z'),
282289
});
283-
const status = await getPrintableShardStatus(configDatabase, false);
290+
const status = await getPrintableShardStatus(db, false);
284291
expect(
285292
status.balancer['Collections with active migrations']
286293
).to.have.lengthOf(1);
@@ -295,7 +302,7 @@ describe('getPrintableShardStatus', function () {
295302
what: 'moveChunk.from',
296303
details: { from: 'shard0', to: 'shard1', note: 'success' },
297304
});
298-
const status = await getPrintableShardStatus(configDatabase, false);
305+
const status = await getPrintableShardStatus(db, false);
299306
expect(
300307
status.balancer['Migration Results for the last 24 hours']
301308
).to.deep.equal({ 1: 'Success' });
@@ -307,7 +314,7 @@ describe('getPrintableShardStatus', function () {
307314
what: 'moveChunk.from',
308315
details: { from: 'shard0', to: 'shard1', errmsg: 'oopsie' },
309316
});
310-
const status = await getPrintableShardStatus(configDatabase, false);
317+
const status = await getPrintableShardStatus(db, false);
311318

312319
expect(
313320
status.balancer['Migration Results for the last 24 hours']
@@ -317,7 +324,7 @@ describe('getPrintableShardStatus', function () {
317324
it('fails when config.version is empty', async function () {
318325
await configDatabase.getCollection('version').drop();
319326
try {
320-
await getPrintableShardStatus(configDatabase, false);
327+
await getPrintableShardStatus(db, false);
321328
} catch (err: any) {
322329
expect(err.name).to.equal('MongoshInvalidInputError');
323330
return;

0 commit comments

Comments
 (0)