summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-01-22 16:51:02 -0600
committerLuke Kanies <luke@madstop.com>2009-02-06 18:08:41 -0600
commite65d7f11dd95ab5432adefeabc3179e9eb5dd050 (patch)
tree52ad7eabbe7b07d5f7496587e40019cbe4e3a76e /spec/unit
parent6b4e5f49a8d1d062aefae31a923cff9e3f0d31ba (diff)
downloadpuppet-e65d7f11dd95ab5432adefeabc3179e9eb5dd050.tar.gz
puppet-e65d7f11dd95ab5432adefeabc3179e9eb5dd050.tar.xz
puppet-e65d7f11dd95ab5432adefeabc3179e9eb5dd050.zip
Refactoring how the Facter integration works
I moved all of the extra Fact modifications into the Facts class, and then moved the calls of those new methods into the Facter terminus. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/agent/fact_handler.rb31
-rwxr-xr-xspec/unit/indirector/facts/facter.rb55
-rwxr-xr-xspec/unit/node/facts.rb55
3 files changed, 99 insertions, 42 deletions
diff --git a/spec/unit/agent/fact_handler.rb b/spec/unit/agent/fact_handler.rb
index b58f55ebc..9622b0649 100755
--- a/spec/unit/agent/fact_handler.rb
+++ b/spec/unit/agent/fact_handler.rb
@@ -82,36 +82,9 @@ describe Puppet::Agent::FactHandler do
@facthandler.reload_facter
end
- it "should load all Puppet Fact plugins" do
- @facthandler.expects(:load_fact_plugins)
+ it "should use the Facter terminus load all Puppet Fact plugins" do
+ Puppet::Node::Facts::Facter.expects(:load_fact_plugins)
@facthandler.reload_facter
end
end
-
- it "should load each directory in the Fact path when loading fact plugins" do
- Puppet.settings.expects(:value).with(:factpath).returns("one%stwo" % File::PATH_SEPARATOR)
-
- @facthandler.expects(:load_facts_in_dir).with("one")
- @facthandler.expects(:load_facts_in_dir).with("two")
-
- @facthandler.load_fact_plugins
- end
-
- it "should skip files when asked to load a directory" do
- FileTest.expects(:directory?).with("myfile").returns false
-
- @facthandler.load_facts_in_dir("myfile")
- end
-
- it "should load each ruby file when asked to load a directory" do
- FileTest.expects(:directory?).with("mydir").returns true
- Dir.expects(:chdir).with("mydir").yields
-
- Dir.expects(:glob).with("*.rb").returns %w{a.rb b.rb}
-
- @facthandler.expects(:load).with("a.rb")
- @facthandler.expects(:load).with("b.rb")
-
- @facthandler.load_facts_in_dir("mydir")
- end
end
diff --git a/spec/unit/indirector/facts/facter.rb b/spec/unit/indirector/facts/facter.rb
index 10b7af398..c0b9dce36 100755
--- a/spec/unit/indirector/facts/facter.rb
+++ b/spec/unit/indirector/facts/facter.rb
@@ -26,7 +26,7 @@ describe Puppet::Node::Facts::Facter do
end
it "should load facts on initialization" do
- Puppet::Node::Facts::Facter.expects(:loadfacts)
+ Puppet::Node::Facts::Facter.expects(:load_fact_plugins)
Puppet::Node::Facts::Facter.new
end
end
@@ -40,7 +40,6 @@ describe Puppet::Node::Facts::Facter do
end
describe Puppet::Node::Facts::Facter, " when finding facts" do
-
it "should return a Facts instance" do
@facter.find(@request).should be_instance_of(Puppet::Node::Facts)
end
@@ -55,21 +54,28 @@ describe Puppet::Node::Facts::Facter do
facts.values["one"].should == "two"
end
- it "should add the Puppet version as a 'clientversion' fact" do
- Facter.expects(:to_hash).returns("one" => "two")
- @facter.find(@request).values["clientversion"].should == Puppet.version.to_s
+ it "should add local facts" do
+ facts = Puppet::Node::Facts.new("foo")
+ Puppet::Node::Facts.expects(:new).returns facts
+ facts.expects(:add_local_facts)
+
+ @facter.find(@request)
end
- it "should add the current environment as a fact if one is not set" do
- Facter.expects(:to_hash).returns("one" => "two")
+ it "should convert all facts into strings" do
+ facts = Puppet::Node::Facts.new("foo")
+ Puppet::Node::Facts.expects(:new).returns facts
+ facts.expects(:stringify)
- @facter.find(@request).values["environment"].should == Puppet[:environment]
+ @facter.find(@request)
end
- it "should not replace any existing environment fact" do
- Facter.expects(:to_hash).returns("one" => "two", "environment" => "foo")
+ it "should call the downcase hook" do
+ facts = Puppet::Node::Facts.new("foo")
+ Puppet::Node::Facts.expects(:new).returns facts
+ facts.expects(:downcase_if_necessary)
- @facter.find(@request).values["environment"].should == "foo"
+ @facter.find(@request)
end
end
@@ -87,7 +93,30 @@ describe Puppet::Node::Facts::Facter do
end
end
- describe Puppet::Node::Facts::Facter, " when loading facts from the factpath" do
- it "should load every fact in each factpath directory"
+ it "should load each directory in the Fact path when loading fact plugins" do
+ Puppet.settings.expects(:value).with(:factpath).returns("one%stwo" % File::PATH_SEPARATOR)
+
+ Puppet::Node::Facts::Facter.expects(:load_facts_in_dir).with("one")
+ Puppet::Node::Facts::Facter.expects(:load_facts_in_dir).with("two")
+
+ Puppet::Node::Facts::Facter.load_fact_plugins
+ end
+
+ it "should skip files when asked to load a directory" do
+ FileTest.expects(:directory?).with("myfile").returns false
+
+ Puppet::Node::Facts::Facter.load_facts_in_dir("myfile")
+ end
+
+ it "should load each ruby file when asked to load a directory" do
+ FileTest.expects(:directory?).with("mydir").returns true
+ Dir.expects(:chdir).with("mydir").yields
+
+ Dir.expects(:glob).with("*.rb").returns %w{a.rb b.rb}
+
+ Puppet::Node::Facts::Facter.expects(:load).with("a.rb")
+ Puppet::Node::Facts::Facter.expects(:load).with("b.rb")
+
+ Puppet::Node::Facts::Facter.load_facts_in_dir("mydir")
end
end
diff --git a/spec/unit/node/facts.rb b/spec/unit/node/facts.rb
index 118713b17..a557066b8 100755
--- a/spec/unit/node/facts.rb
+++ b/spec/unit/node/facts.rb
@@ -5,6 +5,61 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/node/facts'
describe Puppet::Node::Facts, "when indirecting" do
+ before do
+ @facts = Puppet::Node::Facts.new("me")
+ end
+
+ it "should be able to convert all fact values to strings" do
+ @facts.values["one"] = 1
+ @facts.stringify
+ @facts.values["one"].should == "1"
+ end
+
+ it "should add the Puppet version as a 'clientversion' fact when adding local facts" do
+ @facts.add_local_facts
+ @facts.values["clientversion"].should == Puppet.version.to_s
+ end
+
+ it "should add the current environment as a fact if one is not set when adding local facts" do
+ @facts.add_local_facts
+ @facts.values["environment"].should == Puppet[:environment]
+ end
+
+ it "should not replace any existing environment fact when adding local facts" do
+ @facts.values["environment"] = "foo"
+ @facts.add_local_facts
+ @facts.values["environment"].should == "foo"
+ end
+
+ it "should be able to downcase fact values" do
+ Puppet.settings.stubs(:value).returns "eh"
+ Puppet.settings.expects(:value).with(:downcasefacts).returns true
+
+ @facts.values["one"] = "Two"
+
+ @facts.downcase_if_necessary
+ @facts.values["one"].should == "two"
+ end
+
+ it "should only try to downcase strings" do
+ Puppet.settings.stubs(:value).returns "eh"
+ Puppet.settings.expects(:value).with(:downcasefacts).returns true
+
+ @facts.values["now"] = Time.now
+
+ @facts.downcase_if_necessary
+ @facts.values["now"].should be_instance_of(Time)
+ end
+
+ it "should not downcase facts if not configured to do so" do
+ Puppet.settings.stubs(:value).returns "eh"
+ Puppet.settings.expects(:value).with(:downcasefacts).returns false
+
+ @facts.values["one"] = "Two"
+ @facts.downcase_if_necessary
+ @facts.values["one"].should == "Two"
+ end
+
describe "when indirecting" do
before do
@indirection = stub 'indirection', :request => mock('request'), :name => :facts