summaryrefslogtreecommitdiffstats
path: root/test/network/handler
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-05-03 05:24:13 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-05-03 05:24:13 +0000
commit8d7ec14836809f1433e645c3069691d2f6c70e52 (patch)
tree185c06aaaade8fd87b863755eb911a3fde50821a /test/network/handler
parent79dcd33aebf8749719e9eff009b8bb3fdaf77751 (diff)
downloadpuppet-8d7ec14836809f1433e645c3069691d2f6c70e52.tar.gz
puppet-8d7ec14836809f1433e645c3069691d2f6c70e52.tar.xz
puppet-8d7ec14836809f1433e645c3069691d2f6c70e52.zip
Adding a fact handler, along with an abstract interface for fact stores and a simple yaml fact store, towards the Node Classification work.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2457 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/network/handler')
-rwxr-xr-xtest/network/handler/facts.rb112
1 files changed, 112 insertions, 0 deletions
diff --git a/test/network/handler/facts.rb b/test/network/handler/facts.rb
new file mode 100755
index 000000000..03327b8c4
--- /dev/null
+++ b/test/network/handler/facts.rb
@@ -0,0 +1,112 @@
+#!/usr/bin/env ruby
+
+$:.unshift("../../lib") if __FILE__ =~ /\.rb$/
+
+require 'puppettest'
+require 'mocha'
+require 'puppet/network/handler/facts'
+
+class TestFactsHandler < Test::Unit::TestCase
+ include PuppetTest::ServerTest
+
+ def setup
+ super
+
+ @class = Puppet::Network::Handler.handler(:facts)
+
+ @@client_facts = {}
+
+ unless Puppet::Util::FactStore.store(:testing)
+ Puppet::Util::FactStore.newstore(:testing) do
+ def get(node)
+ @@client_facts[node]
+ end
+
+ def set(node, facts)
+ @@client_facts[node] = facts
+ end
+ end
+ end
+
+ Puppet[:factstore] = :testing
+
+ @handler = @class.new
+
+ @facts = {:a => :b, :c => :d}
+ @name = "foo"
+
+ @backend = @handler.instance_variable_get("@backend")
+ end
+
+ def teardown
+ @@client_facts.clear
+ end
+
+ def test_strip_internal
+ @facts[:_puppet_one] = "yay"
+ @facts[:_puppet_two] = "boo"
+ @facts[:_puppetthree] = "foo"
+
+ newfacts = nil
+ assert_nothing_raised("Could not call strip_internal") do
+ newfacts = @handler.send(:strip_internal, @facts)
+ end
+
+ [:_puppet_one, :_puppet_two, :_puppetthree].each do |name|
+ assert(@facts.include?(name), "%s was removed in strip_internal from original hash" % name)
+ end
+ [:_puppet_one, :_puppet_two].each do |name|
+ assert(! newfacts.include?(name), "%s was not removed in strip_internal" % name)
+ end
+ assert_equal("foo", newfacts[:_puppetthree], "_puppetthree was removed in strip_internal")
+ end
+
+ def test_add_internal
+ newfacts = nil
+ assert_nothing_raised("Could not call strip_internal") do
+ newfacts = @handler.send(:add_internal, @facts)
+ end
+
+ assert_instance_of(Time, newfacts[:_puppet_timestamp], "Did not set timestamp in add_internal")
+ assert(! @facts.include?(:_puppet_timestamp), "Modified original hash in add_internal")
+ end
+
+ def test_set
+ newfacts = @facts.dup
+ newfacts[:_puppet_timestamp] = Time.now
+ @handler.expects(:add_internal).with(@facts).returns(newfacts)
+ @backend.expects(:set).with(@name, newfacts).returns(nil)
+
+ assert_nothing_raised("Could not set facts") do
+ assert_nil(@handler.set(@name, @facts), "handler.set did not return nil")
+ end
+ end
+
+ def test_get
+ prefacts = @facts.dup
+ prefacts[:_puppet_timestamp] = Time.now
+ @@client_facts[@name] = prefacts
+ @handler.expects(:strip_internal).with(prefacts).returns(@facts)
+ @backend.expects(:get).with(@name).returns(prefacts)
+
+ assert_nothing_raised("Could not retrieve facts") do
+ assert_equal(@facts, @handler.get(@name), "did not get correct answer from handler.get")
+ end
+
+ @handler = @class.new
+ assert_nothing_raised("Failed to call 'get' with no stored facts") do
+ @handler.get("nosuchname")
+ end
+ end
+
+ def test_store_date
+ time = Time.now
+ @facts[:_puppet_timestamp] = time
+
+ @handler.expects(:get).with(@name).returns(@facts)
+
+ assert_equal(time.to_i, @handler.store_date(@name), "Did not retrieve timestamp correctly")
+ end
+end
+
+# $Id$