facter 1.6.2 → 1.6.3

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 (57) hide show
  1. data/CHANGELOG +11 -0
  2. data/LICENSE +1 -1
  3. data/conf/osx/createpackage.sh +1 -1
  4. data/conf/redhat/facter.spec +9 -6
  5. data/conf/solaris/pkginfo +1 -1
  6. data/install.rb +1 -1
  7. data/lib/facter.rb +2 -2
  8. data/lib/facter/architecture.rb +1 -2
  9. data/lib/facter/augeasversion.rb +1 -2
  10. data/lib/facter/domain.rb +3 -3
  11. data/lib/facter/hardwareisa.rb +1 -1
  12. data/lib/facter/ipaddress.rb +2 -2
  13. data/lib/facter/lsbmajdistrelease.rb +1 -1
  14. data/lib/facter/macaddress.rb +2 -2
  15. data/lib/facter/manufacturer.rb +1 -1
  16. data/lib/facter/netmask.rb +0 -3
  17. data/lib/facter/network.rb +2 -3
  18. data/lib/facter/operatingsystem.rb +5 -2
  19. data/lib/facter/operatingsystemrelease.rb +3 -3
  20. data/lib/facter/osfamily.rb +1 -1
  21. data/lib/facter/processor.rb +2 -2
  22. data/lib/facter/selinux.rb +3 -3
  23. data/lib/facter/uniqueid.rb +1 -1
  24. data/lib/facter/uptime_days.rb +0 -1
  25. data/lib/facter/uptime_hours.rb +0 -1
  26. data/lib/facter/util/manufacturer.rb +2 -3
  27. data/lib/facter/util/processor.rb +3 -3
  28. data/lib/facter/util/resolution.rb +3 -3
  29. data/lib/facter/util/values.rb +1 -1
  30. data/lib/facter/virtual.rb +2 -2
  31. data/lib/facter/vlans.rb +1 -2
  32. data/lib/facter/xendomains.rb +0 -1
  33. data/spec/fixtures/unit/util/manufacturer/solaris_sunfire_v120_prtdiag +33 -0
  34. data/spec/fixtures/unit/util/manufacturer/solaris_t5220_prtdiag +136 -0
  35. data/spec/spec_helper.rb +5 -0
  36. data/spec/unit/architecture_spec.rb +40 -40
  37. data/spec/unit/facter_spec.rb +220 -220
  38. data/spec/unit/id_spec.rb +16 -16
  39. data/spec/unit/interfaces_spec.rb +6 -6
  40. data/spec/unit/memory_spec.rb +105 -105
  41. data/spec/unit/operatingsystem_spec.rb +72 -63
  42. data/spec/unit/operatingsystemrelease_spec.rb +44 -43
  43. data/spec/unit/processor_spec.rb +2 -2
  44. data/spec/unit/selinux_spec.rb +53 -53
  45. data/spec/unit/util/collection_spec.rb +183 -183
  46. data/spec/unit/util/confine_spec.rb +92 -92
  47. data/spec/unit/util/fact_spec.rb +96 -96
  48. data/spec/unit/util/ip_spec.rb +218 -218
  49. data/spec/unit/util/loader_spec.rb +193 -193
  50. data/spec/unit/util/macosx_spec.rb +63 -63
  51. data/spec/unit/util/manufacturer_spec.rb +124 -107
  52. data/spec/unit/util/resolution_spec.rb +235 -235
  53. data/spec/unit/util/virtual_spec.rb +167 -167
  54. data/spec/unit/util/vlans_spec.rb +6 -6
  55. data/spec/unit/virtual_spec.rb +246 -246
  56. data/spec/watchr.rb +1 -1
  57. metadata +6 -4
@@ -5,77 +5,77 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
5
5
  require 'facter/util/macosx'
6
6
 
7
7
  describe Facter::Util::Macosx do
8
- it "should be able to retrieve profiler data as xml for a given data field" do
9
- Facter::Util::Resolution.expects(:exec).with("/usr/sbin/system_profiler -xml foo").returns "yay"
10
- Facter::Util::Macosx.profiler_xml("foo").should == "yay"
11
- end
12
-
13
- it "should use PList to convert xml to data structures" do
14
- Plist.expects(:parse_xml).with("foo").returns "bar"
8
+ it "should be able to retrieve profiler data as xml for a given data field" do
9
+ Facter::Util::Resolution.expects(:exec).with("/usr/sbin/system_profiler -xml foo").returns "yay"
10
+ Facter::Util::Macosx.profiler_xml("foo").should == "yay"
11
+ end
15
12
 
16
- Facter::Util::Macosx.intern_xml("foo").should == "bar"
17
- end
13
+ it "should use PList to convert xml to data structures" do
14
+ Plist.expects(:parse_xml).with("foo").returns "bar"
18
15
 
19
- describe "when collecting profiler data" do
20
- it "should return the first value in the '_items' hash in the first value of the results of the system_profiler data, with the '_name' field removed, if the profiler returns data" do
21
- @result = [
22
- '_items' => [
23
- {'_name' => "foo", "yay" => "bar"}
24
- ]
25
- ]
26
- Facter::Util::Macosx.expects(:profiler_xml).with("foo").returns "eh"
27
- Facter::Util::Macosx.expects(:intern_xml).with("eh").returns @result
28
- Facter::Util::Macosx.profiler_data("foo").should == {"yay" => "bar"}
29
- end
16
+ Facter::Util::Macosx.intern_xml("foo").should == "bar"
17
+ end
30
18
 
