@@ -535,15 +535,16 @@ mocha.describe('lifecycle', () => {
535
535
assert . strictEqual ( versions_list . objects . length , 2 ) ;
536
536
} ) ;
537
537
538
- async function create_mock_version ( version_key , bucket , age , version_count ) {
538
+ async function create_mock_version ( version_key , bucket , age , version_count , expire_all = false ) {
539
539
const obj_upload_ids = [ ] ;
540
540
for ( let i = 0 ; i < version_count ; ++ i ) {
541
541
const content_type = 'application/octet_stream' ;
542
542
const { obj_id } = await rpc_client . object . create_object_upload ( { bucket, key : version_key , content_type } ) ;
543
543
await rpc_client . object . complete_object_upload ( { obj_id, bucket, key : version_key } ) ;
544
544
545
- // everything but last will be aged
546
- if ( i < version_count - 1 ) {
545
+ // everything but last will be aged,
546
+ // For simple Expiration rule all version should be expired
547
+ if ( expire_all || i < version_count - 1 ) {
547
548
obj_upload_ids . push ( new mongodb . ObjectId ( obj_id ) ) ;
548
549
}
549
550
}
@@ -557,6 +558,41 @@ mocha.describe('lifecycle', () => {
557
558
console . log ( 'blow_version_objects: update_objects_by_ids' , update_result ) ;
558
559
}
559
560
}
561
+
562
+ mocha . it ( 'lifecyle - version object expired' , async ( ) => {
563
+ const age = 30 ;
564
+ const version_count = 10 ;
565
+ const version_bucket_key = 'test-lifecycle-version1' ;
566
+ await create_mock_version ( version_bucket_key , version_bucket , age , version_count , true ) ;
567
+ const putLifecycleParams = commonTests . days_lifecycle_configuration ( version_bucket , version_bucket_key ) ;
568
+ await s3 . putBucketLifecycleConfiguration ( putLifecycleParams ) ;
569
+ await lifecycle . background_worker ( ) ;
570
+ // version_count count only, not deleted
571
+ await verify_version_deleted ( version_count + 1 , version_bucket_key ) ;
572
+ } ) ;
573
+
574
+ mocha . it ( 'lifecyle - version object not expired' , async ( ) => {
575
+ const age = 5 ;
576
+ const version_count = 10 ;
577
+ const version_bucket_key = 'test-lifecycle-version2' ;
578
+ await create_mock_version ( version_bucket_key , version_bucket , age , version_count , true ) ;
579
+ const putLifecycleParams = commonTests . days_lifecycle_configuration ( version_bucket , version_bucket_key ) ;
580
+ await s3 . putBucketLifecycleConfiguration ( putLifecycleParams ) ;
581
+ await lifecycle . background_worker ( ) ;
582
+ // version_count count plus delete marker
583
+ await verify_version_deleted ( version_count , version_bucket_key ) ;
584
+ } ) ;
585
+
586
+ async function verify_version_deleted ( expected_length , key ) {
587
+ const obj_params = {
588
+ bucket : version_bucket ,
589
+ prefix : key ,
590
+ } ;
591
+ const list_obj = await rpc_client . object . list_object_versions ( obj_params ) ;
592
+ console . log ( 'list_objects_admin objects: ' , util . inspect ( list_obj . objects ) ) ;
593
+ const actual_length = list_obj . objects . length ;
594
+ assert . strictEqual ( actual_length , expected_length , `listObjectResult actual ${ actual_length } !== ${ expected_length } ` ) ;
595
+ }
560
596
} ) ;
561
597
562
598
function readable_buffer ( data , split = 1 , finish = 'end' ) {
0 commit comments