2020-09-11 03:37:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe Jobs::EnsureS3UploadsExistence do
|
2023-06-21 22:00:19 +08:00
|
|
|
subject(:job) { described_class.new }
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
context "with S3 inventory enabled" do
|
2020-09-11 03:37:42 +08:00
|
|
|
before do
|
2020-09-14 19:32:25 +08:00
|
|
|
setup_s3
|
2020-09-11 03:37:42 +08:00
|
|
|
SiteSetting.enable_s3_inventory = true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "works" do
|
|
|
|
S3Inventory.any_instance.expects(:backfill_etags_and_list_missing).once
|
2023-06-21 22:00:19 +08:00
|
|
|
job.execute({})
|
2020-09-11 03:37:42 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't execute when the site was restored within the last 48 hours" do
|
|
|
|
S3Inventory.any_instance.expects(:backfill_etags_and_list_missing).never
|
|
|
|
BackupMetadata.update_last_restore_date(47.hours.ago)
|
|
|
|
|
2023-06-21 22:00:19 +08:00
|
|
|
job.execute({})
|
2020-09-11 03:37:42 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "executes when the site was restored more than 48 hours ago" do
|
|
|
|
S3Inventory.any_instance.expects(:backfill_etags_and_list_missing).once
|
|
|
|
BackupMetadata.update_last_restore_date(49.hours.ago)
|
|
|
|
|
2023-06-21 22:00:19 +08:00
|
|
|
job.execute({})
|
2020-09-11 03:37:42 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
context "with S3 inventory disabled" do
|
2020-09-11 03:37:42 +08:00
|
|
|
before { SiteSetting.enable_s3_inventory = false }
|
|
|
|
|
|
|
|
it "doesn't execute" do
|
|
|
|
S3Inventory.any_instance.expects(:backfill_etags_and_list_missing).never
|
2023-06-21 22:00:19 +08:00
|
|
|
job.execute({})
|
2020-09-11 03:37:42 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|