Skip to content

Commit

Permalink
WIP: Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BasilMawejje committed Aug 25, 2021
1 parent 953933a commit 16f12dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 9 additions & 1 deletion app/models/conditions_response/backup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,15 @@ def self.iterate_and_log_notify_errors(list, additional_error_info, log, use_sla


STORAGE_CLASSES = %w(STANDARD_IA GLACIER DEEP_ARCHIVE)
define_method(:storage_class_is_valid?) {|storage_class_list| !(storage_class_list & STORAGE_CLASSES).empty? ? true : "Invalid storage class"}
class << self
define_method(:storage_class_is_valid?) do |storage_class_list|
unless storage_class_list.empty?
(storage_class_list + STORAGE_CLASSES).uniq.count <= STORAGE_CLASSES.count ? true : "Invalid storage class"
else
"Empty storage class"
end
end
end

# method signature => s3_lifecycle_rules(string, string, string, {days: integer, storage_class: upcase string in STORAGE_CLASSES list})
# e.g s3_lifecycle_rules('bucket', 'bucket_full_prefix', 'enabled', {days: 30, storage_class: "STANDARD_IA"}, {days: 90, storage_class: "GLACIER"})
Expand Down
16 changes: 14 additions & 2 deletions spec/models/conditions_response/backup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1306,11 +1306,23 @@ def create_faux_backup_file(backups_dir, file_prefix)
end

describe 's3_lifecycle_rules(bucket, bucket_full_prefix, status, *storage_rules_kwargs)' do
it "returns 'Invalid storage class' for invalid storage classes" do
binding.pry
let(:invalid_storage_class_list) { ["INVALID_STORAGE_CLASS", "OTHER_INVALID_STORAGE_CLASS"] }
let(:another_invalid_storage_class_list) { ["INVALID_STORAGE_CLASS", "STANDARD_IA", "GLACIER"] }

it "returns 'Invalid storage class' for a list containing only invalid storage classes" do
expect(described_class.storage_class_is_valid? invalid_storage_class_list).to eq("Invalid storage class")
end

it "returns 'Invalid storage class' for a list containing both valid and invalid storage classes" do
expect(described_class.storage_class_is_valid? another_invalid_storage_class_list).to eq("Invalid storage class")
end

it "fails for empty storage classes list" do
expect(described_class.storage_class_is_valid? []).to eq("Empty storage class")
end

it 'returns the correct lifecycle rules transitions' do
#TODO: Add this test
end
end
end
Expand Down

0 comments on commit 16f12dd

Please sign in to comment.