summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-04-08 21:21:59 -0500
committerLuke Kanies <luke@madstop.com>2008-04-08 21:21:59 -0500
commit7774d9c443f19d44a1e2dab459fc4bfb94e75244 (patch)
tree78287fb85c8a1a5b70617a9e153dcca311dea15d /spec
parentbf728d23caca4f58ae4ede1a2d477c9fc15e0bdc (diff)
downloadpuppet-7774d9c443f19d44a1e2dab459fc4bfb94e75244.tar.gz
puppet-7774d9c443f19d44a1e2dab459fc4bfb94e75244.tar.xz
puppet-7774d9c443f19d44a1e2dab459fc4bfb94e75244.zip
Ported the rest of the indirection terminuses over to
expecting requests instead of having a random interface.
Diffstat (limited to 'spec')
-rwxr-xr-xspec/integration/node.rb104
-rwxr-xr-xspec/integration/node/catalog.rb10
-rwxr-xr-xspec/integration/node/facts.rb34
-rwxr-xr-xspec/integration/transaction/report.rb26
-rwxr-xr-xspec/unit/indirector/catalog/compiler.rb37
-rwxr-xr-xspec/unit/indirector/exec.rb18
-rwxr-xr-xspec/unit/indirector/facts/facter.rb8
-rwxr-xr-xspec/unit/indirector/ldap.rb18
-rwxr-xr-xspec/unit/indirector/node/exec.rb20
-rwxr-xr-xspec/unit/indirector/node/ldap.rb43
-rwxr-xr-xspec/unit/indirector/node/plain.rb9
-rwxr-xr-xspec/unit/indirector/report/processor.rb16
-rwxr-xr-xspec/unit/indirector/terminus.rb54
13 files changed, 225 insertions, 172 deletions
diff --git a/spec/integration/node.rb b/spec/integration/node.rb
index d9c2618c9..b0375e743 100755
--- a/spec/integration/node.rb
+++ b/spec/integration/node.rb
@@ -7,38 +7,86 @@ require File.dirname(__FILE__) + '/../spec_helper'
require 'puppet/node'
-describe Puppet::Node, " when using the memory terminus" do
- before do
- @name = "me"
- @old_terminus = Puppet::Node.indirection.terminus_class
- @terminus = Puppet::Node.indirection.terminus(:memory)
- Puppet::Node.indirection.stubs(:terminus).returns @terminus
- @node = Puppet::Node.new(@name)
- end
+describe Puppet::Node do
+ describe "when delegating indirection calls" do
+ before do
+ @name = "me"
+ @node = Puppet::Node.new(@name)
+ end
- it "should find no nodes by default" do
- Puppet::Node.find(@name).should be_nil
- end
+ it "should be able to use the exec terminus" do
+ Puppet::Node.indirection.stubs(:terminus_class).returns :exec
- it "should be able to find nodes that were previously saved" do
- @node.save
- Puppet::Node.find(@name).should equal(@node)
- end
+ # Load now so we can stub
+ terminus = Puppet::Node.indirection.terminus(:exec)
- it "should replace existing saved nodes when a new node with the same name is saved" do
- @node.save
- two = Puppet::Node.new(@name)
- two.save
- Puppet::Node.find(@name).should equal(two)
- end
+ terminus.expects(:query).with(@name).returns "myresults"
+ terminus.expects(:translate).with(@name, "myresults").returns "translated_results"
+ terminus.expects(:create_node).with(@name, "translated_results").returns @node
- it "should be able to remove previously saved nodes" do
- @node.save
- Puppet::Node.destroy(@node.name)
- Puppet::Node.find(@name).should be_nil
- end
+ Puppet::Node.find(@name).should equal(@node)
+ end
+
+ it "should be able to use the yaml terminus" do
+ Puppet::Node.indirection.stubs(:terminus_class).returns :yaml
+
+ # Load now, before we stub the exists? method.
+ Puppet::Node.indirection.terminus(:yaml)
+
+ file = File.join(Puppet[:yamldir], "node", "me.yaml")
+ FileTest.expects(:exist?).with(file).returns false
+ Puppet::Node.find(@name).should be_nil
+ end
+
+ it "should have an ldap terminus" do
+ Puppet::Node.indirection.terminus(:ldap).should_not be_nil
+ end
+
+ it "should be able to use the plain terminus" do
+ Puppet::Node.indirection.stubs(:terminus_class).returns :plain
+
+ # Load now, before we stub the exists? method.
+ Puppet::Node.indirection.terminus(:plain)
+
+ Puppet::Node.expects(:new).with(@name).returns @node
+
+ Puppet::Node.find(@name).should equal(@node)
+ end
+
+ describe "and using the memory terminus" do
+ before do
+ @name = "me"
+ @old_terminus = Puppet::Node.indirection.terminus_class
+ @terminus = Puppet::Node.indirection.terminus(:memory)
+ Puppet::Node.indirection.stubs(:terminus).returns @terminus
+ @node = Puppet::Node.new(@name)
+ end
+
+ it "should find no nodes by default" do
+ Puppet::Node.find(@name).should be_nil
+ end
+
+ it "should be able to find nodes that were previously saved" do
+ @node.save
+ Puppet::Node.find(@name).should equal(@node)
+ end
+
+ it "should replace existing saved nodes when a new node with the same name is saved" do
+ @node.save
+ two = Puppet::Node.new(@name)
+ two.save
+ Puppet::Node.find(@name).should equal(two)
+ end
+
+ it "should be able to remove previously saved nodes" do
+ @node.save
+ Puppet::Node.destroy(@node.name)
+ Puppet::Node.find(@name).should be_nil
+ end
- it "should fail when asked to destroy a node that does not exist" do
- proc { Puppet::Node.destroy(@node) }.should raise_error(ArgumentError)
+ it "should fail when asked to destroy a node that does not exist" do
+ proc { Puppet::Node.destroy(@node) }.should raise_error(ArgumentError)
+ end
+ end
end
end
diff --git a/spec/integration/node/catalog.rb b/spec/integration/node/catalog.rb
index d0ddfd8aa..ca14c2ea8 100755
--- a/spec/integration/node/catalog.rb
+++ b/spec/integration/node/catalog.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
#
-# Created by Luke Kanies on 2007-10-18.
-# Copyright (c) 2007. All rights reserved.
+# Created by Luke Kanies on 2007-4-8.
+# Copyright (c) 2008. All rights reserved.
require File.dirname(__FILE__) + '/../../spec_helper'
@@ -26,7 +26,11 @@ describe Puppet::Node::Catalog do
# Load now, before we stub the exists? method.
compiler = Puppet::Node::Catalog.indirection.terminus(:compiler)
- compiler.expects(:compile).with("me").returns nil
+ node = mock 'node'
+ node.stub_everything
+
+ Puppet::Node.expects(:find).returns(node)
+ compiler.expects(:compile).with(node).returns nil
Puppet::Node::Catalog.find("me").should be_nil
end
diff --git a/spec/integration/node/facts.rb b/spec/integration/node/facts.rb
new file mode 100755
index 000000000..977a1b6c9
--- /dev/null
+++ b/spec/integration/node/facts.rb
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2008-4-8.
+# Copyright (c) 2008. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe Puppet::Node::Facts do
+ describe "when using the indirector" do
+ after { Puppet::Node::Facts.indirection.clear_cache }
+
+ it "should be able to delegate to the :yaml terminus" do
+ Puppet::Node::Facts.indirection.stubs(:terminus_class).returns :yaml
+
+ # Load now, before we stub the exists? method.
+ Puppet::Node::Facts.indirection.terminus(:yaml)
+
+ file = File.join(Puppet[:yamldir], "facts", "me.yaml")
+ FileTest.expects(:exist?).with(file).returns false
+
+ Puppet::Node::Facts.find("me").should be_nil
+ end
+
+ it "should be able to delegate to the :facter terminus" do
+ Puppet::Node::Facts.indirection.stubs(:terminus_class).returns :facter
+
+ Facter.expects(:to_hash).returns "facter_hash"
+ facts = Puppet::Node::Facts.new("me")
+ Puppet::Node::Facts.expects(:new).with("me", "facter_hash").returns facts
+
+ Puppet::Node::Facts.find("me").should equal(facts)
+ end
+ end
+end
diff --git a/spec/integration/transaction/report.rb b/spec/integration/transaction/report.rb
new file mode 100755
index 000000000..48e59f203
--- /dev/null
+++ b/spec/integration/transaction/report.rb
@@ -0,0 +1,26 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2008-4-8.
+# Copyright (c) 2008. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe Puppet::Transaction::Report do
+ describe "when using the indirector" do
+ after { Puppet::Transaction::Report.indirection.clear_cache }
+
+ it "should be able to delegate to the :processor terminus" do
+ Puppet::Transaction::Report.indirection.stubs(:terminus_class).returns :processor
+
+ terminus = Puppet::Transaction::Report.indirection.terminus(:processor)
+
+ Facter.stubs(:value).returns "host.domain.com"
+
+ report = Puppet::Transaction::Report.new
+
+ terminus.expects(:process).with(report)
+
+ report.save
+ end
+ end
+end
diff --git a/spec/unit/indirector/catalog/compiler.rb b/spec/unit/indirector/catalog/compiler.rb
index 5a26302d1..57bbcdbd0 100755
--- a/spec/unit/indirector/catalog/compiler.rb
+++ b/spec/unit/indirector/catalog/compiler.rb
@@ -26,8 +26,8 @@ describe Puppet::Node::Catalog::Compiler do
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')
+ compiler.find(stub('request', :key => 'node1', :options => {}))
+ compiler.find(stub('node2request', :key => 'node2', :options => {}))
end
it "should provide a method for determining if the catalog is networked" do
@@ -63,21 +63,14 @@ describe Puppet::Node::Catalog::Compiler, " when finding nodes" do
@compiler = Puppet::Node::Catalog::Compiler.new
@name = "me"
@node = mock 'node'
+ @request = stub 'request', :key => @name, :options => {}
@compiler.stubs(:compile)
end
it "should look node information up via the Node class with the provided key" do
@node.stubs :merge
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(:find_by_any_name).with(@name).returns(nil)
- request = stub 'request', :key => @name
- @compiler.find(request)
- proc { @compiler.find(request) }.should raise_error(Puppet::Error)
+ @compiler.find(@request)
end
end
@@ -90,23 +83,24 @@ describe Puppet::Node::Catalog::Compiler, " after finding nodes" do
@compiler = Puppet::Node::Catalog::Compiler.new
@name = "me"
@node = mock 'node'
+ @request = stub 'request', :key => @name, :options => {}
@compiler.stubs(:compile)
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
@node.expects(:merge).with { |args| args["serverversion"] == "1" }
- @compiler.find(@name)
+ @compiler.find(@request)
end
it "should add the server's fqdn to the node's parameters as 'servername'" do
@node.expects(:merge).with { |args| args["servername"] == "my.server.com" }
- @compiler.find(@name)
+ @compiler.find(@request)
end
it "should add the server's IP address to the node's parameters as 'serverip'" do
@node.expects(:merge).with { |args| args["serverip"] == "my.ip.address" }
- @compiler.find(@name)
+ @compiler.find(@request)
end
# LAK:TODO This is going to be difficult, because this whole process is so
@@ -127,19 +121,26 @@ describe Puppet::Node::Catalog::Compiler, " when creating catalogs" do
@name = "me"
@node = Puppet::Node.new @name
@node.stubs(:merge)
+ @request = stub 'request', :key => @name, :options => {}
Puppet::Node.stubs(:find_by_any_name).with(@name).returns(@node)
end
it "should directly use provided nodes" do
Puppet::Node.expects(:find_by_any_name).never
@compiler.interpreter.expects(:compile).with(@node)
- @compiler.find(@node)
+ @request.stubs(:options).returns(:node => @node)
+ @compiler.find(@request)
+ end
+
+ it "should fail if no node is passed and none can be found" do
+ Puppet::Node.stubs(:find_by_any_name).with(@name).returns(nil)
+ proc { @compiler.find(@request) }.should raise_error(ArgumentError)
end
it "should pass the found node to the interpreter for compiling" do
config = mock 'config'
@compiler.interpreter.expects(:compile).with(@node)
- @compiler.find(@name)
+ @compiler.find(@request)
end
it "should return the results of compiling as the catalog" do
@@ -147,7 +148,7 @@ describe Puppet::Node::Catalog::Compiler, " when creating catalogs" do
result = mock 'result', :to_transportable => :catalog
@compiler.interpreter.expects(:compile).with(@node).returns(result)
- @compiler.find(@name).should == :catalog
+ @compiler.find(@request).should == :catalog
end
it "should benchmark the compile process" do
@@ -156,7 +157,7 @@ describe Puppet::Node::Catalog::Compiler, " when creating catalogs" do
level == :notice and message =~ /^Compiled catalog/
end
@compiler.interpreter.stubs(:compile).with(@node)
- @compiler.find(@name)
+ @compiler.find(@request)
end
end
diff --git a/spec/unit/indirector/exec.rb b/spec/unit/indirector/exec.rb
index 3baf06629..e474de8b9 100755
--- a/spec/unit/indirector/exec.rb
+++ b/spec/unit/indirector/exec.rb
@@ -18,31 +18,33 @@ describe Puppet::Indirector::Exec do
@searcher = @exec_class.new
@searcher.command = ["/echo"]
+
+ @request = stub 'request', :key => "foo"
end
it "should throw an exception if the command is not an array" do
@searcher.command = "/usr/bin/echo"
- proc { @searcher.find("foo") }.should raise_error(Puppet::DevError)
+ proc { @searcher.find(@request) }.should raise_error(Puppet::DevError)
end
it "should throw an exception if the command is not fully qualified" do
@searcher.command = ["mycommand"]
- proc { @searcher.find("foo") }.should raise_error(ArgumentError)
+ proc { @searcher.find(@request) }.should raise_error(ArgumentError)
end
it "should execute the command with the object name as the only argument" do
- @searcher.expects(:execute).with(%w{/echo yay})
- @searcher.find("yay")
+ @searcher.expects(:execute).with(%w{/echo foo})
+ @searcher.find(@request)
end
it "should return the output of the script" do
- @searcher.expects(:execute).with(%w{/echo yay}).returns("whatever")
- @searcher.find("yay").should == "whatever"
+ @searcher.expects(:execute).with(%w{/echo foo}).returns("whatever")
+ @searcher.find(@request).should == "whatever"
end
it "should return nil when the command produces no output" do
- @searcher.expects(:execute).with(%w{/echo yay}).returns(nil)
- @searcher.find("yay").should be_nil
+ @searcher.expects(:execute).with(%w{/echo foo}).returns(nil)
+ @searcher.find(@request).should be_nil
end
it "should be able to execute commands with multiple arguments"
diff --git a/spec/unit/indirector/facts/facter.rb b/spec/unit/indirector/facts/facter.rb
index 5ec66555d..225eb153b 100755
--- a/spec/unit/indirector/facts/facter.rb
+++ b/spec/unit/indirector/facts/facter.rb
@@ -36,22 +36,22 @@ describe Puppet::Node::Facts::Facter do
@facter = Puppet::Node::Facts::Facter.new
Facter.stubs(:to_hash).returns({})
@name = "me"
- @facts = @facter.find(@name)
+ @request = stub 'request', :key => @name
end
describe Puppet::Node::Facts::Facter, " when finding facts" do
it "should return a Facts instance" do
- @facts.should be_instance_of(Puppet::Node::Facts)
+ @facter.find(@request).should be_instance_of(Puppet::Node::Facts)
end
it "should return a Facts instance with the provided key as the name" do
- @facts.name.should == @name
+ @facter.find(@request).name.should == @name
end
it "should return the Facter facts as the values in the Facts instance" do
Facter.expects(:to_hash).returns("one" => "two")
- facts = @facter.find(@name)
+ facts = @facter.find(@request)
facts.values["one"].should == "two"
end
end
diff --git a/spec/unit/indirector/ldap.rb b/spec/unit/indirector/ldap.rb
index 6712ccb4f..2599bcecf 100755
--- a/spec/unit/indirector/ldap.rb
+++ b/spec/unit/indirector/ldap.rb
@@ -24,11 +24,13 @@ describe Puppet::Indirector::Ldap, " when searching ldap" do
@searcher.stubs(:search_filter).returns(:filter)
@searcher.stubs(:search_base).returns(:base)
@searcher.stubs(:process)
+
+ @request = stub 'request', :key => "yay"
end
it "should call the ldapsearch method with the name being searched for" do
@searcher.expects(:ldapsearch).with("yay")
- @searcher.find "yay"
+ @searcher.find @request
end
it "should fail if no block is passed to the ldapsearch method" do
@@ -41,7 +43,7 @@ describe Puppet::Indirector::Ldap, " when searching ldap" do
args[0].should == "mybase"
true
end
- @searcher.find "yay"
+ @searcher.find @request
end
it "should default to the value of the :search_base setting as the result of the ldapbase method" do
@@ -56,7 +58,7 @@ describe Puppet::Indirector::Ldap, " when searching ldap" do
args[3].should == :myattrs
true
end
- @searcher.find "yay"
+ @searcher.find @request
end
it "should use the results of the :search_filter method as the search filter" do
@@ -65,7 +67,7 @@ describe Puppet::Indirector::Ldap, " when searching ldap" do
args[2].should == "yay's filter"
true
end
- @searcher.find "yay"
+ @searcher.find @request
end
it "should use depth 2 when searching" do
@@ -73,13 +75,13 @@ describe Puppet::Indirector::Ldap, " when searching ldap" do
args[1].should == 2
true
end
- @searcher.find "yay"
+ @searcher.find @request
end
it "should call process() on the first found entry" do
@connection.expects(:search).yields("myresult")
@searcher.expects(:process).with("yay", "myresult")
- @searcher.find "yay"
+ @searcher.find @request
end
it "should reconnect and retry the search if there is a failure" do
@@ -94,7 +96,7 @@ describe Puppet::Indirector::Ldap, " when searching ldap" do
end.yields("myresult")
@searcher.expects(:process).with("yay", "myresult")
- @searcher.find "yay"
+ @searcher.find @request
end
it "should not reconnect on failure more than once" do
@@ -103,7 +105,7 @@ describe Puppet::Indirector::Ldap, " when searching ldap" do
count += 1
raise ArgumentError, "yay"
end
- proc { @searcher.find("whatever") }.should raise_error(Puppet::Error)
+ proc { @searcher.find(@request) }.should raise_error(Puppet::Error)
count.should == 2
end
diff --git a/spec/unit/indirector/node/exec.rb b/spec/unit/indirector/node/exec.rb
index b67e0fe97..09f13ab90 100755
--- a/spec/unit/indirector/node/exec.rb
+++ b/spec/unit/indirector/node/exec.rb
@@ -11,12 +11,6 @@ describe Puppet::Node::Exec do
@searcher = Puppet::Node::Exec.new
end
- it "should use the version of the facts as its version" do
- version = mock 'version'
- Puppet::Node::Facts.expects(:version).with("me").returns version
- @searcher.version("me").should equal(version)
- end
-
describe "when constructing the command to run" do
it "should use the external_node script as the command" do
Puppet.expects(:[]).with(:external_nodes).returns("/bin/echo")
@@ -25,7 +19,7 @@ describe Puppet::Node::Exec do
it "should throw an exception if no external node command is set" do
Puppet.expects(:[]).with(:external_nodes).returns("none")
- proc { @searcher.find("foo") }.should raise_error(ArgumentError)
+ proc { @searcher.find(stub('request', :key => "foo")) }.should raise_error(ArgumentError)
end
end
@@ -40,34 +34,36 @@ describe Puppet::Node::Exec do
@searcher.meta_def(:execute) do |command|
return YAML.dump(result)
end
+
+ @request = stub 'request', :key => @name
end
it "should translate the YAML into a Node instance" do
# Use an empty hash
- @searcher.find(@name).should equal(@node)
+ @searcher.find(@request).should equal(@node)
end
it "should set the resulting parameters as the node parameters" do
@result[:parameters] = {"a" => "b", "c" => "d"}
@node.expects(:parameters=).with "a" => "b", "c" => "d"
- @searcher.find(@name)
+ @searcher.find(@request)
end
it "should set the resulting classes as the node classes" do
@result[:classes] = %w{one two}
@node.expects(:classes=).with %w{one two}
- @searcher.find(@name)
+ @searcher.find(@request)
end
it "should merge the node's facts with its parameters" do
@node.expects(:fact_merge)
- @searcher.find(@name)
+ @searcher.find(@request)
end
it "should set the node's environment if one is provided" do
@result[:environment] = "yay"
@node.expects(:environment=).with "yay"
- @searcher.find(@name)
+ @searcher.find(@request)
end
end
end
diff --git a/spec/unit/indirector/node/ldap.rb b/spec/unit/indirector/node/ldap.rb
index 34456703d..a40698662 100755
--- a/spec/unit/indirector/node/ldap.rb
+++ b/spec/unit/indirector/node/ldap.rb
@@ -5,13 +5,6 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/indirector/node/ldap'
describe Puppet::Node::Ldap do
- it "should use the version of the facts as its version" do
- @searcher = Puppet::Node::Ldap.new
- version = mock 'version'
- Puppet::Node::Facts.expects(:version).with("me").returns version
- @searcher.version("me").should equal(version)
- end
-
describe "when searching for nodes" do
before :each do
@searcher = Puppet::Node::Ldap.new
@@ -31,16 +24,18 @@ describe Puppet::Node::Ldap do
@node.stubs(:fact_merge)
@name = "mynode"
Puppet::Node.stubs(:new).with(@name).returns(@node)
+
+ @request = stub 'request', :key => @name
end
it "should return nil if no results are found in ldap" do
@connection.stubs(:search)
- @searcher.find("mynode").should be_nil
+ @searcher.find(@request).should be_nil
end
it "should return a node object if results are found in ldap" do
@entry.stubs(:to_hash).returns({})
- @searcher.find("mynode").should equal(@node)
+ @searcher.find(@request).should equal(@node)
end
it "should deduplicate class values" do
@@ -49,7 +44,7 @@ describe Puppet::Node::Ldap do
@entry.stubs(:vals).with("one").returns(%w{a b})
@entry.stubs(:vals).with("two").returns(%w{b c})
@node.expects(:classes=).with(%w{a b c})
- @searcher.find("mynode")
+ @searcher.find(@request)
end
it "should add any values stored in the class_attributes attributes to the node classes" do
@@ -58,38 +53,38 @@ describe Puppet::Node::Ldap do
@entry.stubs(:vals).with("one").returns(%w{a b})
@entry.stubs(:vals).with("two").returns(%w{c d})
@node.expects(:classes=).with(%w{a b c d})
- @searcher.find("mynode")
+ @searcher.find(@request)
end
it "should add all entry attributes as node parameters" do
@entry.stubs(:to_hash).returns("one" => ["two"], "three" => ["four"])
@node.expects(:parameters=).with("one" => "two", "three" => "four")
- @searcher.find("mynode")
+ @searcher.find(@request)
end
it "should set the node's environment to the environment of the results" do
@entry.stubs(:to_hash).returns("environment" => ["test"])
@node.stubs(:parameters=)
@node.expects(:environment=).with("test")
- @searcher.find("mynode")
+ @searcher.find(@request)
end
it "should retain false parameter values" do
@entry.stubs(:to_hash).returns("one" => [false])
@node.expects(:parameters=).with("one" => false)
- @searcher.find("mynode")
+ @searcher.find(@request)
end
it "should turn single-value parameter value arrays into single non-arrays" do
@entry.stubs(:to_hash).returns("one" => ["a"])
@node.expects(:parameters=).with("one" => "a")
- @searcher.find("mynode")
+ @searcher.find(@request)
end
it "should keep multi-valued parametes as arrays" do
@entry.stubs(:to_hash).returns("one" => ["a", "b"])
@node.expects(:parameters=).with("one" => ["a", "b"])
- @searcher.find("mynode")
+ @searcher.find(@request)
end
describe "and a parent node is specified" do
@@ -113,7 +108,7 @@ describe Puppet::Node::Ldap do
@entry.stubs(:to_hash).returns({})
@entry.stubs(:vals).with(:parent).returns(%w{parent})
- proc { @searcher.find("mynode") }.should raise_error(Puppet::Error)
+ proc { @searcher.find(@request) }.should raise_error(Puppet::Error)
end
it "should add any parent classes to the node's classes" do
@@ -127,7 +122,7 @@ describe Puppet::Node::Ldap do
@searcher.stubs(:class_attributes).returns(%w{classes})
@node.expects(:classes=).with(%w{a b c d})
- @searcher.find("mynode")
+ @searcher.find(@request)
end
it "should add any parent parameters to the node's parameters" do
@@ -138,7 +133,7 @@ describe Puppet::Node::Ldap do
@parent.stubs(:vals).with(:parent).returns(nil)
@node.expects(:parameters=).with("one" => "two", "three" => "four")
- @searcher.find("mynode")
+ @searcher.find(@request)
end
it "should prefer node parameters over parent parameters" do
@@ -149,7 +144,7 @@ describe Puppet::Node::Ldap do
@parent.stubs(:vals).with(:parent).returns(nil)
@node.expects(:parameters=).with("one" => "two")
- @searcher.find("mynode")
+ @searcher.find(@request)
end
it "should use the parent's environment if the node has none" do
@@ -161,7 +156,7 @@ describe Puppet::Node::Ldap do
@node.stubs(:parameters=)
@node.expects(:environment=).with("parent")
- @searcher.find("mynode")
+ @searcher.find(@request)
end
it "should prefer the node's environment to the parent's" do
@@ -173,7 +168,7 @@ describe Puppet::Node::Ldap do
@node.stubs(:parameters=)
@node.expects(:environment=).with("child")
- @searcher.find("mynode")
+ @searcher.find(@request)
end
it "should recursively look up parent information" do
@@ -188,7 +183,7 @@ describe Puppet::Node::Ldap do
@parent_parent.stubs(:vals).with(:parent).returns(nil)
@node.expects(:parameters=).with("one" => "two", "three" => "four", "five" => "six")
- @searcher.find("mynode")
+ @searcher.find(@request)
end
it "should not allow loops in parent declarations" do
@@ -197,7 +192,7 @@ describe Puppet::Node::Ldap do
@parent.stubs(:to_hash).returns("three" => "four")
@parent.stubs(:vals).with(:parent).returns([@name])
- proc { @searcher.find("mynode") }.should raise_error(ArgumentError)
+ proc { @searcher.find(@request) }.should raise_error(ArgumentError)
end
end
end
diff --git a/spec/unit/indirector/node/plain.rb b/spec/unit/indirector/node/plain.rb
index 943af52b4..a595998a1 100755
--- a/spec/unit/indirector/node/plain.rb
+++ b/spec/unit/indirector/node/plain.rb
@@ -13,12 +13,7 @@ describe Puppet::Node::Plain do
node = mock 'node'
Puppet::Node.expects(:new).with("mynode").returns(node)
node.expects(:fact_merge)
- @searcher.find("mynode")
- end
-
- it "should use the version of the facts as its version" do
- version = mock 'version'
- Puppet::Node::Facts.expects(:version).with("me").returns version
- @searcher.version("me").should equal(version)
+ request = stub 'request', :key => "mynode"
+ @searcher.find(request)
end
end
diff --git a/spec/unit/indirector/report/processor.rb b/spec/unit/indirector/report/processor.rb
index 587f512ee..bcb400bda 100755
--- a/spec/unit/indirector/report/processor.rb
+++ b/spec/unit/indirector/report/processor.rb
@@ -13,7 +13,6 @@ describe Puppet::Transaction::Report::Processor do
end
end
-
describe Puppet::Transaction::Report::Processor, " when saving a report" do
before do
Puppet.settings.stubs(:use)
@@ -24,7 +23,9 @@ describe Puppet::Transaction::Report::Processor, " when saving a report" do
Puppet::Reports.expects(:report).never
Puppet.settings.expects(:value).with(:reports).returns("none")
- @reporter.save(:whatever)
+ request = stub 'request', :instance => mock("report")
+
+ @reporter.save(request)
end
it "should process the report with each configured report type" do
@@ -44,6 +45,9 @@ describe Puppet::Transaction::Report::Processor, " when processing a report" do
@dup_report.stubs(:process)
@report = mock 'report'
@report.expects(:dup).returns(@dup_report)
+
+ @request = stub 'request', :instance => @report
+
Puppet::Reports.expects(:report).with("one").returns(@report_type)
@dup_report.expects(:extend).with(@report_type)
@@ -53,21 +57,21 @@ describe Puppet::Transaction::Report::Processor, " when processing a report" do
# make sense to split it out, which means I just do the same test
# three times so the spec looks right.
it "should process a duplicate of the report, not the original" do
- @reporter.save(@report)
+ @reporter.save(@request)
end
it "should extend the report with the report type's module" do
- @reporter.save(@report)
+ @reporter.save(@request)
end
it "should call the report type's :process method" do
@dup_report.expects(:process)
- @reporter.save(@report)
+ @reporter.save(@request)
end
it "should not raise exceptions" do
Puppet.settings.stubs(:value).with(:trace).returns(false)
@dup_report.expects(:process).raises(ArgumentError)
- proc { @reporter.save(@report) }.should_not raise_error
+ proc { @reporter.save(@request) }.should_not raise_error
end
end
diff --git a/spec/unit/indirector/terminus.rb b/spec/unit/indirector/terminus.rb
index 86813e4e5..3fcbf9d0c 100755
--- a/spec/unit/indirector/terminus.rb
+++ b/spec/unit/indirector/terminus.rb
@@ -106,60 +106,6 @@ describe Puppet::Indirector::Terminus do
@terminus.model.should == :yay
end
end
-
- describe Puppet::Indirector::Terminus, " when managing indirected instances" do
-
- it "should support comparing an instance's version with the terminus's version using just the instance's key" do
- @terminus.should respond_to(:has_most_recent?)
- end
-
- it "should fail if the :version method has not been overridden and no :find method is available" do
- proc { @terminus.version('yay') }.should raise_error(Puppet::DevError)
- end
-
- it "should use a found instance's version by default" do
- name = 'instance'
- instance = stub name, :version => 2
- @terminus.expects(:find).with(name).returns(instance)
- @terminus.version(name).should == 2
- end
-
- it "should return nil as the version if no instance can be found" do
- name = 'instance'
- @terminus.expects(:find).with(name).returns(nil)
- @terminus.version(name).should be_nil
- end
-
- it "should consider an instance fresh if its version is more recent than the version provided" do
- name = "yay"
- @terminus.expects(:version).with(name).returns(5)
- @terminus.has_most_recent?(name, 4).should be_true
- end
-
- it "should consider an instance fresh if its version is equal to the version provided" do
- name = "yay"
- @terminus.expects(:version).with(name).returns(5)
- @terminus.has_most_recent?(name, 5).should be_true
- end
-
- it "should consider an instance not fresh if the provided version is more recent than its version" do
- name = "yay"
- @terminus.expects(:version).with(name).returns(4)
- @terminus.has_most_recent?(name, 5).should be_false
- end
-
- # Times annoyingly can't be compared directly to numbers, and our
- # default version is 0.
- it "should convert versions to floats when checking for freshness" do
- existing = mock 'existing version'
- new = mock 'new version'
- existing.expects(:to_f).returns(1.0)
- new.expects(:to_f).returns(1.0)
- name = "yay"
- @terminus.expects(:version).with(name).returns(existing)
- @terminus.has_most_recent?(name, new)
- end
- end
end
# LAK: This could reasonably be in the Indirection instances, too. It doesn't make