Skip to content

Commit

Permalink
Merge branch 'bugfix/ZENKO-812-fixesInLifecycleTagMatching' into q/8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bert-e committed Jul 23, 2018
2 parents 5c824ce + 05efb46 commit 42974fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 42 deletions.
24 changes: 12 additions & 12 deletions extensions/lifecycle/tasks/LifecycleTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,22 +385,22 @@ class LifecycleTask extends BackbeatTask {
if (rule.Status === 'Disabled') {
return false;
}
if (rule.Filter && rule.Filter.And) {
// multiple tags or prefix w/ tag(s)
const prefix = rule.Filter.And.Prefix;
if (prefix && !item.Key.startsWith(prefix)) {
return false;
}
return deepCompare(rule.Filter.And.Tags, objTags.TagSet);
}
// only one prefix or one tag to compare in this rule
// check all locations where prefix could possibly be
const prefix = rule.Prefix ||
(rule.Filter && rule.Filter.Prefix);
(rule.Filter && (rule.Filter.And ?
rule.Filter.And.Prefix :
rule.Filter.Prefix));
if (prefix && !item.Key.startsWith(prefix)) {
return false;
}
if (rule.Filter && rule.Filter.Tag && objTags.TagSet) {
return deepCompare([rule.Filter.Tag], objTags.TagSet);
if (!rule.Filter) {
return true;
}
const tags = rule.Filter.And ?
rule.Filter.And.Tags :
(rule.Filter.Tag && [rule.Filter.Tag]);
if (tags && !deepCompare(tags, objTags.TagSet || [])) {
return false;
}
return true;
});
Expand Down
36 changes: 6 additions & 30 deletions tests/unit/lifecycle/LifecycleTask.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,39 +217,15 @@ describe('lifecycle task helper methods', () => {
LastModified: CURRENT,
};
const objTags = { TagSet: [] };
const res = lct._filterRules(mBucketRules, item, objTags);
assert.strictEqual(res.length, 1);
assert.deepStrictEqual(getRuleIDs(res), ['task-9']);
const objNoTagSet = {};
[objTags, objNoTagSet].forEach(obj => {
const res = lct._filterRules(mBucketRules, item, obj);
assert.strictEqual(res.length, 1);
assert.deepStrictEqual(getRuleIDs(res), ['task-9']);
});
});
});

it('should filter correctly for an object with no tags', () => {
const mBucketRules = [
new Rule().addID('task-1').addTag('tag1', 'val1')
.addTag('tag2', 'val1').build(),
new Rule().addID('task-2').addTag('tag1', 'val1').build(),
new Rule().addID('task-3').addTag('tag2', 'val1').build(),
new Rule().addID('task-4').addTag('tag2', 'false').build(),
new Rule().addID('task-5').addTag('tag2', 'val1')
.addTag('tag1', 'false').build(),
new Rule().addID('task-6').addTag('tag2', 'val1')
.addTag('tag1', 'val1').build(),
new Rule().addID('task-7').addTag('tag2', 'val1')
.addTag('tag1', 'val1').addTag('tag3', 'val1').build(),
new Rule().addID('task-8').addTag('tag2', 'val1')
.addTag('tag1', 'val1').addTag('tag3', 'false').build(),
new Rule().addID('task-9').build(),
];
const item = {
Key: 'example-item',
LastModified: CURRENT,
};
const objTags = { TagSet: [] };
const res = lct._filterRules(mBucketRules, item, objTags);
assert.strictEqual(res.length, 1);
assert.deepStrictEqual(getRuleIDs(res), ['task-9']);
});

describe('_getApplicableRules', () => {
it('should return earliest applicable expirations', () => {
const filteredRules = [
Expand Down

0 comments on commit 42974fa

Please sign in to comment.