Skip to content

Commit

Permalink
Fixed unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed May 4, 2023
1 parent 0c0e759 commit a9d1504
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
12 changes: 7 additions & 5 deletions src/lib/y2network/presenters/interface_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,20 @@ def text
if hardware&.name && !hardware.name.empty?
dev_name = _("Device Name: %s") % hardware.name
rich << Yast::HTML.Bold(dev_name) << "<br>"

end

if interface.firmware_configured?
rich << "<p><b>" << _("The device is configured by: ") << "</b>"
rich << interface.firmware_configured_by.to_s << "</p>"
else
unless interface.firmware_configured?
rich << "<p>"
rich << _("The device is not configured. Press <b>Edit</b>\nto configure.\n")
rich << "</p>"
end
end

if interface.firmware_configured?
rich << "<p><b>" << _("The device is configured by: ") << "</b>"
rich << interface.firmware_configured_by.to_s << "</p>"
end

rich
end

Expand Down
10 changes: 6 additions & 4 deletions test/y2network/presenters/interface_summary_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@
let(:interfaces) do
Y2Network::InterfacesCollection.new(
[
double(Y2Network::Interface, hardware: nil, name: "vlan1"),
double(Y2Network::Interface, hardware: double.as_null_object, name: "eth1"),
double(Y2Network::Interface, hardware: double.as_null_object, name: "eth0")
double(Y2Network::Interface, hardware: nil, name: "vlan1", firmware_configured?: false),
double(Y2Network::Interface, hardware: double.as_null_object, name: "eth1",
firmware_configured?: false),
double(Y2Network::Interface, hardware: double.as_null_object, name: "eth0",
firmware_configured?: false)
]
)
end
Expand Down Expand Up @@ -75,7 +77,7 @@
describe "#text" do
it "returns a summary in text form" do
text = presenter.text
expect(text).to be_a(::String)
expect(text).to be_a(String)
end

context "when a remote IP address is configured" do
Expand Down
2 changes: 1 addition & 1 deletion test/y2network/wicked/interfaces_reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
it "reads interfaces configuration"

context "when the interface is configured by hardware" do
let(:firmware_interfaces ) { { :ibft => ["eth0"] } }
let(:firmware_interfaces) { { ibft: ["eth0"] } }

before do
allow(reader).to receive(:firmware_interfaces_by_extension).and_return(firmware_interfaces)
Expand Down
19 changes: 17 additions & 2 deletions test/y2network/widgets/interfaces_table_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@
let(:description) { double(:value= => nil) }

let(:eth0) do
instance_double(Y2Network::Interface, name: "eth0", hardware: hwinfo, old_name: "eth1")
instance_double(Y2Network::Interface, name: "eth0", hardware: hwinfo, old_name: "eth1",
firmware_configured_by: nil, firmware_configured?: false)
end

let(:br0) do
instance_double(Y2Network::VirtualInterface, name: "br0", hardware: nil, old_name: nil)
instance_double(Y2Network::VirtualInterface, name: "br0", hardware: nil, old_name: nil,
firmware_configured_by: nil, firmware_configured?: false)
end
let(:interfaces) { Y2Network::InterfacesCollection.new([eth0, br0]) }
let(:hwinfo) do
Expand Down Expand Up @@ -179,5 +182,17 @@
subject.handle
end
end

context "when the device is configured by hardware" do
let(:eth0) do
instance_double(Y2Network::Interface, name: "eth0", hardware: hwinfo, old_name: "eth1",
firmware_configured_by: :redfish, firmware_configured?: true)
end

it "shows which firmware extension configured the device in the description" do
expect(description).to receive(:value=).with(/configured by: <\/b>redfish/)
subject.handle
end
end
end
end

0 comments on commit a9d1504

Please sign in to comment.