31
- it "should return nil if an exception is thrown during parsing of xml" do
32
- Facter::Util::Macosx.expects(:profiler_xml).with("foo").returns "eh"
33
- Facter::Util::Macosx.expects(:intern_xml).with("eh").raises "boo!"
34
- Facter::Util::Macosx.profiler_data("foo").should be_nil
35
- end
19
+ describe "when collecting profiler data" do
20
+ it "should return the first value in the '_items' hash in the first value of the results of the system_profiler data, with the '_name' field removed, if the profiler returns data" do
21
+ @result = [
22
+ '_items' => [
23
+ {'_name' => "foo", "yay" => "bar"}
24
+ ]
25
+ ]
26
+ Facter::Util::Macosx.expects(:profiler_xml).with("foo").returns "eh"
27
+ Facter::Util::Macosx.expects(:intern_xml).with("eh").returns @result
28
+ Facter::Util::Macosx.profiler_data("foo").should == {"yay" => "bar"}
36
29
  end
37
30
 
38
- it "should return the profiler data for 'SPHardwareDataType' as the hardware information" do
39
- Facter::Util::Macosx.expects(:profiler_data).with("SPHardwareDataType").returns "eh"
40
- Facter::Util::Macosx.hardware_overview.should == "eh"
31
+ it "should return nil if an exception is thrown during parsing of xml" do
32
+ Facter::Util::Macosx.expects(:profiler_xml).with("foo").returns "eh"
33
+ Facter::Util::Macosx.expects(:intern_xml).with("eh").raises "boo!"
34
+ Facter::Util::Macosx.profiler_data("foo").should be_nil
41
35
  end
36
+ end
42
37
 
43
- it "should return the profiler data for 'SPSoftwareDataType' as the os information" do
44
- Facter::Util::Macosx.expects(:profiler_data).with("SPSoftwareDataType").returns "eh"
45
- Facter::Util::Macosx.os_overview.should == "eh"
46
- end
47
-
48
- describe "when working out software version" do
49
-
50
- before do
51
- Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productName").returns "Mac OS X"
52
- Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -buildVersion").returns "9J62"
53
- end
54
-
55
- it "should have called sw_vers three times when determining software version" do
56
- Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "10.5.7"
57
- Facter::Util::Macosx.sw_vers
58
- end
59
-
60
- it "should return a hash with the correct keys when determining software version" do
61
- Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "10.5.7"
62
- Facter::Util::Macosx.sw_vers.keys.sort.should == ["macosx_productName",
63
- "macosx_buildVersion",
64
- "macosx_productversion_minor",
65
- "macosx_productversion_major",
66
- "macosx_productVersion"].sort
67
- end
38
+ it "should return the profiler data for 'SPHardwareDataType' as the hardware information" do
39
+ Facter::Util::Macosx.expects(:profiler_data).with("SPHardwareDataType").returns "eh"
40
+ Facter::Util::Macosx.hardware_overview.should == "eh"
41
+ end
42
+
43
+ it "should return the profiler data for 'SPSoftwareDataType' as the os information" do
44
+ Facter::Util::Macosx.expects(:profiler_data).with("SPSoftwareDataType").returns "eh"
45
+ Facter::Util::Macosx.os_overview.should == "eh"
46
+ end
47
+
48
+ describe "when working out software version" do
68
49
 
69
- it "should split a product version of 'x.y.z' into separate hash entries correctly" do
70
- Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "1.2.3"
71
- sw_vers = Facter::Util::Macosx.sw_vers
72
- sw_vers["macosx_productversion_major"].should == "1.2"
73
- sw_vers["macosx_productversion_minor"].should == "3"
74
- end
50
+ before do
51
+ Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productName").returns "Mac OS X"
52
+ Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -buildVersion").returns "9J62"
53
+ end
75
54
 
76
- it "should treat a product version of 'x.y' as 'x.y.0" do
77
- Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "2.3"
78
- Facter::Util::Macosx.sw_vers["macosx_productversion_minor"].should == "0"
79
- end
55
+ it "should have called sw_vers three times when determining software version" do
56
+ Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "10.5.7"
57
+ Facter::Util::Macosx.sw_vers
58
+ end
59
+
60
+ it "should return a hash with the correct keys when determining software version" do
61
+ Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "10.5.7"
62
+ Facter::Util::Macosx.sw_vers.keys.sort.should == ["macosx_productName",
63
+ "macosx_buildVersion",
64
+ "macosx_productversion_minor",
65
+ "macosx_productversion_major",
66
+ "macosx_productVersion"].sort
67
+ end
68
+
69
+ it "should split a product version of 'x.y.z' into separate hash entries correctly" do
70
+ Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "1.2.3"
71
+ sw_vers = Facter::Util::Macosx.sw_vers
72
+ sw_vers["macosx_productversion_major"].should == "1.2"
73
+ sw_vers["macosx_productversion_minor"].should == "3"
74
+ end
75
+
76
+ it "should treat a product version of 'x.y' as 'x.y.0" do
77
+ Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "2.3"
78
+ Facter::Util::Macosx.sw_vers["macosx_productversion_minor"].should == "0"
80
79
  end
80
+ end
81
81
  end
@@ -3,52 +3,69 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
3
  require 'facter/util/manufacturer'
4
4
 
5
5
  describe Facter::Manufacturer do
