@@ -562,13 +562,31 @@ test_that("BackupQueueIndex: $prune_identical works", {
562562
563563
564564
565+ test_that(" BackupQueueIndex: rotations trigger as expected" , {
566+ dir.create(td , recursive = TRUE )
567+ on.exit(unlink(td , recursive = TRUE ))
568+
569+ tf <- file.path(td , " test" )
570+ saveRDS(iris , tf )
571+ on.exit(unlink(tf ), add = TRUE )
572+ bq <- BackupQueueIndex $ new(tf )
573+
574+ # size threshold is not met
575+ expect_false(bq $ should_rotate(size = file.size(tf ) + 1 ))
576+
577+ # size threshold is met
578+ expect_true(bq $ should_rotate(size = file.size(tf ) / 2 ))
579+ })
580+
581+
582+
565583# BackupQueueDateTime -----------------------------------------------------
566584context(" BackupQueueDateTime" )
567585
568586
569587
570588
571- test_that(" BackupQueueDatetime: backups_cache " , {
589+ test_that(" BackupQueueDatetime: Caching the last rotation date works (cache_backups = TRUE) " , {
572590 dir.create(td , recursive = TRUE )
573591 on.exit(unlink(td , recursive = TRUE ))
574592
@@ -945,6 +963,31 @@ test_that("BackupQueueDateTime: $should_rotate(verbose = TRUE) displays helpful
945963
946964
947965
966+ test_that(" BackupQueueDateTime: rotations trigger as expected" , {
967+ dir.create(td , recursive = TRUE )
968+ on.exit(unlink(td , recursive = TRUE ))
969+
970+ tf <- file.path(td , " test" )
971+ saveRDS(iris , tf )
972+ on.exit(unlink(tf ), add = TRUE )
973+ bq <- BackupQueueDateTime $ new(tf )
974+
975+ fake_time <- as.POSIXct(" 2020-01-01 01:00:00" )
976+
977+ # neither age nor size threshold is met
978+ expect_false(bq $ should_rotate(size = file.size(tf ) + 1 , age = Inf ))
979+
980+ # size threshold is met but not age
981+ expect_false(bq $ should_rotate(size = file.size(tf ) / 2 , age = " 2 days" , now = as.POSIXct(" 2020-01-01 02:00:00" ), last_rotation = fake_time ))
982+
983+ # age threshold is met but not size
984+ expect_false(bq $ should_rotate(size = file.size(tf ) + 1 , age = " 2 days" , now = as.POSIXct(" 2020-01-04 02:00:00" ), last_rotation = fake_time ))
985+
986+ # both criteria are met
987+ expect_true(bq $ should_rotate(size = file.size(tf ) / 2 , age = " 2 days" , now = as.POSIXct(" 2020-01-06 02:00:00" ), last_rotation = fake_time ))
988+ })
989+
990+
948991# BackupQueueDate ---------------------------------------------------------
949992context(" BackupQueueDate" )
950993
@@ -1342,6 +1385,31 @@ test_that("BackupQueueDate: $should_rotate(verbose = TRUE) displays helpful mess
13421385
13431386
13441387
1388+ test_that(" BackupQueueDate: rotations trigger as expected" , {
1389+ dir.create(td , recursive = TRUE )
1390+ on.exit(unlink(td , recursive = TRUE ))
1391+
1392+ tf <- file.path(td , " test" )
1393+ saveRDS(iris , tf )
1394+ on.exit(unlink(tf ), add = TRUE )
1395+ bq <- BackupQueueDate $ new(tf )
1396+
1397+ fake_time <- as.POSIXct(" 2020-01-01 01:00:00" )
1398+
1399+ # neither age nor size threshold is met
1400+ expect_false(bq $ should_rotate(size = file.size(tf ) + 1 , age = Inf ))
1401+
1402+ # size threshold is met but not age
1403+ expect_false(bq $ should_rotate(size = file.size(tf ) / 2 , age = " 2 days" , now = as.POSIXct(" 2020-01-01 02:00:00" ), last_rotation = fake_time ))
1404+
1405+ # age threshold is met but not size
1406+ expect_false(bq $ should_rotate(size = file.size(tf ) + 1 , age = " 2 days" , now = as.POSIXct(" 2020-01-04 02:00:00" ), last_rotation = fake_time ))
1407+
1408+ # both criteria are met
1409+ expect_true(bq $ should_rotate(size = file.size(tf ) / 2 , age = " 2 days" , now = as.POSIXct(" 2020-01-06 02:00:00" ), last_rotation = fake_time ))
1410+ })
1411+
1412+
13451413# cleanup -----------------------------------------------------------------
13461414
13471415test_that(" BackupQueue: all cleanup succesfull" , {
0 commit comments