Skip to content

Commit

Permalink
Return more safety when no product is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Mar 13, 2018
1 parent 3024803 commit 9b9e26f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/registration/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def offline_migration_products(installed_products, target_base_product)
# @see SUSE::Connect::Yast.list_installer_updates
def get_updates_list
product = SwMgmt.base_product_to_register
return [] unless product
id = Yast::ProductFeatures.GetStringFeature("globals", "self_update_id")
if !id.empty?
log.info "Using self update id from control file #{id.inspect}"
Expand Down
2 changes: 2 additions & 0 deletions src/lib/registration/sw_mgmt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ def self.base_product_to_register
# use FAKE_BASE_PRODUCT just for debugging
base_product = ENV["FAKE_BASE_PRODUCT"] ? FAKE_BASE_PRODUCT : find_base_product

return unless base_product

# filter out not needed data
product_info = {
"name" => base_product["name"],
Expand Down
5 changes: 5 additions & 0 deletions test/registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@
.and_return(updates)
expect(subject.get_updates_list).to eq(updates)
end

it "returns an empty list if no base product is selected" do
allow(Registration::SwMgmt).to receive(:base_product_to_register).and_return(nil)
expect(subject.get_updates_list).to eq([])
end
end

describe "#synchronize_products" do
Expand Down
6 changes: 6 additions & 0 deletions test/sw_mgmt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@
end

describe ".base_product_to_register" do
it "returns nil if not able to find a product" do
expect(subject).to receive(:find_base_product).and_return(nil)

expect(subject.base_product_to_register).to eq(nil)
end

it "returns base product base version and release_type" do
expect(subject).to(receive(:find_base_product)
.and_return("name" => "SLES", "arch" => "x86_64",
Expand Down

0 comments on commit 9b9e26f

Please sign in to comment.