6
- before :each do
7
- Facter.clear
8
- end
9
-
10
- it "should return the system DMI table" do
11
- Facter::Manufacturer.should respond_to(:get_dmi_table)
12
- end
13
-
14
- it "should return nil on non-supported operating systems" do
15
- Facter.stubs(:value).with(:kernel).returns("SomeThing")
16
- Facter::Manufacturer.get_dmi_table().should be_nil
17
- end
18
-
19
- it "should parse prtdiag output" do
20
- Facter::Util::Resolution.stubs(:exec).returns("System Configuration: Sun Microsystems sun4u Sun SPARC Enterprise M3000 Server")
21
- Facter::Manufacturer.prtdiag_sparc_find_system_info()
22
- Facter.value(:manufacturer).should == "Sun Microsystems"
23
- Facter.value(:productname).should == "Sun SPARC Enterprise M3000 Server"
24
- end
25
-
26
- it "should strip white space on dmi output with spaces" do
27
- sample_output_file = File.dirname(__FILE__) + "/../data/linux_dmidecode_with_spaces"
28
- dmidecode_output = File.new(sample_output_file).read()
29
- Facter::Manufacturer.expects(:get_dmi_table).returns(dmidecode_output)
30
- Facter.fact(:kernel).stubs(:value).returns("Linux")
31
-
32
- query = { '[Ss]ystem [Ii]nformation' => [ { 'Product(?: Name)?:' => 'productname' } ] }
33
-
34
- Facter::Manufacturer.dmi_find_system_info(query)
35
- Facter.value(:productname).should == "MS-6754"
36
- end
37
-
38
- it "should handle output from smbios when run under sunos" do
39
- sample_output_file = File.dirname(__FILE__) + "/../data/opensolaris_smbios"
40
- smbios_output = File.new(sample_output_file).read()
41
- Facter::Manufacturer.expects(:get_dmi_table).returns(smbios_output)
42
- Facter.fact(:kernel).stubs(:value).returns("SunOS")
43
-
44
- query = { 'BIOS information' => [ { 'Release Date:' => 'reldate' } ] }
45
-
46
- Facter::Manufacturer.dmi_find_system_info(query)
47
- Facter.value(:reldate).should == "12/01/2006"
48
- end
49
-
50
- it "should not split on dmi keys containing the string Handle" do
51
- dmidecode_output = <<-eos
6
+ before :each do
7
+ Facter.clear
8
+ end
9
+
10
+ it "should return the system DMI table" do
11
+ Facter::Manufacturer.should respond_to(:get_dmi_table)
12
+ end
13
+
14
+ it "should return nil on non-supported operating systems" do
15
+ Facter.stubs(:value).with(:kernel).returns("SomeThing")
16
+ Facter::Manufacturer.get_dmi_table().should be_nil
17
+ end
18
+
19
+ it "should parse prtdiag output on a sunfire v120" do
20
+ Facter::Util::Resolution.stubs(:exec).returns(fixture_data(File.join("unit", "util", "manufacturer", "solaris_sunfire_v120_prtdiag")))
21
+ Facter::Manufacturer.prtdiag_sparc_find_system_info()
22
+ Facter.value(:manufacturer).should == "Sun Microsystems"
23
+ Facter.value(:productname).should == "Sun Fire V120 (UltraSPARC-IIe 648MHz)"
24
+ end
25
+
26
+ it "should parse prtdiag output on a t5220" do
27
+ Facter::Util::Resolution.stubs(:exec).returns(fixture_data(File.join("unit", "util", "manufacturer", "solaris_t5220_prtdiag")))
28
+ Facter::Manufacturer.prtdiag_sparc_find_system_info()
29
+ Facter.value(:manufacturer).should == "Sun Microsystems"
30
+ Facter.value(:productname).should == "SPARC Enterprise T5220"
31
+ end
32
+
33
+ it "should not set manufacturer or productname if prtdiag output is nil" do
34
+ # Stub kernel so we don't have windows fall through to its own mechanism
35
+ Facter.fact(:kernel).stubs(:value).returns("SunOS")
36
+
37
+ Facter::Util::Resolution.stubs(:exec).returns(nil)
38
+ Facter::Manufacturer.prtdiag_sparc_find_system_info()
39
+ Facter.value(:manufacturer).should be_nil
40
+ Facter.value(:productname).should be_nil
41
+ end
42
+
43
+ it "should strip white space on dmi output with spaces" do
44
+ sample_output_file = File.dirname(__FILE__) + "/../data/linux_dmidecode_with_spaces"
45
+ dmidecode_output = File.new(sample_output_file).read()
46
+ Facter::Manufacturer.expects(:get_dmi_table).returns(dmidecode_output)
47
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
48
+
49
+ query = { '[Ss]ystem [Ii]nformation' => [ { 'Product(?: Name)?:' => 'productname' } ] }
50
+
51
+ Facter::Manufacturer.dmi_find_system_info(query)
52
+ Facter.value(:productname).should == "MS-6754"
53
+ end
54
+
55
+ it "should handle output from smbios when run under sunos" do
56
+ sample_output_file = File.dirname(__FILE__) + "/../data/opensolaris_smbios"
57
+ smbios_output = File.new(sample_output_file).read()
58
+ Facter::Manufacturer.expects(:get_dmi_table).returns(smbios_output)
59
+ Facter.fact(:kernel).stubs(:value).returns("SunOS")
60
+
61
+ query = { 'BIOS information' => [ { 'Release Date:' => 'reldate' } ] }
62
+
63
+ Facter::Manufacturer.dmi_find_system_info(query)
64
+ Facter.value(:reldate).should == "12/01/2006"
65
+ end
66
+
67
+ it "should not split on dmi keys containing the string Handle" do
68
+ dmidecode_output = <<-eos
52
69
  Handle 0x1000, DMI type 16, 15 bytes
53
70
  Physical Memory Array
54
71
  Location: System Board Or Motherboard
@@ -61,16 +78,16 @@ Physical Memory Array
61
78
  Handle 0x001F
62
79
  DMI type 127, 4 bytes.
63
80
  End Of Table
