summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/indirector/code/configuration.rb16
-rwxr-xr-xspec/unit/indirector/indirector.rb7
-rwxr-xr-xspec/unit/node/configuration.rb24
-rwxr-xr-xspec/unit/node/facts.rb15
-rwxr-xr-xspec/unit/parser/compile.rb10
-rwxr-xr-xspec/unit/parser/interpreter.rb23
6 files changed, 67 insertions, 28 deletions
diff --git a/spec/unit/indirector/code/configuration.rb b/spec/unit/indirector/code/configuration.rb
index 8652f342d..5e2aedc7b 100755
--- a/spec/unit/indirector/code/configuration.rb
+++ b/spec/unit/indirector/code/configuration.rb
@@ -39,6 +39,11 @@ describe Puppet::Indirector::Code::Configuration do
compiler.find('node1')
compiler.find('node2')
end
+
+ it "should provide a method for determining if the configuration is networked" do
+ compiler = Puppet::Indirector::Code::Configuration.new
+ compiler.should respond_to(:networked?)
+ end
end
describe Puppet::Indirector::Code::Configuration, " when creating the interpreter" do
@@ -70,7 +75,6 @@ describe Puppet::Indirector::Code::Configuration, " when creating the interprete
Puppet::Parser::Interpreter.expects(:new).with(:Code => code).returns(interp)
@compiler.send(:interpreter).should equal(interp)
end
-
end
describe Puppet::Indirector::Code::Configuration, " when finding nodes" do
@@ -132,10 +136,17 @@ describe Puppet::Indirector::Code::Configuration, " when creating configurations
before do
@compiler = Puppet::Indirector::Code::Configuration.new
@name = "me"
- @node = stub 'node', :merge => nil, :name => @name, :environment => "yay"
+ @node = Puppet::Node.new @name, :environment => "yay"
+ @node.stubs(:merge)
Puppet::Node.stubs(:search).with(@name).returns(@node)
end
+ it "should directly use provided nodes" do
+ Puppet::Node.expects(:search).never
+ @compiler.interpreter.expects(:compile).with(@node)
+ @compiler.find(@node)
+ end
+
it "should pass the found node to the interpreter for compiling" do
config = mock 'config'
@compiler.interpreter.expects(:compile).with(@node)
@@ -149,6 +160,7 @@ describe Puppet::Indirector::Code::Configuration, " when creating configurations
end
it "should benchmark the compile process" do
+ @compiler.stubs(:networked?).returns(true)
@compiler.expects(:benchmark).with do |level, message|
level == :notice and message =~ /^Compiled configuration/
end
diff --git a/spec/unit/indirector/indirector.rb b/spec/unit/indirector/indirector.rb
index 5c3ddf9d3..390907ca2 100755
--- a/spec/unit/indirector/indirector.rb
+++ b/spec/unit/indirector/indirector.rb
@@ -44,6 +44,13 @@ describe Puppet::Indirector, "when registering an indirection" do
@thingie.indirection.should equal(@indirection)
end
+ it "should allow specification of a default terminus" do
+ klass = mock 'terminus class'
+ Puppet::Indirector::Terminus.stubs(:terminus_class).with(:foo, :first).returns(klass)
+ @indirection = @thingie.indirects :first, :terminus_class => :foo
+ @indirection.terminus_class.should == :foo
+ end
+
after do
@indirection.delete if @indirection
end
diff --git a/spec/unit/node/configuration.rb b/spec/unit/node/configuration.rb
index 6b0677973..c94f31380 100755
--- a/spec/unit/node/configuration.rb
+++ b/spec/unit/node/configuration.rb
@@ -490,3 +490,27 @@ describe Puppet::Node::Configuration, " when writing dot files" do
Puppet.settings.clear
end
end
+
+describe Puppet::Node::Configuration, " when indirecting" do
+ before do
+ @indirection = mock 'indirection'
+
+ Puppet::Indirector::Indirection.clear_cache
+ @configuration = Puppet::Node::Facts.new("me")
+ end
+
+ it "should redirect to the indirection for retrieval" do
+ Puppet::Node::Configuration.stubs(:indirection).returns(@indirection)
+ @indirection.expects(:find).with(:myconfig)
+ Puppet::Node::Configuration.find(:myconfig)
+ end
+
+ it "should default to the code terminus" do
+ Puppet::Node::Configuration.indirection.terminus_class.should == :code
+ end
+
+ after do
+ mocha_verify
+ Puppet::Indirector::Indirection.clear_cache
+ end
+end
diff --git a/spec/unit/node/facts.rb b/spec/unit/node/facts.rb
index 61f05a2b2..ef5c91071 100755
--- a/spec/unit/node/facts.rb
+++ b/spec/unit/node/facts.rb
@@ -6,25 +6,30 @@ require 'puppet/node/facts'
describe Puppet::Node::Facts, " when indirecting" do
before do
- @terminus = mock 'terminus'
- Puppet::Node::Facts.stubs(:indirection).returns(@terminus)
+ @indirection = mock 'indirection'
- # We have to clear the cache so that the facts ask for our terminus stub,
+ # We have to clear the cache so that the facts ask for our indirection stub,
# instead of anything that might be cached.
Puppet::Indirector::Indirection.clear_cache
@facts = Puppet::Node::Facts.new("me", "one" => "two")
end
it "should redirect to the specified fact store for retrieval" do
- @terminus.expects(:find).with(:my_facts)
+ Puppet::Node::Facts.stubs(:indirection).returns(@indirection)
+ @indirection.expects(:find).with(:my_facts)
Puppet::Node::Facts.find(:my_facts)
end
it "should redirect to the specified fact store for storage" do
- @terminus.expects(:save).with(@facts)
+ Puppet::Node::Facts.stubs(:indirection).returns(@indirection)
+ @indirection.expects(:save).with(@facts)
@facts.save
end
+ it "should default to the code terminus" do
+ Puppet::Node::Facts.indirection.terminus_class.should == :code
+ end
+
after do
mocha_verify
Puppet::Indirector::Indirection.clear_cache
diff --git a/spec/unit/parser/compile.rb b/spec/unit/parser/compile.rb
index f6b3c9b3f..8bfcdd495 100755
--- a/spec/unit/parser/compile.rb
+++ b/spec/unit/parser/compile.rb
@@ -49,4 +49,14 @@ describe Puppet::Parser::Compile, " when compiling" do
@compile.resources.find { |r| r.to_s == "Class[two]" }.should be_nil
@compile.resources.find { |r| r.to_s == "Class[four]" }.should be_nil
end
+
+ it "should enable ast_nodes if the parser has any nodes" do
+ @parser.expects(:nodes).returns(:one => :yay)
+ @compile.ast_nodes?.should be_true
+ end
+
+ it "should disable ast_nodes if the parser has no nodes" do
+ @parser.expects(:nodes).returns({})
+ @compile.ast_nodes?.should be_false
+ end
end
diff --git a/spec/unit/parser/interpreter.rb b/spec/unit/parser/interpreter.rb
index b4aa2a2d1..fbf3bdb23 100755
--- a/spec/unit/parser/interpreter.rb
+++ b/spec/unit/parser/interpreter.rb
@@ -24,16 +24,6 @@ describe Puppet::Parser::Interpreter, " when initializing" do
interp.code.should equal(:code)
interp.file.should be_nil
end
-
- it "should default to usenodes" do
- interp = Puppet::Parser::Interpreter.new
- interp.usenodes?.should be_true
- end
-
- it "should allow disabling of usenodes" do
- interp = Puppet::Parser::Interpreter.new :UseNodes => false
- interp.usenodes?.should be_false
- end
end
describe Puppet::Parser::Interpreter, " when creating parser instances" do
@@ -159,22 +149,13 @@ describe Puppet::Parser::Interpreter, " when compiling configurations" do
@parser = mock 'parser'
end
- it "should create a compile with the node, parser, and whether to use ast nodes when ast nodes is true" do
+ it "should create a compile with the node and parser" do
@compile.expects(:compile).returns(:config)
@interp.expects(:parser).with(:myenv).returns(@parser)
- @interp.expects(:usenodes?).returns(true)
- Puppet::Parser::Compile.expects(:new).with(@node, @parser, :ast_nodes => true).returns(@compile)
+ Puppet::Parser::Compile.expects(:new).with(@node, @parser).returns(@compile)
@interp.compile(@node)
end
- it "should create a compile with the node, parser, and whether to use ast nodes when ast nodes is false" do
- @compile.expects(:compile).returns(:config)
- @interp.expects(:parser).with(:myenv).returns(@parser)
- @interp.expects(:usenodes?).returns(false)
- Puppet::Parser::Compile.expects(:new).with(@node, @parser, :ast_nodes => false).returns(@compile)
- @interp.compile(@node).should equal(:config)
- end
-
it "should fail intelligently when no parser can be found" do
@interp.expects(:parser).with(:myenv).returns(nil)
proc { @interp.compile(@node) }.should raise_error(Puppet::ParseError)