summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-12-10 21:13:48 -0600
committerLuke Kanies <luke@madstop.com>2007-12-10 21:13:48 -0600
commitf127d04934b679b3e5edd7f55d31342abce3c96e (patch)
treebb8bc15e086b473bc27104cd6fcbbf548a68678e /spec/unit
parent7a4ae082c216d68092f140ed1f5cca40ffb1a09e (diff)
downloadpuppet-f127d04934b679b3e5edd7f55d31342abce3c96e.tar.gz
puppet-f127d04934b679b3e5edd7f55d31342abce3c96e.tar.xz
puppet-f127d04934b679b3e5edd7f55d31342abce3c96e.zip
Fixing #951 -- external nodes work again, but you have to
set the 'node_terminus' setting to 'exec'.
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/indirector/configuration/compiler.rb16
-rwxr-xr-xspec/unit/indirector/indirection.rb35
-rwxr-xr-xspec/unit/node.rb66
-rwxr-xr-xspec/unit/node/searching.rb79
4 files changed, 109 insertions, 87 deletions
diff --git a/spec/unit/indirector/configuration/compiler.rb b/spec/unit/indirector/configuration/compiler.rb
index c024fe995..d949a28a5 100755
--- a/spec/unit/indirector/configuration/compiler.rb
+++ b/spec/unit/indirector/configuration/compiler.rb
@@ -23,8 +23,8 @@ describe Puppet::Node::Configuration::Compiler do
node1 = stub 'node1', :merge => nil
node2 = stub 'node2', :merge => nil
compiler.stubs(:compile)
- Puppet::Node.stubs(:search).with('node1').returns(node1)
- Puppet::Node.stubs(:search).with('node2').returns(node2)
+ Puppet::Node.stubs(:find_by_any_name).with('node1').returns(node1)
+ Puppet::Node.stubs(:find_by_any_name).with('node2').returns(node2)
compiler.find('node1')
compiler.find('node2')
@@ -68,13 +68,13 @@ describe Puppet::Node::Configuration::Compiler, " when finding nodes" do
it "should look node information up via the Node class with the provided key" do
@node.stubs :merge
- Puppet::Node.expects(:search).with(@name).returns(@node)
+ Puppet::Node.expects(:find_by_any_name).with(@name).returns(@node)
@compiler.find(@name)
end
it "should fail if it cannot find the node" do
@node.stubs :merge
- Puppet::Node.expects(:search).with(@name).returns(nil)
+ Puppet::Node.expects(:find_by_any_name).with(@name).returns(nil)
proc { @compiler.find(@name) }.should raise_error(Puppet::Error)
end
end
@@ -89,7 +89,7 @@ describe Puppet::Node::Configuration::Compiler, " after finding nodes" do
@name = "me"
@node = mock 'node'
@compiler.stubs(:compile)
- Puppet::Node.stubs(:search).with(@name).returns(@node)
+ Puppet::Node.stubs(:find_by_any_name).with(@name).returns(@node)
end
it "should add the server's Puppet version to the node's parameters as 'serverversion'" do
@@ -125,11 +125,11 @@ describe Puppet::Node::Configuration::Compiler, " when creating configurations"
@name = "me"
@node = Puppet::Node.new @name
@node.stubs(:merge)
- Puppet::Node.stubs(:search).with(@name).returns(@node)
+ Puppet::Node.stubs(:find_by_any_name).with(@name).returns(@node)
end
it "should directly use provided nodes" do
- Puppet::Node.expects(:search).never
+ Puppet::Node.expects(:find_by_any_name).never
@compiler.interpreter.expects(:compile).with(@node)
@compiler.find(@node)
end
@@ -195,7 +195,7 @@ describe Puppet::Node::Configuration::Compiler, " when determining a client's av
end
it "should return a version of 0 if no information on the node can be found" do
- Puppet::Node.stubs(:search).returns(nil)
+ Puppet::Node.stubs(:find_by_any_name).returns(nil)
@configuration.version(@name).should == 0
end
diff --git a/spec/unit/indirector/indirection.rb b/spec/unit/indirector/indirection.rb
index 5d8453905..36192b8e5 100755
--- a/spec/unit/indirector/indirection.rb
+++ b/spec/unit/indirector/indirection.rb
@@ -9,6 +9,7 @@ module IndirectionTesting
@indirection = Puppet::Indirector::Indirection.new(mock('model'), :test)
@terminus = stub 'terminus', :has_most_recent? => false
@indirection.stubs(:terminus).returns(@terminus)
+ @indirection.stubs(:terminus_class).returns(:whatever)
@instance = stub 'instance', :version => nil, :version= => nil, :name => "whatever"
@name = :mything
end
@@ -176,6 +177,40 @@ describe Puppet::Indirector::Indirection, " when managing indirection instances"
end
end
+describe Puppet::Indirector::Indirection, " when choosing the terminus class" do
+ before do
+ @indirection = Puppet::Indirector::Indirection.new(mock('model'), :test)
+ @terminus = mock 'terminus'
+ @terminus_class = stub 'terminus class', :new => @terminus
+ Puppet::Indirector::Terminus.stubs(:terminus_class).with(:test, :default).returns(@terminus_class)
+ end
+
+ it "should choose the default terminus class if one is specified and no specific terminus class is provided" do
+ @indirection.terminus_class = :default
+ @indirection.terminus_class.should equal(:default)
+ end
+
+ it "should use the provided Puppet setting if told to do so" do
+ Puppet::Indirector::Terminus.stubs(:terminus_class).with(:test, :my_terminus).returns(mock("terminus_class2"))
+ Puppet.settings.expects(:value).with(:my_setting).returns("my_terminus")
+ @indirection.terminus_setting = :my_setting
+ @indirection.terminus_class.should equal(:my_terminus)
+ end
+
+ it "should fail if the provided terminus class is not valid" do
+ Puppet::Indirector::Terminus.stubs(:terminus_class).with(:test, :nosuchclass).returns(nil)
+ proc { @indirection.terminus_class = :nosuchclass }.should raise_error(ArgumentError)
+ end
+
+ it "should fail if no terminus class is picked" do
+ proc { @indirection.terminus_class }.should raise_error(Puppet::DevError)
+ end
+
+ after do
+ @indirection.delete if defined? @indirection
+ end
+end
+
describe Puppet::Indirector::Indirection, " when specifying the terminus class to use" do
before do
@indirection = Puppet::Indirector::Indirection.new(mock('model'), :test)
diff --git a/spec/unit/node.rb b/spec/unit/node.rb
index 26aec4196..8aea6ef0b 100755
--- a/spec/unit/node.rb
+++ b/spec/unit/node.rb
@@ -138,3 +138,69 @@ describe Puppet::Node do
# central server.
it "should provide a method for noting that the node has connected"
end
+
+describe Puppet::Node, " when searching for nodes" do
+ before do
+ @searcher = Puppet::Node
+ @facts = Puppet::Node::Facts.new("foo", "hostname" => "yay", "domain" => "domain.com")
+ @node = Puppet::Node.new("foo")
+ Puppet::Node::Facts.stubs(:find).with("foo").returns(@facts)
+ end
+
+ it "should return the first node found using the generated list of names" do
+ @searcher.expects(:find).with("foo").returns(nil)
+ @searcher.expects(:find).with("yay.domain.com").returns(@node)
+ @searcher.find_by_any_name("foo").should equal(@node)
+ end
+
+ it "should search for the node by its key first" do
+ names = []
+ @searcher.expects(:find).with do |name|
+ names << name
+ names == %w{foo}
+ end.returns(@node)
+ @searcher.find_by_any_name("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(:find).with do |name|
+ names << name
+ end
+ @searcher.find_by_any_name("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(:find).with do |name|
+ names << name
+ end.returns(nil)
+ @searcher.find_by_any_name("foo")
+ names[-1].should == "default"
+ 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(:find).returns(@node, node2).then.raises(ArgumentError)
+ @searcher.find_by_any_name("foo").should equal(@node)
+ @searcher.find_by_any_name("foo").should equal(node2)
+ end
+
+ after do
+ Puppet.settings.clear
+ end
+end
diff --git a/spec/unit/node/searching.rb b/spec/unit/node/searching.rb
deleted file mode 100755
index e747996e4..000000000
--- a/spec/unit/node/searching.rb
+++ /dev/null
@@ -1,79 +0,0 @@
-#!/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(:find).with("foo").returns(@facts)
- end
-
- it "should search for the node by its key first" do
- names = []
- @searcher.expects(:find).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(:find).with("foo").returns(nil)
- @searcher.expects(:find).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(:find).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(:find).with do |name|
- names << name
- end.returns(nil)
- @searcher.search("foo")
- names[-1].should == "default"
- end
-
- it "should cache the nodes" do
- @searcher.expects(:find).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(:find).returns(@node, node2).then.raises(ArgumentError)
- @searcher.search("foo").should equal(@node)
- @searcher.search("foo").should equal(node2)
- end
-
- after do
- Puppet.settings.clear
- end
-end