Skip to content

Commit

Permalink
Log a message when profile has not valid sofware section
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Feb 22, 2019
1 parent f8a95af commit a4fda81
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
11 changes: 8 additions & 3 deletions src/modules/AutoinstFunctions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,15 @@ def identify_product_by_selection(profile)
# @param profile [Hash] AutoYaST profile
# @return [String] product name
def base_product_name(profile)
software = profile["software"] || {}
products = software["products"] || []
software = profile["software"]

if software.nil?
log.info("Error: given profile has not a valid `software` section")

return nil
end

products.first
software.fetch("products", []).first
end
end

Expand Down
21 changes: 15 additions & 6 deletions test/AutoinstFunctions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,22 @@ def base_product(name)

expect(subject.selected_product.name).to eql "SLED"
end
end
context "when there is not a valis software section" do
before do
allow(Yast::Profile)
.to receive(:current)
.and_return("software" => nil)
end

it "does not crash when there is not a software section" do
allow(Yast::Profile)
.to receive(:current)
.and_return("software" => nil)
it "returns nil" do
expect(subject.selected_product).to be_nil
end

it "logs a message" do
expect(subject.log).to receive(:info).at_least(1).with(/not a valid/)

expect(subject.selected_product).to be_nil
subject.selected_product
end
end
end
end

0 comments on commit a4fda81

Please sign in to comment.