Skip to content

Commit

Permalink
Removed profile sections convenience methods
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed May 28, 2020
1 parent ae899be commit dd147c7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 69 deletions.
2 changes: 1 addition & 1 deletion src/clients/inst_autosetup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def main
AutoinstSoftware.merge_product(AutoinstFunctions.selected_product)

# configure general settings
general_section = profile_section("general")
general_section = Profile.current["general"] || {}
AutoinstGeneral.Import(general_section)
log.info("general: #{general_section}")
AutoinstGeneral.Write
Expand Down
27 changes: 4 additions & 23 deletions src/lib/autoinstall/autosetup_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def suse_register
#
# @return [Boolean]
def semi_auto?(name)
!!profile_section("general")["semi-automatic"]&.include?(name)
general_section = Yast::Profile.current["general"] || {}
!!general_section["semi-automatic"]&.include?(name)
end

# Autosetup the network
Expand Down Expand Up @@ -154,29 +155,9 @@ def autosetup_network
def network_before_proposal?
return @network_before_proposal unless @network_before_proposal.nil?

@network_before_proposal = profile_section("networking").fetch("setup_before_proposal", false)
end

# Convenience method to fetch the content of the given section name from
# the current {Yast::Profile}
#
# @note not all the sections are expected to return a hash like the
# partitioning one; in these cases please avoid to use it
#
# @param name [String] section name to be fetched from the profile
# @return [Hash] the profile section with the given name when present;
# an empty hash when not
def profile_section(name)
Yast::Profile.current[name] || {}
end
networking_section = Yast::Profile.current["networking"] || {}

# Convenience method to check whether the current {Yast::Profile} contains
# a specific section
#
# @param name [String] profile section name
# @return [Boolean] true when the section is present; false when not
def profile_section?(name)
Yast::Profile.current.key?(name)
@network_before_proposal = networking_section.fetch("setup_before_proposal", false)
end

private
Expand Down
45 changes: 0 additions & 45 deletions test/lib/autosetup_helpers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,51 +297,6 @@ class DummyClient < Yast::Client
end
end

describe "#profile_section" do
let(:profile) { general_section }
let(:general_section) { { "general" => { "semi-automatic" => ["networking"] } } }
let(:register_section) { { "suse_register" => { "reg_code" => "12345" } } }

before do
Yast::Profile.current = profile
end

context "when the profile contains the given section" do
it "returns it" do
expect(client.profile_section("general")).to eql(general_section["general"])
end
end

context "when the profile does not contain the given section" do
let(:profile) { register_section }
it "returns and empty hash" do
expect(client.profile_section("general")).to eql({})
end
end
end

describe "#profile_section?" do
let(:profile) { { "general" => { "semi-automatic" => ["networking"] } } }

before do
Yast::Profile.current = profile
end

context "when the profile contains the given section" do
it "returns true" do
expect(client.profile_section?("general")).to eql(true)
end
end

context "when the profile does not contain the given section" do
let(:profile) { { "suse_register" => { "reg_code" => "12345" } } }

it "returns false" do
expect(client.profile_section?("general")).to eql(false)
end
end
end

describe "#semi_auto?" do
let(:profile) { general_section }
let(:general_section) { { "general" => { "semi-automatic" => ["networking"] } } }
Expand Down

0 comments on commit dd147c7

Please sign in to comment.