64
- eos
65
- Facter::Manufacturer.expects(:get_dmi_table).returns(dmidecode_output)
66
- Facter.fact(:kernel).stubs(:value).returns("Linux")
67
- query = { 'Physical Memory Array' => [ { 'Number Of Devices:' => 'ramslots'}]}
68
- Facter::Manufacturer.dmi_find_system_info(query)
69
- Facter.value(:ramslots).should == "123"
70
- end
71
-
72
- it "should match the key in the defined section and not the first one found" do
73
- dmidecode_output = <<-eos
81
+ eos
82
+ Facter::Manufacturer.expects(:get_dmi_table).returns(dmidecode_output)
83
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
84
+ query = { 'Physical Memory Array' => [ { 'Number Of Devices:' => 'ramslots'}]}
85
+ Facter::Manufacturer.dmi_find_system_info(query)
86
+ Facter.value(:ramslots).should == "123"
87
+ end
88
+
89
+ it "should match the key in the defined section and not the first one found" do
90
+ dmidecode_output = <<-eos
74
91
  Handle 0x000C, DMI type 7, 19 bytes
75
92
  Cache Information
76
93
  Socket Designation: Internal L2 Cache
@@ -99,55 +116,55 @@ Physical Memory Array
99
116
  Handle 0x001F
100
117
  DMI type 127, 4 bytes.
101
118
  End Of Table
102
- eos
103
- Facter::Manufacturer.expects(:get_dmi_table).returns(dmidecode_output)
104
- Facter.fact(:kernel).stubs(:value).returns("Linux")
105
- query = { 'Physical Memory Array' => [ { 'Location:' => 'ramlocation'}]}
106
- Facter::Manufacturer.dmi_find_system_info(query)
107
- Facter.value(:ramlocation).should == "System Board Or Motherboard"
108
- end
109
-
110
- def find_product_name(os)
111
- output_file = case os
112
- when "FreeBSD" then File.dirname(__FILE__) + "/../data/freebsd_dmidecode"
113
- when "SunOS" then File.dirname(__FILE__) + "/../data/opensolaris_smbios"
114
- end
115
-
116
- output = File.new(output_file).read()
117
- query = { '[Ss]ystem [Ii]nformation' => [ { 'Product(?: Name)?:' => "product_name_#{os}" } ] }
118
-
119
- Facter.fact(:kernel).stubs(:value).returns(os)
120
- Facter::Manufacturer.expects(:get_dmi_table).returns(output)
121
-
122
- Facter::Manufacturer.dmi_find_system_info(query)
123
-
124
- return Facter.value("product_name_#{os}")
125
- end
126
-
127
- it "should return the same result with smbios than with dmidecode" do
128
- find_product_name("FreeBSD").should_not == nil
129
- find_product_name("FreeBSD").should == find_product_name("SunOS")
130
- end
131
-
132
- it "should find information on Windows" do
133
- Facter.fact(:kernel).stubs(:value).returns("windows")
134
- require 'facter/util/wmi'
135
-
136
- bios = stubs 'bios'
137
- bios.stubs(:Manufacturer).returns("Phoenix Technologies LTD")
138
- bios.stubs(:Serialnumber).returns("56 4d 40 2b 4d 81 94 d6-e6 c5 56 a4 56 0c 9e 9f")
139
-
140
- product = stubs 'product'
141
- product.stubs(:Name).returns("VMware Virtual Platform")
142
-
143
- wmi = stubs 'wmi'
144
- wmi.stubs(:ExecQuery).with("select * from Win32_Bios").returns([bios])
145
- wmi.stubs(:ExecQuery).with("select * from Win32_Bios").returns([bios])
146
- wmi.stubs(:ExecQuery).with("select * from Win32_ComputerSystemProduct").returns([product])
147
-
148
- Facter::Util::WMI.stubs(:connect).returns(wmi)
149
- Facter.value(:manufacturer).should == "Phoenix Technologies LTD"
150
- Facter.value(:serialnumber).should == "56 4d 40 2b 4d 81 94 d6-e6 c5 56 a4 56 0c 9e 9f"
151
- Facter.value(:productname).should == "VMware Virtual Platform"
152
- end
119
+ eos
120
+ Facter::Manufacturer.expects(:get_dmi_table).returns(dmidecode_output)
121
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
122
+ query = { 'Physical Memory Array' => [ { 'Location:' => 'ramlocation'}]}
123
+ Facter::Manufacturer.dmi_find_system_info(query)
124
+ Facter.value(:ramlocation).should == "System Board Or Motherboard"
125
+ end
126
+
127
+ def find_product_name(os)
128
+ output_file = case os
129
+ when "FreeBSD" then File.dirname(__FILE__) + "/../data/freebsd_dmidecode"
130
+ when "SunOS" then File.dirname(__FILE__) + "/../data/opensolaris_smbios"
131
+ end
132
+
133
+ output = File.new(output_file).read()
134
+ query = { '[Ss]ystem [Ii]nformation' => [ { 'Product(?: Name)?:' => "product_name_#{os}" } ] }
135
+
136
+ Facter.fact(:kernel).stubs(:value).returns(os)
137
+ Facter::Manufacturer.expects(:get_dmi_table).returns(output)
138
+
139
+ Facter::Manufacturer.dmi_find_system_info(query)
140
+
141
+ return Facter.value("product_name_#{os}")
142
+ end
143
+
144
+ it "should return the same result with smbios than with dmidecode" do
145
+ find_product_name("FreeBSD").should_not == nil
146
+ find_product_name("FreeBSD").should == find_product_name("SunOS")
147
+ end
148
+
149
+ it "should find information on Windows" do
150
+ Facter.fact(:kernel).stubs(:value).returns("windows")
151
+ require 'facter/util/wmi'
152
+
153
+ bios = stubs 'bios'
154
+ bios.stubs(:Manufacturer).returns("Phoenix Technologies LTD")
155
+ bios.stubs(:Serialnumber).returns("56 4d 40 2b 4d 81 94 d6-e6 c5 56 a4 56 0c 9e 9f")
156
+
157
+ product = stubs 'product'
158
+ product.stubs(:Name).returns("VMware Virtual Platform")
159
+
160
+ wmi = stubs 'wmi'
161
+ wmi.stubs(:ExecQuery).with("select * from Win32_Bios").returns([bios])
162
+ wmi.stubs(:ExecQuery).with("select * from Win32_Bios").returns([bios])
163
+ wmi.stubs(:ExecQuery).with("select * from Win32_ComputerSystemProduct").returns([product])
164
+
165
+ Facter::Util::WMI.stubs(:connect).returns(wmi)
166
+ Facter.value(:manufacturer).should == "Phoenix Technologies LTD"
167
+ Facter.value(:serialnumber).should == "56 4d 40 2b 4d 81 94 d6-e6 c5 56 a4 56 0c 9e 9f"
168
+ Facter.value(:productname).should == "VMware Virtual Platform"
169
+ end
153
170
  end
