Skip to content

Commit

Permalink
cleanup testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Nov 28, 2024
1 parent bbc87d5 commit 078bde4
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 81 deletions.
13 changes: 7 additions & 6 deletions test/bls_sections_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require_relative "./test_helper"

require "bootloader/bls_sections"
require "bootloader/bls"
require "cfa/memory_file"

describe Bootloader::BlsSections do
Expand All @@ -16,8 +17,7 @@
.with("/usr/bin/bootctl", "--json=short", "list", stdout: :capture)
.and_return("[{\"title\" : \"openSUSE Tumbleweed\", \"isDefault\" : true }," \
"{\"title\" : \"Snapper: *openSUSE Tumbleweed 20241107\", \"isDefault\" : false}]")
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "get-default", stdout: :capture)
allow(Bootloader::Bls).to receive(:default_menu)
.and_return("openSUSE Tumbleweed")

subject.read
Expand Down Expand Up @@ -48,15 +48,16 @@
describe "#write" do
it "writes default value if set" do
subject.default = "Snapper: *openSUSE Tumbleweed 20241107"
expect(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "set-default", subject.default)
expect(Bootloader::Bls).to receive(:write_default_menu)
.with(subject.default)

subject.write
end

it "does not write default value if not set" do
subject.default = ""
expect(Yast::Execute).to_not receive(:on_target!)
.with("/usr/bin/sdbootutil", "set-default", subject.default)
expect(Bootloader::Bls).to_not receive(:write_default_menu)

subject.write
end

Expand Down
59 changes: 59 additions & 0 deletions test/bls_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

require_relative "test_helper"

describe Bootloader::Bls do
subject = described_class

describe "#create_menu_entries" do
it "calls sdbootutil add-all-kernels" do
expect(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "add-all-kernels")
subject.create_menu_entries
end
end

describe "#install_bootloader" do
it "calls sdbootutil install" do
expect(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "install")
subject.install_bootloader
end
end

describe "#write_menu_timeout" do
it "calls sdbootutil set-timeout" do
expect(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "set-timeout",
10)
subject.write_menu_timeout(10)
end
end

describe "#menu_timeout" do
it "calls sdbootutil get-timeout" do
expect(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "get-timeout", stdout: :capture)
.and_return(10)
expect(subject.menu_timeout).to eq 10
end
end

describe "#write_default_menu" do
it "calls sdbootutil set-default" do
expect(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "set-default", "openSUSE")
subject.write_default_menu("openSUSE")
end
end

describe "#default_menu" do
it "calls sdbootutil get-default" do
expect(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "get-default", stdout: :capture)
.and_return("openSUSE")
expect(subject.default_menu).to eq "openSUSE"
end
end

end
88 changes: 47 additions & 41 deletions test/grub2_bls_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require_relative "test_helper"

require "bootloader/bls"
require "bootloader/grub2bls"

describe Bootloader::Grub2Bls do
Expand All @@ -15,16 +15,14 @@

before do
allow(Yast::Arch).to receive(:architecture).and_return("x86_64")
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "get-default", stdout: :capture)
.and_return("openSUSE Tumbleweed")
allow(Bootloader::Bls).to receive(:default_menu)
.and_return(subject.sections.default)
end

describe "#read" do
before do
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "get-timeout", stdout: :capture)
.and_return("10")
allow(Bootloader::Bls).to receive(:menu_timeout)
.and_return(10)
allow(Yast::Installation).to receive(:destdir).and_return(destdir)
end

Expand All @@ -50,40 +48,52 @@
subject.grub_default.timeout = 10
end

it "setups protective mbr to real disks containing /boot/efi" do
subject.pmbr_action = :add
allow(Bootloader::Bls).to receive(:default_menu)
.and_return(subject.sections.default)
allow(Bootloader::Bls).to receive(:write_default_menu)
.with(subject.sections.default)
allow(Bootloader::Bls).to receive(:menu_timeout)
.and_return(subject.grub_default.timeout)
allow(Bootloader::Bls).to receive(:write_menu_timeout)
.with(subject.grub_default.timeout)
allow(Bootloader::Bls).to receive(:create_menu_entries)
allow(Bootloader::Bls).to receive(:install_bootloader)
allow(Yast::BootStorage).to receive(:gpt_boot_disk?).and_return(true)

expect(Yast::Execute).to receive(:locally)
.with("/usr/sbin/parted", "-s", "/dev/sda", "disk_set", "pmbr_boot", "on")

subject.write
end

