Compare commits

..

No commits in common. "b978010ef2a034fa868e2ff1e11c67dbbb9bb8d2" and "f8dfa378a1faafed313095bffe9cb7c16427f7e8" have entirely different histories.

6 changed files with 11 additions and 92 deletions

View File

@ -148,18 +148,10 @@ class Delimiter extends Extension {
filter(obj) {
const key = obj.key;
const value = obj.value;
if (this.prefix && !key.startsWith(this.prefix)) {
// If the key has overstepped the bounds of the prefix we're
// listing, given the flat k/v behavior we're expecting, then let's
// stop listing there.
if (inc(this.prefix) < key) {
return FILTER_END;
}
return FILTER_SKIP;
}
if (this.alphabeticalOrder
&& typeof this.NextMarker === 'string'
&& key <= this.NextMarker) {
if ((this.prefix && !key.startsWith(this.prefix))
|| (this.alphabeticalOrder
&& typeof this.NextMarker === 'string'
&& key <= this.NextMarker)) {
return FILTER_SKIP;
}
if (this.delimiter) {

View File

@ -6,7 +6,7 @@ const MultipartUploads =
const werelogs = require('werelogs').Logger;
// eslint-disable-next-line new-cap
const logger = new werelogs('listMpuTest');
const { performListing } = require('../../../utils/performListing');
const performListing = require('../../../utils/performListing');
describe('Multipart Uploads listing algorithm', () => {
const splitter = '**';
const overviewPrefix = `overview${splitter}`;

View File

@ -4,7 +4,7 @@ const assert = require('assert');
const Basic = require('../../../../lib/algos/list/basic').List;
const Werelogs = require('werelogs').Logger;
const logger = new Werelogs('listTest');
const { performListing } = require('../../../utils/performListing');
const performListing = require('../../../utils/performListing');
class Test {
constructor(name, input, output) {

View File

@ -7,8 +7,7 @@ const DelimiterMaster =
require('../../../../lib/algos/list/delimiterMaster').DelimiterMaster;
const Werelogs = require('werelogs').Logger;
const logger = new Werelogs('listTest');
const { performListing, performListingExtended } =
require('../../../utils/performListing');
const performListing = require('../../../utils/performListing');
const zpad = require('../../helpers').zpad;
class Test {
@ -372,47 +371,4 @@ describe('Delimiter listing algorithm', () => {
res = performListing(d, Delimiter, test.input, logger);
assert.deepStrictEqual(res, test.output);
});
it('Should interrupt listing if greater value than the prefix is found',
done => {
const data = [
{ key: '/tata.txt', value },
{ key: '/toto/titi/doggy', value },
{ key: '/toto/titi/tata', value },
{ key: '/toto/titi/tutu', value },
{ key: '/toto/tutu', value },
{ key: '/tutu.txt', value },
];
const test = new Test('interrupt on greater than prefix', {
delimiter: '/',
alphabeticalOrder: true,
prefix: '/toto/titi/',
// This marker simulates the bug from MD-653,
// Where a marker is set to a wrong, further-on value, and
// the listing was not interrupted despite that.
marker: '/toto/titi',
maxKeys: 10,
}, {
CommonPrefixes: [],
Contents: [
{ key: '/toto/titi/doggy', value },
{ key: '/toto/titi/tata', value },
{ key: '/toto/titi/tutu', value },
],
Delimiter: '/',
IsTruncated: false,
NextMarker: undefined,
});
const { res, counters } =
performListingExtended(data, Delimiter, test.input, logger);
assert.deepStrictEqual(res, test.output);
assert.strictEqual(counters.accepted, 3,
'Expected 3 accepted entries');
assert.strictEqual(counters.skipped, 1,
'Expected 1 skipped entries');
assert.strictEqual(counters.ended, 1,
'Expected 1 ended event');
return done();
});
});

View File

@ -5,7 +5,7 @@ const DelimiterVersions =
require('../../../../lib/algos/list/delimiterVersions').DelimiterVersions;
const Werelogs = require('werelogs').Logger;
const logger = new Werelogs('listTest');
const { performListing } = require('../../../utils/performListing');
const performListing = require('../../../utils/performListing');
const zpad = require('../../helpers').zpad;
class Test {

View File

@ -1,34 +1,5 @@
const {
FILTER_END,
FILTER_ACCEPT,
FILTER_SKIP } = require('../../lib/algos/list/tools');
function performListingExtended(data, Extension, params, logger) {
module.exports = function performListing(data, Extension, params, logger) {
const listing = new Extension(params, logger);
const counters = { skipped: 0, ended: 0, accepted: 0 };
data.every(e => {
const ret = listing.filter(e);
if (ret === FILTER_END) {
counters.ended += 1;
return false;
} else if (ret === FILTER_SKIP) {
counters.skipped += 1;
} else if (ret === FILTER_ACCEPT) {
counters.accepted += 1;
} else {
throw new Error('Unknown filter return value');
}
return true;
});
return { res: listing.result(), counters };
}
function performListing(data, Extension, params, logger) {
const retData = performListingExtended(data, Extension, params, logger);
return retData.res;
}
module.exports = {
performListing,
performListingExtended,
data.every(e => listing.filter(e) >= 0);
return listing.result();
};