@@ -5,295 +5,295 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
5
5
  require 'facter/util/resolution'
6
6
 
7
7
  describe Facter::Util::Resolution do
8
- it "should require a name" do
9
- lambda { Facter::Util::Resolution.new }.should raise_error(ArgumentError)
8
+ it "should require a name" do
9
+ lambda { Facter::Util::Resolution.new }.should raise_error(ArgumentError)
10
+ end
11
+
12
+ it "should have a name" do
13
+ Facter::Util::Resolution.new("yay").name.should == "yay"
14
+ end
15
+
16
+ it "should have a method for setting the weight" do
17
+ Facter::Util::Resolution.new("yay").should respond_to(:has_weight)
18
+ end
19
+
20
+ it "should have a method for setting the code" do
21
+ Facter::Util::Resolution.new("yay").should respond_to(:setcode)
22
+ end
23
+
24
+ it "should support a timeout value" do
25
+ Facter::Util::Resolution.new("yay").should respond_to(:timeout=)
26
+ end
27
+
28
+ it "should default to a timeout of 0 seconds" do
29
+ Facter::Util::Resolution.new("yay").limit.should == 0
30
+ end
31
+
32
+ it "should default to nil for code" do
33
+ Facter::Util::Resolution.new("yay").code.should be_nil
34
+ end
35
+
36
+ it "should default to nil for interpreter" do
37
+ Facter.expects(:warnonce).with("The 'Facter::Util::Resolution.interpreter' method is deprecated and will be removed in a future version.")
38
+ Facter::Util::Resolution.new("yay").interpreter.should be_nil
39
+ end
40
+
41
+ it "should provide a 'limit' method that returns the timeout" do
42
+ res = Facter::Util::Resolution.new("yay")
43
+ res.timeout = "testing"
44
+ res.limit.should == "testing"
45
+ end
46
+
47
+ describe "when setting the code" do
48
+ before do
49
+ Facter.stubs(:warnonce)
50
+ @resolve = Facter::Util::Resolution.new("yay")
10
51
  end
11
52
 
12
- it "should have a name" do
13
- Facter::Util::Resolution.new("yay").name.should == "yay"
53
+ it "should deprecate the interpreter argument to 'setcode'" do
54
+ Facter.expects(:warnonce).with("The interpreter parameter to 'setcode' is deprecated and will be removed in a future version.")
55
+ @resolve.setcode "foo", "bar"
56
+ @resolve.interpreter.should == "bar"
14
57
  end
15
58
 
16
- it "should have a method for setting the weight" do
17
- Facter::Util::Resolution.new("yay").should respond_to(:has_weight)
59
+ it "should deprecate the interpreter= method" do
60
+ Facter.expects(:warnonce).with("The 'Facter::Util::Resolution.interpreter=' method is deprecated and will be removed in a future version.")
61
+ @resolve.interpreter = "baz"
62
+ @resolve.interpreter.should == "baz"
18
63
  end
19
64
 
20
- it "should have a method for setting the code" do
21
- Facter::Util::Resolution.new("yay").should respond_to(:setcode)
65
+ it "should deprecate the interpreter method" do
66
+ Facter.expects(:warnonce).with("The 'Facter::Util::Resolution.interpreter' method is deprecated and will be removed in a future version.")
67
+ @resolve.interpreter
22
68
  end
23
69
 
24
- it "should support a timeout value" do
25
- Facter::Util::Resolution.new("yay").should respond_to(:timeout=)
70
+ it "should set the code to any provided string" do
71
+ @resolve.setcode "foo"
72
+ @resolve.code.should == "foo"
26
73
  end
27
74
 
28
- it "should default to a timeout of 0 seconds" do
29
- Facter::Util::Resolution.new("yay").limit.should == 0
75
+ it "should set the code to any provided block" do
76
+ block = lambda { }
77
+ @resolve.setcode(&block)
78
+ @resolve.code.should equal(block)
30
79
  end
31
80
 
32
- it "should default to nil for code" do
33
- Facter::Util::Resolution.new("yay").code.should be_nil
81
+ it "should prefer the string over a block" do
82
+ @resolve.setcode("foo") { }
83
+ @resolve.code.should == "foo"
34
84
  end
35
85
 
36
- it "should default to nil for interpreter" do
37
- Facter.expects(:warnonce).with("The 'Facter::Util::Resolution.interpreter' method is deprecated and will be removed in a future version.")
38
- Facter::Util::Resolution.new("yay").interpreter.should be_nil
86
+ it "should fail if neither a string nor block has been provided" do
87
+ lambda { @resolve.setcode }.should raise_error(ArgumentError)
39
88
  end
