~gandelman-a/ubuntu/precise/facter/merge922788

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman
  • Date: 2011-10-18 10:32:42 UTC
  • mfrom: (1.3.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: package-import@ubuntu.com-20111018103242-ag8i8vejfp8v7b1b
Tags: upstream-1.6.1
ImportĀ upstreamĀ versionĀ 1.6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
require 'facter/util/ip'
6
6
 
7
7
describe Facter::Util::IP do
8
 
    [:freebsd, :linux, :netbsd, :openbsd, :sunos, :darwin, :"hp-ux", :"gnu/kfreebsd"].each do |platform|
 
8
    before :each do
 
9
        Facter::Util::Config.stubs(:is_windows?).returns(false)
 
10
    end
 
11
 
 
12
    [:freebsd, :linux, :netbsd, :openbsd, :sunos, :darwin, :"hp-ux", :"gnu/kfreebsd", :windows].each do |platform|
9
13
        it "should be supported on #{platform}" do
 
14
            Facter::Util::Config.stubs(:is_windows?).returns(platform == :windows)
10
15
            Facter::Util::IP.supported_platforms.should be_include(platform)
11
16
        end
12
17
    end
22
27
 
23
28
    it "should return a list with a single interface and the loopback interface on Linux with a single interface" do
24
29
        sample_output_file = File.dirname(__FILE__) + '/../data/linux_ifconfig_all_with_single_interface'
25
 
        linux_ifconfig = File.new(sample_output_file).read()
 
30
        linux_ifconfig = File.read(sample_output_file)
26
31
        Facter::Util::IP.stubs(:get_all_interface_output).returns(linux_ifconfig)
27
32
        Facter::Util::IP.get_interfaces().should == ["eth0", "lo"]
28
33
    end
29
34
 
30
35
    it "should return a list two interfaces on Darwin with two interfaces" do
31
36
        sample_output_file = File.dirname(__FILE__) + '/../data/darwin_ifconfig_all_with_multiple_interfaces'
32
 
        darwin_ifconfig = File.new(sample_output_file).read()
 
37
        darwin_ifconfig = File.read(sample_output_file)
33
38
        Facter::Util::IP.stubs(:get_all_interface_output).returns(darwin_ifconfig)
34
39
        Facter::Util::IP.get_interfaces().should == ["lo0", "en0"]
35
40
    end
36
41
 
37
42
    it "should return a list two interfaces on Solaris with two interfaces multiply reporting" do
38
43
        sample_output_file = File.dirname(__FILE__) + '/../data/solaris_ifconfig_all_with_multiple_interfaces'
39
 
        solaris_ifconfig = File.new(sample_output_file).read()
 
44
        solaris_ifconfig = File.read(sample_output_file)
40
45
        Facter::Util::IP.stubs(:get_all_interface_output).returns(solaris_ifconfig)
41
46
        Facter::Util::IP.get_interfaces().should == ["lo0", "e1000g0"]
42
47
    end
43
48
 
44
49
    it "should return a list three interfaces on HP-UX with three interfaces multiply reporting" do
45
50
        sample_output_file = File.dirname(__FILE__) + '/../data/hpux_netstat_all_interfaces'
46
 
        hpux_netstat = File.new(sample_output_file).read()
 
51
        hpux_netstat = File.read(sample_output_file)
47
52
        Facter::Util::IP.stubs(:get_all_interface_output).returns(hpux_netstat)
48
53
        Facter::Util::IP.get_interfaces().should == ["lan1", "lan0", "lo0"]
49
54
    end
50
55
 
51
56
    it "should return a list of six interfaces on a GNU/kFreeBSD with six interfaces" do
52
57
        sample_output_file = File.dirname(__FILE__) + '/../data/debian_kfreebsd_ifconfig'
53
 
        kfreebsd_ifconfig = File.new(sample_output_file).read()
 
58
        kfreebsd_ifconfig = File.read(sample_output_file)
54
59
        Facter::Util::IP.stubs(:get_all_interface_output).returns(kfreebsd_ifconfig)
55
60
        Facter::Util::IP.get_interfaces().should == ["em0", "em1", "bge0", "bge1", "lo0", "vlan0"]
56
61
    end
57
62
 
 
63
    it "should return a list of only connected interfaces on Windows" do
 
64
        Facter.fact(:kernel).stubs(:value).returns("windows")
 
65
        sample_output_file = File.dirname(__FILE__) + '/../data/windows_netsh_all_interfaces'
 
66
        windows_netsh = File.read(sample_output_file)
 
67
        Facter::Util::IP.stubs(:get_all_interface_output).returns(windows_netsh)
 
68
        Facter::Util::IP.get_interfaces().should == ["Loopback Pseudo-Interface 1", "Local Area Connection", "Teredo Tunneling Pseudo-Interface"]
 
69
    end
 
70
 
58
71
    it "should return a value for a specific interface" do
59
72
        Facter::Util::IP.should respond_to(:get_interface_value)
60
73
    end
66
79
 
67
80
    it "should return ipaddress information for Solaris" do
68
81
        sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface"
69
 
        solaris_ifconfig_interface = File.new(sample_output_file).read()
 
82
        solaris_ifconfig_interface = File.read(sample_output_file)
70
83
 
71
84
        Facter::Util::IP.expects(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface)
72
85
        Facter.stubs(:value).with(:kernel).returns("SunOS")
76
89
 
77
90
    it "should return netmask information for Solaris" do
78
91
        sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface"
79
 
        solaris_ifconfig_interface = File.new(sample_output_file).read()
 
92
        solaris_ifconfig_interface = File.read(sample_output_file)
80
93
 
81
94
        Facter::Util::IP.expects(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface)
82
95
        Facter.stubs(:value).with(:kernel).returns("SunOS")
86
99
 
87
100
    it "should return calculated network information for Solaris" do
88
101
        sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface"
89
 
        solaris_ifconfig_interface = File.new(sample_output_file).read()
 
102
        solaris_ifconfig_interface = File.read(sample_output_file)
90
103
 
91
104
        Facter::Util::IP.stubs(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface)
92
105
        Facter.stubs(:value).with(:kernel).returns("SunOS")
96
109
 
97
110
    it "should return ipaddress information for HP-UX" do
98
111
        sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface"
99
 
        hpux_ifconfig_interface = File.new(sample_output_file).read()
 
112
        hpux_ifconfig_interface = File.read(sample_output_file)
100
113
 
101
114
        Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface)
