Skip to content

Commit b7cfd85

Browse files
committed
Test fixes
Signed-off-by: Aayush Chouhan <[email protected]>
1 parent aa6e51b commit b7cfd85

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/test/unit_tests/test_lifecycle.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -829,11 +829,15 @@ mocha.describe('lifecycle', () => {
829829
};
830830

831831
function generate_rule(id, prefix, tags, size_gt, size_lt, expiration_days) {
832-
const filter = {};
833-
if (prefix) filter.Prefix = prefix;
834-
if (tags.length) filter.Tags = tags;
835-
if (size_gt !== undefined) filter.ObjectSizeGreaterThan = size_gt;
836-
if (size_lt !== undefined) filter.ObjectSizeLessThan = size_lt;
832+
const filters = {};
833+
if (prefix) filters.Prefix = prefix;
834+
if (Array.isArray(tags) && tags.length) filters.Tags = tags;
835+
if (size_gt !== undefined) filters.ObjectSizeGreaterThan = size_gt;
836+
if (size_lt !== undefined) filters.ObjectSizeLessThan = size_lt;
837+
838+
const filter = Object.keys(filters).length > 1
839+
? { And: filters }
840+
: filters;
837841

838842
return {
839843
ID: id,
@@ -849,11 +853,11 @@ mocha.describe('lifecycle', () => {
849853
console.log("match: ", match);
850854

851855
const [, expiry_str, rule_id] = match;
852-
const expiration_date = new Date(expiry_str);
856+
const expiration = new Date(expiry_str);
853857
const start = new Date(start_time);
854-
start_time.setUTCHours(0, 0, 0, 0); // adjusting to midnight UTC otherwise the tests will fail - similar to ceph-s3 tests
858+
start.setUTCHours(0, 0, 0, 0); // adjusting to midnight UTC otherwise the tests will fail - fix for ceph-s3 tests
855859

856-
const days_diff = Math.floor((expiration_date.getTime() - start.getTime()) / (24 * 60 * 60 * 1000));
860+
const days_diff = Math.floor((expiration.getTime() - start.getTime()) / (24 * 60 * 60 * 1000));
857861

858862
return days_diff === delta_days && rule_id === expected_rule_id;
859863
}

src/util/lifecycle_utils.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,11 @@ function get_lifecycle_rule_for_object(rules, object_info) {
8989
for (const rule of rules) {
9090
if (rule?.status !== 'Enabled') continue;
9191

92-
const filter = rule?.filter || {};
92+
const filter_func = build_lifecycle_filter(rule);
9393

94-
const filter_func = build_lifecycle_filter(filter);
94+
if (!filter_func(object_info)) continue;
9595

96-
if (!filter_func(object_info)) { continue; }
97-
98-
const new_priority = get_rule_priority(filter);
96+
const new_priority = get_rule_priority(rule.filter);
9997

10098
if (compare_rule_priority(curr_priority, new_priority)) {
10199
matched_rule = rule;

0 commit comments

Comments
 (0)