89
+ end
40
90
 
41
- it "should provide a 'limit' method that returns the timeout" do
42
- res = Facter::Util::Resolution.new("yay")
43
- res.timeout = "testing"
44
- res.limit.should == "testing"
45
- end
46
-
47
- describe "when setting the code" do
48
- before do
49
- Facter.stubs(:warnonce)
50
- @resolve = Facter::Util::Resolution.new("yay")
51
- end
52
-
53
- it "should deprecate the interpreter argument to 'setcode'" do
54
- Facter.expects(:warnonce).with("The interpreter parameter to 'setcode' is deprecated and will be removed in a future version.")
55
- @resolve.setcode "foo", "bar"
56
- @resolve.interpreter.should == "bar"
57
- end
91
+ it "should be able to return a value" do
92
+ Facter::Util::Resolution.new("yay").should respond_to(:value)
93
+ end
58
94
 
59
- it "should deprecate the interpreter= method" do
60
- Facter.expects(:warnonce).with("The 'Facter::Util::Resolution.interpreter=' method is deprecated and will be removed in a future version.")
61
- @resolve.interpreter = "baz"
62
- @resolve.interpreter.should == "baz"
63
- end
95
+ describe "when returning the value" do
96
+ before do
97
+ @resolve = Facter::Util::Resolution.new("yay")
98
+ end
64
99
 
65
- it "should deprecate the interpreter method" do
66
- Facter.expects(:warnonce).with("The 'Facter::Util::Resolution.interpreter' method is deprecated and will be removed in a future version.")
67
- @resolve.interpreter
68
- end
100
+ describe "and setcode has not been called" do
101
+ it "should return nil" do
102
+ Facter::Util::Resolution.expects(:exec).with(nil, nil).never
103
+ @resolve.value.should be_nil
104
+ end
105
+ end
69
106
 
70
- it "should set the code to any provided string" do
71
- @resolve.setcode "foo"
72
- @resolve.code.should == "foo"
107
+ describe "and the code is a string" do
108
+ describe "on windows" do
109
+ before do
110
+ Facter::Util::Config.stubs(:is_windows?).returns(true)
73
111
  end
74
112
 
75
- it "should set the code to any provided block" do
76
- block = lambda { }
77
- @resolve.setcode(&block)
78
- @resolve.code.should equal(block)
79
- end
113
+ it "should return the result of executing the code" do
114
+ @resolve.setcode "/bin/foo"
115
+ Facter::Util::Resolution.expects(:exec).once.with("/bin/foo").returns "yup"
80
116
 
81
- it "should prefer the string over a block" do
82
- @resolve.setcode("foo") { }
83
- @resolve.code.should == "foo"
117
+ @resolve.value.should == "yup"
84
118
  end
85
119
 
86
- it "should fail if neither a string nor block has been provided" do
87
- lambda { @resolve.setcode }.should raise_error(ArgumentError)
120
+ it "should return nil if the value is an empty string" do
121
+ @resolve.setcode "/bin/foo"
122
+ Facter::Util::Resolution.expects(:exec).once.returns ""
123
+ @resolve.value.should be_nil
88
124
  end
89
- end
90
-
91
- it "should be able to return a value" do
92
- Facter::Util::Resolution.new("yay").should respond_to(:value)
93
- end
125
+ end
94
126
 
95
- describe "when returning the value" do
127
+ describe "on non-windows systems" do
96
128
  before do
97
- @resolve = Facter::Util::Resolution.new("yay")
129
+ Facter::Util::Config.stubs(:is_windows?).returns(false)
98
130
  end
99
131
 
100
- describe "and setcode has not been called" do
101
- it "should return nil" do
102
- Facter::Util::Resolution.expects(:exec).with(nil, nil).never
103
- @resolve.value.should be_nil
104
- end
105
- end
132
+ it "should return the result of executing the code" do
133
+ @resolve.setcode "/bin/foo"
134
+ Facter::Util::Resolution.expects(:exec).once.with("/bin/foo").returns "yup"
106
135
 
107
- describe "and the code is a string" do
108
- describe "on windows" do
109
- before do
110
- Facter::Util::Resolution::WINDOWS = true
111
- end
112
-
113
- it "should return the result of executing the code" do
114
- @resolve.setcode "/bin/foo"
115
- Facter::Util::Resolution.expects(:exec).once.with("/bin/foo").returns "yup"
116
-
117
- @resolve.value.should == "yup"
118
- end
119
-
120
- it "should return nil if the value is an empty string" do
121
- @resolve.setcode "/bin/foo"
122
- Facter::Util::Resolution.expects(:exec).once.returns ""
123
- @resolve.value.should be_nil
124
- end
125
- end
126
-
127
- describe "on non-windows systems" do
128
- before do
129
- Facter::Util::Resolution::WINDOWS = false
130
- end
131
-
132
- it "should return the result of executing the code" do
133
- @resolve.setcode "/bin/foo"
134
- Facter::Util::Resolution.expects(:exec).once.with("/bin/foo").returns "yup"
135
-
136
- @resolve.value.should == "yup"
137
- end
138
-
139
- it "should return nil if the value is an empty string" do
140
- @resolve.setcode "/bin/foo"
141
- Facter::Util::Resolution.expects(:exec).once.returns ""
142
- @resolve.value.should be_nil
143
- end
144
- end
136
+ @resolve.value.should == "yup"
145
137
  end
146
138
 
