Skip to content

Commit

Permalink
Added test for duplicate id in rules
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Chouhan <[email protected]>
  • Loading branch information
achouhan09 committed Jan 3, 2025
1 parent 34704e8 commit 76339d3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/test/lifecycle/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,36 @@ function id_lifecycle_configuration(Bucket, Key) {
};
}

function duplicate_id_lifecycle_configuration(Bucket, Key) {
const ID1 = 'rule_id1';
const ID2 = 'rule_id2';
return {
Bucket,
LifecycleConfiguration: {
Rules: [{
ID1,
Expiration: {
Days: 17,
},
Filter: {
Prefix: Key,
},
Status: 'Enabled',
},
{
ID2,
Expiration: {
Days: 18,
},
Filter: {
Prefix: Key,
},
Status: 'Enabled',
}, ],
},
};
}

async function put_get_lifecycle_configuration(Bucket, putLifecycleParams, s3) {
const putLifecycleResult = await s3.putBucketLifecycleConfiguration(putLifecycleParams);
console.log('put lifecycle params:', putLifecycleParams, 'result', putLifecycleResult);
Expand Down Expand Up @@ -512,3 +542,13 @@ exports.test_and_prefix_size = async function(Bucket, Key, s3) {
assert(actualFilter.ObjectSizeGreaterThan === expectedFilter.ObjectSizeGreaterThan, 'and prefix size filter - ObjectSizeGreaterThan');
assert(actualFilter.ObjectSizeLessThan === expectedFilter.ObjectSizeLessThan, 'and prefix size filter - ObjectSizeLessThan');
};

exports.test_rule_duplicate_id = async function(Bucket, Key, s3) {
const putLifecycleParams = duplicate_id_lifecycle_configuration(Bucket, Key);

await s3.putBucketLifecycleConfiguration(putLifecycleParams)
.catch(error => {
assert(error.code === 'InvalidArgument', 'Expected InvalidArgument: duplicate id found in the rules');
console.log('Expected error received, duplicate id found in the rules each rule must have a unique id');
});
};
1 change: 1 addition & 0 deletions src/test/system_tests/test_lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async function main() {
await commonTests.test_rule_id(Bucket, Key, s3);
await commonTests.test_filter_size(Bucket, s3);
await commonTests.test_and_prefix_size(Bucket, Key, s3);
await commonTests.test_rule_duplicate_id(Bucket, Key, s3);

const getObjectParams = {
Bucket,
Expand Down

0 comments on commit 76339d3

Please sign in to comment.