Skip to content

Commit

Permalink
Merge 304569e into 9aa07b9
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Sep 14, 2018
2 parents 9aa07b9 + 304569e commit 89ce450
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/lib/bootloader/sections.rb
Expand Up @@ -52,9 +52,11 @@ def write
# or something goes wrong
# @note shows error popup if calling grub2-editenv failed
def read_default
# Execute.on_target can return nil if call failed. It shows users error popup, but bootloader
# can continue with empty default section
saved = Yast::Execute.on_target("/usr/bin/grub2-editenv", "list", stdout: :capture) || ""
saved = Yast::SCR.Execute(
Yast::Path.new(".target.bash_output"),
"/usr/bin/grub2-editenv list"
)
saved = saved["exit"] == 0 ? saved["stdout"] : ""
saved_line = saved.lines.grep(/saved_entry=/).first || ""

default_path = saved_line[/saved_entry=(.*)$/, 1]
Expand Down
12 changes: 6 additions & 6 deletions test/sections_test.rb
Expand Up @@ -24,17 +24,17 @@

describe "#default" do
it "gets name of default section stored in grub2" do
expect(Yast::Execute).to receive(:on_target)
.with("/usr/bin/grub2-editenv", "list", stdout: :capture)
.and_return("saved_entry=alien>windows\nbla_bla=no\n")
expect(Yast::SCR).to receive(:Execute)
.with(anything, "/usr/bin/grub2-editenv list")
.and_return("exit" => 0, "stdout" => "saved_entry=alien>windows\nbla_bla=no\n")

expect(subject.default).to eq "windows"
end

it "gets first section if nothing stored in grub2" do
expect(Yast::Execute).to receive(:on_target)
.with("/usr/bin/grub2-editenv", "list", stdout: :capture)
.and_return("\n")
expect(Yast::SCR).to receive(:Execute)
.with(anything, "/usr/bin/grub2-editenv list")
.and_return("exit" => 0, "stdout" => "\n")

expect(subject.default).to eq "linux"
end
Expand Down

0 comments on commit 89ce450

Please sign in to comment.