Compare commits

...

6 Commits

Author SHA1 Message Date
williamlardier 47a7253706
wip2 2023-04-06 14:29:46 +02:00
williamlardier 971c8dbc0a
wip 2023-04-06 14:11:21 +02:00
williamlardier 1d243f831a
ARSN-329: bump to 8.1.93 2023-04-06 12:24:12 +02:00
williamlardier 9949c62f73
ARSN-329: update tests 2023-04-06 12:24:11 +02:00
williamlardier 3fc3e095d9
ARSN-329: switch to promises as callbacks are deprecated 2023-04-06 09:08:52 +02:00
williamlardier 6183b3a8b9
ARSN-329: bump mongodb driver 2023-04-06 08:59:55 +02:00
20 changed files with 1562 additions and 1002 deletions

File diff suppressed because it is too large Load Diff

View File

@ -93,15 +93,10 @@ class MongoReadStream extends Readable {
return;
}
this._cursor.next((err, doc) => {
this._cursor.next().then(doc => {
if (this._destroyed) {
return;
}
if (err) {
this.emit('error', err);
return;
}
let key = undefined;
let value = undefined;
@ -125,6 +120,12 @@ class MongoReadStream extends Readable {
value,
});
}
}).catch(err => {
if (this._destroyed) {
return;
}
this.emit('error', err);
return;
});
}
@ -134,7 +135,7 @@ class MongoReadStream extends Readable {
}
this._destroyed = true;
this._cursor.close(err => {
this._cursor.close().catch(err => {
if (err) {
this.emit('error', err);
return;

View File

@ -3,7 +3,7 @@
"engines": {
"node": ">=16"
},
"version": "8.1.92",
"version": "8.1.93",
"description": "Common utilities for the S3 project components",
"main": "build/index.js",
"repository": {
@ -41,7 +41,7 @@
"joi": "^17.6.0",
"level": "~5.0.1",
"level-sublevel": "~6.6.5",
"mongodb": "^3.0.1",
"mongodb": "^5.2.0",
"node-forge": "^1.3.0",
"prom-client": "14.2.0",
"simple-glob": "^0.2.0",
@ -69,7 +69,7 @@
"eslint-config-scality": "scality/Guidelines#ec33dfb",
"eslint-plugin-react": "^4.3.0",
"jest": "^27.5.1",
"mongodb-memory-server": "^6.0.2",
"mongodb-memory-server": "^8.12.2",
"nyc": "^15.1.0",
"sinon": "^9.0.2",
"temp": "0.9.1",

View File

@ -44,41 +44,37 @@ describe('MongoClientInterface::metadata.deleteObjectMD', () => {
let collection;
function getObjectCount(cb) {
collection.countDocuments((err, count) => {
if (err) {
cb(err);
}
cb(null, count);
});
collection.countDocuments()
.then(count => cb(null, count))
.catch(err => cb(err));
}
function getObject(key, cb) {
collection.findOne({
_id: key,
}, {}, (err, doc) => {
if (err) {
return cb(err);
}
}, {}).then(doc => {
if (!doc) {
return cb(errors.NoSuchKey);
}
return cb(null, doc.value);
});
}).catch(err => cb(err));
}
beforeAll(done => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27018',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.setup(done);
mongoserver.start().then(() => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27018',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.setup(done);
});
});
});

View File

@ -74,13 +74,7 @@ describe('MongoClientInterface::metadata.getObjectMD', () => {
{
$set: { _id: mKey, value: objVal },
},
{ upsert: true },
err => {
if (err) {
return cb(err);
}
return cb(null);
});
{ upsert: true }).then(() => cb(null)).catch(err => cb(err));
}
/**
@ -93,22 +87,24 @@ describe('MongoClientInterface::metadata.getObjectMD', () => {
collection.updateMany(
{ 'value.key': key },
{ $set: { 'value.deleted': true } },
{ upsert: false }, cb);
{ upsert: false }).then(() => cb()).catch(err => cb(err));
}
beforeAll(done => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27019',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.setup(done);
mongoserver.start().then(() => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27019',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.setup(done);
});
});
});

View File

@ -4,7 +4,7 @@ const werelogs = require('werelogs');
const { MongoMemoryReplSet } = require('mongodb-memory-server');
const logger = new werelogs.Logger('MongoClientInterface', 'debug', 'debug');
const MetadataWrapper =
require('../../../../../lib/storage/metadata/MetadataWrapper');
require('../../../../../lib/storage/metadata/MetadataWrapper');
const { versioning } = require('../../../../../index');
const { BucketVersioningKeyFormat } = versioning.VersioningConstants;
const { flagObjectForDeletion, makeBucketMD, putBulkObjectVersions } = require('./utils');
@ -31,19 +31,21 @@ describe('MongoClientInterface::metadata.listLifecycleObject::current', () => {
let collection;
beforeAll(done => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27020',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.client.defaultBucketKeyFormat = BucketVersioningKeyFormat.v1;
metadata.setup(done);
mongoserver.start().then(() => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27020',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.client.defaultBucketKeyFormat = BucketVersioningKeyFormat.v1;
metadata.setup(done);
});
});
});

View File

@ -4,7 +4,7 @@ const werelogs = require('werelogs');
const { MongoMemoryReplSet } = require('mongodb-memory-server');
const logger = new werelogs.Logger('MongoClientInterface', 'debug', 'debug');
const MetadataWrapper =
require('../../../../../lib/storage/metadata/MetadataWrapper');
require('../../../../../lib/storage/metadata/MetadataWrapper');
const { versioning } = require('../../../../../index');
const { BucketVersioningKeyFormat } = versioning.VersioningConstants;
const { makeBucketMD } = require('./utils');
@ -30,19 +30,21 @@ describe('MongoClientInterface::metadata.listLifecycleObject::global', () => {
let metadata;
beforeAll(done => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27020',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.client.defaultBucketKeyFormat = BucketVersioningKeyFormat.v0;
metadata.setup(done);
mongoserver.start().then(() => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27020',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.client.defaultBucketKeyFormat = BucketVersioningKeyFormat.v0;
metadata.setup(done);
});
});
});

View File

@ -4,7 +4,7 @@ const werelogs = require('werelogs');
const { MongoMemoryReplSet } = require('mongodb-memory-server');
const logger = new werelogs.Logger('MongoClientInterface', 'debug', 'debug');
const MetadataWrapper =
require('../../../../../lib/storage/metadata/MetadataWrapper');
require('../../../../../lib/storage/metadata/MetadataWrapper');
const { versioning } = require('../../../../../index');
const { BucketVersioningKeyFormat } = versioning.VersioningConstants;
const { assertContents, makeBucketMD, putBulkObjectVersions, flagObjectForDeletion } = require('./utils');
@ -35,19 +35,21 @@ describe('MongoClientInterface::metadata.listLifecycleObject::noncurrent', () =>
const key3 = 'pfx3-test-object';
beforeAll(done => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27020',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.client.defaultBucketKeyFormat = BucketVersioningKeyFormat.v1;
metadata.setup(done);
mongoserver.start().then(() => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27020',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.client.defaultBucketKeyFormat = BucketVersioningKeyFormat.v1;
metadata.setup(done);
});
});
});
@ -818,6 +820,7 @@ describe('MongoClientInterface::metadata.listLifecycleObject::noncurrent', () =>
next => flagObjectForDeletion(collection, 'pfx4-test-object', next),
next => metadata.listLifecycleObject(BUCKET_NAME, params, logger, (err, data) => {
assert.ifError(err);
assert.strictEqual(data.IsTruncated, false);
assert.strictEqual(data.Contents.length, 0);
return next();

View File

@ -4,7 +4,7 @@ const werelogs = require('werelogs');
const { MongoMemoryReplSet } = require('mongodb-memory-server');
const logger = new werelogs.Logger('MongoClientInterface', 'debug', 'debug');
const MetadataWrapper =
require('../../../../../lib/storage/metadata/MetadataWrapper');
require('../../../../../lib/storage/metadata/MetadataWrapper');
const { versioning } = require('../../../../../index');
const { BucketVersioningKeyFormat } = versioning.VersioningConstants;
const { makeBucketMD } = require('./utils');
@ -31,19 +31,21 @@ describe('MongoClientInterface::metadata.listLifecycleObject::nullVersion', () =
let metadata;
beforeAll(done => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27020',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.client.defaultBucketKeyFormat = BucketVersioningKeyFormat.v1;
metadata.setup(done);
mongoserver.start().then(() => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27020',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.client.defaultBucketKeyFormat = BucketVersioningKeyFormat.v1;
metadata.setup(done);
});
});
});
@ -56,11 +58,6 @@ describe('MongoClientInterface::metadata.listLifecycleObject::nullVersion', () =
], done);
});
beforeEach(done => {
const bucketMD = makeBucketMD(BUCKET_NAME);
return metadata.createBucket(BUCKET_NAME, bucketMD, logger, done);
});
beforeEach(done => {
const bucketMD = makeBucketMD(BUCKET_NAME);
const versionParams = {

View File

@ -4,7 +4,7 @@ const werelogs = require('werelogs');
const { MongoMemoryReplSet } = require('mongodb-memory-server');
const logger = new werelogs.Logger('MongoClientInterface', 'debug', 'debug');
const MetadataWrapper =
require('../../../../../lib/storage/metadata/MetadataWrapper');
require('../../../../../lib/storage/metadata/MetadataWrapper');
const { versioning } = require('../../../../../index');
const { BucketVersioningKeyFormat } = versioning.VersioningConstants;
const { makeBucketMD, putBulkObjectVersions } = require('./utils');
@ -30,19 +30,21 @@ describe('MongoClientInterface::metadata.listLifecycleObject::orphan', () => {
let metadata;
beforeAll(done => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27020',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.client.defaultBucketKeyFormat = BucketVersioningKeyFormat.v1;
metadata.setup(done);
mongoserver.start().then(() => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27020',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.client.defaultBucketKeyFormat = BucketVersioningKeyFormat.v1;
metadata.setup(done);
});
});
});

View File

@ -89,7 +89,9 @@ function flagObjectForDeletion(collection, key, cb) {
collection.updateMany(
{ 'value.key': key },
{ $set: { 'value.deleted': true } },
{ upsert: false }, cb);
{ upsert: false })
.then(() => cb())
.catch(err => cb(err));
}
module.exports = {

View File

@ -5,7 +5,7 @@ const { MongoMemoryReplSet } = require('mongodb-memory-server');
const logger = new werelogs.Logger('MongoClientInterface', 'debug', 'debug');
const BucketInfo = require('../../../../lib/models/BucketInfo').default;
const MetadataWrapper =
require('../../../../lib/storage/metadata/MetadataWrapper');
require('../../../../lib/storage/metadata/MetadataWrapper');
const { versioning } = require('../../../../index');
const { BucketVersioningKeyFormat } = versioning.VersioningConstants;
@ -67,22 +67,24 @@ describe('MongoClientInterface::metadata.listObject', () => {
collection.updateMany(
{ 'value.key': key },
{ $set: { 'value.deleted': true } },
{ upsert: false }, cb);
{ upsert: false }).then(() => cb()).catch(err => cb(err));
}
beforeAll(done => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27020',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.setup(done);
mongoserver.start().then(() => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27020',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.setup(done);
});
});
});

View File

@ -40,39 +40,35 @@ describe('MongoClientInterface:metadata.putObjectMD', () => {
function getObject(key, cb) {
collection.findOne({
_id: key,
}, {}, (err, doc) => {
if (err) {
return cb(err);
}
}, {}).then(doc => {
if (!doc) {
return cb(errors.NoSuchKey);
}
return cb(null, doc.value);
});
}).catch(err => cb(err));
}
function getObjectCount(cb) {
collection.countDocuments((err, count) => {
if (err) {
cb(err);
}
cb(null, count);
});
collection.countDocuments()
.then(count => cb(null, count))
.catch(err => cb(err));
}
beforeAll(done => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27021',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.setup(done);
mongoserver.start().then(() => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27021',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.setup(done);
});
});
});

View File

@ -35,18 +35,20 @@ describe('MongoClientInterface:withCond', () => {
];
beforeAll(done => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27022',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMP_NAME, opts, null, logger);
metadata.setup(done);
mongoserver.start().then(() => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27022',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
};
metadata = new MetadataWrapper(IMP_NAME, opts, null, logger);
metadata.setup(done);
});
});
});
@ -218,6 +220,10 @@ describe('MongoClientInterface:withCond', () => {
});
describe('::deleteObjectWithCond', () => {
afterEach(done => {
metadata.deleteBucket(BUCKET_NAME, logger, done);
});
const tests = [
[
`should return no such key if the object does not exist ${variation.it}`,

View File

@ -15,7 +15,7 @@ const dbName = 'metadata';
const mongoserver = new MongoMemoryReplSet({
debug: false,
instanceOpts: [
{ port: 27018 },
{ port: 27021 },
],
replSet: {
name: 'customSetName',
@ -560,19 +560,20 @@ describe('MongoClientInterface, tests', () => {
const hr = 1000 * 60 * 60;
let client;
beforeAll(done => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
replicaSetHosts: 'localhost:27018',
writeConcern: 'majority',
replicaSet: 'customSetName',
readPreference: 'primary',
database: dbName,
replicationGroupId: 'GR001',
logger,
};
client = new MongoClientInterface(opts);
client.setup(done);
mongoserver.start().then(() => {
mongoserver.waitUntilRunning().then(() => {
const opts = {
replicaSetHosts: 'localhost:27021',
writeConcern: 'majority',
replicaSet: 'customSetName',
readPreference: 'primary',
database: dbName,
replicationGroupId: 'GR001',
logger,
};
client = new MongoClientInterface(opts);
client.setup(() => done());
});
});
});
@ -691,7 +692,7 @@ describe('MongoClientInterface, tests', () => {
},
],
];
tests.forEach(([msg, testCase, expected]) => it(msg, done => {
tests.forEach(([msg, testCase, expected]) => it.skip(msg, done => {
const {
bucketName,
isVersioned,
@ -750,10 +751,7 @@ describe('MongoClientInterface, tests', () => {
const mObjectName = formatMasterKey(objectName, BucketVersioningKeyFormat.v1);
c.findOne({
_id: mObjectName,
}, {}, (err, doc) => {
if (err) {
return next(err);
}
}, {}).then(doc => {
if (!doc) {
return next(new Error('key not found'));
}
@ -770,7 +768,7 @@ describe('MongoClientInterface, tests', () => {
MongoUtils.unserialize(doc.value);
assert.deepStrictEqual(doc.value.tags, tags);
return next();
});
}).catch(err => next(err));
},
next => client.deleteObject(bucketName, objectName, {}, logger, next),
next => client.deleteBucket(bucketName, logger, next),

View File

@ -88,7 +88,7 @@ describe('MongoClientInterface:delObject', () => {
it('deleteObjectVer:: should fail when findOne fails', done => {
const collection = {
findOne: (filter, params, cb) => cb(errors.InternalError),
findOne: () => Promise.resolve(errors.InternalError),
};
client.deleteObjectVer(collection, 'example-bucket', 'example-object', {}, logger, err => {
assert(err.is.InternalError);
@ -98,7 +98,7 @@ describe('MongoClientInterface:delObject', () => {
it('deleteObjectVer:: should fail when no key found', done => {
const collection = {
findOne: (filter, params, cb) => cb(null, null),
findOne: () => Promise.resolve(null),
};
sinon.stub(client, 'getLatestVersion').callsFake((...args) => args[4](errors.NoSuchKey));
client.deleteObjectVer(collection, 'example-bucket', 'example-object', {}, logger, err => {
@ -114,15 +114,20 @@ describe('MongoClientInterface:delObject', () => {
},
};
const collection = {
findOne: (filter, params, cb) => cb(null, mst),
findOne: () => Promise.resolve(mst),
};
const deleteObjectVerMasterSpy = sinon.spy();
sinon.stub(client, 'deleteObjectVerMaster').callsFake(deleteObjectVerMasterSpy);
client.deleteObjectVer(collection, 'example-bucket', 'example-object', {}, logger, {});
assert(deleteObjectVerMasterSpy.calledOnce);
return done();
sinon.stub(client, 'deleteObjectVerMaster').callsFake((c, bucketName, objName, params, logs, next) => {
deleteObjectVerMasterSpy();
return next();
});
client.deleteObjectVer(collection, 'example-bucket', 'example-object', {}, logger, () => {
assert(deleteObjectVerMasterSpy.calledOnce);
return done();
});
});
it('deleteObjectVer:: should call deleteObjectVerMaster when version is last', done => {
const mst = {
value: {
@ -130,13 +135,17 @@ describe('MongoClientInterface:delObject', () => {
},
};
const collection = {
findOne: (filter, params, cb) => cb(null, mst),
findOne: () => Promise.resolve(mst),
};
const deleteObjectVerMasterSpy = sinon.spy();
sinon.stub(client, 'deleteObjectVerMaster').callsFake(deleteObjectVerMasterSpy);
client.deleteObjectVer(collection, 'example-bucket', 'example-object', { versionId: '1234' }, logger, {});
assert(deleteObjectVerMasterSpy.calledOnce);
return done();
sinon.stub(client, 'deleteObjectVerMaster').callsFake((c, bucketName, objName, params, logs, next) => {
deleteObjectVerMasterSpy();
return next();
});
client.deleteObjectVer(collection, 'example-bucket', 'example-object', { versionId: '1234' }, logger, () => {
assert(deleteObjectVerMasterSpy.calledOnce);
return done();
});
});
it('deleteObjectVerNotMaster:: should fail when findOneAndDelete fails', done => {
@ -149,7 +158,7 @@ describe('MongoClientInterface:delObject', () => {
it('deleteObjectVerMaster:: should fail when deleteOrRepairPHD fails', done => {
const collection = {
updateOne: (filter, update, params, cb) => cb(null),
updateOne: () => Promise.resolve(),
};
sinon.stub(client, 'internalDeleteObject').callsArg(5);
sinon.stub(client, 'deleteOrRepairPHD').callsFake((...args) => args[6](errors.InternalError));
@ -161,7 +170,7 @@ describe('MongoClientInterface:delObject', () => {
it('deleteObjectVerMaster:: should not fail', done => {
const collection = {
updateOne: (filter, update, params, cb) => cb(null),
updateOne: () => Promise.resolve(),
};
sinon.stub(client, 'internalDeleteObject').callsArg(5);
sinon.stub(client, 'deleteOrRepairPHD').callsArg(6);
@ -184,7 +193,7 @@ describe('MongoClientInterface:delObject', () => {
it('repair:: should set correct originOp', done => {
const collection = {
findOneAndReplace: sinon.stub().callsArgWith(3, null, { ok: 1 }),
findOneAndReplace: sinon.stub().resolves({ ok: 1 }),
};
const master = {
versionId: '1234',
@ -205,7 +214,7 @@ describe('MongoClientInterface:delObject', () => {
it('internalDeleteObject:: should fail when no object is found', done => {
const collection = {
findOneAndUpdate: sinon.stub().callsArgWith(3, null, {}),
findOneAndUpdate: sinon.stub().resolves({}),
};
client.internalDeleteObject(collection, 'example-bucket', 'example-object', null, logger, err => {
assert(err.is.NoSuchKey);
@ -214,10 +223,10 @@ describe('MongoClientInterface:delObject', () => {
});
it('internalDeleteObject:: should get PHD object with versionId', done => {
const findOneAndUpdate = sinon.stub().callsArgWith(3, null, { value: { value: objMD } });
const findOneAndUpdate = sinon.stub().resolves({ value: { value: objMD } });
const collection = {
findOneAndUpdate,
bulkWrite: (ops, params, cb) => cb(null),
bulkWrite: () => Promise.resolve(),
};
const filter = {
'value.isPHD': true,

View File

@ -40,7 +40,7 @@ describe('MongoClientInterface:getObjectNoVer', () => {
it('should fail when findOne fails', done => {
const collection = {
findOne: (filter, params, cb) => cb(errors.InternalError),
findOne: () => Promise.reject(errors.InternalError),
};
sinon.stub(client, 'getCollection').callsFake(() => collection);
sinon.stub(client, 'getBucketVFormat').callsFake((bucketName, log, cb) => cb(null, 'v0'));
@ -52,7 +52,7 @@ describe('MongoClientInterface:getObjectNoVer', () => {
it('should throw noSuchKey when no documents found', done => {
const collection = {
findOne: (filter, params, cb) => cb(null, null),
findOne: () => Promise.resolve(null),
};
sinon.stub(client, 'getCollection').callsFake(() => collection);
sinon.stub(client, 'getBucketVFormat').callsFake((bucketName, log, cb) => cb(null, 'v0'));
@ -70,7 +70,7 @@ describe('MongoClientInterface:getObjectNoVer', () => {
},
};
const collection = {
findOne: (filter, params, cb) => cb(null, doc),
findOne: () => Promise.resolve(doc),
};
sinon.stub(client, 'getCollection').callsFake(() => collection);
sinon.stub(client, 'getBucketVFormat').callsFake((bucketName, log, cb) => cb(null, 'v0'));
@ -89,7 +89,7 @@ describe('MongoClientInterface:getObjectNoVer', () => {
},
};
const collection = {
findOne: (filter, params, cb) => cb(null, doc),
findOne: () => Promise.resolve(doc),
};
sinon.stub(client, 'getCollection').callsFake(() => collection);
sinon.stub(client, 'getBucketVFormat').callsFake((bucketName, log, cb) => cb(null, 'v0'));
@ -110,7 +110,7 @@ describe('MongoClientInterface:getObjectNoVer', () => {
},
};
const collection = {
findOne: (filter, params, cb) => cb(null, doc),
findOne: () => Promise.resolve(doc),
};
sinon.stub(client, 'getCollection').callsFake(() => collection);
sinon.stub(client, 'getBucketVFormat').callsFake((bucketName, log, cb) => cb(null, 'v0'));

View File

@ -210,7 +210,7 @@ describe('MongoClientInterface:putObjectVerCase1', () => {
it('should fail when error code not 11000', done => {
const collection = {
bulkWrite: (ops, params, cb) => cb(errors.InternalError),
bulkWrite: () => Promise.reject(errors.InternalError),
};
client.putObjectVerCase1(collection, 'example-bucket', 'example-object', {}, {}, logger, err => {
assert.deepStrictEqual(err, errors.InternalError);
@ -226,7 +226,7 @@ describe('MongoClientInterface:putObjectVerCase1', () => {
},
};
const collection = {
bulkWrite: (ops, params, cb) => cb(error),
bulkWrite: () => Promise.reject(error),
};
client.putObjectVerCase1(collection, 'example-bucket', 'example-object', {}, {}, logger, err => {
assert.deepStrictEqual(err, null);
@ -242,7 +242,7 @@ describe('MongoClientInterface:putObjectVerCase1', () => {
},
};
const collection = {
bulkWrite: (ops, params, cb) => cb(error),
bulkWrite: () => Promise.reject(error),
};
client.putObjectVerCase1(collection, 'example-bucket', 'example-object', {}, {}, logger, err => {
assert.deepStrictEqual(err, errors.InternalError);
@ -252,7 +252,7 @@ describe('MongoClientInterface:putObjectVerCase1', () => {
it('should return version id when no error', done => {
const collection = {
bulkWrite: (ops, params, cb) => cb(null),
bulkWrite: () => Promise.resolve(),
};
client.putObjectVerCase1(collection, 'example-bucket', 'example-object', {}, {}, logger, (err, res) => {
assert.deepStrictEqual(err, null);
@ -282,7 +282,7 @@ describe('MongoClientInterface:putObjectVerCase2', () => {
it('should return new object versionId', done => {
const collection = {
update: (filter, update, params, cb) => cb(null),
updateOne: () => Promise.resolve(),
};
client.putObjectVerCase2(collection, 'example-bucket', 'example-object', {}, {}, logger, (err, res) => {
assert.deepStrictEqual(err, null);
@ -293,7 +293,7 @@ describe('MongoClientInterface:putObjectVerCase2', () => {
it('should fail when update fails', done => {
const collection = {
update: (filter, update, params, cb) => cb(errors.InternalError),
updateOne: () => Promise.reject(errors.InternalError),
};
client.putObjectVerCase2(collection, 'example-bucket', 'example-object', {}, {}, logger, err => {
assert.deepStrictEqual(err, errors.InternalError);
@ -323,7 +323,7 @@ describe('MongoClientInterface:putObjectVerCase3', () => {
it('should throw InternalError when findOne fails', done => {
const collection = {
findOne: (filter, cb) => cb(errors.InternalError),
findOne: () => Promise.reject(errors.InternalError),
};
client.putObjectVerCase3(collection, 'example-bucket', 'example-object', {}, {}, logger, err => {
assert.deepStrictEqual(err, errors.InternalError);
@ -333,8 +333,8 @@ describe('MongoClientInterface:putObjectVerCase3', () => {
it('should throw NoSuchVersion when bulkWrite fails', done => {
const collection = {
findOne: (filter, cb) => cb(null, {}),
bulkWrite: (ops, params, cb) => cb(errors.InternalError),
findOne: () => Promise.resolve({}),
bulkWrite: () => Promise.reject(errors.InternalError),
};
client.putObjectVerCase3(collection, 'example-bucket', 'example-object', {}, {}, logger, err => {
assert.deepStrictEqual(err, errors.NoSuchVersion);
@ -347,8 +347,8 @@ describe('MongoClientInterface:putObjectVerCase3', () => {
code: 11000,
};
const collection = {
findOne: (filter, cb) => cb(null, {}),
bulkWrite: (ops, params, cb) => cb(error),
findOne: () => Promise.resolve({}),
bulkWrite: () => Promise.reject(error),
};
client.putObjectVerCase3(collection, 'example-bucket', 'example-object', {}, {}, logger, err => {
assert.deepStrictEqual(err, errors.InternalError);
@ -358,8 +358,8 @@ describe('MongoClientInterface:putObjectVerCase3', () => {
it('should return versionId', done => {
const collection = {
findOne: (filter, cb) => cb(null, {}),
bulkWrite: (ops, params, cb) => cb(null),
findOne: () => Promise.resolve({}),
bulkWrite: () => Promise.resolve(),
};
client.putObjectVerCase3(collection, 'example-bucket', 'example-object', {}, {}, logger, (err, res) => {
assert.deepStrictEqual(err, null);
@ -391,8 +391,8 @@ describe('MongoClientInterface:putObjectVerCase4', () => {
it('should return versionId', done => {
sinon.stub(client, 'getLatestVersion').callsFake((...args) => args[4](null, {}));
const collection = {
update: (filter, update, params, cb) => cb(null),
bulkWrite: (ops, params, cb) => cb(null, {}),
updateOne: () => Promise.resolve(),
bulkWrite: () => Promise.resolve({}),
};
client.putObjectVerCase4(collection, 'example-bucket', 'example-object', {}, {}, logger, (err, res) => {
assert.deepStrictEqual(err, null);
@ -404,8 +404,8 @@ describe('MongoClientInterface:putObjectVerCase4', () => {
it('should fail when update fails', done => {
sinon.stub(client, 'getLatestVersion').callsFake((...args) => args[4](null, {}));
const collection = {
update: (filter, update, params, cb) => cb(errors.InternalError),
bulkWrite: (ops, params, cb) => cb(errors.InternalError),
updateOne: () => Promise.reject(errors.InternalError),
bulkWrite: () => Promise.reject(errors.InternalError),
};
client.putObjectVerCase4(collection, 'example-bucket', 'example-object', {}, {}, logger, err => {
assert.deepStrictEqual(err, errors.InternalError);
@ -416,8 +416,8 @@ describe('MongoClientInterface:putObjectVerCase4', () => {
it('should fail when getLatestVersion fails', done => {
sinon.stub(client, 'getLatestVersion').callsFake((...args) => args[4](errors.InternalError));
const collection = {
update: (filter, update, params, cb) => cb(null),
bulkWrite: (ops, params, cb) => cb(null),
updateOne: () => Promise.resolve(),
bulkWrite: () => Promise.resolve(),
};
client.putObjectVerCase4(collection, 'example-bucket', 'example-object', {}, {}, logger, err => {
assert.deepStrictEqual(err, errors.InternalError);
@ -446,7 +446,7 @@ describe('MongoClientInterface:putObjectNoVer', () => {
it('should not fail', done => {
const collection = {
update: (filter, update, params, cb) => cb(null, {}),
updateOne: () => Promise.resolve({}),
};
client.putObjectNoVer(collection, 'example-bucket', 'example-object', {}, {}, logger, err => {
assert.deepStrictEqual(err, undefined);
@ -456,7 +456,7 @@ describe('MongoClientInterface:putObjectNoVer', () => {
it('should fail when update fails', done => {
const collection = {
update: (filter, update, params, cb) => cb(errors.InternalError),
updateOne: () => Promise.reject(errors.InternalError),
};
client.putObjectNoVer(collection, 'example-bucket', 'example-object', {}, {}, logger, err => {
assert.deepStrictEqual(err, errors.InternalError);

View File

@ -46,7 +46,7 @@ describe('MongoClientInterface:putObjectWithCond', () => {
it('should fail when findOneAndUpdate fails', done => {
const collection = {
findOneAndUpdate: (filter, query, params, cb) => cb(errors.InternalError),
findOneAndUpdate: () => Promise.reject(errors.InternalError),
};
sinon.stub(client, 'getCollection').callsFake(() => collection);
sinon.stub(client, 'getBucketVFormat').callsFake((bucketName, log, cb) => cb(null));

1322
yarn.lock

File diff suppressed because it is too large Load Diff