Skip to content

Commit

Permalink
Add verify_file_depot tests
Browse files Browse the repository at this point in the history
Add tests to validate that MiqSchedule.verify_file_depot does the right thing with regard to calling
FileDepot.merged_uri.
  • Loading branch information
jerryk55 committed Mar 1, 2019
1 parent 9a23d86 commit 15eaa13
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spec/factories/file_depot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions spec/models/miq_schedule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 15eaa13

Please sign in to comment.