Skip to content

Commit

Permalink
updated testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Apr 25, 2024
1 parent 22ac8ab commit 305ba42
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/lib/bootloader/grub2_widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def store
end

# Represents decision if smt is enabled
class Grub2CpuMitigationsWidget < CpuMitigationsWidget
class GrubCpuMitigationsWidget < CpuMitigationsWidget
include Grub2Helper

def init
Expand Down Expand Up @@ -1012,7 +1012,7 @@ def contents
VBox(
VSpacing(1),
MarginBox(1, 0.5, KernelAppendWidget.new),
MarginBox(1, 0.5, Left(Grub2CpuMitigationsWidget.new)),
MarginBox(1, 0.5, Left(GrubCpuMitigationsWidget.new)),
MarginBox(1, 0.5, console_widget),
VStretch()
)
Expand Down
8 changes: 7 additions & 1 deletion src/lib/bootloader/systemdboot_widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ class SdCpuMitigationsWidget < CpuMitigationsWidget
include SystemdBootHelper

def init
self.value = systemdboot.cpu_mitigations.value.to_s
if systemdboot.respond_to?(:cpu_mitigations)
self.value = systemdboot.cpu_mitigations.value.to_s
else
# do not crash when use no bootloader. This widget is also used in security dialog.
# (bsc#1184968)
disable
end
end

def store
Expand Down
2 changes: 1 addition & 1 deletion test/grub2_widgets_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def stub_widget_value(id, value)
end
end

describe Bootloader::Grub2Widget::Grub2CpuMitigationsWidget do
describe Bootloader::Grub2Widget::GrubCpuMitigationsWidget do
before do
assign_bootloader
end
Expand Down
54 changes: 54 additions & 0 deletions test/systemdboot_widgets_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,60 @@ def stub_widget_value(id, value)
end
end

describe Bootloader::Grub2Widget::SdCpuMitigationsWidget do
before do
assign_bootloader
end

it_behaves_like "labeled widget"
it_behaves_like "CWM::ComboBox"

context "when none bootloader is selected" do
before do
assign_bootloader("none")
end

describe "#init" do
it "disables widget" do
expect(subject).to receive(:disable)

subject.init
end
end

describe "#store" do
it "does nothing on disabled widget" do
expect(subject).to receive(:enabled?).and_return(false)
expect(subject).to_not receive(:value)

subject.store
end
end
end
end

describe Bootloader::Grub2Widget::SdKernelAppendWidget do
before do
assign_bootloader
end

it_behaves_like "labeled widget"

it "is initialized to kernel command line option" do
bootloader.kernel_params.replace("verbose showopts")
expect(subject).to receive(:value=).with("verbose showopts")

subject.init
end

it "stores text as kernel command line option" do
expect(subject).to receive(:value).and_return("showopts quiet")
subject.store

expect(bootloader.kernel_params.serialize).to eq "showopts quiet"
end
end

describe Bootloader::SystemdBootWidget::KernelTab do
before do
assign_systemd_bootloader
Expand Down

0 comments on commit 305ba42

Please sign in to comment.