147
- describe "and the code is a block" do
148
- it "should warn but not fail if the code fails" do
149
- @resolve.setcode { raise "feh" }
150
- @resolve.expects(:warn)
151
- @resolve.value.should be_nil
152
- end
153
-
154
- it "should return the value returned by the block" do
155
- @resolve.setcode { "yayness" }
156
- @resolve.value.should == "yayness"
157
- end
158
-
159
- it "should return nil if the value is an empty string" do
160
- @resolve.setcode { "" }
161
- @resolve.value.should be_nil
162
- end
163
-
164
- it "should return nil if the value is an empty block" do
165
- @resolve.setcode { "" }
166
- @resolve.value.should be_nil
167
- end
168
-
169
- it "should use its limit method to determine the timeout, to avoid conflict when a 'timeout' method exists for some other reason" do
170
- @resolve.expects(:timeout).never
171
- @resolve.expects(:limit).returns "foo"
172
- Timeout.expects(:timeout).with("foo")
173
-
174
- @resolve.setcode { sleep 2; "raise This is a test"}
175
- @resolve.value
176
- end
177
-
178
- it "should timeout after the provided timeout" do
179
- @resolve.expects(:warn)
180
- @resolve.timeout = 0.1
181
- @resolve.setcode { sleep 2; raise "This is a test" }
182
- Thread.expects(:new).yields
183
-
184
- @resolve.value.should be_nil
185
- end
186
-
187
- it "should waitall to avoid zombies if the timeout is exceeded" do
188
- @resolve.stubs(:warn)
189
- @resolve.timeout = 0.1
190
- @resolve.setcode { sleep 2; raise "This is a test" }
191
-
192
- Thread.expects(:new).yields
193
- Process.expects(:waitall)
194
-
195
- @resolve.value
196
- end
139
+ it "should return nil if the value is an empty string" do
140
+ @resolve.setcode "/bin/foo"
141
+ Facter::Util::Resolution.expects(:exec).once.returns ""
142
+ @resolve.value.should be_nil
197
143
  end
144
+ end
198
145
  end
199
146
 
200
- it "should return its value when converted to a string" do
201
- @resolve = Facter::Util::Resolution.new("yay")
202
- @resolve.expects(:value).returns "myval"
203
- @resolve.to_s.should == "myval"
147
+ describe "and the code is a block" do
148
+ it "should warn but not fail if the code fails" do
149
+ @resolve.setcode { raise "feh" }
150
+ @resolve.expects(:warn)
151
+ @resolve.value.should be_nil
152
+ end
153
+
154
+ it "should return the value returned by the block" do
155
+ @resolve.setcode { "yayness" }
156
+ @resolve.value.should == "yayness"
157
+ end
158
+
159
+ it "should return nil if the value is an empty string" do
160
+ @resolve.setcode { "" }
161
+ @resolve.value.should be_nil
162
+ end
163
+
164
+ it "should return nil if the value is an empty block" do
165
+ @resolve.setcode { "" }
166
+ @resolve.value.should be_nil
167
+ end
168
+
169
+ it "should use its limit method to determine the timeout, to avoid conflict when a 'timeout' method exists for some other reason" do
170
+ @resolve.expects(:timeout).never
171
+ @resolve.expects(:limit).returns "foo"
172
+ Timeout.expects(:timeout).with("foo")
173
+
174
+ @resolve.setcode { sleep 2; "raise This is a test"}
175
+ @resolve.value
176
+ end
177
+
178
+ it "should timeout after the provided timeout" do
179
+ @resolve.expects(:warn)
180
+ @resolve.timeout = 0.1
181
+ @resolve.setcode { sleep 2; raise "This is a test" }
182
+ Thread.expects(:new).yields
183
+
184
+ @resolve.value.should be_nil
185
+ end
186
+
187
+ it "should waitall to avoid zombies if the timeout is exceeded" do
188
+ @resolve.stubs(:warn)
189
+ @resolve.timeout = 0.1
190
+ @resolve.setcode { sleep 2; raise "This is a test" }
191
+
192
+ Thread.expects(:new).yields
193
+ Process.expects(:waitall)
194
+
195
+ @resolve.value
196
+ end
204
197
  end
205
-
206
- it "should allow the adding of confines" do
207
- Facter::Util::Resolution.new("yay").should respond_to(:confine)
198
+ end
199
+
200
+ it "should return its value when converted to a string" do
201
+ @resolve = Facter::Util::Resolution.new("yay")
202
+ @resolve.expects(:value).returns "myval"
203
+ @resolve.to_s.should == "myval"
204
+ end
205
+
206
+ it "should allow the adding of confines" do
207
+ Facter::Util::Resolution.new("yay").should respond_to(:confine)
208
+ end
209
+
210
+ it "should provide a method for returning the number of confines" do
211
+ @resolve = Facter::Util::Resolution.new("yay")
212
+ @resolve.confine "one" => "foo", "two" => "fee"
213
+ @resolve.weight.should == 2
214
+ end
215
+
216
+ it "should return 0 confines when no confines have been added" do
217
+ Facter::Util::Resolution.new("yay").weight.should == 0
218
+ end
219
+
220
+ it "should provide a way to set the weight" do
221
+ @resolve = Facter::Util::Resolution.new("yay")
222
+ @resolve.has_weight(45)
223
+ @resolve.weight.should == 45
224
+ end
225
+
226
+ it "should allow the weight to override the number of confines" do
227
+ @resolve = Facter::Util::Resolution.new("yay")
228
+ @resolve.confine "one" => "foo", "two" => "fee"
229
+ @resolve.weight.should == 2
230
+ @resolve.has_weight(45)
231
+ @resolve.weight.should == 45
232
+ end
233
+
234
+ it "should have a method for determining if it is suitable" do
235
+ Facter::Util::Resolution.new("yay").should respond_to(:suitable?)
236
+ end
237
+
238
+ describe "when adding confines" do
239
+ before do
240
+ @resolve = Facter::Util::Resolution.new("yay")
208
241
  end
