From 15eaa13a52c54b57092ccb85510175468208083e Mon Sep 17 00:00:00 2001 From: Jerry Keselman Date: Fri, 1 Mar 2019 10:59:49 -0500 Subject: [PATCH] Add verify_file_depot tests Add tests to validate that MiqSchedule.verify_file_depot does the right thing with regard to calling FileDepot.merged_uri. --- spec/factories/file_depot.rb | 4 ++++ spec/models/miq_schedule_spec.rb | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/spec/factories/file_depot.rb b/spec/factories/file_depot.rb index c3f765acd082..685ee6978612 100644 --- a/spec/factories/file_depot.rb +++ b/spec/factories/file_depot.rb @@ -5,7 +5,11 @@ end factory(:file_depot_ftp, :class => "FileDepotFtp", :parent => :file_depot) { uri { "ftp://somehost/export" } } + factory(:file_depot_swift, :class => "FileDepotSwift", :parent => :file_depot) { uri { "swift://swifthost/swiftbucket" } } factory :file_depot_ftp_with_authentication, :parent => :file_depot_ftp do after(:create) { |x| x.authentications << FactoryBot.create(:authentication) } end + factory :file_depot_swift_with_authentication, :parent => :file_depot_swift do + after(:create) { |x| x.authentications << FactoryBot.create(:authentication) } + end end diff --git a/spec/models/miq_schedule_spec.rb b/spec/models/miq_schedule_spec.rb index 42ea322bde54..de4c24dfbcf0 100644 --- a/spec/models/miq_schedule_spec.rb +++ b/spec/models/miq_schedule_spec.rb @@ -690,6 +690,24 @@ expect(FileDepot.count).to eq(1) expect(MiqSchedule.count).to eq(0) end + + let(:swift_file_depot) { FactoryBot.create(:file_depot_swift_with_authentication) } + let(:swift_params) { {:uri_prefix => "swift", :uri => "swift://swift.example.com/test_depot", :name => "Test Backup Swift Depot", :username => "user", :password => "password"} } + let(:swift_run_at) { {:interval => {:value => "1", :unit => "hourly"}, :start_time => "2012-03-10 01:35:00 Z", :tz => "Central Time (US & Canada)"} } + + it "does not merge the swift uri if the port is blank" do + swift_schedule = FactoryBot.create(:miq_schedule_validation, :run_at => swift_run_at, :file_depot => swift_file_depot, :sched_action => {:method => "db_backup"}, :resource_type => "DatabaseBackup") + swift_schedule.verify_file_depot(swift_params.merge(:save => true)) + expect(swift_schedule.file_depot.uri).to eq (swift_params[:uri]) + end + + it "merges the swift uri and port if the port is specified" do + another_swift_schedule = FactoryBot.create(:miq_schedule_validation, :run_at => swift_run_at, :file_depot => swift_file_depot, :sched_action => {:method => "db_backup"}, :resource_type => "DatabaseBackup") + swift_api_port = 5000 + merged_uri = "swift://swift.example.com:5000/test_depot" + another_swift_schedule.verify_file_depot(swift_params.merge(:swift_api_port => swift_api_port, :save => true)) + expect(another_swift_schedule.file_depot.uri).to eq (merged_uri) + end end describe ".updated_since" do