Skip to content

Commit

Permalink
WIP: [service] More robust transport and bus checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorgs committed Apr 1, 2024
1 parent 70159c6 commit 4a7a434
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
8 changes: 4 additions & 4 deletions service/lib/agama/dbus/storage/interfaces/device/drive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ def drive_model
#
# @return [String]
def drive_bus
# FIXME: not sure how robust this is (is the value always in English?)
return "" if storage_device.bus.casecmp?("none")
# FIXME: not sure whether checking for "none" is robust (is the value always in English?)
return "" if storage_device.bus.nil? || storage_device.bus.casecmp?("none")

storage_device.bus || ""
storage_device.bus
end

# Bus Id for DASD
Expand All @@ -114,7 +114,7 @@ def drive_transport
return "" unless storage_device.respond_to?(:transport)

transport = storage_device.transport
return "" if transport.is?(:unknown)
return "" if transport.nil? || transport.is?(:unknown)

# FIXME: transport does not have proper i18n support at yast2-storage-ng, so we are
# just duplicating some logic from yast2-storage-ng here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,29 @@
allow(device).to receive(:transport).and_return(transport)
end

let(:transport) { instance_double(Y2Storage::DataTransport, to_s: "usb") }
let(:transport) { Y2Storage::DataTransport::FCOE }

it "returns the transport" do
expect(subject.drive_transport).to eq("usb")
expect(subject.drive_transport).to eq("fcoe")
end

context "if transport is unknown" do
context "if transport is Unknown" do
let(:transport) { Y2Storage::DataTransport::UNKNOWN }

it "returns an empty string" do
expect(subject.drive_transport).to eq("")
end
end

context "if transport is USB" do
let(:transport) { Y2Storage::DataTransport::USB }

it "returns the corresponding string" do
expect(subject.drive_transport).to eq("USB")
end
end

context "if transport is missing" do
let(:transport) { nil }

it "returns an empty string" do
Expand Down

0 comments on commit 4a7a434

Please sign in to comment.