summaryrefslogtreecommitdiff
path: root/spec/unit/facter
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/facter')
-rw-r--r--spec/unit/facter/pe_required_facts_spec.rb70
-rw-r--r--spec/unit/facter/root_home_spec.rb29
2 files changed, 90 insertions, 9 deletions
diff --git a/spec/unit/facter/pe_required_facts_spec.rb b/spec/unit/facter/pe_required_facts_spec.rb
new file mode 100644
index 0000000..85ff6ab
--- /dev/null
+++ b/spec/unit/facter/pe_required_facts_spec.rb
@@ -0,0 +1,70 @@
+# Puppet Enterprise requires the following facts to be set in order to operate.
+# These facts are set using the file ???? and the two facts are
+# `fact_stomp_port`, and `fact_stomp_server`.
+#
+
+require 'spec_helper'
+
+describe "External facts in /etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt" do
+ context "With Facter 1.6.17 which does not have external facts support" do
+ before :each do
+ Facter.stubs(:version).returns("1.6.17")
+ Facter::Util::Root.stubs(:root?).returns(true)
+ # Stub out the filesystem for stdlib
+ Dir.stubs(:entries).with("/etc/puppetlabs/facter/facts.d").
+ returns(['puppet_enterprise_installer.txt'])
+ Dir.stubs(:entries).with("/etc/facter/facts.d").returns([])
+ File.stubs(:readlines).with('/etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt').
+ returns([
+ "fact_stomp_port=61613\n",
+ "fact_stomp_server=puppetmaster.acme.com\n",
+ "fact_is_puppetagent=true\n",
+ "fact_is_puppetmaster=false\n",
+ "fact_is_puppetca=false\n",
+ "fact_is_puppetconsole=false\n",
+ ])
+ if Facter.collection.respond_to? :load
+ Facter.collection.load(:facter_dot_d)
+ else
+ Facter.collection.loader.load(:facter_dot_d)
+ end
+ end
+
+ it 'defines fact_stomp_port' do
+ Facter.fact(:fact_stomp_port).value.should == '61613'
+ end
+ it 'defines fact_stomp_server' do
+ Facter.fact(:fact_stomp_server).value.should == 'puppetmaster.acme.com'
+ end
+ it 'defines fact_is_puppetagent' do
+ Facter.fact(:fact_is_puppetagent).value.should == 'true'
+ end
+ it 'defines fact_is_puppetmaster' do
+ Facter.fact(:fact_is_puppetmaster).value.should == 'false'
+ end
+ it 'defines fact_is_puppetca' do
+ Facter.fact(:fact_is_puppetca).value.should == 'false'
+ end
+ it 'defines fact_is_puppetconsole' do
+ Facter.fact(:fact_is_puppetconsole).value.should == 'false'
+ end
+ end
+
+ [ '1.7.1', '2.0.1' ].each do |v|
+ context "With Facter #{v} which has external facts support" do
+ before :each do
+ Facter.stubs(:version).returns(v)
+ end
+
+ it 'does not call Facter::Util::DotD.new' do
+ Facter::Util::DotD.expects(:new).never
+
+ if Facter.collection.respond_to? :load
+ Facter.collection.load(:facter_dot_d)
+ else
+ Facter.collection.loader.load(:facter_dot_d)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/unit/facter/root_home_spec.rb b/spec/unit/facter/root_home_spec.rb
index ce80684..532fae1 100644
--- a/spec/unit/facter/root_home_spec.rb
+++ b/spec/unit/facter/root_home_spec.rb
@@ -20,15 +20,6 @@ describe Facter::Util::RootHome do
Facter::Util::RootHome.get_root_home.should == expected_root_home
end
end
- context "macosx" do
- let(:root_ent) { "root:*:0:0:System Administrator:/var/root:/bin/sh" }
- let(:expected_root_home) { "/var/root" }
-
- it "should return /var/root" do
- Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
- Facter::Util::RootHome.get_root_home.should == expected_root_home
- end
- end
context "windows" do
before :each do
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(nil)
@@ -38,3 +29,23 @@ describe Facter::Util::RootHome do
end
end
end
+
+describe 'root_home', :type => :fact do
+ before { Facter.clear }
+ after { Facter.clear }
+
+ context "macosx" do
+ before do
+ Facter.fact(:kernel).stubs(:value).returns("Darwin")
+ Facter.fact(:osfamily).stubs(:value).returns("Darwin")
+ end
+ let(:expected_root_home) { "/var/root" }
+ sample_dscacheutil = File.read(fixtures('dscacheutil','root'))
+
+ it "should return /var/root" do
+ Facter::Util::Resolution.stubs(:exec).with("dscacheutil -q user -a name root").returns(sample_dscacheutil)
+ Facter.fact(:root_home).value.should == expected_root_home
+ end
+ end
+
+end