facter 1.7.6 → 2.0.1.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.
- checksums.yaml +7 -0
- data/COMMITTERS.md +194 -0
- data/CONTRIBUTING.md +63 -235
- data/Gemfile +12 -8
- data/README.md +1 -2
- data/Rakefile +1 -1
- data/bin/facter +0 -4
- data/ext/build_defaults.yaml +2 -2
- data/ext/project_data.yaml +18 -0
- data/install.rb +1 -16
- data/lib/facter.rb +171 -171
- data/lib/facter/application.rb +65 -54
- data/lib/facter/core/aggregate.rb +220 -0
- data/lib/facter/core/directed_graph.rb +46 -0
- data/lib/facter/core/execution.rb +100 -0
- data/lib/facter/core/execution/base.rb +73 -0
- data/lib/facter/core/execution/posix.rb +50 -0
- data/lib/facter/core/execution/windows.rb +57 -0
- data/lib/facter/core/logging.rb +169 -0
- data/lib/facter/core/resolvable.rb +94 -0
- data/lib/facter/core/suitable.rb +117 -0
- data/lib/facter/domain.rb +15 -9
- data/lib/facter/filesystems.rb +1 -1
- data/lib/facter/hardwaremodel.rb +1 -1
- data/lib/facter/hostname.rb +3 -3
- data/lib/facter/interfaces.rb +6 -1
- data/lib/facter/ipaddress.rb +2 -2
- data/lib/facter/kernel.rb +1 -1
- data/lib/facter/kernelrelease.rb +1 -1
- data/lib/facter/ldom.rb +1 -1
- data/lib/facter/lsbdistcodename.rb +1 -1
- data/lib/facter/lsbdistdescription.rb +1 -1
- data/lib/facter/lsbdistid.rb +1 -1
- data/lib/facter/lsbdistrelease.rb +1 -1
- data/lib/facter/lsbrelease.rb +1 -1
- data/lib/facter/macaddress.rb +1 -14
- data/lib/facter/macosx.rb +2 -2
- data/lib/facter/memory.rb +8 -19
- data/lib/facter/operatingsystem.rb +1 -1
- data/lib/facter/operatingsystemrelease.rb +34 -1
- data/lib/facter/physicalprocessorcount.rb +6 -6
- data/lib/facter/processor.rb +11 -10
- data/lib/facter/selinux.rb +4 -15
- data/lib/facter/ssh.rb +5 -2
- data/lib/facter/util/architecture.rb +2 -2
- data/lib/facter/util/collection.rb +42 -38
- data/lib/facter/util/config.rb +19 -9
- data/lib/facter/util/confine.rb +34 -4
- data/lib/facter/util/ec2.rb +1 -1
- data/lib/facter/util/fact.rb +108 -36
- data/lib/facter/util/file_read.rb +7 -6
- data/lib/facter/util/formatter.rb +38 -0
- data/lib/facter/util/ip.rb +3 -3
- data/lib/facter/util/loader.rb +62 -42
- data/lib/facter/util/macosx.rb +7 -8
- data/lib/facter/util/manufacturer.rb +3 -3
- data/lib/facter/util/memory.rb +13 -13
- data/lib/facter/util/monkey_patches.rb +0 -31
- data/lib/facter/util/netmask.rb +3 -3
- data/lib/facter/util/normalization.rb +94 -0
- data/lib/facter/util/nothing_loader.rb +3 -6
- data/lib/facter/util/parser.rb +3 -5
- data/lib/facter/util/plist/generator.rb +1 -1
- data/lib/facter/util/processor.rb +15 -15
- data/lib/facter/util/resolution.rb +112 -289
- data/lib/facter/util/solaris_zones.rb +4 -4
- data/lib/facter/util/uptime.rb +8 -3
- data/lib/facter/util/values.rb +67 -1
- data/lib/facter/util/virtual.rb +10 -10
- data/lib/facter/util/xendomains.rb +1 -1
- data/lib/facter/version.rb +42 -39
- data/lib/facter/virtual.rb +6 -7
- data/lib/facter/zfs_version.rb +3 -3
- data/lib/facter/zpool_version.rb +3 -3
- data/spec/fixtures/unit/netmask/darwin_10_8_5.txt +30 -0
- data/spec/unit/application_spec.rb +46 -1
- data/spec/unit/core/aggregate_spec.rb +125 -0
- data/spec/unit/core/directed_graph_spec.rb +79 -0
- data/spec/unit/core/execution/base_spec.rb +119 -0
- data/spec/unit/core/execution/posix_spec.rb +86 -0
- data/spec/unit/core/execution/windows_spec.rb +106 -0
- data/spec/unit/core/execution_spec.rb +37 -0
- data/spec/unit/core/logging_spec.rb +104 -0
- data/spec/unit/core/resolvable_spec.rb +81 -0
- data/spec/unit/core/suitable_spec.rb +96 -0
- data/spec/unit/domain_spec.rb +5 -5
- data/spec/unit/facter_spec.rb +61 -222
- data/spec/unit/filesystems_spec.rb +2 -2
- data/spec/unit/hardwareisa_spec.rb +5 -5
- data/spec/unit/hardwaremodel_spec.rb +1 -1
- data/spec/unit/hostname_spec.rb +4 -4
- data/spec/unit/id_spec.rb +3 -3
- data/spec/unit/interfaces_spec.rb +10 -0
- data/spec/unit/ipaddress6_spec.rb +4 -4
- data/spec/unit/ipaddress_spec.rb +1 -1
- data/spec/unit/kernel_spec.rb +2 -2
- data/spec/unit/kernelmajversion_spec.rb +1 -1
- data/spec/unit/kernelrelease_spec.rb +4 -4
- data/spec/unit/kernelversion_spec.rb +2 -2
- data/spec/unit/ldom_spec.rb +2 -2
- data/spec/unit/lsbdistcodename_spec.rb +2 -2
- data/spec/unit/lsbdistdescription_spec.rb +2 -2
- data/spec/unit/lsbdistid_spec.rb +2 -2
- data/spec/unit/lsbdistrelease_spec.rb +2 -2
- data/spec/unit/lsbrelease_spec.rb +2 -2
- data/spec/unit/manufacturer_spec.rb +1 -1
- data/spec/unit/memory_spec.rb +24 -31
- data/spec/unit/netmask_spec.rb +9 -0
- data/spec/unit/operatingsystem_spec.rb +1 -1
- data/spec/unit/operatingsystemrelease_spec.rb +62 -4
- data/spec/unit/physicalprocessorcount_spec.rb +10 -10
- data/spec/unit/processor_spec.rb +11 -11
- data/spec/unit/selinux_spec.rb +2 -8
- data/spec/unit/ssh_spec.rb +3 -2
- data/spec/unit/uniqueid_spec.rb +3 -3
- data/spec/unit/util/collection_spec.rb +37 -35
- data/spec/unit/util/config_spec.rb +20 -0
- data/spec/unit/util/confine_spec.rb +21 -0
- data/spec/unit/util/directory_loader_spec.rb +1 -0
- data/spec/unit/util/ec2_spec.rb +6 -6
- data/spec/unit/util/fact_spec.rb +92 -90
- data/spec/unit/util/ip_spec.rb +2 -2
- data/spec/unit/util/loader_spec.rb +127 -186
- data/spec/unit/util/macaddress_spec.rb +2 -2
- data/spec/unit/util/macosx_spec.rb +8 -8
- data/spec/unit/util/manufacturer_spec.rb +3 -3
- data/spec/unit/util/normalization_spec.rb +113 -0
- data/spec/unit/util/parser_spec.rb +25 -3
- data/spec/unit/util/processor_spec.rb +2 -2
- data/spec/unit/util/resolution_spec.rb +60 -631
- data/spec/unit/util/solaris_zones_spec.rb +5 -5
- data/spec/unit/util/uptime_spec.rb +1 -1
- data/spec/unit/util/values_spec.rb +131 -0
- data/spec/unit/util/virtual_spec.rb +16 -16
- data/spec/unit/util/xendomains_spec.rb +2 -2
- data/spec/unit/virtual_spec.rb +39 -39
- data/spec/unit/zfs_version_spec.rb +11 -11
- data/spec/unit/zonename_spec.rb +2 -2
- data/spec/unit/zones_spec.rb +1 -1
- data/spec/unit/zpool_version_spec.rb +11 -11
- metadata +466 -447
- data/lib/facter/util/cfpropertylist.rb +0 -6
- data/lib/facter/util/cfpropertylist/LICENSE +0 -19
- data/lib/facter/util/cfpropertylist/README +0 -44
- data/lib/facter/util/cfpropertylist/Rakefile +0 -44
- data/lib/facter/util/cfpropertylist/THANKS +0 -7
- data/lib/facter/util/cfpropertylist/lib/cfpropertylist.rb +0 -6
- data/lib/facter/util/cfpropertylist/lib/rbBinaryCFPropertyList.rb +0 -562
- data/lib/facter/util/cfpropertylist/lib/rbCFPlistError.rb +0 -26
- data/lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb +0 -407
- data/lib/facter/util/cfpropertylist/lib/rbCFTypes.rb +0 -244
- data/lib/facter/util/cfpropertylist/lib/rbLibXMLParser.rb +0 -135
- data/lib/facter/util/cfpropertylist/lib/rbNokogiriParser.rb +0 -140
- data/lib/facter/util/cfpropertylist/lib/rbREXMLParser.rb +0 -136
- data/spec/unit/util/monkey_patches_spec.rb +0 -42
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'facter/core/execution'
|
3
|
+
|
4
|
+
describe Facter::Core::Execution do
|
5
|
+
subject { described_class}
|
6
|
+
let(:impl) { described_class.impl }
|
7
|
+
|
8
|
+
it "delegates #search_paths to the implementation" do
|
9
|
+
impl.expects(:search_paths)
|
10
|
+
subject.search_paths
|
11
|
+
end
|
12
|
+
|
13
|
+
it "delegates #which to the implementation" do
|
14
|
+
impl.expects(:which).with('waffles')
|
15
|
+
subject.which('waffles')
|
16
|
+
end
|
17
|
+
|
18
|
+
it "delegates #absolute_path? to the implementation" do
|
19
|
+
impl.expects(:absolute_path?).with('waffles', nil)
|
20
|
+
subject.absolute_path?('waffles')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "delegates #absolute_path? with an optional platform to the implementation" do
|
24
|
+
impl.expects(:absolute_path?).with('waffles', :windows)
|
25
|
+
subject.absolute_path?('waffles', :windows)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "delegates #expand_command to the implementation" do
|
29
|
+
impl.expects(:expand_command).with('waffles')
|
30
|
+
subject.expand_command('waffles')
|
31
|
+
end
|
32
|
+
|
33
|
+
it "delegates #exec to the implementation" do
|
34
|
+
impl.expects(:exec).with('waffles')
|
35
|
+
subject.exec('waffles')
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'facter/core/logging'
|
3
|
+
|
4
|
+
describe Facter::Core::Logging do
|
5
|
+
|
6
|
+
subject { described_class }
|
7
|
+
|
8
|
+
after(:all) do
|
9
|
+
subject.debugging(false)
|
10
|
+
subject.timing(false)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "emitting debug messages" do
|
14
|
+
it "doesn't log a message when debugging is disabled" do
|
15
|
+
subject.debugging(false)
|
16
|
+
subject.expects(:puts).never
|
17
|
+
subject.debug("foo")
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "and debugging is enabled" do
|
21
|
+
before { subject.debugging(true) }
|
22
|
+
it "emits a warning when called with nil" do
|
23
|
+
subject.expects(:warn).with { |msg| expect(msg).to match /invalid message nil:NilClass/ }
|
24
|
+
subject.debug(nil)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "emits a warning when called with an empty string" do
|
28
|
+
subject.expects(:warn).with { |msg| expect(msg).to match /invalid message "":String/ }
|
29
|
+
subject.debug("")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "prints the message when logging is enabled" do
|
33
|
+
subject.expects(:puts).with { |msg| expect(msg).to match /foo/ }
|
34
|
+
subject.debug("foo")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "when warning" do
|
40
|
+
it "emits a warning when given a string" do
|
41
|
+
subject.debugging(true)
|
42
|
+
Kernel.expects(:warn).with('foo')
|
43
|
+
subject.warn('foo')
|
44
|
+
end
|
45
|
+
|
46
|
+
it "emits a warning regardless of log level" do
|
47
|
+
subject.debugging(false)
|
48
|
+
Kernel.expects(:warn).with "foo"
|
49
|
+
subject.warn "foo"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "emits a warning if nil is passed" do
|
53
|
+
Kernel.expects(:warn).with { |msg| expect(msg).to match /invalid message nil:NilClass/ }
|
54
|
+
subject.warn(nil)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "emits a warning if an empty string is passed" do
|
58
|
+
Kernel.expects(:warn).with { |msg| expect(msg).to match /invalid message "":String/ }
|
59
|
+
subject.warn('')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "when warning once" do
|
64
|
+
it "only logs a given warning string once" do
|
65
|
+
subject.expects(:warn).with('foo').once
|
66
|
+
subject.warnonce('foo')
|
67
|
+
subject.warnonce('foo')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "when setting the debugging mode" do
|
72
|
+
it "is enabled when the given value is true" do
|
73
|
+
subject.debugging(true)
|
74
|
+
expect(subject.debugging?).to be_true
|
75
|
+
end
|
76
|
+
|
77
|
+
it "is disabled when the given value is false" do
|
78
|
+
subject.debugging(false)
|
79
|
+
expect(subject.debugging?).to be_false
|
80
|
+
end
|
81
|
+
|
82
|
+
it "is disabled when the given value is nil" do
|
83
|
+
subject.debugging(nil)
|
84
|
+
expect(subject.debugging?).to be_false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "when setting the timing mode" do
|
89
|
+
it "is enabled when the given value is true" do
|
90
|
+
subject.timing(true)
|
91
|
+
expect(subject.timing?).to be_true
|
92
|
+
end
|
93
|
+
|
94
|
+
it "is disabled when the given value is false" do
|
95
|
+
subject.timing(false)
|
96
|
+
expect(subject.timing?).to be_false
|
97
|
+
end
|
98
|
+
|
99
|
+
it "is disabled when the given value is nil" do
|
100
|
+
subject.timing(nil)
|
101
|
+
expect(subject.timing?).to be_false
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'facter/core/resolvable'
|
3
|
+
|
4
|
+
describe Facter::Core::Resolvable do
|
5
|
+
|
6
|
+
class ResolvableClass
|
7
|
+
def initialize(name)
|
8
|
+
@name = name
|
9
|
+
@fact = Facter::Util::Fact.new("stub fact")
|
10
|
+
end
|
11
|
+
attr_accessor :name, :resolve_value
|
12
|
+
attr_reader :fact
|
13
|
+
include Facter::Core::Resolvable
|
14
|
+
end
|
15
|
+
|
16
|
+
subject { ResolvableClass.new('resolvable') }
|
17
|
+
|
18
|
+
it "has a default timeout of 0 seconds" do
|
19
|
+
expect(subject.limit).to eq 0
|
20
|
+
end
|
21
|
+
|
22
|
+
it "can specify a custom timeout" do
|
23
|
+
subject.timeout = 10
|
24
|
+
expect(subject.limit).to eq 10
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "generating a value" do
|
28
|
+
it "returns the results of #resolve_value" do
|
29
|
+
subject.resolve_value = 'stuff'
|
30
|
+
expect(subject.value).to eq 'stuff'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "normalizes the resolved value" do
|
34
|
+
Facter::Util::Normalization.expects(:normalize).returns 'stuff'
|
35
|
+
subject.resolve_value = 'stuff'
|
36
|
+
expect(subject.value).to eq('stuff')
|
37
|
+
end
|
38
|
+
|
39
|
+
it "logs a warning if an exception was raised" do
|
40
|
+
subject.expects(:resolve_value).raises RuntimeError, "kaboom!"
|
41
|
+
Facter.expects(:warn).with(regexp_matches(/Could not retrieve .*: kaboom!/))
|
42
|
+
expect(subject.value).to eq nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "timing out" do
|
47
|
+
it "uses #limit instead of #timeout to determine the timeout period" do
|
48
|
+
subject.expects(:timeout).never
|
49
|
+
subject.expects(:limit).returns 25
|
50
|
+
|
51
|
+
Timeout.expects(:timeout).with(25)
|
52
|
+
subject.value
|
53
|
+
end
|
54
|
+
|
55
|
+
it "returns nil if the timeout was reached" do
|
56
|
+
Facter.expects(:warn).with(regexp_matches(/Timed out after 0\.1 seconds while resolving/))
|
57
|
+
Timeout.expects(:timeout).raises Timeout::Error
|
58
|
+
|
59
|
+
subject.timeout = 0.1
|
60
|
+
|
61
|
+
expect(subject.value).to be_nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'callbacks when flushing facts' do
|
66
|
+
class FlushFakeError < StandardError; end
|
67
|
+
|
68
|
+
context '#on_flush' do
|
69
|
+
it 'accepts a block with on_flush' do
|
70
|
+
subject.on_flush() { raise NotImplementedError }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context '#flush' do
|
75
|
+
it 'calls the block passed to on_flush' do
|
76
|
+
subject.on_flush() { raise FlushFakeError }
|
77
|
+
expect { subject.flush }.to raise_error FlushFakeError
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'facter/core/suitable'
|
3
|
+
|
4
|
+
describe Facter::Core::Suitable do
|
5
|
+
|
6
|
+
class SuitableClass
|
7
|
+
def initialize
|
8
|
+
@confines = []
|
9
|
+
end
|
10
|
+
attr_reader :confines
|
11
|
+
include Facter::Core::Suitable
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { SuitableClass.new }
|
15
|
+
|
16
|
+
describe "confining on facts" do
|
17
|
+
it "can add confines with a fact and a single value" do
|
18
|
+
subject.confine :kernel => 'Linux'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "creates a Facter::Util::Confine object for the confine call" do
|
22
|
+
subject.confine :kernel => 'Linux'
|
23
|
+
conf = subject.confines.first
|
24
|
+
expect(conf).to be_a_kind_of Facter::Util::Confine
|
25
|
+
expect(conf.fact).to eq :kernel
|
26
|
+
expect(conf.values).to eq ['Linux']
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "confining on blocks" do
|
31
|
+
it "can add a single fact with a block parameter" do
|
32
|
+
subject.confine(:one) { true }
|
33
|
+
end
|
34
|
+
|
35
|
+
it "creates a Util::Confine instance for the provided fact with block parameter" do
|
36
|
+
block = lambda { true }
|
37
|
+
Facter::Util::Confine.expects(:new).with("one")
|
38
|
+
|
39
|
+
subject.confine("one", &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should accept a single block parameter" do
|
43
|
+
subject.confine() { true }
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should create a Util::Confine instance for the provided block parameter" do
|
47
|
+
block = lambda { true }
|
48
|
+
Facter::Util::Confine.expects(:new)
|
49
|
+
|
50
|
+
subject.confine(&block)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "determining weight" do
|
55
|
+
it "is zero if no confines are set" do
|
56
|
+
expect(subject.weight).to eq 0
|
57
|
+
end
|
58
|
+
|
59
|
+
it "defaults to the number of confines" do
|
60
|
+
subject.confine :kernel => 'Linux'
|
61
|
+
expect(subject.weight).to eq 1
|
62
|
+
end
|
63
|
+
|
64
|
+
it "can be explicitly set" do
|
65
|
+
subject.has_weight 10
|
66
|
+
expect(subject.weight).to eq 10
|
67
|
+
end
|
68
|
+
|
69
|
+
it "prefers an explicit weight over the number of confines" do
|
70
|
+
subject.confine :kernel => 'Linux'
|
71
|
+
subject.has_weight 11
|
72
|
+
expect(subject.weight).to eq 11
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "determining suitability" do
|
77
|
+
it "is true if all confines for the object evaluate to true" do
|
78
|
+
subject.confine :kernel => 'Linux'
|
79
|
+
subject.confine :operatingsystem => 'Redhat'
|
80
|
+
|
81
|
+
subject.confines.each { |confine| confine.stubs(:true?).returns true }
|
82
|
+
|
83
|
+
expect(subject).to be_suitable
|
84
|
+
end
|
85
|
+
|
86
|
+
it "is false if any confines for the object evaluate to false" do
|
87
|
+
subject.confine :kernel => 'Linux'
|
88
|
+
subject.confine :operatingsystem => 'Redhat'
|
89
|
+
|
90
|
+
subject.confines.first.stubs(:true?).returns true
|
91
|
+
subject.confines.first.stubs(:true?).returns false
|
92
|
+
|
93
|
+
expect(subject).to_not be_suitable
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/spec/unit/domain_spec.rb
CHANGED
@@ -24,11 +24,11 @@ describe "Domain name facts" do
|
|
24
24
|
let(:dnsdomain_command) { "dnsdomainname 2> /dev/null" }
|
25
25
|
|
26
26
|
def the_hostname_is(value)
|
27
|
-
Facter::
|
27
|
+
Facter::Core::Execution.stubs(:exec).with(hostname_command).returns(value)
|
28
28
|
end
|
29
29
|
|
30
30
|
def the_dnsdomainname_is(value)
|
31
|
-
Facter::
|
31
|
+
Facter::Core::Execution.stubs(:exec).with(dnsdomain_command).returns(value)
|
32
32
|
end
|
33
33
|
|
34
34
|
before do
|
@@ -197,7 +197,7 @@ describe "Domain name facts" do
|
|
197
197
|
it "should return nil" do
|
198
198
|
expects_dnsdomains([nil])
|
199
199
|
|
200
|
-
Facter::
|
200
|
+
Facter::Core::Execution.stubs(:exec).with(hostname_command).returns('sometest')
|
201
201
|
FileTest.stubs(:exists?).with("/etc/resolv.conf").returns(false)
|
202
202
|
|
203
203
|
Facter.fact(:domain).value.should be_nil
|
@@ -288,8 +288,8 @@ describe "Domain name facts" do
|
|
288
288
|
|
289
289
|
describe scenario[:scenario] do
|
290
290
|
before(:each) do
|
291
|
-
Facter::
|
292
|
-
Facter::
|
291
|
+
Facter::Core::Execution.stubs(:exec).with("hostname -f 2> /dev/null").returns(scenario[:hostname])
|
292
|
+
Facter::Core::Execution.stubs(:exec).with("dnsdomainname 2> /dev/null").returns(scenario[:dnsdomainname])
|
293
293
|
resolv_conf_contains(
|
294
294
|
"search #{scenario[:resolve_search]}",
|
295
295
|
"domain #{scenario[:resolve_domain]}"
|
data/spec/unit/facter_spec.rb
CHANGED
@@ -3,267 +3,106 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Facter do
|
6
|
-
it "
|
7
|
-
Facter.should respond_to(:collection)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should cache the collection" do
|
6
|
+
it "caches the collection" do
|
11
7
|
Facter.collection.should equal(Facter.collection)
|
12
8
|
end
|
13
9
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
it "should delegate the :fact method to the collection" do
|
20
|
-
Facter.collection.expects(:fact)
|
21
|
-
Facter.fact
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should delegate the :list method to the collection" do
|
25
|
-
Facter.collection.expects(:list)
|
26
|
-
Facter.list
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should load all facts when listing" do
|
30
|
-
Facter.collection.expects(:load_all)
|
31
|
-
Facter.collection.stubs(:list)
|
32
|
-
Facter.list
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should delegate the :to_hash method to the collection" do
|
36
|
-
Facter.collection.expects(:to_hash)
|
37
|
-
Facter.to_hash
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should load all facts when calling :to_hash" do
|
41
|
-
Facter.collection.expects(:load_all)
|
42
|
-
Facter.collection.stubs(:to_hash)
|
43
|
-
Facter.to_hash
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should delegate the :value method to the collection" do
|
47
|
-
Facter.collection.expects(:value)
|
48
|
-
Facter.value
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should delegate the :each method to the collection" do
|
52
|
-
Facter.collection.expects(:each)
|
53
|
-
Facter.each
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should load all facts when calling :each" do
|
57
|
-
Facter.collection.expects(:load_all)
|
58
|
-
Facter.collection.stubs(:each)
|
59
|
-
Facter.each
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should yield to the block when using :each" do
|
63
|
-
Facter.collection.stubs(:load_all)
|
64
|
-
Facter.collection.stubs(:each).yields "foo"
|
65
|
-
result = []
|
66
|
-
Facter.each { |f| result << f }
|
67
|
-
result.should == %w{foo}
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "when provided code as a string" do
|
71
|
-
it "should execute the code in the shell" do
|
72
|
-
test_command = Facter::Util::Config.is_windows? ? 'cmd.exe /c echo yup' : 'echo yup'
|
73
|
-
Facter.add("shell_testing") do
|
74
|
-
setcode test_command
|
75
|
-
end
|
76
|
-
|
77
|
-
Facter["shell_testing"].value.should == "yup"
|
10
|
+
describe "methods on the collection" do
|
11
|
+
it "delegates the :flush method to the collection" do
|
12
|
+
Facter.collection.expects(:flush)
|
13
|
+
Facter.flush
|
78
14
|
end
|
79
|
-
end
|
80
15
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
Facter.collection
|
85
|
-
Facter.ipaddress.should == Facter['ipaddress'].value
|
86
|
-
end
|
16
|
+
it "delegates the :fact method to the collection" do
|
17
|
+
Facter.collection.expects(:fact).with("afact")
|
18
|
+
Facter.fact("afact")
|
87
19
|
end
|
88
20
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
Facter.ipaddress.should == Facter['ipaddress'].value
|
93
|
-
end
|
21
|
+
it "delegates the :list method to the collection" do
|
22
|
+
Facter.collection.expects(:list)
|
23
|
+
Facter.list
|
94
24
|
end
|
95
|
-
end
|
96
25
|
|
97
|
-
|
98
|
-
|
99
|
-
Facter.
|
100
|
-
|
101
|
-
Facter["block_testing"].value.should == "foo"
|
26
|
+
it "loads all facts when listing" do
|
27
|
+
Facter.collection.expects(:load_all)
|
28
|
+
Facter.list
|
102
29
|
end
|
103
|
-
end
|
104
30
|
|
105
|
-
|
106
|
-
|
107
|
-
Facter
|
31
|
+
it "delegates the :to_hash method to the collection" do
|
32
|
+
Facter.collection.expects(:to_hash)
|
33
|
+
Facter.to_hash
|
108
34
|
end
|
109
|
-
end
|
110
35
|
|
111
|
-
|
112
|
-
|
113
|
-
Facter
|
36
|
+
it "loads all facts when calling :to_hash" do
|
37
|
+
Facter.collection.expects(:load_all)
|
38
|
+
Facter.collection.stubs(:to_hash)
|
39
|
+
Facter.to_hash
|
114
40
|
end
|
115
|
-
end
|
116
|
-
|
117
|
-
# #33 Make sure we only get one mac address
|
118
|
-
it "should only return one mac address" do
|
119
|
-
if macaddress = Facter.value(:macaddress)
|
120
|
-
macaddress.should_not be_include(" ")
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
it "should have a method for registering directories to search" do
|
125
|
-
Facter.should respond_to(:search)
|
126
|
-
end
|
127
41
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
it "should have a method to query debugging mode" do
|
133
|
-
Facter.should respond_to(:debugging?)
|
134
|
-
end
|
135
|
-
|
136
|
-
it "should have a method to query timing mode" do
|
137
|
-
Facter.should respond_to(:timing?)
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should have a method to show timing information" do
|
141
|
-
Facter.should respond_to(:show_time)
|
142
|
-
end
|
143
|
-
|
144
|
-
it "should have a method to warn" do
|
145
|
-
Facter.should respond_to(:warn)
|
146
|
-
end
|
147
|
-
|
148
|
-
describe "when warning" do
|
149
|
-
it "should warn if debugging is enabled" do
|
150
|
-
Facter.debugging(true)
|
151
|
-
Kernel.stubs(:warn)
|
152
|
-
Kernel.expects(:warn).with('foo')
|
153
|
-
Facter.warn('foo')
|
42
|
+
it "delegates the :value method to the collection" do
|
43
|
+
Facter.collection.expects(:value).with("myvaluefact")
|
44
|
+
Facter.value("myvaluefact")
|
154
45
|
end
|
155
46
|
|
156
|
-
it "
|
157
|
-
Facter.
|
158
|
-
|
159
|
-
Kernel.expects(:warn).never
|
160
|
-
Facter.warn(nil)
|
47
|
+
it "delegates the :each method to the collection" do
|
48
|
+
Facter.collection.expects(:each)
|
49
|
+
Facter.each
|
161
50
|
end
|
162
51
|
|
163
|
-
it "
|
164
|
-
Facter.
|
165
|
-
|
166
|
-
Kernel.expects(:warn).never
|
167
|
-
Facter.warn('')
|
52
|
+
it "delegates the :add method to the collection" do
|
53
|
+
Facter.collection.expects(:add).with("factname", {})
|
54
|
+
Facter.add("factname")
|
168
55
|
end
|
169
56
|
|
170
|
-
it "
|
171
|
-
Facter.
|
172
|
-
|
173
|
-
Kernel.expects(:warn).never
|
174
|
-
Facter.warn('foo')
|
57
|
+
it "delegates the :define_fact method to the collection" do
|
58
|
+
Facter.collection.expects(:define_fact).with("factname", {})
|
59
|
+
Facter.define_fact("factname")
|
175
60
|
end
|
176
61
|
|
177
|
-
it "
|
178
|
-
Facter.
|
179
|
-
|
180
|
-
|
181
|
-
Kernel.expects(:warn).with('bar')
|
182
|
-
Facter.warn( ['foo','bar'])
|
62
|
+
it "loads all facts when calling :each" do
|
63
|
+
Facter.collection.expects(:load_all)
|
64
|
+
Facter.collection.stubs(:each)
|
65
|
+
Facter.each
|
183
66
|
end
|
184
67
|
end
|
185
68
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
69
|
+
it "yields to the block when using :each" do
|
70
|
+
Facter.collection.stubs(:load_all)
|
71
|
+
Facter.collection.stubs(:each).yields "foo"
|
72
|
+
result = []
|
73
|
+
Facter.each { |f| result << f }
|
74
|
+
result.should == %w{foo}
|
75
|
+
end
|
193
76
|
|
194
|
-
|
195
|
-
|
196
|
-
Kernel.expects(:warnonce).never
|
197
|
-
Facter.warnonce(nil)
|
198
|
-
end
|
77
|
+
describe "when registering directories to search" do
|
78
|
+
after { Facter.reset_search_path! }
|
199
79
|
|
200
|
-
it "
|
201
|
-
|
202
|
-
Kernel.expects(:warnonce).never
|
203
|
-
Facter.warnonce('')
|
80
|
+
it "allows registration of a directory" do
|
81
|
+
Facter.search "/my/dir"
|
204
82
|
end
|
205
|
-
end
|
206
83
|
|
207
|
-
|
208
|
-
|
209
|
-
Facter.debugging(1)
|
210
|
-
Facter.should be_debugging
|
211
|
-
end
|
212
|
-
it "should have debugging enabled using true" do
|
213
|
-
Facter.debugging(true)
|
214
|
-
Facter.should be_debugging
|
215
|
-
end
|
216
|
-
it "should have debugging enabled using any string except off" do
|
217
|
-
Facter.debugging('aaaaa')
|
218
|
-
Facter.should be_debugging
|
219
|
-
end
|
220
|
-
it "should have debugging disabled using 0" do
|
221
|
-
Facter.debugging(0)
|
222
|
-
Facter.should_not be_debugging
|
223
|
-
end
|
224
|
-
it "should have debugging disabled using false" do
|
225
|
-
Facter.debugging(false)
|
226
|
-
Facter.should_not be_debugging
|
227
|
-
end
|
228
|
-
it "should have debugging disabled using the string 'off'" do
|
229
|
-
Facter.debugging('off')
|
230
|
-
Facter.should_not be_debugging
|
84
|
+
it "allows registration of multiple directories" do
|
85
|
+
Facter.search "/my/dir", "/other/dir"
|
231
86
|
end
|
232
|
-
end
|
233
87
|
|
234
|
-
|
235
|
-
|
236
|
-
Facter.
|
237
|
-
Facter.should be_timing
|
238
|
-
end
|
239
|
-
it "should have timing enabled using true" do
|
240
|
-
Facter.timing(true)
|
241
|
-
Facter.should be_timing
|
242
|
-
end
|
243
|
-
it "should have timing disabled using 0" do
|
244
|
-
Facter.timing(0)
|
245
|
-
Facter.should_not be_timing
|
246
|
-
end
|
247
|
-
it "should have timing disabled using false" do
|
248
|
-
Facter.timing(false)
|
249
|
-
Facter.should_not be_timing
|
88
|
+
it "returns all registered directories when asked" do
|
89
|
+
Facter.search "/my/dir", "/other/dir"
|
90
|
+
Facter.search_path.should == %w{/my/dir /other/dir}
|
250
91
|
end
|
251
92
|
end
|
252
93
|
|
253
|
-
describe "when registering directories to search" do
|
254
|
-
|
255
|
-
|
256
|
-
it "should allow registration of a directory" do
|
257
|
-
Facter.search "/my/dir"
|
94
|
+
describe "when registering directories to search for external facts" do
|
95
|
+
it "allows registration of a directory" do
|
96
|
+
Facter.search_external ["/my/dir"]
|
258
97
|
end
|
259
98
|
|
260
|
-
it "
|
261
|
-
Facter.
|
99
|
+
it "allows registration of multiple directories" do
|
100
|
+
Facter.search_external ["/my/dir", "/other/dir"]
|
262
101
|
end
|
263
102
|
|
264
|
-
it "
|
265
|
-
Facter.
|
266
|
-
Facter.
|
103
|
+
it "returns all registered directories when asked" do
|
104
|
+
Facter.search_external ["/my/dir", "/other/dir"]
|
105
|
+
Facter.search_external_path.should include("/my/dir", "/other/dir")
|
267
106
|
end
|
268
107
|
end
|
269
108
|
end
|