Skip to content

Commit

Permalink
Merge pull request #18497 from jerryk55/refix_merged_uri
Browse files Browse the repository at this point in the history
default merged_uri should return the parameter not the attribute
  • Loading branch information
roliveri authored Mar 5, 2019
2 parents ae3965e + f1e0d16 commit c9ae719
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/models/file_depot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def upload_file(file)
@file = file
end

def merged_uri(_uri, _api_port)
def merged_uri(uri, _api_port)
uri
end
end
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
4 changes: 2 additions & 2 deletions spec/models/file_depot_ftp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ def putbinaryfile(local_path, remote_path)
file_depot_ftp.uri = uri
end

it "should return the uri attribute from the file depot object and ignore the parameter" do
expect(file_depot_ftp.merged_uri(nil, nil)).to eq uri
it "should ignore the uri attribute from the file depot object and return the parameter" do
expect(file_depot_ftp.merged_uri(nil, nil)).to eq nil
end
end
end
12 changes: 4 additions & 8 deletions spec/models/file_depot_nfs_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe FileDepotNfs do
let(:uri) { "nfs://foo.com/directory" }
let(:swift_uri) { "swift://foo_bucket/doo_directory" }
let(:uri) { "nfs://ignore.com/directory" }
let(:actual_uri) { "nfs://actual_bucket/doo_directory" }
let(:file_depot_nfs) { FileDepotNfs.new(:uri => uri) }

it "should return a valid prefix" do
Expand All @@ -12,12 +12,8 @@
file_depot_nfs.uri = uri
end

it "should return the uri set on the depot object and ignore the uri parameter" do
expect(file_depot_nfs.merged_uri(swift_uri, nil)).to eq uri
end

it "should return the uri set on the depot object and ignore an empty uri parameter" do
expect(file_depot_nfs.merged_uri(nil, nil)).to eq uri
it "should ignore the uri set on the depot object and return the uri parameter" do
expect(file_depot_nfs.merged_uri(actual_uri, nil)).to eq actual_uri
end
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 c9ae719

Please sign in to comment.