5
5
require 'facter/util/ip'
7
describe Facter::IPAddress do
7
describe Facter::Util::IP do
8
[:freebsd, :linux, :netbsd, :openbsd, :sunos, :darwin].each do |platform|
9
it "should be supported on #{platform}" do
10
Facter::Util::IP.supported_platforms.should be_include(platform)
9
14
it "should return a list of interfaces" do
10
Facter::IPAddress.should respond_to(:get_interfaces)
15
Facter::Util::IP.should respond_to(:get_interfaces)
13
18
it "should return an empty list of interfaces on an unknown kernel" do
14
19
Facter.stubs(:value).returns("UnknownKernel")
15
Facter::IPAddress.get_interfaces().should == []
20
Facter::Util::IP.get_interfaces().should == []
18
23
it "should return a list with a single interface on Linux with a single interface" do
19
24
sample_output_file = File.dirname(__FILE__) + '/../data/linux_ifconfig_all_with_single_interface'
20
25
linux_ifconfig = File.new(sample_output_file).read()
21
Facter::IPAddress.stubs(:get_all_interface_output).returns(linux_ifconfig)
22
Facter::IPAddress.get_interfaces().should == ["eth0"]
26
Facter::Util::IP.stubs(:get_all_interface_output).returns(linux_ifconfig)
27
Facter::Util::IP.get_interfaces().should == ["eth0"]
25
31
it "should return a value for a specific interface" do
26
Facter::IPAddress.should respond_to(:get_interface_value)
32
Facter::Util::IP.should respond_to(:get_interface_value)
35
it "should not return interface information for unsupported platforms" do
36
Facter.stubs(:value).with(:kernel).returns("bleah")
37
Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == []
40
it "should return interface information for directly supported platforms" do
41
sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface"
42
solaris_ifconfig_interface = File.new(sample_output_file).read()
44
Facter::Util::IP.expects(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface)
45
Facter.stubs(:value).with(:kernel).returns("SunOS")
47
Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == "255.255.255.0"
50
it "should return interface information for platforms supported via an alias" do
51
sample_output_file = File.dirname(__FILE__) + "/../data/6.0-STABLE_FreeBSD_ifconfig"
52
ifconfig_interface = File.new(sample_output_file).read()
54
Facter::Util::IP.expects(:get_single_interface_output).with("fxp0").returns(ifconfig_interface)
55
Facter.stubs(:value).with(:kernel).returns("FreeBSD")
57
Facter::Util::IP.get_interface_value("fxp0", "macaddress").should == "00:0e:0c:68:67:7c"
60
it "should return interface information for OS X" do
61
sample_output_file = File.dirname(__FILE__) + "/../data/Mac_OS_X_10.5.5_ifconfig"
62
ifconfig_interface = File.new(sample_output_file).read()
64
Facter::Util::IP.expects(:get_single_interface_output).with("en1").returns(ifconfig_interface)
65
Facter.stubs(:value).with(:kernel).returns("Darwin")
67
Facter::Util::IP.get_interface_value("en1", "macaddress").should == "00:1b:63:ae:02:66"
29
70
it "should return a human readable netmask on Solaris" do
30
71
sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface"
31
72
solaris_ifconfig_interface = File.new(sample_output_file).read()
33
Facter::IPAddress.expects(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface)
74
Facter::Util::IP.expects(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface)
34
75
Facter.stubs(:value).with(:kernel).returns("SunOS")
36
Facter::IPAddress.get_interface_value("e1000g0", "netmask").should == "255.255.255.0"
77
Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == "255.255.255.0"
80
it "should return a human readable netmask on Darwin" do
81
sample_output_file = File.dirname(__FILE__) + "/../data/darwin_ifconfig_single_interface"
83
darwin_ifconfig_interface = File.new(sample_output_file).read()
85
Facter::Util::IP.expects(:get_single_interface_output).with("en1").returns(darwin_ifconfig_interface)
86
Facter.stubs(:value).with(:kernel).returns("Darwin")
88
Facter::Util::IP.get_interface_value("en1", "netmask").should == "255.255.255.0"
91
[:freebsd, :netbsd, :openbsd, :sunos, :darwin].each do |platform|
92
it "should require conversion from hex on #{platform}" do
93
Facter::Util::IP.convert_from_hex?(platform).should == true