Skip to content

Commit

Permalink
guests/linux: Always order discovered network interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisroberts committed Aug 12, 2016
1 parent 4b1d45b commit a4a8ab9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/guests/linux/cap/network_interfaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def self.network_interfaces(machine, path = "/sbin/ip")
machine.communicate.sudo("#{path} -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |type, data|
s << data if type == :stdout
end
s.split("\n")
s.split("\n").sort
end
end
end
Expand Down
30 changes: 30 additions & 0 deletions test/unit/plugins/guests/linux/cap/network_interfaces_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require_relative "../../../../base"

describe "VagrantPlugins::GuestLinux::Cap::NetworkInterfaces" do
let(:caps) do
VagrantPlugins::GuestLinux::Plugin
.components
.guest_capabilities[:linux]
end

let(:machine) { double("machine") }
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }

before do
allow(machine).to receive(:communicate).and_return(comm)
end

after do
comm.verify_expectations!
end

describe ".network_interfaces" do
let(:cap){ caps.get(:network_interfaces) }

it "sorts discovered interfaces" do
expect(comm).to receive(:sudo).and_yield(:stdout, "eth1\neth2\neth0")
result = cap.network_interfaces(machine)
expect(result).to eq(["eth0", "eth1", "eth2"])
end
end
end

0 comments on commit a4a8ab9

Please sign in to comment.