facter 1.6.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of facter might be problematic. Click here for more details.

Files changed (63) hide show
  1. data/CHANGELOG +53 -0
  2. data/CONTRIBUTING.md +299 -0
  3. data/Rakefile +3 -3
  4. data/conf/redhat/facter.spec +1 -1
  5. data/install.rb +25 -10
  6. data/lib/facter.rb +16 -1
  7. data/lib/facter/arp.rb +1 -1
  8. data/lib/facter/augeasversion.rb +29 -0
  9. data/lib/facter/domain.rb +9 -10
  10. data/lib/facter/hardwareisa.rb +2 -2
  11. data/lib/facter/hostname.rb +4 -9
  12. data/lib/facter/ipaddress6.rb +9 -0
  13. data/lib/facter/kernel.rb +3 -3
  14. data/lib/facter/kernelrelease.rb +2 -4
  15. data/lib/facter/lsbmajdistrelease.rb +1 -1
  16. data/lib/facter/macaddress.rb +11 -31
  17. data/lib/facter/manufacturer.rb +5 -0
  18. data/lib/facter/memory.rb +32 -4
  19. data/lib/facter/operatingsystem.rb +6 -0
  20. data/lib/facter/operatingsystemrelease.rb +11 -2
  21. data/lib/facter/physicalprocessorcount.rb +8 -0
  22. data/lib/facter/processor.rb +38 -0
  23. data/lib/facter/ps.rb +5 -0
  24. data/lib/facter/selinux.rb +63 -48
  25. data/lib/facter/uniqueid.rb +2 -2
  26. data/lib/facter/util/config.rb +9 -0
  27. data/lib/facter/util/ip.rb +26 -3
  28. data/lib/facter/util/loader.rb +11 -0
  29. data/lib/facter/util/macaddress.rb +20 -0
  30. data/lib/facter/util/manufacturer.rb +10 -5
  31. data/lib/facter/util/resolution.rb +18 -9
  32. data/lib/facter/util/uptime.rb +6 -5
  33. data/lib/facter/util/wmi.rb +16 -0
  34. data/lib/facter/virtual.rb +15 -8
  35. data/spec/fixtures/netsh/windows_netsh_addresses_with_multiple_interfaces +35 -0
  36. data/spec/fixtures/unit/util/loader/nosuchfact.rb +1 -0
  37. data/spec/spec_helper.rb +1 -0
  38. data/spec/unit/data/windows_netsh_all_interfaces +12 -0
  39. data/spec/unit/data/windows_netsh_single_interface +7 -0
  40. data/spec/unit/data/windows_netsh_single_interface6 +18 -0
  41. data/spec/unit/domain_spec.rb +91 -0
  42. data/spec/unit/facter_spec.rb +21 -0
  43. data/spec/unit/hostname_spec.rb +38 -0
  44. data/spec/unit/id_spec.rb +6 -5
  45. data/spec/unit/interfaces_spec.rb +7 -0
  46. data/spec/unit/ipaddress6_spec.rb +19 -0
  47. data/spec/unit/macaddress_spec.rb +38 -0
  48. data/spec/unit/memory_spec.rb +26 -0
  49. data/spec/unit/operatingsystem_spec.rb +28 -0
  50. data/spec/unit/operatingsystemrelease_spec.rb +19 -8
  51. data/spec/unit/physicalprocessorcount_spec.rb +11 -0
  52. data/spec/unit/processor_spec.rb +66 -0
  53. data/spec/unit/selinux_spec.rb +1 -0
  54. data/spec/unit/util/ip_spec.rb +83 -21
  55. data/spec/unit/util/loader_spec.rb +8 -0
  56. data/spec/unit/util/macaddress_spec.rb +28 -1
  57. data/spec/unit/util/manufacturer_spec.rb +21 -0
  58. data/spec/unit/util/resolution_spec.rb +26 -14
  59. data/spec/unit/util/uptime_spec.rb +7 -1
  60. data/spec/unit/util/wmi_spec.rb +20 -0
  61. data/spec/unit/virtual_spec.rb +41 -5
  62. metadata +19 -8
  63. data/spec/spec.opts +0 -5
@@ -44,4 +44,30 @@ describe "Memory facts" do
44
44
  swapusage =~ /\(encrypted\)/
45
45
  Facter.fact(:swapencrypted).value.should == true