102
115
        Facter.stubs(:value).with(:kernel).returns("HP-UX")
106
119
 
107
120
    it "should return macaddress information for HP-UX" do
108
121
        sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface"
109
 
        hpux_ifconfig_interface = File.new(sample_output_file).read()
 
122
        hpux_ifconfig_interface = File.read(sample_output_file)
110
123
 
111
124
        Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface)
112
125
        Facter.stubs(:value).with(:kernel).returns("HP-UX")
116
129
 
117
130
    it "should return macaddress with leading zeros stripped off for GNU/kFreeBSD" do
118
131
        sample_output_file = File.dirname(__FILE__) + "/../data/debian_kfreebsd_ifconfig"
119
 
        kfreebsd_ifconfig = File.new(sample_output_file).read()
 
132
        kfreebsd_ifconfig = File.read(sample_output_file)
120
133
 
121
134
        Facter::Util::IP.expects(:get_single_interface_output).with("em0").returns(kfreebsd_ifconfig)
122
135
        Facter.stubs(:value).with(:kernel).returns("GNU/kFreeBSD")
126
139
 
127
140
    it "should return netmask information for HP-UX" do
128
141
        sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface"
129
 
        hpux_ifconfig_interface = File.new(sample_output_file).read()
 
142
        hpux_ifconfig_interface = File.read(sample_output_file)
130
143
 
131
144
        Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface)
132
145
        Facter.stubs(:value).with(:kernel).returns("HP-UX")
136
149
 
137
150
    it "should return calculated network information for HP-UX" do
138
151
        sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface"
139
 
        hpux_ifconfig_interface = File.new(sample_output_file).read()
 
152
        hpux_ifconfig_interface = File.read(sample_output_file)
140
153
 
141
154
        Facter::Util::IP.stubs(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface)
142
155
        Facter.stubs(:value).with(:kernel).returns("HP-UX")
146
159
 
147
160
    it "should return interface information for FreeBSD supported via an alias" do
148
161
        sample_output_file = File.dirname(__FILE__) + "/../data/6.0-STABLE_FreeBSD_ifconfig"
149
 
        ifconfig_interface = File.new(sample_output_file).read()
 
162
        ifconfig_interface = File.read(sample_output_file)
150
163
 
151
164
        Facter::Util::IP.expects(:get_single_interface_output).with("fxp0").returns(ifconfig_interface)
152
165
        Facter.stubs(:value).with(:kernel).returns("FreeBSD")
156
169
 
157
170
    it "should return macaddress information for OS X" do
158
171
        sample_output_file = File.dirname(__FILE__) + "/../data/Mac_OS_X_10.5.5_ifconfig"
159
 
        ifconfig_interface = File.new(sample_output_file).read()
 
172
        ifconfig_interface = File.read(sample_output_file)
160
173
 
161
174
        Facter::Util::IP.expects(:get_single_interface_output).with("en1").returns(ifconfig_interface)
162
175
        Facter.stubs(:value).with(:kernel).returns("Darwin")
166
179
 
167
180
    it "should return all interfaces correctly on OS X" do
168
181
        sample_output_file = File.dirname(__FILE__) + "/../data/Mac_OS_X_10.5.5_ifconfig"
169
 
        ifconfig_interface = File.new(sample_output_file).read()
 
182
        ifconfig_interface = File.read(sample_output_file)
170
183
 
171
184
        Facter::Util::IP.expects(:get_all_interface_output).returns(ifconfig_interface)
172
185
        Facter.stubs(:value).with(:kernel).returns("Darwin")
176
189
 
177
190
    it "should return a human readable netmask on Solaris" do
178
191
        sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface"
179
 
        solaris_ifconfig_interface = File.new(sample_output_file).read()
 
