summaryrefslogtreecommitdiffstats
path: root/test/network/handler/node.rb
diff options
context:
space:
mode:
authorJeffrey J McCune <jeff.mccune@northstarlabs.net>2007-09-10 15:27:57 -0400
committerJeffrey J McCune <jeff.mccune@northstarlabs.net>2007-09-10 15:27:57 -0400
commite826453107fc3888da4667be9cce9cb7661072f8 (patch)
tree92878fa77a20bd76b27ad34507f4f32274ee1ff2 /test/network/handler/node.rb
parent09f7da5a5000876e03e9103c76089cfad9a1ba88 (diff)
parent6700adcacdec4381ee4a27a215ee4b45207aa448 (diff)
downloadpuppet-e826453107fc3888da4667be9cce9cb7661072f8.tar.gz
puppet-e826453107fc3888da4667be9cce9cb7661072f8.tar.xz
puppet-e826453107fc3888da4667be9cce9cb7661072f8.zip
Merge branch 'master' of git://reductivelabs.com/puppet
Diffstat (limited to 'test/network/handler/node.rb')
-rwxr-xr-xtest/network/handler/node.rb83
1 files changed, 23 insertions, 60 deletions
diff --git a/test/network/handler/node.rb b/test/network/handler/node.rb
index 9fad3f765..6b8ab9290 100755
--- a/test/network/handler/node.rb
+++ b/test/network/handler/node.rb
@@ -12,7 +12,7 @@ require 'puppet/network/handler/node'
module NodeTesting
include PuppetTest
Node = Puppet::Network::Handler::Node
- SimpleNode = Puppet::Network::Handler::Node::SimpleNode
+ SimpleNode = Puppet::Node
def mk_node_mapper
# First, make sure our nodesearch command works as we expect
@@ -66,7 +66,7 @@ module NodeTesting
end
end
-class TestNodeInterface < Test::Unit::TestCase
+class TestNodeHandler < Test::Unit::TestCase
include NodeTesting
def setup
@@ -193,6 +193,9 @@ class TestNodeInterface < Test::Unit::TestCase
# Make sure its source is set
node.expects(:source=).with(handler.source)
+ # And that the names are retained
+ node.expects(:names=).with(%w{a b c})
+
# And make sure we actually get it back
handler.expects(:nodesearch).with("c").returns(node)
@@ -315,70 +318,30 @@ class TestNodeInterface < Test::Unit::TestCase
end
assert_equal(%w{yay foo}, result, "Did not get classes back")
end
-end
-
-class TestSimpleNode < Test::Unit::TestCase
- include NodeTesting
-
- # Make sure we get all the defaults correctly.
- def test_simplenode_initialize
- node = nil
- assert_nothing_raised("could not create a node without classes or parameters") do
- node = SimpleNode.new("testing")
- end
- assert_equal("testing", node.name, "Did not set name correctly")
- assert_equal({}, node.parameters, "Node parameters did not default correctly")
- assert_equal([], node.classes, "Node classes did not default correctly")
-
- # Now test it with values for both
- params = {"a" => "b"}
- classes = %w{one two}
- assert_nothing_raised("could not create a node with classes and parameters") do
- node = SimpleNode.new("testing", :parameters => params, :classes => classes)
- end
- assert_equal("testing", node.name, "Did not set name correctly")
- assert_equal(params, node.parameters, "Node parameters did not get set correctly")
- assert_equal(classes, node.classes, "Node classes did not get set correctly")
-
- # And make sure a single class gets turned into an array
- assert_nothing_raised("could not create a node with a class as a string") do
- node = SimpleNode.new("testing", :classes => "test")
- end
- assert_equal(%w{test}, node.classes, "A node class string was not converted to an array")
- # Make sure we get environments
- assert_nothing_raised("could not create a node with an environment") do
- node = SimpleNode.new("testing", :environment => "test")
- end
- assert_equal("test", node.environment, "Environment was not set")
+ # We reuse the filetimeout for the node caching timeout.
+ def test_node_caching
+ handler = Node.new
- # Now make sure we get the default env
- Puppet[:environment] = "prod"
- assert_nothing_raised("could not create a node with no environment") do
- node = SimpleNode.new("testing")
+ node = Object.new
+ node.metaclass.instance_eval do
+ attr_accessor :time, :name
end
- assert_equal("prod", node.environment, "Did not get default environment")
+ node.time = Time.now
+ node.name = "yay"
- # But that it stays nil if there's no default env set
- Puppet[:environment] = ""
- assert_nothing_raised("could not create a node with no environment and no default env") do
- node = SimpleNode.new("testing")
+ # Make sure caching works normally
+ assert_nothing_raised("Could not cache node") do
+ handler.send(:cache, node)
end
- assert_nil(node.environment, "Got a default env when none was set")
-
- end
+ assert_equal(node.object_id, handler.send(:cached?, "yay").object_id, "Did not get node back from the cache")
- # Verify that the node source wins over facter.
- def test_fact_merge
- node = SimpleNode.new("yay", :parameters => {"a" => "one", "b" => "two"})
+ # And that it's returned if we ask for it, instead of creating a new node.
+ assert_equal(node.object_id, handler.details("yay").object_id, "Did not use cached node")
- assert_nothing_raised("Could not merge parameters") do
- node.fact_merge("b" => "three", "c" => "yay")
- end
- params = node.parameters
- assert_equal("one", params["a"], "Lost nodesource parameters in parameter merge")
- assert_equal("two", params["b"], "Overrode nodesource parameters in parameter merge")
- assert_equal("yay", params["c"], "Did not get facts in parameter merge")
+ # Now set the node's time to be a long time ago
+ node.time = Time.now - 50000
+ assert(! handler.send(:cached?, "yay"), "Timed-out node was returned from cache")
end
end
@@ -568,7 +531,7 @@ class LdapNodeTest < PuppetTest::TestCase
end
def ldaphost(name)
- node = NodeDef.new(:name => name)
+ node = Puppet::Node.new(name)
parent = nil
found = false
@ldap.search( "ou=hosts, dc=madstop, dc=com", 2,