46
46
  end
47
+
48
+ describe "on Windows" do
49
+ before :each do
50
+ Facter.clear
51
+ Facter.fact(:kernel).stubs(:value).returns("windows")
52
+ Facter.collection.loader.load(:memory)
53
+
54
+ require 'facter/util/wmi'
55
+ end
56
+
57
+ it "should return free memory" do
58
+ os = stubs 'os'
59
+ os.stubs(:FreePhysicalMemory).returns("3415624")
60
+ Facter::Util::WMI.stubs(:execquery).returns([os])
61
+
62
+ Facter.fact(:MemoryFree).value.should == '3.26 GB'
63
+ end
64
+
65
+ it "should return total memory" do
66
+ computer = stubs 'computer'
67
+ computer.stubs(:TotalPhysicalMemory).returns("4193837056")
68
+ Facter::Util::WMI.stubs(:execquery).returns([computer])
69
+
70
+ Facter.fact(:MemoryTotal).value.should == '3.91 GB'
71
+ end
72
+ end
47
73
  end
@@ -52,4 +52,32 @@ describe "Operating System fact" do
52
52
 
53
53
  Facter.fact(:operatingsystem).value.should == "VMWareESX"
54
54
  end
55
+
56
+ it "should identify Alpine Linux" do
57
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
58
+
59
+ FileTest.stubs(:exists?).returns false
60
+
61
+ FileTest.expects(:exists?).with("/etc/alpine-release").returns true
62
+
63
+ Facter.fact(:operatingsystem).value.should == "Alpine"
64
+ end
65
+
66
+ it "should identify Scientific Linux" do
67
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
68
+ FileTest.stubs(:exists?).returns false
69
+
70
+ FileTest.expects(:exists?).with("/etc/redhat-release").returns true
71
+ File.expects(:read).with("/etc/redhat-release").returns("Scientific Linux SLC 5.7 (Boron)")
72
+ Facter.fact(:operatingsystem).value.should == "Scientific"
73
+ end
74
+
75
+ it "should differentiate between Scientific Linux CERN and Scientific Linux" do
76
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
77
+ FileTest.stubs(:exists?).returns false
78
+
79
+ FileTest.expects(:exists?).with("/etc/redhat-release").returns true
80
+ File.expects(:read).with("/etc/redhat-release").returns("Scientific Linux CERN SLC 5.7 (Boron)")
81
+ Facter.fact(:operatingsystem).value.should == "SLC"
82
+ end
55
83
  end
@@ -15,14 +15,16 @@ describe "Operating System Release fact" do
15
15
  end
16
16
 
17
17
  test_cases = {
18
- "CentOS" => "/etc/redhat-release",
19
- "RedHat" => "/etc/redhat-release",
20
- "Fedora" => "/etc/fedora-release",
21
- "MeeGo" => "/etc/meego-release",
22
- "OEL" => "/etc/enterprise-release",
23
- "oel" => "/etc/enterprise-release",
24
- "OVS" => "/etc/ovs-release",
25
- "ovs" => "/etc/ovs-release",
18
+ "CentOS" => "/etc/redhat-release",
19
+ "RedHat" => "/etc/redhat-release",
20
+ "Scientific" => "/etc/redhat-release",
21
+ "Fedora" => "/etc/fedora-release",
22
+ "MeeGo" => "/etc/meego-release",
23
+ "OEL" => "/etc/enterprise-release",
24
+ "oel" => "/etc/enterprise-release",
25
+ "OVS" => "/etc/ovs-release",
26
+ "ovs" => "/etc/ovs-release",
27
+ "OracleLinux" => "/etc/oracle-release",
26
28
  }
27
29
 
28
30
  test_cases.each do |system, file|
@@ -46,4 +48,13 @@ describe "Operating System Release fact" do
46
48
 
47
49
  Facter.fact(:operatingsystemrelease).value
48
50
  end
51
+
52
+ it "for Alpine it should use the contents of /etc/alpine-release" do
53
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
54
+ Facter.fact(:operatingsystem).stubs(:value).returns("Alpine")
55
+
56
+ File.expects(:read).with("/etc/alpine-release").returns("foo")
57
+
58
+ Facter.fact(:operatingsystemrelease).value.should == "foo"
59
+ end
49
60
  end