192
        solaris_ifconfig_interface = File.read(sample_output_file)
180
193
 
181
194
        Facter::Util::IP.expects(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface)
182
195
        Facter.stubs(:value).with(:kernel).returns("SunOS")
186
199
 
187
200
    it "should return a human readable netmask on HP-UX" do
188
201
        sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface"
189
 
        hpux_ifconfig_interface = File.new(sample_output_file).read()
 
202
        hpux_ifconfig_interface = File.read(sample_output_file)
190
203
 
191
204
        Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface)
192
205
        Facter.stubs(:value).with(:kernel).returns("HP-UX")
197
210
    it "should return a human readable netmask on Darwin" do
198
211
        sample_output_file = File.dirname(__FILE__) + "/../data/darwin_ifconfig_single_interface"
199
212
 
200
 
        darwin_ifconfig_interface = File.new(sample_output_file).read()
 
213
        darwin_ifconfig_interface = File.read(sample_output_file)
201
214
 
202
215
        Facter::Util::IP.expects(:get_single_interface_output).with("en1").returns(darwin_ifconfig_interface)
203
216
        Facter.stubs(:value).with(:kernel).returns("Darwin")
208
221
    it "should return a human readable netmask on GNU/kFreeBSD" do
209
222
        sample_output_file = File.dirname(__FILE__) + "/../data/debian_kfreebsd_ifconfig"
210
223
 
211
 
        kfreebsd_ifconfig = File.new(sample_output_file).read()
 
224
        kfreebsd_ifconfig = File.read(sample_output_file)
212
225
 
213
226
        Facter::Util::IP.expects(:get_single_interface_output).with("em1").returns(kfreebsd_ifconfig)
214
227
        Facter.stubs(:value).with(:kernel).returns("GNU/kFreeBSD")
228
241
        end
229
242
    end
230
243
 
 
244
    [:windows].each do |platform|
 
245
        it "should not require conversion from hex on #{platform}" do
 
246
            Facter::Util::IP.convert_from_hex?(platform).should be_false
 
247
        end
 
248
    end
 
249
 
231
250
    it "should return an arp address on Linux" do
232
251
        Facter.stubs(:value).with(:kernel).returns("Linux")
233
252
 
234
253
        Facter::Util::IP.expects(:get_arp_value).with("eth0").returns("00:00:0c:9f:f0:04")
235
254
        Facter::Util::IP.get_arp_value("eth0").should == "00:00:0c:9f:f0:04"
236
255
    end
 
256
 
 
257
    describe "on Windows" do
 
258
        before :each do
 
259
            Facter.stubs(:value).with(:kernel).returns("windows")
 
260
        end
 
261
 
 
262
        it "should return ipaddress information" do
 
263
            sample_output_file = File.dirname(__FILE__) + "/../data/windows_netsh_single_interface"
 
264
            windows_netsh = File.read(sample_output_file)
 
265
 
 
266
            Facter::Util::IP.expects(:get_output_for_interface_and_label).with("Local Area Connection", "ipaddress").returns(windows_netsh)
 
267
 
 
268
            Facter::Util::IP.get_interface_value("Local Area Connection", "ipaddress").should == "172.16.138.216"
 
269
        end
 
270
 
 
271
        it "should return a human readable netmask" do
 
272
            sample_output_file = File.dirname(__FILE__) + "/../data/windows_netsh_single_interface"
 
273
            windows_netsh = File.read(sample_output_file)
 
274
 
 
275
            Facter::Util::IP.expects(:get_output_for_interface_and_label).with("Local Area Connection", "netmask").returns(windows_netsh)
 
276
 
 
277
            Facter::Util::IP.get_interface_value("Local Area Connection", "netmask").should == "255.255.255.0"
 
278
        end
 
279
 
 
280
        it "should return network information" do
 
281
            sample_output_file = File.dirname(__FILE__) + "/../data/windows_netsh_single_interface"
 
282
            windows_netsh = File.read(sample_output_file)
 
283
 
 
284
            Facter::Util::IP.stubs(:get_output_for_interface_and_label).with("Local Area Connection", "ipaddress").returns(windows_netsh)
 
285
            Facter::Util::IP.stubs(:get_output_for_interface_and_label).with("Local Area Connection", "netmask").returns(windows_netsh)
 
286
 
 
287
            Facter::Util::IP.get_network_value("Local Area Connection").should == "172.16.138.0"
 
288
        end
 
289
 
 
290
        it "should return ipaddress6 information" do
 
291
            sample_output_file = File.dirname(__FILE__) + "/../data/windows_netsh_single_interface6"
 
292
            windows_netsh = File.read(sample_output_file)
 
293
 
 
294
            Facter::Util::IP.expects(:get_output_for_interface_and_label).with("Teredo Tunneling Pseudo-Interface", "ipaddress6").returns(windows_netsh)
 
295
 
 
296
            Facter::Util::IP.get_interface_value("Teredo Tunneling Pseudo-Interface", "ipaddress6").should == "2001:0:4137:9e76:2087:77a:53ef:7527"
 
297
        end
 
298
    end
237
299
end