summaryrefslogtreecommitdiff
path: root/spec/unit/facter
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/facter')
-rwxr-xr-xspec/unit/facter/facter_dot_d_spec.rb32
-rw-r--r--spec/unit/facter/pe_required_facts_spec.rb69
-rwxr-xr-x[-rw-r--r--]spec/unit/facter/pe_version_spec.rb20
-rwxr-xr-x[-rw-r--r--]spec/unit/facter/root_home_spec.rb36
-rwxr-xr-x[-rw-r--r--]spec/unit/facter/util/puppet_settings_spec.rb7
5 files changed, 70 insertions, 94 deletions
diff --git a/spec/unit/facter/facter_dot_d_spec.rb b/spec/unit/facter/facter_dot_d_spec.rb
new file mode 100755
index 0000000..0afadb2
--- /dev/null
+++ b/spec/unit/facter/facter_dot_d_spec.rb
@@ -0,0 +1,32 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+require 'facter/facter_dot_d'
+
+describe Facter::Util::DotD do
+
+ context 'returns a simple fact' do
+ before :each do
+ Facter.stubs(:version).returns('1.6.1')
+ subject.stubs(:entries).returns(['/etc/facter/facts.d/fake_fact.txt'])
+ File.stubs(:readlines).with('/etc/facter/facts.d/fake_fact.txt').returns(['fake_fact=fake fact'])
+ subject.create
+ end
+
+ it 'should return successfully' do
+ expect(Facter.fact(:fake_fact).value).to eq('fake fact')
+ end
+ end
+
+ context 'returns a fact with equals signs' do
+ before :each do
+ Facter.stubs(:version).returns('1.6.1')
+ subject.stubs(:entries).returns(['/etc/facter/facts.d/foo.txt'])
+ File.stubs(:readlines).with('/etc/facter/facts.d/foo.txt').returns(['foo=1+1=2'])
+ subject.create
+ end
+
+ it 'should return successfully' do
+ expect(Facter.fact(:foo).value).to eq('1+1=2')
+ end
+ end
+end
diff --git a/spec/unit/facter/pe_required_facts_spec.rb b/spec/unit/facter/pe_required_facts_spec.rb
deleted file mode 100644
index f219b37..0000000
--- a/spec/unit/facter/pe_required_facts_spec.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-# 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")
- # 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/pe_version_spec.rb b/spec/unit/facter/pe_version_spec.rb
index 931c6d4..4d0349e 100644..100755
--- a/spec/unit/facter/pe_version_spec.rb
+++ b/spec/unit/facter/pe_version_spec.rb
@@ -26,23 +26,23 @@ describe "PE Version specs" do
(major,minor,patch) = version.split(".")
it "Should return true" do
- Facter.fact(:is_pe).value.should == true
+ expect(Facter.fact(:is_pe).value).to eq(true)
end
it "Should have a version of #{version}" do
- Facter.fact(:pe_version).value.should == version
+ expect(Facter.fact(:pe_version).value).to eq(version)
end
it "Should have a major version of #{major}" do
- Facter.fact(:pe_major_version).value.should == major
+ expect(Facter.fact(:pe_major_version).value).to eq(major)
end
it "Should have a minor version of #{minor}" do
- Facter.fact(:pe_minor_version).value.should == minor
+ expect(Facter.fact(:pe_minor_version).value).to eq(minor)
end
it "Should have a patch version of #{patch}" do
- Facter.fact(:pe_patch_version).value.should == patch
+ expect(Facter.fact(:pe_patch_version).value).to eq(patch)
end
end
end
@@ -54,23 +54,23 @@ describe "PE Version specs" do
end
it "is_pe is false" do
- Facter.fact(:is_pe).value.should == false
+ expect(Facter.fact(:is_pe).value).to eq(false)
end
it "pe_version is nil" do
- Facter.fact(:pe_version).value.should be_nil
+ expect(Facter.fact(:pe_version).value).to be_nil
end
it "pe_major_version is nil" do
- Facter.fact(:pe_major_version).value.should be_nil
+ expect(Facter.fact(:pe_major_version).value).to be_nil
end
it "pe_minor_version is nil" do
- Facter.fact(:pe_minor_version).value.should be_nil
+ expect(Facter.fact(:pe_minor_version).value).to be_nil
end
it "Should have a patch version" do
- Facter.fact(:pe_patch_version).value.should be_nil
+ expect(Facter.fact(:pe_patch_version).value).to be_nil
end
end
end
diff --git a/spec/unit/facter/root_home_spec.rb b/spec/unit/facter/root_home_spec.rb
index ce80684..98fe141 100644..100755
--- a/spec/unit/facter/root_home_spec.rb
+++ b/spec/unit/facter/root_home_spec.rb
@@ -1,3 +1,4 @@
+#! /usr/bin/env ruby -S rspec
require 'spec_helper'
require 'facter/root_home'
@@ -8,7 +9,7 @@ describe Facter::Util::RootHome do
it "should return /" do
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
- Facter::Util::RootHome.get_root_home.should == expected_root_home
+ expect(Facter::Util::RootHome.get_root_home).to eq(expected_root_home)
end
end
context "linux" do
@@ -17,16 +18,7 @@ describe Facter::Util::RootHome do
it "should return /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 "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
+ expect(Facter::Util::RootHome.get_root_home).to eq(expected_root_home)
end
end
context "windows" do
@@ -34,7 +26,27 @@ describe Facter::Util::RootHome do
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(nil)
end
it "should be nil on windows" do
- Facter::Util::RootHome.get_root_home.should be_nil
+ expect(Facter::Util::RootHome.get_root_home).to be_nil
+ 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)
+ expect(Facter.fact(:root_home).value).to eq(expected_root_home)
end
end
+
end
diff --git a/spec/unit/facter/util/puppet_settings_spec.rb b/spec/unit/facter/util/puppet_settings_spec.rb
index c3ce6ea..c06137d 100644..100755
--- a/spec/unit/facter/util/puppet_settings_spec.rb
+++ b/spec/unit/facter/util/puppet_settings_spec.rb
@@ -1,3 +1,4 @@
+#! /usr/bin/env ruby -S rspec
require 'spec_helper'
require 'facter/util/puppet_settings'
@@ -10,11 +11,11 @@ describe Facter::Util::PuppetSettings do
end
it 'should be nil' do
- subject.with_puppet { Puppet[:vardir] }.should be_nil
+ expect(subject.with_puppet { Puppet[:vardir] }).to be_nil
end
it 'should not yield to the block' do
Puppet.expects(:[]).never
- subject.with_puppet { Puppet[:vardir] }.should be_nil
+ expect(subject.with_puppet { Puppet[:vardir] }).to be_nil
end
end
context "With Puppet loaded" do
@@ -28,7 +29,7 @@ describe Facter::Util::PuppetSettings do
subject.with_puppet { Puppet[:vardir] }
end
it 'should return the nodes vardir' do
- subject.with_puppet { Puppet[:vardir] }.should eq vardir
+ expect(subject.with_puppet { Puppet[:vardir] }).to eq vardir
end
end
end