facter 1.6.18 → 1.7.0.rc1
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/Gemfile +23 -8
- data/bin/facter +4 -1
- data/ext/build_defaults.yaml +1 -1
- data/ext/debian/changelog.erb +4 -22
- data/ext/debian/control +2 -2
- data/ext/project_data.yaml +1 -1
- data/ext/redhat/facter.spec.erb +10 -9
- data/install.rb +27 -53
- data/lib/facter.rb +23 -5
- data/lib/facter/application.rb +21 -0
- data/lib/facter/blockdevices.rb +105 -0
- data/lib/facter/domain.rb +19 -7
- data/lib/facter/filesystems.rb +38 -0
- data/lib/facter/hardwaremodel.rb +3 -2
- data/lib/facter/ipaddress6.rb +1 -2
- data/lib/facter/kernelrelease.rb +10 -2
- data/lib/facter/ldom.rb +47 -0
- data/lib/facter/macaddress.rb +1 -1
- data/lib/facter/manufacturer.rb +7 -1
- data/lib/facter/memory.rb +58 -160
- data/lib/facter/operatingsystem.rb +17 -2
- data/lib/facter/operatingsystemmajrelease.rb +33 -0
- data/lib/facter/operatingsystemrelease.rb +88 -37
- data/lib/facter/osfamily.rb +6 -2
- data/lib/facter/processor.rb +2 -2
- data/lib/facter/ps.rb +5 -0
- data/lib/facter/ssh.rb +50 -12
- data/lib/facter/util/cfpropertylist.rb +6 -0
- data/lib/facter/util/cfpropertylist/LICENSE +19 -0
- data/lib/facter/util/cfpropertylist/README +44 -0
- data/lib/facter/util/cfpropertylist/Rakefile +44 -0
- data/lib/facter/util/cfpropertylist/THANKS +7 -0
- data/lib/facter/util/cfpropertylist/lib/cfpropertylist.rb +6 -0
- data/lib/facter/util/cfpropertylist/lib/rbBinaryCFPropertyList.rb +562 -0
- data/lib/facter/util/cfpropertylist/lib/rbCFPlistError.rb +26 -0
- data/lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb +402 -0
- data/lib/facter/util/cfpropertylist/lib/rbCFTypes.rb +244 -0
- data/lib/facter/util/cfpropertylist/lib/rbLibXMLParser.rb +135 -0
- data/lib/facter/util/cfpropertylist/lib/rbNokogiriParser.rb +140 -0
- data/lib/facter/util/cfpropertylist/lib/rbREXMLParser.rb +136 -0
- data/lib/facter/util/collection.rb +36 -14
- data/lib/facter/util/composite_loader.rb +12 -0
- data/lib/facter/util/config.rb +36 -0
- data/lib/facter/util/confine.rb +1 -6
- data/lib/facter/util/directory_loader.rb +83 -0
- data/lib/facter/util/fact.rb +49 -42
- data/lib/facter/util/file_read.rb +32 -0
- data/lib/facter/util/ip.rb +2 -9
- data/lib/facter/util/loader.rb +16 -2
- data/lib/facter/util/macosx.rb +15 -2
- data/lib/facter/util/memory.rb +154 -27
- data/lib/facter/util/nothing_loader.rb +15 -0
- data/lib/facter/util/parser.rb +141 -0
- data/lib/facter/util/processor.rb +27 -35
- data/lib/facter/util/resolution.rb +97 -26
- data/lib/facter/util/solaris_zones.rb +153 -0
- data/lib/facter/util/virtual.rb +32 -3
- data/lib/facter/version.rb +72 -2
- data/lib/facter/virtual.rb +56 -3
- data/lib/facter/zfs_version.rb +10 -0
- data/lib/facter/zonename.rb +6 -0
- data/lib/facter/zones.rb +17 -0
- data/lib/facter/zpool_version.rb +10 -0
- data/spec/fixtures/ifconfig/ifconfig_net_tools_1.60.txt +19 -0
- data/spec/fixtures/ifconfig/ifconfig_ubuntu_1204.txt +16 -0
- data/spec/fixtures/ldom/ldom_v1 +6 -0
- data/spec/fixtures/unit/filesystems/linux +28 -0
- data/spec/fixtures/unit/util/manufacturer/intel_linux_dmidecode +549 -0
- data/spec/fixtures/unit/virtual/sysfs_dmi_entries_raw.txt +0 -0
- data/spec/fixtures/unit/zfs_version/freebsd_8.2 +14 -0
- data/spec/fixtures/unit/zfs_version/freebsd_9.0 +13 -0
- data/spec/fixtures/unit/zfs_version/linux-fuse_0.6.9 +14 -0
- data/spec/fixtures/unit/zfs_version/solaris_10 +10 -0
- data/spec/fixtures/unit/zfs_version/solaris_11 +12 -0
- data/spec/fixtures/unit/zpool_version/freebsd_8.2 +26 -0
- data/spec/fixtures/unit/zpool_version/freebsd_9.0 +38 -0
- data/spec/fixtures/unit/zpool_version/linux-fuse_0.6.9 +35 -0
- data/spec/fixtures/unit/zpool_version/solaris_10 +31 -0
- data/spec/fixtures/unit/zpool_version/solaris_11 +43 -0
- data/spec/integration/facter_spec.rb +12 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/unit/architecture_spec.rb +1 -1
- data/spec/unit/blockdevices_spec.rb +109 -0
- data/spec/unit/domain_spec.rb +189 -81
- data/spec/unit/ec2_spec.rb +15 -8
- data/spec/unit/filesystems_spec.rb +50 -0
- data/spec/unit/hardwaremodel_spec.rb +8 -1
- data/spec/unit/id_spec.rb +6 -5
- data/spec/unit/ipaddress6_spec.rb +14 -2
- data/spec/unit/ipaddress_spec.rb +1 -1
- data/spec/unit/kernel_spec.rb +24 -0
- data/spec/unit/kernelmajversion_spec.rb +17 -0
- data/spec/unit/kernelrelease_spec.rb +53 -0
- data/spec/unit/kernelversion_spec.rb +32 -0
- data/spec/unit/ldom_spec.rb +74 -0
- data/spec/unit/macaddress_spec.rb +3 -1
- data/spec/unit/manufacturer_spec.rb +115 -0
- data/spec/unit/memory_spec.rb +442 -75
- data/spec/unit/operatingsystem_spec.rb +16 -2
- data/spec/unit/operatingsystemmajrelease_spec.rb +16 -0
- data/spec/unit/operatingsystemrelease_spec.rb +110 -1
- data/spec/unit/processor_spec.rb +22 -7
- data/spec/unit/ps_spec.rb +42 -0
- data/spec/unit/ssh_spec.rb +76 -0
- data/spec/unit/util/collection_spec.rb +94 -118
- data/spec/unit/util/config_spec.rb +36 -5
- data/spec/unit/util/confine_spec.rb +31 -43
- data/spec/unit/util/directory_loader_spec.rb +87 -0
- data/spec/unit/util/fact_spec.rb +37 -25
- data/spec/unit/util/file_read_spec.rb +29 -0
- data/spec/unit/util/ip_spec.rb +4 -2
- data/spec/unit/util/loader_spec.rb +102 -45
- data/spec/unit/util/macosx_spec.rb +40 -9
- data/spec/unit/util/manufacturer_spec.rb +12 -1
- data/spec/unit/util/parser_spec.rb +135 -0
- data/spec/unit/util/resolution_spec.rb +136 -4
- data/spec/unit/util/solaris_zones_spec.rb +127 -0
- data/spec/unit/util/virtual_spec.rb +54 -0
- data/spec/unit/version_spec.rb +42 -0
- data/spec/unit/virtual_spec.rb +102 -27
- data/spec/unit/zfs_version_spec.rb +76 -0
- data/spec/unit/zonename_spec.rb +14 -0
- data/spec/unit/zones_spec.rb +55 -0
- data/spec/unit/zpool_version_spec.rb +76 -0
- metadata +113 -11
- data/lib/facter/arp.rb +0 -28
@@ -1,24 +1,55 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
-
require 'facter/util/config'
|
5
4
|
|
6
5
|
describe Facter::Util::Config do
|
6
|
+
include PuppetlabsSpec::Files
|
7
|
+
|
7
8
|
describe "is_windows? function" do
|
8
|
-
it "should detect windows if RbConfig returns a windows OS" do
|
9
|
+
it "should detect windows if Ruby RbConfig::CONFIG['host_os'] returns a windows OS" do
|
9
10
|
host_os = ["mswin","win32","dos","mingw","cygwin"]
|
10
11
|
host_os.each do |h|
|
11
|
-
RbConfig::CONFIG.
|
12
|
+
RbConfig::CONFIG.stubs(:[]).with('host_os').returns(h)
|
12
13
|
Facter::Util::Config.is_windows?.should be_true
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
|
-
it "should not detect windows if RbConfig returns a non-windows OS" do
|
17
|
+
it "should not detect windows if Ruby RbConfig::CONFIG['host_os'] returns a non-windows OS" do
|
17
18
|
host_os = ["darwin","linux"]
|
18
19
|
host_os.each do |h|
|
19
|
-
RbConfig::CONFIG.
|
20
|
+
RbConfig::CONFIG.stubs(:[]).with('host_os').returns(h)
|
20
21
|
Facter::Util::Config.is_windows?.should be_false
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
25
|
+
|
26
|
+
describe "is_mac? function" do
|
27
|
+
it "should detect mac if Ruby RbConfig::CONFIG['host_os'] returns darwin" do
|
28
|
+
host_os = ["darwin"]
|
29
|
+
host_os.each do |h|
|
30
|
+
RbConfig::CONFIG.stubs(:[]).with('host_os').returns(h)
|
31
|
+
Facter::Util::Config.is_mac?.should be_true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "external_facts_dirs" do
|
37
|
+
it "should return the default value for linux" do
|
38
|
+
Facter::Util::Config.stubs(:is_windows?).returns(false)
|
39
|
+
Facter::Util::Config.stubs(:windows_data_dir).returns(nil)
|
40
|
+
Facter::Util::Config.external_facts_dirs.should == ["/etc/facter/facts.d", "/etc/puppetlabs/facter/facts.d"]
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return the default value for windows 2008" do
|
44
|
+
Facter::Util::Config.stubs(:is_windows?).returns(true)
|
45
|
+
Facter::Util::Config.stubs(:windows_data_dir).returns("C:\\ProgramData")
|
46
|
+
Facter::Util::Config.external_facts_dirs.should == [File.join("C:\\ProgramData", 'PuppetLabs', 'facter', 'facts.d')]
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return the default value for windows 2003R2" do
|
50
|
+
Facter::Util::Config.stubs(:is_windows?).returns(true)
|
51
|
+
Facter::Util::Config.stubs(:windows_data_dir).returns("C:\\Documents")
|
52
|
+
Facter::Util::Config.external_facts_dirs.should == [File.join("C:\\Documents", 'PuppetLabs', 'facter', 'facts.d')]
|
53
|
+
end
|
54
|
+
end
|
24
55
|
end
|
@@ -32,8 +32,12 @@ describe Facter::Util::Confine do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
describe "when evaluating" do
|
35
|
+
def confined(fact_value, *confines)
|
36
|
+
@fact.stubs(:value).returns fact_value
|
37
|
+
Facter::Util::Confine.new("yay", *confines).true?
|
38
|
+
end
|
39
|
+
|
35
40
|
before do
|
36
|
-
@confine = Facter::Util::Confine.new("yay", "one", "two", "Four", :xy, true, 1, [3,4])
|
37
41
|
@fact = mock 'fact'
|
38
42
|
Facter.stubs(:[]).returns @fact
|
39
43
|
end
|
@@ -41,7 +45,7 @@ describe Facter::Util::Confine do
|
|
41
45
|
it "should return false if the fact does not exist" do
|
42
46
|
Facter.expects(:[]).with("yay").returns nil
|
43
47
|
|
44
|
-
|
48
|
+
Facter::Util::Confine.new("yay", "test").true?.should be_false
|
45
49
|
end
|
46
50
|
|
47
51
|
it "should use the returned fact to get the value" do
|
@@ -49,91 +53,75 @@ describe Facter::Util::Confine do
|
|
49
53
|
|
50
54
|
@fact.expects(:value).returns nil
|
51
55
|
|
52
|
-
|
56
|
+
Facter::Util::Confine.new("yay", "test").true?
|
53
57
|
end
|
54
58
|
|
55
59
|
it "should return false if the fact has no value" do
|
56
|
-
|
57
|
-
|
58
|
-
@confine.true?.should be_false
|
60
|
+
confined(nil, "test").should be_false
|
59
61
|
end
|
60
62
|
|
61
63
|
it "should return true if any of the provided values matches the fact's value" do
|
62
|
-
|
63
|
-
|
64
|
-
@confine.true?.should be_true
|
64
|
+
confined("two", "two").should be_true
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should return true if any of the provided symbol values matches the fact's value" do
|
68
|
-
|
69
|
-
|
70
|
-
@confine.true?.should be_true
|
68
|
+
confined(:xy, :xy).should be_true
|
71
69
|
end
|
72
70
|
|
73
71
|
it "should return true if any of the provided integer values matches the fact's value" do
|
74
|
-
|
75
|
-
|
76
|
-
@confine.true?.should be_true
|
72
|
+
confined(1, 1).should be_true
|
77
73
|
end
|
78
74
|
|
79
75
|
it "should return true if any of the provided boolan values matches the fact's value" do
|
80
|
-
|
81
|
-
|
82
|
-
@confine.true?.should be_true
|
76
|
+
confined(true, true).should be_true
|
83
77
|
end
|
84
78
|
|
85
79
|
it "should return true if any of the provided array values matches the fact's value" do
|
86
|
-
|
87
|
-
|
88
|
-
@confine.true?.should be_true
|
80
|
+
confined([3,4], [3,4]).should be_true
|
89
81
|
end
|
90
82
|
|
91
83
|
it "should return true if any of the provided symbol values matches the fact's string value" do
|
92
|
-
|
93
|
-
|
94
|
-
@confine.true?.should be_true
|
84
|
+
confined(:one, "one").should be_true
|
95
85
|
end
|
96
86
|
|
97
87
|
it "should return true if any of the provided string values matches case-insensitive the fact's value" do
|
98
|
-
|
99
|
-
|
100
|
-
@confine.true?.should be_true
|
88
|
+
confined("four", "Four").should be_true
|
101
89
|
end
|
102
90
|
|
103
91
|
it "should return true if any of the provided symbol values matches case-insensitive the fact's string value" do
|
104
|
-
|
105
|
-
|
106
|
-
@confine.true?.should be_true
|
92
|
+
confined(:four, "Four").should be_true
|
107
93
|
end
|
108
94
|
|
109
95
|
it "should return true if any of the provided symbol values matches the fact's string value" do
|
110
|
-
|
96
|
+
confined("xy", :xy).should be_true
|
97
|
+
end
|
111
98
|
|
112
|
-
|
99
|
+
it "should return true if any of the provided regexp values matches the fact's string value" do
|
100
|
+
confined("abc", /abc/).should be_true
|
113
101
|
end
|
114
102
|
|
115
|
-
it "should return
|
116
|
-
|
103
|
+
it "should return true if any of the provided ranges matches the fact's value" do
|
104
|
+
confined(6, (5..7)).should be_true
|
105
|
+
end
|
117
106
|
|
118
|
-
|
107
|
+
it "should return false if none of the provided values matches the fact's value" do
|
108
|
+
confined("three", "two", "four").should be_false
|
119
109
|
end
|
120
110
|
|
121
111
|
it "should return false if none of the provided integer values matches the fact's value" do
|
122
|
-
|
123
|
-
|
124
|
-
@confine.true?.should be_false
|
112
|
+
confined(2, 1, [3,4], (5..7)).should be_false
|
125
113
|
end
|
126
114
|
|
127
115
|
it "should return false if none of the provided boolan values matches the fact's value" do
|
128
|
-
|
129
|
-
|
130
|
-
@confine.true?.should be_false
|
116
|
+
confined(false, true).should be_false
|
131
117
|
end
|
132
118
|
|
133
119
|
it "should return false if none of the provided array values matches the fact's value" do
|
134
|
-
|
120
|
+
confined([1,2], [3,4]).should be_false
|
121
|
+
end
|
135
122
|
|
136
|
-
|
123
|
+
it "should return false if none of the provided ranges matches the fact's value" do
|
124
|
+
confined(8, (5..7)).should be_false
|
137
125
|
end
|
138
126
|
end
|
139
127
|
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
require 'facter/util/directory_loader'
|
6
|
+
|
7
|
+
describe Facter::Util::DirectoryLoader do
|
8
|
+
include PuppetlabsSpec::Files
|
9
|
+
include FacterSpec::ConfigHelper
|
10
|
+
|
11
|
+
subject { Facter::Util::DirectoryLoader.new(tmpdir('directory_loader')) }
|
12
|
+
let(:collection) { Facter::Util::Collection.new(mock("internal loader"), subject) }
|
13
|
+
|
14
|
+
it "should make the directory available" do
|
15
|
+
subject.directory.should be_instance_of(String)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "can be created with a given directory" do
|
19
|
+
Facter::Util::DirectoryLoader.loader_for("ext").directory.should == "ext"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raises an error when the directory does not exist" do
|
23
|
+
missing_dir = "missing"
|
24
|
+
File.stubs(:directory?).with(missing_dir).returns(false)
|
25
|
+
expect { Facter::Util::DirectoryLoader.loader_for(missing_dir) }.to raise_error Facter::Util::DirectoryLoader::NoSuchDirectoryError
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should do nothing bad when dir doesn't exist" do
|
29
|
+
fakepath = "/foobar/path"
|
30
|
+
my_loader = Facter::Util::DirectoryLoader.new(fakepath)
|
31
|
+
FileTest.exists?(my_loader.directory).should be_false
|
32
|
+
expect { my_loader.load(collection) }.to_not raise_error
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "when loading facts from disk" do
|
36
|
+
it "should be able to load files from disk and set facts" do
|
37
|
+
data = {"f1" => "one", "f2" => "two"}
|
38
|
+
write_to_file("data.yaml", YAML.dump(data))
|
39
|
+
|
40
|
+
subject.load(collection)
|
41
|
+
|
42
|
+
collection.value("f1").should == "one"
|
43
|
+
collection.value("f2").should == "two"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should ignore files that begin with '.'" do
|
47
|
+
not_to_be_used_collection = mock("collection should not be used")
|
48
|
+
not_to_be_used_collection.expects(:add).never
|
49
|
+
|
50
|
+
data = {"f1" => "one", "f2" => "two"}
|
51
|
+
write_to_file(".data.yaml", YAML.dump(data))
|
52
|
+
|
53
|
+
subject.load(not_to_be_used_collection)
|
54
|
+
end
|
55
|
+
|
56
|
+
%w{bak orig}.each do |ext|
|
57
|
+
it "should ignore files with an extension of '#{ext}'" do
|
58
|
+
write_to_file("data" + ".#{ext}", "foo=bar")
|
59
|
+
|
60
|
+
subject.load(collection)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should warn when trying to parse unknown file types" do
|
65
|
+
write_to_file("file.unknownfiletype", "stuff=bar")
|
66
|
+
|
67
|
+
Facter.expects(:warn).with(regexp_matches(/file.unknownfiletype/))
|
68
|
+
|
69
|
+
subject.load(collection)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "external facts should almost always precedence over all other facts" do
|
73
|
+
Facter.add("f1", :value => "lower_weight_fact") { has_weight(Facter::Util::DirectoryLoader::EXTERNAL_FACT_WEIGHT - 1) }
|
74
|
+
data = {"f1" => "external_fact"}
|
75
|
+
write_to_file("data.yaml", YAML.dump(data))
|
76
|
+
|
77
|
+
subject.load(collection)
|
78
|
+
|
79
|
+
collection.value("f1").should == "external_fact"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def write_to_file(file_name, to_write)
|
84
|
+
file = File.join(subject.directory, file_name)
|
85
|
+
File.open(file, "w") { |f| f.print to_write}
|
86
|
+
end
|
87
|
+
end
|
data/spec/unit/util/fact_spec.rb
CHANGED
@@ -32,39 +32,26 @@ describe Facter::Util::Fact do
|
|
32
32
|
before do
|
33
33
|
@fact = Facter::Util::Fact.new("yay")
|
34
34
|
|
35
|
-
@resolution =
|
36
|
-
@resolution.stub_everything
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should fail if no block is given" do
|
41
|
-
lambda { @fact.add }.should raise_error(ArgumentError)
|
35
|
+
@resolution = Facter::Util::Resolution.new("yay")
|
42
36
|
end
|
43
37
|
|
44
|
-
it "should create a new resolution instance" do
|
38
|
+
it "should be to create a new resolution instance with a block" do
|
45
39
|
Facter::Util::Resolution.expects(:new).returns @resolution
|
46
40
|
|
47
41
|
@fact.add { }
|
48
42
|
end
|
49
|
-
|
50
43
|
it "should instance_eval the passed block on the new resolution" do
|
51
|
-
@
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
@fact.add { }
|
44
|
+
@fact.add {
|
45
|
+
setcode { "foo" }
|
46
|
+
}
|
47
|
+
@fact.value.should == "foo"
|
56
48
|
end
|
57
49
|
|
58
50
|
it "should re-sort the resolutions by weight, so the most restricted resolutions are first" do
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
@fact.add { }
|
64
|
-
@fact.add { }
|
65
|
-
@fact.add { }
|
66
|
-
|
67
|
-
@fact.instance_variable_get("@resolves").should == [r2, r1, r3]
|
51
|
+
@fact.add { self.value = "1"; self.weight = 1 }
|
52
|
+
@fact.add { self.value = "2"; self.weight = 2 }
|
53
|
+
@fact.add { self.value = "0"; self.weight = 0 }
|
54
|
+
@fact.value.should == "2"
|
68
55
|
end
|
69
56
|
end
|
70
57
|
|
@@ -122,7 +109,32 @@ describe Facter::Util::Fact do
|
|
122
109
|
end
|
123
110
|
end
|
124
111
|
|
125
|
-
|
126
|
-
|
112
|
+
describe '#flush' do
|
113
|
+
subject do
|
114
|
+
Facter::Util::Fact.new(:foo)
|
115
|
+
end
|
116
|
+
context 'basic facts using setcode' do
|
117
|
+
it "flushes the cached value when invoked" do
|
118
|
+
system = mock('some_system_call')
|
119
|
+
system.expects(:data).twice.returns(100,200)
|
120
|
+
|
121
|
+
subject.add { setcode { system.data } }
|
122
|
+
5.times { subject.value.should == 100 }
|
123
|
+
subject.flush
|
124
|
+
subject.value.should == 200
|
125
|
+
end
|
126
|
+
end
|
127
|
+
context 'facts using setcode and on_flush' do
|
128
|
+
it 'invokes the block passed to on_flush' do
|
129
|
+
model = { :data => "Hello World" }
|
130
|
+
subject.add do
|
131
|
+
on_flush { model[:data] = "FLUSHED!" }
|
132
|
+
setcode { model[:data] }
|
133
|
+
end
|
134
|
+
subject.value.should == "Hello World"
|
135
|
+
subject.flush
|
136
|
+
subject.value.should == "FLUSHED!"
|
137
|
+
end
|
138
|
+
end
|
127
139
|
end
|
128
140
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'facter/util/file_read'
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
describe Facter::Util::FileRead do
|
7
|
+
let(:issue) { "Ubuntu 10.04.4 LTS \\n \\l\n\n" }
|
8
|
+
|
9
|
+
it "reads a file" do
|
10
|
+
File.expects(:read).with("/etc/issue").returns(issue)
|
11
|
+
Facter::Util::FileRead.read("/etc/issue").should == issue
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns nil if the file cannot be accessed" do
|
15
|
+
File.stubs(:read).with("/etc/issue").raises(Errno::EACCES.new("/etc/issue"))
|
16
|
+
Facter::Util::FileRead.read("/etc/issue").should be_nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns nil if the file does not exist" do
|
20
|
+
File.stubs(:read).with("/etc/issue").raises(Errno::ENOENT.new("/etc/issue"))
|
21
|
+
Facter::Util::FileRead.read("/etc/issue").should be_nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it "logs a message when handing exceptions" do
|
25
|
+
File.stubs(:read).with("/etc/issue").raises(Errno::EACCES.new("/etc/issue"))
|
26
|
+
Facter.expects(:debug).with("Could not read /etc/issue: Permission denied - /etc/issue")
|
27
|
+
Facter::Util::FileRead.read("/etc/issue")
|
28
|
+
end
|
29
|
+
end
|
data/spec/unit/util/ip_spec.rb
CHANGED
@@ -4,13 +4,15 @@ require 'spec_helper'
|
|
4
4
|
require 'facter/util/ip'
|
5
5
|
|
6
6
|
describe Facter::Util::IP do
|
7
|
+
include FacterSpec::ConfigHelper
|
8
|
+
|
7
9
|
before :each do
|
8
|
-
|
10
|
+
given_a_configuration_of(:is_windows => false)
|
9
11
|
end
|
10
12
|
|
11
13
|
[:freebsd, :linux, :netbsd, :openbsd, :sunos, :darwin, :"hp-ux", :"gnu/kfreebsd", :windows].each do |platform|
|
12
14
|
it "should be supported on #{platform}" do
|
13
|
-
|
15
|
+
given_a_configuration_of(:is_windows => platform == :windows)
|
14
16
|
Facter::Util::IP.supported_platforms.should be_include(platform)
|
15
17
|
end
|
16
18
|
end
|
@@ -21,24 +21,6 @@ describe Facter::Util::Loader do
|
|
21
21
|
Facter::Util::Loader.any_instance.unstub(:load_all)
|
22
22
|
end
|
23
23
|
|
24
|
-
def with_env(values)
|
25
|
-
old = {}
|
26
|
-
values.each do |var, value|
|
27
|
-
if old_val = ENV[var]
|
28
|
-
old[var] = old_val
|
29
|
-
end
|
30
|
-
ENV[var] = value
|
31
|
-
end
|
32
|
-
yield
|
33
|
-
values.each do |var, value|
|
34
|
-
if old.include?(var)
|
35
|
-
ENV[var] = old[var]
|
36
|
-
else
|
37
|
-
ENV.delete(var)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
24
|
it "should have a method for loading individual facts by name" do
|
43
25
|
Facter::Util::Loader.new.should respond_to(:load)
|
44
26
|
end
|
@@ -51,6 +33,62 @@ describe Facter::Util::Loader do
|
|
51
33
|
Facter::Util::Loader.new.should respond_to(:search_path)
|
52
34
|
end
|
53
35
|
|
36
|
+
describe "#valid_seach_path?" do
|
37
|
+
before :each do
|
38
|
+
@loader = Facter::Util::Loader.new
|
39
|
+
@settings = mock 'settings'
|
40
|
+
@settings.stubs(:value).returns "/eh"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should cache the result of a previous check" do
|
44
|
+
Pathname.any_instance.expects(:absolute?).returns(true).once
|
45
|
+
|
46
|
+
# we explicitly want two calls here to check that we get
|
47
|
+
# the second from the cache
|
48
|
+
@loader.should be_valid_search_path "/foo"
|
49
|
+
@loader.should be_valid_search_path "/foo"
|
50
|
+
end
|
51
|
+
|
52
|
+
# Used to have test for " " as a directory since that should
|
53
|
+
# be a relative directory, but on Windows in both 1.8.7 and
|
54
|
+
# 1.9.3 it is an absolute directory (WTF Windows). Considering
|
55
|
+
# we didn't have a valid use case for a " " directory, the
|
56
|
+
# test was removed.
|
57
|
+
|
58
|
+
[
|
59
|
+
'.',
|
60
|
+
'..',
|
61
|
+
'...',
|
62
|
+
'.foo',
|
63
|
+
'../foo',
|
64
|
+
'foo',
|
65
|
+
'foo/bar',
|
66
|
+
'foo/../bar',
|
67
|
+
' /',
|
68
|
+
' \/',
|
69
|
+
].each do |dir|
|
70
|
+
it "should be false for relative path #{dir}" do
|
71
|
+
@loader.should_not be_valid_search_path dir
|
72
|
+
end
|
73
|
+
end
|
74
|
+
[
|
75
|
+
'/.',
|
76
|
+
'/..',
|
77
|
+
'/...',
|
78
|
+
'/.foo',
|
79
|
+
'/../foo',
|
80
|
+
'/foo',
|
81
|
+
'/foo/bar',
|
82
|
+
'/foo/../bar',
|
83
|
+
'/ ',
|
84
|
+
'/ /..',
|
85
|
+
].each do |dir|
|
86
|
+
it "should be true for absolute path #{dir}" do
|
87
|
+
@loader.should be_valid_search_path dir
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
54
92
|
describe "when determining the search path" do
|
55
93
|
before do
|
56
94
|
@loader = Facter::Util::Loader.new
|
@@ -60,6 +98,7 @@ describe Facter::Util::Loader do
|
|
60
98
|
|
61
99
|
it "should include the facter subdirectory of all paths in ruby LOAD_PATH" do
|
62
100
|
dirs = $LOAD_PATH.collect { |d| File.join(d, "facter") }
|
101
|
+
@loader.stubs(:valid_search_path?).returns(true)
|
63
102
|
paths = @loader.search_path
|
64
103
|
|
65
104
|
dirs.each do |dir|
|
@@ -67,6 +106,24 @@ describe Facter::Util::Loader do
|
|
67
106
|
end
|
68
107
|
end
|
69
108
|
|
109
|
+
it "should warn the user when an invalid search path has been excluded" do
|
110
|
+
dirs = $LOAD_PATH.collect { |d| File.join(d, "facter") }
|
111
|
+
@loader.stubs(:valid_search_path?).returns(false)
|
112
|
+
dirs.each do |dir|
|
113
|
+
Facter.expects(:debugonce).with("Relative directory #{dir} removed from search path.").once
|
114
|
+
end
|
115
|
+
paths = @loader.search_path
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should exclude invalid search paths" do
|
119
|
+
dirs = $LOAD_PATH.collect { |d| File.join(d, "facter") }
|
120
|
+
@loader.stubs(:valid_search_path?).returns(false)
|
121
|
+
paths = @loader.search_path
|
122
|
+
dirs.each do |dir|
|
123
|
+
paths.should_not be_include(dir)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
70
127
|
it "should include all search paths registered with Facter" do
|
71
128
|
Facter.expects(:search_path).returns %w{/one /two}
|
72
129
|
paths = @loader.search_path
|
@@ -76,7 +133,7 @@ describe Facter::Util::Loader do
|
|
76
133
|
|
77
134
|
describe "and the FACTERLIB environment variable is set" do
|
78
135
|
it "should include all paths in FACTERLIB" do
|
79
|
-
with_env "FACTERLIB" => "/one/path
|
136
|
+
Facter::Util::Resolution.with_env "FACTERLIB" => "/one/path#{File::PATH_SEPARATOR}/two/path" do
|
80
137
|
paths = @loader.search_path
|
81
138
|
%w{/one/path /two/path}.each do |dir|
|
82
139
|
paths.should be_include(dir)
|
@@ -95,7 +152,7 @@ describe Facter::Util::Loader do
|
|
95
152
|
it "should load values from the matching environment variable if one is present" do
|
96
153
|
Facter.expects(:add).with("testing")
|
97
154
|
|
98
|
-
with_env "facter_testing" => "yayness" do
|
155
|
+
Facter::Util::Resolution.with_env "facter_testing" => "yayness" do
|
99
156
|
@loader.load(:testing)
|
100
157
|
end
|
101
158
|
end
|
@@ -113,21 +170,21 @@ describe Facter::Util::Loader do
|
|
113
170
|
end
|
114
171
|
|
115
172
|
it 'should load any ruby files in directories matching the fact name in the search path in sorted order regardless of the order returned by Dir.entries' do
|
116
|
-
|
173
|
+
@loader = TestLoader.new
|
117
174
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
175
|
+
@loader.stubs(:search_path).returns %w{/one/dir}
|
176
|
+
FileTest.stubs(:exist?).returns false
|
177
|
+
FileTest.stubs(:directory?).with("/one/dir/testing").returns true
|
178
|
+
@loader.stubs(:search_path).returns %w{/one/dir}
|
122
179
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
180
|
+
Dir.stubs(:entries).with("/one/dir/testing").returns %w{foo.rb bar.rb}
|
181
|
+
%w{/one/dir/testing/foo.rb /one/dir/testing/bar.rb}.each do |f|
|
182
|
+
File.stubs(:directory?).with(f).returns false
|
183
|
+
Kernel.stubs(:load).with(f)
|
184
|
+
end
|
128
185
|
|
129
|
-
|
130
|
-
|
186
|
+
@loader.load(:testing)
|
187
|
+
@loader.loaded_files.should == %w{/one/dir/testing/bar.rb /one/dir/testing/foo.rb}
|
131
188
|
end
|
132
189
|
|
133
190
|
it "should load any ruby files in directories matching the fact name in the search path" do
|
@@ -156,7 +213,7 @@ describe Facter::Util::Loader do
|
|
156
213
|
end
|
157
214
|
|
158
215
|
describe "when loading all facts" do
|
159
|
-
before do
|
216
|
+
before :each do
|
160
217
|
@loader = Facter::Util::Loader.new
|
161
218
|
@loader.stubs(:search_path).returns []
|
162
219
|
|
@@ -201,21 +258,21 @@ describe Facter::Util::Loader do
|
|
201
258
|
end
|
202
259
|
|
203
260
|
it 'should load all files in sorted order for any given directory regardless of the order returned by Dir.entries' do
|
204
|
-
|
261
|
+
@loader = TestLoader.new
|
205
262
|
|
206
|
-
|
207
|
-
|
263
|
+
@loader.stubs(:search_path).returns %w{/one/dir}
|
264
|
+
Dir.stubs(:entries).with("/one/dir").returns %w{foo.rb bar.rb}
|
208
265
|
|
209
|
-
|
266
|
+
%w{/one/dir}.each { |f| File.stubs(:directory?).with(f).returns true }
|
210
267
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
268
|
+
%w{/one/dir/foo.rb /one/dir/bar.rb}.each do |f|
|
269
|
+
File.stubs(:directory?).with(f).returns false
|
270
|
+
Kernel.expects(:load).with(f)
|
271
|
+
end
|
215
272
|
|
216
|
-
|
273
|
+
@loader.load_all
|
217
274
|
|
218
|
-
|
275
|
+
@loader.loaded_files.should == %w{/one/dir/bar.rb /one/dir/foo.rb}
|
219
276
|
end
|
220
277
|
|
221
278
|
it "should not load files in the util subdirectory" do
|
@@ -267,7 +324,7 @@ describe Facter::Util::Loader do
|
|
267
324
|
Facter.expects(:add).with('one')
|
268
325
|
Facter.expects(:add).with('two')
|
269
326
|
|
270
|
-
with_env "facter_one" => "yayness", "facter_two" => "boo" do
|
327
|
+
Facter::Util::Resolution.with_env "facter_one" => "yayness", "facter_two" => "boo" do
|
271
328
|
@loader.load_all
|
272
329
|
end
|
273
330
|
end
|
@@ -281,7 +338,7 @@ describe Facter::Util::Loader do
|
|
281
338
|
|
282
339
|
it "should load facts on the facter search path only once" do
|
283
340
|
facterlibdir = File.expand_path(File.dirname(__FILE__) + '../../../fixtures/unit/util/loader')
|
284
|
-
with_env 'FACTERLIB' => facterlibdir do
|
341
|
+
Facter::Util::Resolution.with_env 'FACTERLIB' => facterlibdir do
|
285
342
|
Facter::Util::Loader.new.load_all
|
286
343
|
Facter.value(:nosuchfact).should be_nil
|
287
344
|
end
|