Skip to content

Commit

Permalink
Add custom listing parser to MongoDB listObject
Browse files Browse the repository at this point in the history
test to check for location param is absent

Issue: ARSN-372
  • Loading branch information
KillianG committed Nov 17, 2023
1 parent 2537f8a commit 842b102
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/functional/metadata/mongodb/listObject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ describe('MongoClientInterface::metadata.listObject', () => {
{ upsert: false }).then(() => cb()).catch(err => cb(err));
}

function customListingParser(entries) {
return entries.map(entry => {
const tmp = JSON.parse(entry.value);
return tmp;
});
}

beforeAll(done => {
mongoserver.start().then(() => {
mongoserver.waitUntilRunning().then(() => {
Expand Down Expand Up @@ -152,6 +159,12 @@ describe('MongoClientInterface::metadata.listObject', () => {
objVal: {
key: 'pfx1-test-object',
versionId: 'null',
location: [{
start: 0,
size: 150,
dataStoreETag: 'etag',
dataStoreVersionId: 'versionId',
}],
},
nbVersions: 5,
};
Expand Down Expand Up @@ -523,6 +536,37 @@ describe('MongoClientInterface::metadata.listObject', () => {
return done();
});
});

it('Should not include location in listing result and use custom listing parser', done => {
const opts = {
mongodb: {
replicaSetHosts: 'localhost:27020',
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'primary',
database: DB_NAME,
},
customListingParser,
};

const parserSpy = sinon.spy(opts, 'customListingParser');

const md = new MetadataWrapper(IMPL_NAME, opts, null, logger);
md.setup(() => {
const params = {
listingType: 'DelimiterMaster',
maxKeys: 100,
};
return md.listObject(BUCKET_NAME, params, logger, (err, data) => {
assert.ifError(err);
assert.strictEqual(data.Contents.length, 3);
assert.strictEqual(data.Contents[0].key, 'pfx1-test-object');
assert.strictEqual(data.Contents[0].location, undefined);
assert(parserSpy.calledOnce);
return done();
});
});
});
});
});
});

0 comments on commit 842b102

Please sign in to comment.