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.
- data/CHANGELOG +11 -0
- data/LICENSE +1 -1
- data/conf/osx/createpackage.sh +1 -1
- data/conf/redhat/facter.spec +9 -6
- data/conf/solaris/pkginfo +1 -1
- data/install.rb +1 -1
- data/lib/facter.rb +2 -2
- data/lib/facter/architecture.rb +1 -2
- data/lib/facter/augeasversion.rb +1 -2
- data/lib/facter/domain.rb +3 -3
- data/lib/facter/hardwareisa.rb +1 -1
- data/lib/facter/ipaddress.rb +2 -2
- data/lib/facter/lsbmajdistrelease.rb +1 -1
- data/lib/facter/macaddress.rb +2 -2
- data/lib/facter/manufacturer.rb +1 -1
- data/lib/facter/netmask.rb +0 -3
- data/lib/facter/network.rb +2 -3
- data/lib/facter/operatingsystem.rb +5 -2
- data/lib/facter/operatingsystemrelease.rb +3 -3
- data/lib/facter/osfamily.rb +1 -1
- data/lib/facter/processor.rb +2 -2
- data/lib/facter/selinux.rb +3 -3
- data/lib/facter/uniqueid.rb +1 -1
- data/lib/facter/uptime_days.rb +0 -1
- data/lib/facter/uptime_hours.rb +0 -1
- data/lib/facter/util/manufacturer.rb +2 -3
- data/lib/facter/util/processor.rb +3 -3
- data/lib/facter/util/resolution.rb +3 -3
- data/lib/facter/util/values.rb +1 -1
- data/lib/facter/virtual.rb +2 -2
- data/lib/facter/vlans.rb +1 -2
- data/lib/facter/xendomains.rb +0 -1
- data/spec/fixtures/unit/util/manufacturer/solaris_sunfire_v120_prtdiag +33 -0
- data/spec/fixtures/unit/util/manufacturer/solaris_t5220_prtdiag +136 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/unit/architecture_spec.rb +40 -40
- data/spec/unit/facter_spec.rb +220 -220
- data/spec/unit/id_spec.rb +16 -16
- data/spec/unit/interfaces_spec.rb +6 -6
- data/spec/unit/memory_spec.rb +105 -105
- data/spec/unit/operatingsystem_spec.rb +72 -63
- data/spec/unit/operatingsystemrelease_spec.rb +44 -43
- data/spec/unit/processor_spec.rb +2 -2
- data/spec/unit/selinux_spec.rb +53 -53
- data/spec/unit/util/collection_spec.rb +183 -183
- data/spec/unit/util/confine_spec.rb +92 -92
- data/spec/unit/util/fact_spec.rb +96 -96
- data/spec/unit/util/ip_spec.rb +218 -218
- data/spec/unit/util/loader_spec.rb +193 -193
- data/spec/unit/util/macosx_spec.rb +63 -63
- data/spec/unit/util/manufacturer_spec.rb +124 -107
- data/spec/unit/util/resolution_spec.rb +235 -235
- data/spec/unit/util/virtual_spec.rb +167 -167
- data/spec/unit/util/vlans_spec.rb +6 -6
- data/spec/unit/virtual_spec.rb +246 -246
- data/spec/watchr.rb +1 -1
- metadata +6 -4
@@ -6,55 +6,56 @@ require 'facter'
|
|
6
6
|
|
7
7
|
describe "Operating System Release fact" do
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
before do
|
10
|
+
Facter.clear
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
Facter.clear
|
15
|
+
end
|
16
|
+
|
17
|
+
test_cases = {
|
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",
|
28
|
+
"Ascendos" => "/etc/redhat-release",
|
29
|
+
}
|
30
|
+
|
31
|
+
test_cases.each do |system, file|
|
32
|
+
describe "with operatingsystem reported as #{system.inspect}" do
|
33
|
+
it "should read the #{file.inspect} file" do
|
34
|
+
Facter.fact(:operatingsystem).stubs(:value).returns(system)
|
35
|
+
|
36
|
+
File.expects(:open).with(file, "r").at_least(1)
|
12
37
|
|
13
|
-
|
14
|
-
|
38
|
+
Facter.fact(:operatingsystemrelease).value
|
39
|
+
end
|
15
40
|
end
|
41
|
+
end
|
16
42
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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",
|
28
|
-
}
|
29
|
-
|
30
|
-
test_cases.each do |system, file|
|
31
|
-
describe "with operatingsystem reported as #{system.inspect}" do
|
32
|
-
it "should read the #{file.inspect} file" do
|
33
|
-
Facter.fact(:operatingsystem).stubs(:value).returns(system)
|
34
|
-
|
35
|
-
File.expects(:open).with(file, "r").at_least(1)
|
36
|
-
|
37
|
-
Facter.fact(:operatingsystemrelease).value
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
43
|
+
it "for VMWareESX it should run the vmware -v command" do
|
44
|
+
Facter.fact(:kernel).stubs(:value).returns("VMkernel")
|
45
|
+
Facter.fact(:kernelrelease).stubs(:value).returns("4.1.0")
|
46
|
+
Facter.fact(:operatingsystem).stubs(:value).returns("VMwareESX")
|
41
47
|
|
42
|
-
|
43
|
-
Facter.fact(:kernel).stubs(:value).returns("VMkernel")
|
44
|
-
Facter.fact(:kernelrelease).stubs(:value).returns("4.1.0")
|
45
|
-
Facter.fact(:operatingsystem).stubs(:value).returns("VMwareESX")
|
48
|
+
Facter::Util::Resolution.stubs(:exec).with('vmware -v').returns('foo')
|
46
49
|
|
47
|
-
|
50
|
+
Facter.fact(:operatingsystemrelease).value
|
51
|
+
end
|
48
52
|
|
49
|
-
|
50
|
-
|
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")
|
53
|
+
it "for Alpine it should use the contents of /etc/alpine-release" do
|
54
|
+
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
55
|
+
Facter.fact(:operatingsystem).stubs(:value).returns("Alpine")
|
55
56
|
|
56
|
-
|
57
|
+
File.expects(:read).with("/etc/alpine-release").returns("foo")
|
57
58
|
|
58
|
-
|
59
|
-
|
59
|
+
Facter.fact(:operatingsystemrelease).value.should == "foo"
|
60
|
+
end
|
60
61
|
end
|
data/spec/unit/processor_spec.rb
CHANGED
@@ -207,7 +207,7 @@ describe "Processor facts" do
|
|
207
207
|
File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true)
|
208
208
|
## sysfs method is only used if cpuinfo method returned no processors
|
209
209
|
File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
|
210
|
-
File.stubs(:readlines).with("/proc/cpuinfo").returns(
|
210
|
+
File.stubs(:readlines).with("/proc/cpuinfo").returns([])
|
211
211
|
Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu[0-9]*").returns(%w{
|
212
212
|
/sys/devices/system/cpu/cpu0
|
213
213
|
/sys/devices/system/cpu/cpu1
|
@@ -221,7 +221,7 @@ describe "Processor facts" do
|
|
221
221
|
File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true)
|
222
222
|
## sysfs method is only used if cpuinfo method returned no processors
|
223
223
|
File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
|
224
|
-
File.stubs(:readlines).with("/proc/cpuinfo").returns(
|
224
|
+
File.stubs(:readlines).with("/proc/cpuinfo").returns([])
|
225
225
|
Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu[0-9]*").returns(%w{
|
226
226
|
/sys/devices/system/cpu/cpu0
|
227
227
|
/sys/devices/system/cpu/cpu1
|
data/spec/unit/selinux_spec.rb
CHANGED
@@ -7,84 +7,84 @@ require 'facter'
|
|
7
7
|
describe "SELinux facts" do
|
8
8
|
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
after do
|
11
|
+
Facter.clear
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
it "should return true if SELinux enabled" do
|
15
|
+
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
FileTest.stubs(:exists?).returns false
|
18
|
+
File.stubs(:read).with("/proc/self/attr/current").returns("notkernel")
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
FileTest.expects(:exists?).with("/selinux/enforce").returns true
|
21
|
+
FileTest.expects(:exists?).with("/proc/self/attr/current").returns true
|
22
|
+
File.expects(:read).with("/proc/self/attr/current").returns("kernel")
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
Facter.fact(:selinux).value.should == "true"
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
it "should return true if SELinux policy enabled" do
|
28
|
+
Facter.fact(:selinux).stubs(:value).returns("true")
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
FileTest.stubs(:exists?).returns false
|
31
|
+
File.stubs(:read).with("/selinux/enforce").returns("0")
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
FileTest.expects(:exists?).with("/selinux/enforce").returns true
|
34
|
+
File.expects(:read).with("/selinux/enforce").returns("1")
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
Facter.fact(:selinux_enforced).value.should == "true"
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
it "should return an SELinux policy version" do
|
40
|
+
Facter.fact(:selinux).stubs(:value).returns("true")
|
41
|
+
FileTest.stubs(:exists?).with("/proc/self/mountinfo").returns false
|
42
42
|
|
43
|
-
|
43
|
+
File.stubs(:read).with("/selinux/policyvers").returns("")
|
44
44
|
|
45
|
-
|
45
|
+
File.expects(:read).with("/selinux/policyvers").returns("1")
|
46
46
|
|
47
|
-
|
48
|
-
|
47
|
+
Facter.fact(:selinux_policyversion).value.should == "1"
|
48
|
+
end
|
49
49
|
|
50
|
-
|
51
|
-
|
50
|
+
it "should return the SELinux current mode" do
|
51
|
+
Facter.fact(:selinux).stubs(:value).returns("true")
|
52
52
|
|
53
|
-
|
54
|
-
|
53
|
+
sample_output_file = File.dirname(__FILE__) + '/data/selinux_sestatus'
|
54
|
+
selinux_sestatus = File.read(sample_output_file)
|
55
55
|
|
56
|
-
|
56
|
+
Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(selinux_sestatus)
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
Facter.fact(:selinux_current_mode).value.should == "permissive"
|
59
|
+
end
|
60
60
|
|
61
|
-
|
62
|
-
|
61
|
+
it "should return the SELinux mode from the configuration file" do
|
62
|
+
Facter.fact(:selinux).stubs(:value).returns("true")
|
63
63
|
|
64
|
-
|
65
|
-
|
64
|
+
sample_output_file = File.dirname(__FILE__) + '/data/selinux_sestatus'
|
65
|
+
selinux_sestatus = File.read(sample_output_file)
|
66
66
|
|
67
|
-
|
67
|
+
Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(selinux_sestatus)
|
68
68
|
|
69
|
-
|
70
|
-
|
69
|
+
Facter.fact(:selinux_config_mode).value.should == "permissive"
|
70
|
+
end
|
71
71
|
|
72
|
-
|
73
|
-
|
72
|
+
it "should return the SELinux configuration file policy" do
|
73
|
+
Facter.fact(:selinux).stubs(:value).returns("true")
|
74
74
|
|
75
|
-
|
76
|
-
|
75
|
+
sample_output_file = File.dirname(__FILE__) + '/data/selinux_sestatus'
|
76
|
+
selinux_sestatus = File.read(sample_output_file)
|
77
77
|
|
78
|
-
|
78
|
+
Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(selinux_sestatus)
|
79
79
|
|
80
|
-
|
81
|
-
|
80
|
+
Facter.fact(:selinux_config_policy).value.should == "targeted"
|
81
|
+
end
|
82
82
|
|
83
|
-
|
84
|
-
|
83
|
+
it "should ensure legacy selinux_mode facts returns same value as selinux_config_policy fact" do
|
84
|
+
Facter.fact(:selinux).stubs(:value).returns("true")
|
85
85
|
|
86
|
-
|
86
|
+
Facter.fact(:selinux_config_policy).stubs(:value).returns("targeted")
|
87
87
|
|
88
|
-
|
89
|
-
|
88
|
+
Facter.fact(:selinux_mode).value.should == "targeted"
|
89
|
+
end
|
90
90
|
end
|
@@ -5,251 +5,251 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
5
5
|
require 'facter/util/collection'
|
6
6
|
|
7
7
|
describe Facter::Util::Collection do
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
it "should have a method for adding facts" do
|
9
|
+
Facter::Util::Collection.new.should respond_to(:add)
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
it "should have a method for returning a loader" do
|
13
|
+
Facter::Util::Collection.new.should respond_to(:loader)
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
it "should use an instance of the Loader class as its loader" do
|
17
|
+
Facter::Util::Collection.new.loader.should be_instance_of(Facter::Util::Loader)
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
it "should cache its loader" do
|
21
|
+
coll = Facter::Util::Collection.new
|
22
|
+
coll.loader.should equal(coll.loader)
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
it "should have a method for loading all facts" do
|
26
|
+
Facter::Util::Collection.new.should respond_to(:load_all)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should delegate its load_all method to its loader" do
|
30
|
+
coll = Facter::Util::Collection.new
|
31
|
+
coll.loader.expects(:load_all)
|
32
|
+
coll.load_all
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "when adding facts" do
|
36
|
+
before do
|
37
|
+
@coll = Facter::Util::Collection.new
|
27
38
|
end
|
28
39
|
|
29
|
-
it "should
|
30
|
-
|
31
|
-
|
32
|
-
|
40
|
+
it "should create a new fact if no fact with the same name already exists" do
|
41
|
+
fact = mock 'fact'
|
42
|
+
Facter::Util::Fact.expects(:new).with { |name, *args| name == :myname }.returns fact
|
43
|
+
|
44
|
+
@coll.add(:myname)
|
33
45
|
end
|
34
46
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
47
|
+
it "should accept options" do
|
48
|
+
@coll.add(:myname, :ldapname => "whatever") { }
|
49
|
+
end
|
39
50
|
|
40
|
-
|
41
|
-
|
42
|
-
|
51
|
+
it "should set any appropriate options on the fact instances" do
|
52
|
+
# Use a real fact instance, because we're using respond_to?
|
53
|
+
fact = Facter::Util::Fact.new(:myname)
|
54
|
+
fact.expects(:ldapname=).with("testing")
|
55
|
+
Facter::Util::Fact.expects(:new).with(:myname).returns fact
|
43
56
|
|
44
|
-
|
45
|
-
|
57
|
+
@coll.add(:myname, :ldapname => "testing")
|
58
|
+
end
|
46
59
|
|
47
|
-
|
48
|
-
|
49
|
-
|
60
|
+
it "should set appropriate options on the resolution instance" do
|
61
|
+
fact = Facter::Util::Fact.new(:myname)
|
62
|
+
Facter::Util::Fact.expects(:new).with(:myname).returns fact
|
50
63
|
|
51
|
-
|
52
|
-
|
53
|
-
fact = Facter::Util::Fact.new(:myname)
|
54
|
-
fact.expects(:ldapname=).with("testing")
|
55
|
-
Facter::Util::Fact.expects(:new).with(:myname).returns fact
|
64
|
+
resolve = Facter::Util::Resolution.new(:myname) {}
|
65
|
+
fact.expects(:add).returns resolve
|
56
66
|
|
57
|
-
|
58
|
-
|
67
|
+
@coll.add(:myname, :timeout => "myval") {}
|
68
|
+
end
|
59
69
|
|
60
|
-
|
61
|
-
|
62
|
-
|
70
|
+
it "should not pass fact-specific options to resolutions" do
|
71
|
+
fact = Facter::Util::Fact.new(:myname)
|
72
|
+
Facter::Util::Fact.expects(:new).with(:myname).returns fact
|
63
73
|
|
64
|
-
|
65
|
-
|
74
|
+
resolve = Facter::Util::Resolution.new(:myname) {}
|
75
|
+
fact.expects(:add).returns resolve
|
66
76
|
|
67
|
-
|
68
|
-
|
77
|
+
fact.expects(:ldapname=).with("foo")
|
78
|
+
resolve.expects(:timeout=).with("myval")
|
69
79
|
|
70
|
-
|
71
|
-
|
72
|
-
Facter::Util::Fact.expects(:new).with(:myname).returns fact
|
80
|
+
@coll.add(:myname, :timeout => "myval", :ldapname => "foo") {}
|
81
|
+
end
|
73
82
|
|
74
|
-
|
75
|
-
|
83
|
+
it "should fail if invalid options are provided" do
|
84
|
+
lambda { @coll.add(:myname, :foo => :bar) }.should raise_error(ArgumentError)
|
85
|
+
end
|
76
86
|
|
77
|
-
|
78
|
-
|
87
|
+
describe "and a block is provided" do
|
88
|
+
it "should use the block to add a resolution to the fact" do
|
89
|
+
fact = mock 'fact'
|
90
|
+
Facter::Util::Fact.expects(:new).returns fact
|
79
91
|
|
80
|
-
|
81
|
-
end
|
92
|
+
fact.expects(:add)
|
82
93
|
|
83
|
-
|
84
|
-
|
85
|
-
|
94
|
+
@coll.add(:myname) {}
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
86
98
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
Facter::Util::Fact.expects(:new).returns fact
|
99
|
+
it "should have a method for retrieving facts by name" do
|
100
|
+
Facter::Util::Collection.new.should respond_to(:fact)
|
101
|
+
end
|
91
102
|
|
92
|
-
|
103
|
+
describe "when retrieving facts" do
|
104
|
+
before do
|
105
|
+
@coll = Facter::Util::Collection.new
|
93
106
|
|
94
|
-
|
95
|
-
end
|
96
|
-
end
|
107
|
+
@fact = @coll.add("YayNess")
|
97
108
|
end
|
98
109
|
|
99
|
-
it "should
|
100
|
-
|
110
|
+
it "should return the fact instance specified by the name" do
|
111
|
+
@coll.fact("YayNess").should equal(@fact)
|
101
112
|
end
|
102
113
|
|
103
|
-
|
104
|
-
|
105
|
-
|
114
|
+
it "should be case-insensitive" do
|
115
|
+
@coll.fact("yayness").should equal(@fact)
|
116
|
+
end
|
106
117
|
|
107
|
-
|
108
|
-
|
118
|
+
it "should treat strings and symbols equivalently" do
|
119
|
+
@coll.fact(:yayness).should equal(@fact)
|
120
|
+
end
|
109
121
|
|
110
|
-
|
111
|
-
|
112
|
-
|
122
|
+
it "should use its loader to try to load the fact if no fact can be found" do
|
123
|
+
@coll.loader.expects(:load).with(:testing)
|
124
|
+
@coll.fact("testing")
|
125
|
+
end
|
113
126
|
|
114
|
-
|
115
|
-
|
116
|
-
|
127
|
+
it "should return nil if it cannot find or load the fact" do
|
128
|
+
@coll.loader.expects(:load).with(:testing)
|
129
|
+
@coll.fact("testing").should be_nil
|
130
|
+
end
|
131
|
+
end
|
117
132
|
|
118
|
-
|
119
|
-
|
120
|
-
|
133
|
+
it "should have a method for returning a fact's value" do
|
134
|
+
Facter::Util::Collection.new.should respond_to(:value)
|
135
|
+
end
|
121
136
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
137
|
+
describe "when returning a fact's value" do
|
138
|
+
before do
|
139
|
+
@coll = Facter::Util::Collection.new
|
140
|
+
@fact = @coll.add("YayNess")
|
126
141
|
|
127
|
-
|
128
|
-
@coll.loader.expects(:load).with(:testing)
|
129
|
-
@coll.fact("testing").should be_nil
|
130
|
-
end
|
142
|
+
@fact.stubs(:value).returns "result"
|
131
143
|
end
|
132
144
|
|
133
|
-
it "should
|
134
|
-
|
145
|
+
it "should use the 'fact' method to retrieve the fact" do
|
146
|
+
@coll.expects(:fact).with(:yayness).returns @fact
|
147
|
+
@coll.value(:yayness)
|
135
148
|
end
|
136
149
|
|
137
|
-
|
138
|
-
|
139
|
-
@coll = Facter::Util::Collection.new
|
140
|
-
@fact = @coll.add("YayNess")
|
150
|
+
it "should return the result of calling :value on the fact" do
|
151
|
+
@fact.expects(:value).returns "result"
|
141
152
|
|
142
|
-
|
143
|
-
|
153
|
+
@coll.value("YayNess").should == "result"
|
154
|
+
end
|
144
155
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
end
|
156
|
+
it "should be case-insensitive" do
|
157
|
+
@coll.value("yayness").should_not be_nil
|
158
|
+
end
|
149
159
|
|
150
|
-
|
151
|
-
|
160
|
+
it "should treat strings and symbols equivalently" do
|
161
|
+
@coll.value(:yayness).should_not be_nil
|
162
|
+
end
|
163
|
+
end
|
152
164
|
|
153
|
-
|
154
|
-
|
165
|
+
it "should return the fact's value when the array index method is used" do
|
166
|
+
@coll = Facter::Util::Collection.new
|
167
|
+
@coll.expects(:value).with("myfact").returns "foo"
|
168
|
+
@coll["myfact"].should == "foo"
|
169
|
+
end
|
155
170
|
|
156
|
-
|
157
|
-
|
158
|
-
|
171
|
+
it "should have a method for flushing all facts" do
|
172
|
+
@coll = Facter::Util::Collection.new
|
173
|
+
@fact = @coll.add("YayNess")
|
159
174
|
|
160
|
-
|
161
|
-
@coll.value(:yayness).should_not be_nil
|
162
|
-
end
|
163
|
-
end
|
175
|
+
@fact.expects(:flush)
|
164
176
|
|
165
|
-
|
166
|
-
|
167
|
-
@coll.expects(:value).with("myfact").returns "foo"
|
168
|
-
@coll["myfact"].should == "foo"
|
169
|
-
end
|
177
|
+
@coll.flush
|
178
|
+
end
|
170
179
|
|
171
|
-
|
172
|
-
|
173
|
-
|
180
|
+
it "should have a method that returns all fact names" do
|
181
|
+
@coll = Facter::Util::Collection.new
|
182
|
+
@coll.add(:one)
|
183
|
+
@coll.add(:two)
|
174
184
|
|
175
|
-
|
185
|
+
@coll.list.sort { |a,b| a.to_s <=> b.to_s }.should == [:one, :two]
|
186
|
+
end
|
176
187
|
|
177
|
-
|
178
|
-
|
188
|
+
it "should have a method for returning a hash of fact values" do
|
189
|
+
Facter::Util::Collection.new.should respond_to(:to_hash)
|
190
|
+
end
|
179
191
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
192
|
+
describe "when returning a hash of values" do
|
193
|
+
before do
|
194
|
+
@coll = Facter::Util::Collection.new
|
195
|
+
@fact = @coll.add(:one)
|
196
|
+
@fact.stubs(:value).returns "me"
|
197
|
+
end
|
184
198
|
|
185
|
-
|
199
|
+
it "should return a hash of fact names and values with the fact names as strings" do
|
200
|
+
@coll.to_hash.should == {"one" => "me"}
|
186
201
|
end
|
187
202
|
|
188
|
-
it "should
|
189
|
-
|
203
|
+
it "should not include facts that did not return a value" do
|
204
|
+
f = @coll.add(:two)
|
205
|
+
f.stubs(:value).returns nil
|
206
|
+
@coll.to_hash.should_not be_include(:two)
|
190
207
|
end
|
208
|
+
end
|
191
209
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
@fact = @coll.add(:one)
|
196
|
-
@fact.stubs(:value).returns "me"
|
197
|
-
end
|
210
|
+
it "should have a method for iterating over all facts" do
|
211
|
+
Facter::Util::Collection.new.should respond_to(:each)
|
212
|
+
end
|
198
213
|
|
199
|
-
|
200
|
-
|
201
|
-
|
214
|
+
it "should include Enumerable" do
|
215
|
+
Facter::Util::Collection.ancestors.should be_include(Enumerable)
|
216
|
+
end
|
202
217
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
218
|
+
describe "when iterating over facts" do
|
219
|
+
before do
|
220
|
+
@coll = Facter::Util::Collection.new
|
221
|
+
@one = @coll.add(:one)
|
222
|
+
@two = @coll.add(:two)
|
208
223
|
end
|
209
224
|
|
210
|
-
it "should
|
211
|
-
|
225
|
+
it "should yield each fact name and the fact value" do
|
226
|
+
@one.stubs(:value).returns "ONE"
|
227
|
+
@two.stubs(:value).returns "TWO"
|
228
|
+
facts = {}
|
229
|
+
@coll.each do |fact, value|
|
230
|
+
facts[fact] = value
|
231
|
+
end
|
232
|
+
facts.should == {"one" => "ONE", "two" => "TWO"}
|
212
233
|
end
|
213
234
|
|
214
|
-
it "should
|
215
|
-
|
235
|
+
it "should convert the fact name to a string" do
|
236
|
+
@one.stubs(:value).returns "ONE"
|
237
|
+
@two.stubs(:value).returns "TWO"
|
238
|
+
facts = {}
|
239
|
+
@coll.each do |fact, value|
|
240
|
+
fact.should be_instance_of(String)
|
241
|
+
end
|
216
242
|
end
|
217
243
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
it "should yield each fact name and the fact value" do
|
226
|
-
@one.stubs(:value).returns "ONE"
|
227
|
-
@two.stubs(:value).returns "TWO"
|
228
|
-
facts = {}
|
229
|
-
@coll.each do |fact, value|
|
230
|
-
facts[fact] = value
|
231
|
-
end
|
232
|
-
facts.should == {"one" => "ONE", "two" => "TWO"}
|
233
|
-
end
|
234
|
-
|
235
|
-
it "should convert the fact name to a string" do
|
236
|
-
@one.stubs(:value).returns "ONE"
|
237
|
-
@two.stubs(:value).returns "TWO"
|
238
|
-
facts = {}
|
239
|
-
@coll.each do |fact, value|
|
240
|
-
fact.should be_instance_of(String)
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
it "should only yield facts that have values" do
|
245
|
-
@one.stubs(:value).returns "ONE"
|
246
|
-
@two.stubs(:value).returns nil
|
247
|
-
facts = {}
|
248
|
-
@coll.each do |fact, value|
|
249
|
-
facts[fact] = value
|
250
|
-
end
|
244
|
+
it "should only yield facts that have values" do
|
245
|
+
@one.stubs(:value).returns "ONE"
|
246
|
+
@two.stubs(:value).returns nil
|
247
|
+
facts = {}
|
248
|
+
@coll.each do |fact, value|
|
249
|
+
facts[fact] = value
|
250
|
+
end
|
251
251
|
|
252
|
-
|
253
|
-
end
|
252
|
+
facts.should_not be_include("two")
|
254
253
|
end
|
254
|
+
end
|
255
255
|
end
|