Skip to content

Commit

Permalink
Only mock for sharding information
Browse files Browse the repository at this point in the history
  • Loading branch information
gagik committed Oct 24, 2024
1 parent f25c329 commit c4f06b9
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions packages/shell-api/src/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,34 +167,15 @@ describe('getPrintableShardStatus', function () {
configDatabase = new Database(mongo, 'config_test');
expect(configDatabase.getName()).to.equal('config_test');

const mockedAdminDb = {
aggregate: stub()
.withArgs([{ $shardedDataDistribution: {} }])
.resolves({
toArray: stub().resolves(mockedShardedDataDistribution),
}),
};
const getSiblingDB = stub();
getSiblingDB.withArgs('admin').returns(mockedAdminDb);
getSiblingDB.withArgs('config').returns(configDatabase);

configDatabase.getSiblingDB = getSiblingDB;
configDatabase._maybeCachedHello = stub().returns({ msg: 'isdbgrid' });

const origRunCommandWithCheck = serviceProvider.runCommandWithCheck;
serviceProvider.runCommandWithCheck = async (configDatabase, cmd) => {
serviceProvider.runCommandWithCheck = async (db, cmd) => {
if (cmd.hello) {
return { ok: 1, msg: 'isdbgrid' };
}
if (configDatabase === 'admin' && cmd.balancerStatus) {
if (db === 'admin' && cmd.balancerStatus) {
return { ok: 1, inBalancerRound };
}
return origRunCommandWithCheck.call(
serviceProvider,
configDatabase,
cmd,
{}
);
return origRunCommandWithCheck.call(serviceProvider, db, cmd, {});
};

await Promise.all(
Expand Down Expand Up @@ -222,6 +203,20 @@ describe('getPrintableShardStatus', function () {
});

it('returns an object with sharding information', async function () {
const mockedAdminDb = {
aggregate: stub()
.withArgs([{ $shardedDataDistribution: {} }])
.resolves({
toArray: stub().resolves(mockedShardedDataDistribution),
}),
};
const getSiblingDB = stub();
getSiblingDB.withArgs('admin').returns(mockedAdminDb);
getSiblingDB.withArgs('config').returns(configDatabase);

configDatabase.getSiblingDB = getSiblingDB;
configDatabase._maybeCachedHello = stub().returns({ msg: 'isdbgrid' });

const status = await getPrintableShardStatus(configDatabase, false);
expect(status.shardingVersion.clusterId).to.be.instanceOf(bson.ObjectId);
expect(status.shards.map(({ host }: { host: string }) => host)).to.include(
Expand Down

0 comments on commit c4f06b9

Please sign in to comment.