summaryrefslogtreecommitdiffstats
path: root/spec/unit/node
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-09-11 16:19:03 -0500
committerLuke Kanies <luke@madstop.com>2007-09-11 16:19:03 -0500
commit65c1501504dd7e9166176661f9ed9f80300954db (patch)
tree9e1bc22b924457561ce0de1b25590effbcd33a4a /spec/unit/node
parent5aa4440b6fb8c9199ee549bd8fe0e4afb296c259 (diff)
downloadpuppet-65c1501504dd7e9166176661f9ed9f80300954db.tar.gz
puppet-65c1501504dd7e9166176661f9ed9f80300954db.tar.xz
puppet-65c1501504dd7e9166176661f9ed9f80300954db.zip
The Node handler is now obsolete. Node searching is handled through the indirector. I have not yet added the tests for the node handlers themselves, which is next.
Diffstat (limited to 'spec/unit/node')
-rwxr-xr-xspec/unit/node/searching.rb79
1 files changed, 79 insertions, 0 deletions
diff --git a/spec/unit/node/searching.rb b/spec/unit/node/searching.rb
new file mode 100755
index 000000000..553822576
--- /dev/null
+++ b/spec/unit/node/searching.rb
@@ -0,0 +1,79 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+require 'puppet/node/searching'
+require 'puppet/node/facts'
+
+describe Puppet::Node::Searching, " when searching for nodes" do
+ before do
+ @searcher = Object.new
+ @searcher.extend(Puppet::Node::Searching)
+ @facts = Puppet::Node::Facts.new("foo", "hostname" => "yay", "domain" => "domain.com")
+ @node = Puppet::Node.new("foo")
+ Puppet::Node::Facts.stubs(:get).with("foo").returns(@facts)
+ end
+
+ it "should search for the node by its key first" do
+ names = []
+ @searcher.expects(:get).with do |name|
+ names << name
+ names == %w{foo}
+ end.returns(@node)
+ @searcher.search("foo").should equal(@node)
+ end
+
+ it "should return the first node found using the generated list of names" do
+ names = []
+ @searcher.expects(:get).with("foo").returns(nil)
+ @searcher.expects(:get).with("yay.domain.com").returns(@node)
+ @searcher.search("foo").should equal(@node)
+ end
+
+ it "should search for the rest of the names inversely by length" do
+ names = []
+ @facts.values["fqdn"] = "longer.than.the.normal.fqdn.com"
+ @searcher.stubs(:get).with do |name|
+ names << name
+ end
+ @searcher.search("foo")
+ # Strip off the key
+ names.shift
+
+ # And the 'default'
+ names.pop
+
+ length = 100
+ names.each do |name|
+ (name.length < length).should be_true
+ length = name.length
+ end
+ end
+
+ it "should attempt to find a default node if no names are found" do
+ names = []
+ @searcher.stubs(:get).with do |name|
+ names << name
+ end.returns(nil)
+ @searcher.search("foo")
+ names[-1].should == "default"
+ end
+
+ it "should cache the nodes" do
+ @searcher.expects(:get).with("foo").returns(@node)
+ @searcher.search("foo").should equal(@node)
+ @searcher.search("foo").should equal(@node)
+ end
+
+ it "should flush the node cache using the :filetimeout parameter" do
+ node2 = Puppet::Node.new("foo2")
+ Puppet[:filetimeout] = -1
+ # I couldn't get this to work with :expects
+ @searcher.stubs(:get).returns(@node, node2).then.raises(ArgumentError)
+ @searcher.search("foo").should equal(@node)
+ @searcher.search("foo").should equal(node2)
+ end
+
+ after do
+ Puppet.config.clear
+ end
+end