~ubuntu-branches/ubuntu/trusty/facter/trusty

« back to all changes in this revision

Viewing changes to spec/unit/util/ip.rb

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Pollock, Nigel Kersten, Andrew Pollock
  • Date: 2009-04-13 15:20:21 UTC
  • mfrom: (1.1.5 upstream) (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090413152021-t3uagjamr3ee4njl
Tags: 1.5.4-1
[ Nigel Kersten ]
* New upstream release
* Switch maintainer to pkg-puppet-devel list
* Modify uploaders
* Update watch file regexp to exclude release canditate tarballs
* Use upstream install.rb script to build rather than copying manually

[ Andrew Pollock ]
* debian/control: add libopenssl-ruby to build dependencies
* debian/control: bump Standards-Version (no changes)
* debian/compat: increase to 5
* debian/control: add pciutils and ${misc:Depends} to dependencies

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
require 'facter/util/ip'
6
6
 
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)
 
11
        end
 
12
    end
8
13
 
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)
11
16
    end
12
17
 
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 == []
16
21
    end
17
22
 
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"]
23
28
    end
24
29
 
 
30
 
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)
 
33
    end
 
34
 
 
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 == []
 
38
    end
 
39
 
 
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()
 
43
 
 
44
        Facter::Util::IP.expects(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface)
 
45
        Facter.stubs(:value).with(:kernel).returns("SunOS")
 
46
 
 
47
        Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == "255.255.255.0"
 
48
    end
 
49
 
 
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()
 
53
 
 
54
        Facter::Util::IP.expects(:get_single_interface_output).with("fxp0").returns(ifconfig_interface)
 
55
        Facter.stubs(:value).with(:kernel).returns("FreeBSD")
 
56
 
 
57
        Facter::Util::IP.get_interface_value("fxp0", "macaddress").should == "00:0e:0c:68:67:7c"
 
58
    end
 
59
 
 
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()
 
63
 
 
64
        Facter::Util::IP.expects(:get_single_interface_output).with("en1").returns(ifconfig_interface)
 
65
        Facter.stubs(:value).with(:kernel).returns("Darwin")
 
66
 
 
67
        Facter::Util::IP.get_interface_value("en1", "macaddress").should == "00:1b:63:ae:02:66"
27
68
    end
28
69
 
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()
32
73
 
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")
35
76
 
36
 
        Facter::IPAddress.get_interface_value("e1000g0", "netmask").should == "255.255.255.0"
37
 
    end
38
 
 
 
77
        Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == "255.255.255.0"
 
78
    end
 
79
 
 
80
    it "should return a human readable netmask on Darwin" do
 
81
        sample_output_file = File.dirname(__FILE__) + "/../data/darwin_ifconfig_single_interface"
 
82
 
 
83
        darwin_ifconfig_interface = File.new(sample_output_file).read()
 
84
 
 
85
        Facter::Util::IP.expects(:get_single_interface_output).with("en1").returns(darwin_ifconfig_interface)
 
86
        Facter.stubs(:value).with(:kernel).returns("Darwin")
 
87
 
 
88
        Facter::Util::IP.get_interface_value("en1", "netmask").should == "255.255.255.0"
 
89
    end
 
90
 
 
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
 
94
        end
 
95
    end
39
96
end
40