@@ -37,4 +37,15 @@ describe "Physical processor count facts" do
37
37
 
38
38
  Facter.fact(:physicalprocessorcount).value.should == 4
39
39
  end
40
+
41
+ it "should return 4 physical CPUs on Windows" do
42
+ Facter.fact(:kernel).stubs(:value).returns("windows")
43
+
44
+ require 'facter/util/wmi'
45
+ ole = stub 'WIN32OLE'
46
+ Facter::Util::WMI.expects(:execquery).with("select Name from Win32_Processor").returns(ole)
47
+ ole.stubs(:Count).returns(4)
48
+
49
+ Facter.fact(:physicalprocessorcount).value.should == 4
50
+ end
40
51
  end
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
+
5
+ require 'facter'
6
+
7
+ describe "Processor facts" do
8
+ describe "on Windows" do
9
+ before :each do
10
+ Facter.clear
11
+ Facter.fact(:kernel).stubs(:value).returns("windows")
12
+ end
13
+
14
+ def load(procs)
15
+ require 'facter/util/wmi'
16
+ Facter::Util::WMI.stubs(:execquery).with("select * from Win32_Processor").returns(procs)
17
+
18
+ # processor facts belong to a file with a different name,
19
+ # so load the file explicitly (after stubbing kernel),
20
+ # but we have to stub execquery first
21
+ Facter.collection.loader.load(:processor)
22
+ end
23
+
24
+ describe "2003" do
25
+ before :each do
26
+ proc = stubs 'proc'
27
+ proc.stubs(:NumberOfLogicalProcessors).raises(RuntimeError)
28
+ proc.stubs(:Name).returns("Intel(R) Celeron(R) processor")
29
+
30
+ load(Array.new(2, proc))
31
+ end
32
+
33
+ it "should count 2 processors" do
34
+ Facter.fact(:processorcount).value.should == "2"
35
+ end
36
+
37
+ it "should squeeze the processor name 2 times" do
38
+ 2.times do |i|
39
+ Facter.fact("processor#{i}".to_sym).value.should == "Intel(R) Celeron(R) processor"
40
+ end
41
+ end
42
+ end
43
+
44
+ describe "2008" do
45
+ before :each do
46
+ proc = stubs 'proc'
47
+ proc.stubs(:NumberOfLogicalProcessors).returns(2)
48
+ proc.stubs(:Name).returns("Intel(R) Celeron(R) processor")
49
+
50
+ load(Array.new(2, proc))
51
+ end
52
+
53
+ it "should count 4 processors" do
54
+ Facter.fact(:processorcount).value.should == "4"
55
+ end
56
+
57
+ it "should squeeze the processor name 4 times" do
58
+ 4.times do |i|
59
+ Facter.fact("processor#{i}".to_sym).value.should == "Intel(R) Celeron(R) processor"
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+
@@ -38,6 +38,7 @@ describe "SELinux facts" do
38
38
 
39
39
  it "should return an SELinux policy version" do
40
40
  Facter.fact(:selinux).stubs(:value).returns("true")
41
+ FileTest.stubs(:exists?).with("/proc/self/mountinfo").returns false
41
42
 
42
43
  File.stubs(:read).with("/selinux/policyvers").returns("")
43
44
 
@@ -5,8 +5,13 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
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,39 +27,47 @@ describe Facter::Util::IP do
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,7 +79,7 @@ describe Facter::Util::IP do
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,7 +89,7 @@ describe Facter::Util::IP do
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,7 +99,7 @@ describe Facter::Util::IP do
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,7 +109,7 @@ describe Facter::Util::IP do
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,7 +119,7 @@ describe Facter::Util::IP do
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,7 +129,7 @@ describe Facter::Util::IP do
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,7 +139,7 @@ describe Facter::Util::IP do
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,7 +149,7 @@ describe Facter::Util::IP do
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,7 +159,7 @@ describe Facter::Util::IP do
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,7 +169,7 @@ describe Facter::Util::IP do
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,7 +179,7 @@ describe Facter::Util::IP do
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,7 +189,7 @@ describe Facter::Util::IP do
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,7 +199,7 @@ describe Facter::Util::IP do
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,7 +210,7 @@ describe Facter::Util::IP do
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,7 +221,7 @@ describe Facter::Util::IP do
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,10 +241,59 @@ describe Facter::Util::IP do
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