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

View File

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

View File

@ -44,41 +44,37 @@ describe('MongoClientInterface::metadata.deleteObjectMD', () => {
let collection; let collection;
function getObjectCount(cb) { function getObjectCount(cb) {
collection.countDocuments((err, count) => { collection.countDocuments()
if (err) { .then(count => cb(null, count))
cb(err); .catch(err => cb(err));
}
cb(null, count);
});
} }
function getObject(key, cb) { function getObject(key, cb) {
collection.findOne({ collection.findOne({
_id: key, _id: key,
}, {}, (err, doc) => { }, {}).then(doc => {
if (err) {
return cb(err);
}
if (!doc) { if (!doc) {
return cb(errors.NoSuchKey); return cb(errors.NoSuchKey);
} }
return cb(null, doc.value); return cb(null, doc.value);
}); }).catch(err => cb(err));
} }
beforeAll(done => { beforeAll(done => {
mongoserver.waitUntilRunning().then(() => { mongoserver.start().then(() => {
const opts = { mongoserver.waitUntilRunning().then(() => {
mongodb: { const opts = {
replicaSetHosts: 'localhost:27018', mongodb: {
writeConcern: 'majority', replicaSetHosts: 'localhost:27018',
replicaSet: 'rs0', writeConcern: 'majority',
readPreference: 'primary', replicaSet: 'rs0',
database: DB_NAME, readPreference: 'primary',
}, database: DB_NAME,
}; },
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger); };
metadata.setup(done); 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 }, $set: { _id: mKey, value: objVal },
}, },
{ upsert: true }, { upsert: true }).then(() => cb(null)).catch(err => cb(err));
err => {
if (err) {
return cb(err);
}
return cb(null);
});
} }
/** /**
@ -93,22 +87,24 @@ describe('MongoClientInterface::metadata.getObjectMD', () => {
collection.updateMany( collection.updateMany(
{ 'value.key': key }, { 'value.key': key },
{ $set: { 'value.deleted': true } }, { $set: { 'value.deleted': true } },
{ upsert: false }, cb); { upsert: false }).then(() => cb()).catch(err => cb(err));
} }
beforeAll(done => { beforeAll(done => {
mongoserver.waitUntilRunning().then(() => { mongoserver.start().then(() => {
const opts = { mongoserver.waitUntilRunning().then(() => {
mongodb: { const opts = {
replicaSetHosts: 'localhost:27019', mongodb: {
writeConcern: 'majority', replicaSetHosts: 'localhost:27019',
replicaSet: 'rs0', writeConcern: 'majority',
readPreference: 'primary', replicaSet: 'rs0',
database: DB_NAME, readPreference: 'primary',
}, database: DB_NAME,
}; },
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger); };
metadata.setup(done); 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 { MongoMemoryReplSet } = require('mongodb-memory-server');
const logger = new werelogs.Logger('MongoClientInterface', 'debug', 'debug'); const logger = new werelogs.Logger('MongoClientInterface', 'debug', 'debug');
const MetadataWrapper = const MetadataWrapper =
require('../../../../../lib/storage/metadata/MetadataWrapper'); require('../../../../../lib/storage/metadata/MetadataWrapper');
const { versioning } = require('../../../../../index'); const { versioning } = require('../../../../../index');
const { BucketVersioningKeyFormat } = versioning.VersioningConstants; const { BucketVersioningKeyFormat } = versioning.VersioningConstants;
const { flagObjectForDeletion, makeBucketMD, putBulkObjectVersions } = require('./utils'); const { flagObjectForDeletion, makeBucketMD, putBulkObjectVersions } = require('./utils');
@ -31,19 +31,21 @@ describe('MongoClientInterface::metadata.listLifecycleObject::current', () => {
let collection; let collection;
beforeAll(done => { beforeAll(done => {
mongoserver.waitUntilRunning().then(() => { mongoserver.start().then(() => {
const opts = { mongoserver.waitUntilRunning().then(() => {
mongodb: { const opts = {
replicaSetHosts: 'localhost:27020', mongodb: {
writeConcern: 'majority', replicaSetHosts: 'localhost:27020',
replicaSet: 'rs0', writeConcern: 'majority',
readPreference: 'primary', replicaSet: 'rs0',
database: DB_NAME, readPreference: 'primary',
}, database: DB_NAME,
}; },
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger); };
metadata.client.defaultBucketKeyFormat = BucketVersioningKeyFormat.v1; metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.setup(done); 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 { MongoMemoryReplSet } = require('mongodb-memory-server');
const logger = new werelogs.Logger('MongoClientInterface', 'debug', 'debug'); const logger = new werelogs.Logger('MongoClientInterface', 'debug', 'debug');
const MetadataWrapper = const MetadataWrapper =
require('../../../../../lib/storage/metadata/MetadataWrapper'); require('../../../../../lib/storage/metadata/MetadataWrapper');
const { versioning } = require('../../../../../index'); const { versioning } = require('../../../../../index');
const { BucketVersioningKeyFormat } = versioning.VersioningConstants; const { BucketVersioningKeyFormat } = versioning.VersioningConstants;
const { makeBucketMD } = require('./utils'); const { makeBucketMD } = require('./utils');
@ -30,19 +30,21 @@ describe('MongoClientInterface::metadata.listLifecycleObject::global', () => {
let metadata; let metadata;
beforeAll(done => { beforeAll(done => {
mongoserver.waitUntilRunning().then(() => { mongoserver.start().then(() => {
const opts = { mongoserver.waitUntilRunning().then(() => {
mongodb: { const opts = {
replicaSetHosts: 'localhost:27020', mongodb: {
writeConcern: 'majority', replicaSetHosts: 'localhost:27020',
replicaSet: 'rs0', writeConcern: 'majority',
readPreference: 'primary', replicaSet: 'rs0',
database: DB_NAME, readPreference: 'primary',
}, database: DB_NAME,
}; },
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger); };
metadata.client.defaultBucketKeyFormat = BucketVersioningKeyFormat.v0; metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.setup(done); 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 { MongoMemoryReplSet } = require('mongodb-memory-server');
const logger = new werelogs.Logger('MongoClientInterface', 'debug', 'debug'); const logger = new werelogs.Logger('MongoClientInterface', 'debug', 'debug');
const MetadataWrapper = const MetadataWrapper =
require('../../../../../lib/storage/metadata/MetadataWrapper'); require('../../../../../lib/storage/metadata/MetadataWrapper');
const { versioning } = require('../../../../../index'); const { versioning } = require('../../../../../index');
const { BucketVersioningKeyFormat } = versioning.VersioningConstants; const { BucketVersioningKeyFormat } = versioning.VersioningConstants;
const { assertContents, makeBucketMD, putBulkObjectVersions, flagObjectForDeletion } = require('./utils'); const { assertContents, makeBucketMD, putBulkObjectVersions, flagObjectForDeletion } = require('./utils');
@ -35,19 +35,21 @@ describe('MongoClientInterface::metadata.listLifecycleObject::noncurrent', () =>
const key3 = 'pfx3-test-object'; const key3 = 'pfx3-test-object';
beforeAll(done => { beforeAll(done => {
mongoserver.waitUntilRunning().then(() => { mongoserver.start().then(() => {
const opts = { mongoserver.waitUntilRunning().then(() => {
mongodb: { const opts = {
replicaSetHosts: 'localhost:27020', mongodb: {
writeConcern: 'majority', replicaSetHosts: 'localhost:27020',
replicaSet: 'rs0', writeConcern: 'majority',
readPreference: 'primary', replicaSet: 'rs0',
database: DB_NAME, readPreference: 'primary',
}, database: DB_NAME,
}; },
metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger); };
metadata.client.defaultBucketKeyFormat = BucketVersioningKeyFormat.v1; metadata = new MetadataWrapper(IMPL_NAME, opts, null, logger);
metadata.setup(done); 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 => flagObjectForDeletion(collection, 'pfx4-test-object', next),
next => metadata.listLifecycleObject(BUCKET_NAME, params, logger, (err, data) => { next => metadata.listLifecycleObject(BUCKET_NAME, params, logger, (err, data) => {
assert.ifError(err); assert.ifError(err);
assert.strictEqual(data.IsTruncated, false); assert.strictEqual(data.IsTruncated, false);
assert.strictEqual(data.Contents.length, 0); assert.strictEqual(data.Contents.length, 0);
return next(); return next();

View File

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

View File

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

View File

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

View File

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

View File

@ -35,18 +35,20 @@ describe('MongoClientInterface:withCond', () => {
]; ];
beforeAll(done => { beforeAll(done => {
mongoserver.waitUntilRunning().then(() => { mongoserver.start().then(() => {
const opts = { mongoserver.waitUntilRunning().then(() => {
mongodb: { const opts = {
replicaSetHosts: 'localhost:27022', mongodb: {
writeConcern: 'majority', replicaSetHosts: 'localhost:27022',
replicaSet: 'rs0', writeConcern: 'majority',
readPreference: 'primary', replicaSet: 'rs0',
database: DB_NAME, readPreference: 'primary',
}, database: DB_NAME,
}; },
metadata = new MetadataWrapper(IMP_NAME, opts, null, logger); };
metadata.setup(done); metadata = new MetadataWrapper(IMP_NAME, opts, null, logger);
metadata.setup(done);
});
}); });
}); });
@ -218,6 +220,10 @@ describe('MongoClientInterface:withCond', () => {
}); });
describe('::deleteObjectWithCond', () => { describe('::deleteObjectWithCond', () => {
afterEach(done => {
metadata.deleteBucket(BUCKET_NAME, logger, done);
});
const tests = [ const tests = [
[ [
`should return no such key if the object does not exist ${variation.it}`, `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({ const mongoserver = new MongoMemoryReplSet({
debug: false, debug: false,
instanceOpts: [ instanceOpts: [
{ port: 27018 }, { port: 27021 },
], ],
replSet: { replSet: {
name: 'customSetName', name: 'customSetName',
@ -560,19 +560,20 @@ describe('MongoClientInterface, tests', () => {
const hr = 1000 * 60 * 60; const hr = 1000 * 60 * 60;
let client; let client;
beforeAll(done => { beforeAll(done => {
mongoserver.waitUntilRunning().then(() => { mongoserver.start().then(() => {
const opts = { mongoserver.waitUntilRunning().then(() => {
replicaSetHosts: 'localhost:27018', const opts = {
writeConcern: 'majority', replicaSetHosts: 'localhost:27021',
replicaSet: 'customSetName', writeConcern: 'majority',
readPreference: 'primary', replicaSet: 'customSetName',
database: dbName, readPreference: 'primary',
replicationGroupId: 'GR001', database: dbName,
logger, replicationGroupId: 'GR001',
}; logger,
};
client = new MongoClientInterface(opts); client = new MongoClientInterface(opts);
client.setup(done); 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 { const {
bucketName, bucketName,
isVersioned, isVersioned,
@ -750,10 +751,7 @@ describe('MongoClientInterface, tests', () => {
const mObjectName = formatMasterKey(objectName, BucketVersioningKeyFormat.v1); const mObjectName = formatMasterKey(objectName, BucketVersioningKeyFormat.v1);
c.findOne({ c.findOne({
_id: mObjectName, _id: mObjectName,
}, {}, (err, doc) => { }, {}).then(doc => {
if (err) {
return next(err);
}
if (!doc) { if (!doc) {
return next(new Error('key not found')); return next(new Error('key not found'));
} }
@ -770,7 +768,7 @@ describe('MongoClientInterface, tests', () => {
MongoUtils.unserialize(doc.value); MongoUtils.unserialize(doc.value);
assert.deepStrictEqual(doc.value.tags, tags); assert.deepStrictEqual(doc.value.tags, tags);
return next(); return next();
}); }).catch(err => next(err));
}, },
next => client.deleteObject(bucketName, objectName, {}, logger, next), next => client.deleteObject(bucketName, objectName, {}, logger, next),
next => client.deleteBucket(bucketName, 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 => { it('deleteObjectVer:: should fail when findOne fails', done => {
const collection = { const collection = {
findOne: (filter, params, cb) => cb(errors.InternalError), findOne: () => Promise.resolve(errors.InternalError),
}; };
client.deleteObjectVer(collection, 'example-bucket', 'example-object', {}, logger, err => { client.deleteObjectVer(collection, 'example-bucket', 'example-object', {}, logger, err => {
assert(err.is.InternalError); assert(err.is.InternalError);
@ -98,7 +98,7 @@ describe('MongoClientInterface:delObject', () => {
it('deleteObjectVer:: should fail when no key found', done => { it('deleteObjectVer:: should fail when no key found', done => {
const collection = { const collection = {
findOne: (filter, params, cb) => cb(null, null), findOne: () => Promise.resolve(null),
}; };
sinon.stub(client, 'getLatestVersion').callsFake((...args) => args[4](errors.NoSuchKey)); sinon.stub(client, 'getLatestVersion').callsFake((...args) => args[4](errors.NoSuchKey));
client.deleteObjectVer(collection, 'example-bucket', 'example-object', {}, logger, err => { client.deleteObjectVer(collection, 'example-bucket', 'example-object', {}, logger, err => {
@ -114,15 +114,20 @@ describe('MongoClientInterface:delObject', () => {
}, },
}; };
const collection = { const collection = {
findOne: (filter, params, cb) => cb(null, mst), findOne: () => Promise.resolve(mst),
}; };
const deleteObjectVerMasterSpy = sinon.spy(); const deleteObjectVerMasterSpy = sinon.spy();
sinon.stub(client, 'deleteObjectVerMaster').callsFake(deleteObjectVerMasterSpy); sinon.stub(client, 'deleteObjectVerMaster').callsFake((c, bucketName, objName, params, logs, next) => {
client.deleteObjectVer(collection, 'example-bucket', 'example-object', {}, logger, {}); deleteObjectVerMasterSpy();
assert(deleteObjectVerMasterSpy.calledOnce); return next();
return done(); });
client.deleteObjectVer(collection, 'example-bucket', 'example-object', {}, logger, () => {
assert(deleteObjectVerMasterSpy.calledOnce);
return done();
});
}); });
it('deleteObjectVer:: should call deleteObjectVerMaster when version is last', done => { it('deleteObjectVer:: should call deleteObjectVerMaster when version is last', done => {
const mst = { const mst = {
value: { value: {
@ -130,13 +135,17 @@ describe('MongoClientInterface:delObject', () => {
}, },
}; };
const collection = { const collection = {
findOne: (filter, params, cb) => cb(null, mst), findOne: () => Promise.resolve(mst),
}; };
const deleteObjectVerMasterSpy = sinon.spy(); const deleteObjectVerMasterSpy = sinon.spy();
sinon.stub(client, 'deleteObjectVerMaster').callsFake(deleteObjectVerMasterSpy); sinon.stub(client, 'deleteObjectVerMaster').callsFake((c, bucketName, objName, params, logs, next) => {
client.deleteObjectVer(collection, 'example-bucket', 'example-object', { versionId: '1234' }, logger, {}); deleteObjectVerMasterSpy();
assert(deleteObjectVerMasterSpy.calledOnce); return next();
return done(); });
client.deleteObjectVer(collection, 'example-bucket', 'example-object', { versionId: '1234' }, logger, () => {
assert(deleteObjectVerMasterSpy.calledOnce);
return done();
});
}); });
it('deleteObjectVerNotMaster:: should fail when findOneAndDelete fails', done => { it('deleteObjectVerNotMaster:: should fail when findOneAndDelete fails', done => {
@ -149,7 +158,7 @@ describe('MongoClientInterface:delObject', () => {
it('deleteObjectVerMaster:: should fail when deleteOrRepairPHD fails', done => { it('deleteObjectVerMaster:: should fail when deleteOrRepairPHD fails', done => {
const collection = { const collection = {
updateOne: (filter, update, params, cb) => cb(null), updateOne: () => Promise.resolve(),
}; };
sinon.stub(client, 'internalDeleteObject').callsArg(5); sinon.stub(client, 'internalDeleteObject').callsArg(5);
sinon.stub(client, 'deleteOrRepairPHD').callsFake((...args) => args[6](errors.InternalError)); sinon.stub(client, 'deleteOrRepairPHD').callsFake((...args) => args[6](errors.InternalError));
@ -161,7 +170,7 @@ describe('MongoClientInterface:delObject', () => {
it('deleteObjectVerMaster:: should not fail', done => { it('deleteObjectVerMaster:: should not fail', done => {
const collection = { const collection = {
updateOne: (filter, update, params, cb) => cb(null), updateOne: () => Promise.resolve(),
}; };
sinon.stub(client, 'internalDeleteObject').callsArg(5); sinon.stub(client, 'internalDeleteObject').callsArg(5);
sinon.stub(client, 'deleteOrRepairPHD').callsArg(6); sinon.stub(client, 'deleteOrRepairPHD').callsArg(6);
@ -184,7 +193,7 @@ describe('MongoClientInterface:delObject', () => {
it('repair:: should set correct originOp', done => { it('repair:: should set correct originOp', done => {
const collection = { const collection = {
findOneAndReplace: sinon.stub().callsArgWith(3, null, { ok: 1 }), findOneAndReplace: sinon.stub().resolves({ ok: 1 }),
}; };
const master = { const master = {
versionId: '1234', versionId: '1234',
@ -205,7 +214,7 @@ describe('MongoClientInterface:delObject', () => {
it('internalDeleteObject:: should fail when no object is found', done => { it('internalDeleteObject:: should fail when no object is found', done => {
const collection = { const collection = {
findOneAndUpdate: sinon.stub().callsArgWith(3, null, {}), findOneAndUpdate: sinon.stub().resolves({}),
}; };
client.internalDeleteObject(collection, 'example-bucket', 'example-object', null, logger, err => { client.internalDeleteObject(collection, 'example-bucket', 'example-object', null, logger, err => {
assert(err.is.NoSuchKey); assert(err.is.NoSuchKey);
@ -214,10 +223,10 @@ describe('MongoClientInterface:delObject', () => {
}); });
it('internalDeleteObject:: should get PHD object with versionId', done => { 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 = { const collection = {
findOneAndUpdate, findOneAndUpdate,
bulkWrite: (ops, params, cb) => cb(null), bulkWrite: () => Promise.resolve(),
}; };
const filter = { const filter = {
'value.isPHD': true, 'value.isPHD': true,

View File

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

View File

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

1322
yarn.lock

File diff suppressed because it is too large Load Diff