209
242
 
210
- it "should provide a method for returning the number of confines" do
211
- @resolve = Facter::Util::Resolution.new("yay")
212
- @resolve.confine "one" => "foo", "two" => "fee"
213
- @resolve.weight.should == 2
243
+ it "should accept a hash of fact names and values" do
244
+ lambda { @resolve.confine :one => "two" }.should_not raise_error
214
245
  end
215
246
 
216
- it "should return 0 confines when no confines have been added" do
217
- Facter::Util::Resolution.new("yay").weight.should == 0
218
- end
247
+ it "should create a Util::Confine instance for every argument in the provided hash" do
248
+ Facter::Util::Confine.expects(:new).with("one", "foo")
249
+ Facter::Util::Confine.expects(:new).with("two", "fee")
219
250
 
220
- it "should provide a way to set the weight" do
221
- @resolve = Facter::Util::Resolution.new("yay")
222
- @resolve.has_weight(45)
223
- @resolve.weight.should == 45
251
+ @resolve.confine "one" => "foo", "two" => "fee"
224
252
  end
225
253
 
226
- it "should allow the weight to override the number of confines" do
227
- @resolve = Facter::Util::Resolution.new("yay")
228
- @resolve.confine "one" => "foo", "two" => "fee"
229
- @resolve.weight.should == 2
230
- @resolve.has_weight(45)
231
- @resolve.weight.should == 45
232
- end
254
+ end
233
255
 
234
- it "should have a method for determining if it is suitable" do
235
- Facter::Util::Resolution.new("yay").should respond_to(:suitable?)
256
+ describe "when determining suitability" do
257
+ before do
258
+ @resolve = Facter::Util::Resolution.new("yay")
236
259
  end
237
260
 
238
- describe "when adding confines" do
239
- before do
240
- @resolve = Facter::Util::Resolution.new("yay")
241
- end
242
-
243
- it "should accept a hash of fact names and values" do
244
- lambda { @resolve.confine :one => "two" }.should_not raise_error
245
- end
246
-
247
- it "should create a Util::Confine instance for every argument in the provided hash" do
248
- Facter::Util::Confine.expects(:new).with("one", "foo")
249
- Facter::Util::Confine.expects(:new).with("two", "fee")
250
-
251
- @resolve.confine "one" => "foo", "two" => "fee"
252
- end
253
-
261
+ it "should always be suitable if no confines have been added" do
262
+ @resolve.should be_suitable
254
263
  end
255
264
 
256
- describe "when determining suitability" do
257
- before do
258
- @resolve = Facter::Util::Resolution.new("yay")
259
- end
265
+ it "should be unsuitable if any provided confines return false" do
266
+ confine1 = mock 'confine1', :true? => true
267
+ confine2 = mock 'confine2', :true? => false
268
+ Facter::Util::Confine.expects(:new).times(2).returns(confine1).then.returns(confine2)
269
+ @resolve.confine :one => :two, :three => :four
260
270
 
261
- it "should always be suitable if no confines have been added" do
262
- @resolve.should be_suitable
263
- end
264
-
265
- it "should be unsuitable if any provided confines return false" do
266
- confine1 = mock 'confine1', :true? => true
267
- confine2 = mock 'confine2', :true? => false
268
- Facter::Util::Confine.expects(:new).times(2).returns(confine1).then.returns(confine2)
269
- @resolve.confine :one => :two, :three => :four
270
-
271
- @resolve.should_not be_suitable
272
- end
271
+ @resolve.should_not be_suitable
272
+ end
273
273
 
274
- it "should be suitable if all provided confines return true" do
275
- confine1 = mock 'confine1', :true? => true
276
- confine2 = mock 'confine2', :true? => true
277
- Facter::Util::Confine.expects(:new).times(2).returns(confine1).then.returns(confine2)
278
- @resolve.confine :one => :two, :three => :four
274
+ it "should be suitable if all provided confines return true" do
275
+ confine1 = mock 'confine1', :true? => true
276
+ confine2 = mock 'confine2', :true? => true
277
+ Facter::Util::Confine.expects(:new).times(2).returns(confine1).then.returns(confine2)
278
+ @resolve.confine :one => :two, :three => :four
279
279
 
280
- @resolve.should be_suitable
281
- end
280
+ @resolve.should be_suitable
282
281
  end
282
+ end
283
283
 
284
- it "should have a class method for executing code" do
285
- Facter::Util::Resolution.should respond_to(:exec)
286
- end
284
+ it "should have a class method for executing code" do
285
+ Facter::Util::Resolution.should respond_to(:exec)
286
+ end
287
287
 
288
- # It's not possible, AFAICT, to mock %x{}, so I can't really test this bit.
289
- describe "when executing code" do
290
- it "should deprecate the interpreter parameter" do
291
- Facter.expects(:warnonce).with("The interpreter parameter to 'exec' is deprecated and will be removed in a future version.")
292
- Facter::Util::Resolution.exec("/something", "/bin/perl")
293
- end
288
+ # It's not possible, AFAICT, to mock %x{}, so I can't really test this bit.
289
+ describe "when executing code" do
290
+ it "should deprecate the interpreter parameter" do
291
+ Facter.expects(:warnonce).with("The interpreter parameter to 'exec' is deprecated and will be removed in a future version.")
292
+ Facter::Util::Resolution.exec("/something", "/bin/perl")
293
+ end
294
294
 
295
- it "should execute the binary" do
296
- Facter::Util::Resolution.exec("echo foo").should == "foo"
297
- end
295
+ it "should execute the binary" do
296
+ Facter::Util::Resolution.exec("echo foo").should == "foo"
298
297
  end
298
+ end
299
299
  end