it "installs the bootloader" do
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "set-timeout",
subject.grub_default.timeout)
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "set-default", subject.sections.default)
allow(Bootloader::Bls).to receive(:write_default_menu)
.with(subject.sections.default)
allow(Bootloader::Bls).to receive(:write_menu_timeout)
.with(subject.grub_default.timeout)

# install bootloader
expect(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "install")
expect(Bootloader::Bls).to receive(:install_bootloader)

# create menu entries
expect(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "add-all-kernels")
expect(Bootloader::Bls).to receive(:create_menu_entries)

subject.write
end

it "writes kernel cmdline" do
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "get-default", stdout: :capture)
.and_return("openSUSE Tumbleweed")
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "get-timeout", stdout: :capture)
.and_return(10)
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "set-timeout",
subject.grub_default.timeout)
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "set-default", subject.sections.default)
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "install")
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "add-all-kernels")
allow(Bootloader::Bls).to receive(:default_menu)
.and_return(subject.sections.default)
allow(Bootloader::Bls).to receive(:write_default_menu)
.with(subject.sections.default)
allow(Bootloader::Bls).to receive(:menu_timeout)
.and_return(subject.grub_default.timeout)
allow(Bootloader::Bls).to receive(:write_menu_timeout)
.with(subject.grub_default.timeout)
allow(Bootloader::Bls).to receive(:create_menu_entries)
allow(Bootloader::Bls).to receive(:install_bootloader)

subject.write
# Checking written kernel parameters
Expand All @@ -93,17 +103,13 @@
end

it "saves menu timeout" do
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "set-default", subject.sections.default)
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "install")
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "add-all-kernels")

allow(Bootloader::Bls).to receive(:create_menu_entries)
allow(Bootloader::Bls).to receive(:install_bootloader)
allow(Bootloader::Bls).to receive(:write_default_menu)
.with(subject.sections.default)
# Saving menu timeout
expect(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "set-timeout",
subject.grub_default.timeout)
expect(Bootloader::Bls).to receive(:write_menu_timeout)
.with(subject.grub_default.timeout)
subject.write
end
end
Expand Down
55 changes: 21 additions & 34 deletions test/systemdboot_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_relative "test_helper"

require "bootloader/bls"
require "bootloader/systemdboot"

describe Bootloader::SystemdBoot do
Expand All @@ -17,12 +18,10 @@
allow(Yast::BootStorage).to receive(:available_swap_partitions).and_return([])
allow(Yast::Arch).to receive(:architecture).and_return("x86_64")
allow(Yast::Package).to receive(:Available).and_return(true)
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "get-timeout", stdout: :capture)
.and_return(10)
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "set-timeout",
subject.menu_timeout)
allow(Bootloader::Bls).to receive(:menu_timeout)
.and_return(subject.menu_timeout)
allow(Bootloader::Bls).to receive(:write_menu_timeout)
.with(subject.menu_timeout)
end

describe "#read" do
Expand Down Expand Up @@ -55,27 +54,20 @@
end

it "installs the bootloader" do
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "set-timeout",
subject.menu_timeout)
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "add-all-kernels")

allow(Bootloader::Bls).to receive(:write_menu_timeout)
.with(subject.menu_timeout)
allow(Bootloader::Bls).to receive(:create_menu_entries)
# install bootloader
expect(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "install")
expect(Bootloader::Bls).to receive(:install_bootloader)

subject.write
end

it "writes kernel cmdline" do
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "set-timeout",
subject.menu_timeout)
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "install")
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "add-all-kernels")
allow(Bootloader::Bls).to receive(:write_menu_timeout)
.with(subject.menu_timeout)
allow(Bootloader::Bls).to receive(:create_menu_entries)
allow(Bootloader::Bls).to receive(:install_bootloader)

subject.write
# Checking written kernel parameters
Expand All @@ -85,28 +77,23 @@
end

it "creates menu entries" do
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "set-timeout",
subject.menu_timeout)
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "install")
allow(Bootloader::Bls).to receive(:write_menu_timeout)
.with(subject.menu_timeout)
allow(Bootloader::Bls).to receive(:install_bootloader)

# create menu entries
expect(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "add-all-kernels")
expect(Bootloader::Bls).to receive(:create_menu_entries)

subject.write
end

it "saves menu timeout" do
allow(Bootloader::Bls).to receive(:create_menu_entries)
allow(Bootloader::Bls).to receive(:install_bootloader)

# Saving menu timeout
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "add-all-kernels")
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "install")
expect(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "set-timeout", subject.menu_timeout)
expect(Bootloader::Bls).to receive(:write_menu_timeout)
.with(subject.menu_timeout)

subject.write
end
Expand Down

0 comments on commit 078bde4

Please sign in to comment.