Skip to content

Commit

Permalink
Merge 49dd09d into 12e4859
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Jan 27, 2021
2 parents 12e4859 + 49dd09d commit 71338c3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/lib/y2network/interfaces_collection.rb
Expand Up @@ -83,9 +83,10 @@ def by_busid(busid)

# Returns list of interfaces of given type
#
# @param type [InterfaceType] device type
# @param type [InterfaceType,String,Symbol] device type or its short name
# @return [InterfacesCollection] list of found interfaces
def by_type(type)
type = InterfaceType.from_short_name(type.to_s) unless type.is_a?(InterfaceType)
InterfacesCollection.new(interfaces.select { |i| i.type == type })
end

Expand Down
34 changes: 32 additions & 2 deletions test/y2network/interfaces_collection_test.rb
Expand Up @@ -26,8 +26,12 @@
subject(:collection) { described_class.new(interfaces) }

let(:eth0) { Y2Network::PhysicalInterface.new("eth0") }
let(:br0) { Y2Network::VirtualInterface.new("br0") }
let(:wlan0) { Y2Network::PhysicalInterface.new("wlan0") }
let(:br0) do
Y2Network::VirtualInterface.new("br0", type: Y2Network::InterfaceType::BRIDGE)
end
let(:wlan0) do
Y2Network::PhysicalInterface.new("wlan0", type: Y2Network::InterfaceType::WIRELESS)
end
let(:interfaces) { [eth0, br0, wlan0] }

describe "#by_name" do
Expand All @@ -52,6 +56,32 @@
end
end

describe "#by_type" do
context "when an InterfaceType instance is given" do
it "returns a collection containing the interfaces with the given type" do
by_type = collection.by_type(Y2Network::InterfaceType::WIRELESS)
expect(by_type.to_a).to eq([wlan0])
expect(by_type).to be_a(described_class)
end
end

context "when type's shortname is given as string" do
it "returns a collection containing the interfaces with the given type" do
by_type = collection.by_type("br")
expect(by_type.to_a).to eq([br0])
expect(by_type).to be_a(described_class)
end
end

context "when type's shortname is given as symbol" do
it "returns a collection containing the interfaces with the given type" do
by_type = collection.by_type(:eth)
expect(by_type.to_a).to eq([eth0])
expect(by_type).to be_a(described_class)
end
end
end

describe "#push" do
let(:wlan1) { Y2Network::PhysicalInterface.new("wlan1") }

Expand Down

0 comments on commit 71338c3

Please sign in to comment.