From e12e2d53743aad09fc57d786713e28411933820b Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 20 Dec 2017 16:52:54 -0800 Subject: [PATCH] Add test coverage for darwin host configured addresses capability --- .../cap/configured_ip_addresses_test.rb | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/unit/plugins/hosts/darwin/cap/configured_ip_addresses_test.rb diff --git a/test/unit/plugins/hosts/darwin/cap/configured_ip_addresses_test.rb b/test/unit/plugins/hosts/darwin/cap/configured_ip_addresses_test.rb new file mode 100644 index 000000000..71d79ed24 --- /dev/null +++ b/test/unit/plugins/hosts/darwin/cap/configured_ip_addresses_test.rb @@ -0,0 +1,31 @@ +require_relative "../../../../base" + +require_relative "../../../../../../plugins/hosts/darwin/cap/configured_ip_addresses" + +describe VagrantPlugins::HostDarwin::Cap::ConfiguredIPAddresses do + + let(:subject){ VagrantPlugins::HostDarwin::Cap::ConfiguredIPAddresses } + let(:interfaces){ ["192.168.1.2"] } + before{ allow(Socket).to receive(:getifaddrs).and_return( + interfaces.map{|i| double(:socket, addr: Addrinfo.ip(i))}) } + + it "should get list of available addresses" do + expect(subject.configured_ip_addresses(nil)).to eq(["192.168.1.2"]) + end + + context "with loopback address" do + let(:interfaces){ ["192.168.1.2", "127.0.0.1"] } + + it "should not include loopback address" do + expect(subject.configured_ip_addresses(nil)).not_to include(["127.0.0.1"]) + end + end + + context "with IPv6 address" do + let(:interfaces){ ["192.168.1.2", "2001:200:dff:fff1:216:3eff:feb1:44d7"] } + + it "should not include IPv6 address" do + expect(subject.configured_ip_addresses(nil)).not_to include(["2001:200:dff:fff1:216:3eff:feb1:44d7"]) + end + end +end