diff options
| author | Rick Bradley <rick@rickbradley.com> | 2007-10-04 08:04:44 -0500 |
|---|---|---|
| committer | Rick Bradley <rick@rickbradley.com> | 2007-10-04 08:04:44 -0500 |
| commit | 92d23e0398ffbaf7e264bb7ff716bd6f83130b07 (patch) | |
| tree | af4a9296a11733c4636a88d38925804ea6f0793d /spec | |
| parent | 1334b786ac622a6094ba68b3e66fce3f5841deed (diff) | |
| parent | bd8e38236a23ae687c418fcbb90e5f61c8c67b01 (diff) | |
Merge branch 'master' of git://reductivelabs.com/puppet into routing
Diffstat (limited to 'spec')
| -rwxr-xr-x | spec/unit/node/configuration.rb | 17 | ||||
| -rwxr-xr-x | spec/unit/other/transobject.rb | 1 | ||||
| -rwxr-xr-x | spec/unit/parser/interpreter.rb | 51 | ||||
| -rwxr-xr-x | spec/unit/util/settings.rb | 19 |
4 files changed, 63 insertions, 25 deletions
diff --git a/spec/unit/node/configuration.rb b/spec/unit/node/configuration.rb index 8ba55f50c..6893c8581 100755 --- a/spec/unit/node/configuration.rb +++ b/spec/unit/node/configuration.rb @@ -68,6 +68,23 @@ describe Puppet::Node::Configuration, " when extracting transobjects" do Puppet::Parser::Resource.new(:type => type, :title => name, :source => @source, :scope => @scope) end + it "should always create a TransBucket for the 'main' class" do + config = Puppet::Node::Configuration.new("mynode") + + @scope = mkscope + @source = mock 'source' + + main = mkresource("class", :main) + config.add_vertex!(main) + + bucket = mock 'bucket' + bucket.expects(:classes=).with(config.classes) + main.stubs(:builtin?).returns(false) + main.expects(:to_transbucket).returns(bucket) + + config.extract_to_transportable.should equal(bucket) + end + # This isn't really a spec-style test, but I don't know how better to do it. it "should transform the resource graph into a tree of TransBuckets and TransObjects" do config = Puppet::Node::Configuration.new("mynode") diff --git a/spec/unit/other/transobject.rb b/spec/unit/other/transobject.rb index 07c9dc761..144940b7e 100755 --- a/spec/unit/other/transobject.rb +++ b/spec/unit/other/transobject.rb @@ -113,4 +113,3 @@ class TestTransportable < Test::Unit::TestCase end end -# $Id$ diff --git a/spec/unit/parser/interpreter.rb b/spec/unit/parser/interpreter.rb index a79267b52..b4aa2a2d1 100755 --- a/spec/unit/parser/interpreter.rb +++ b/spec/unit/parser/interpreter.rb @@ -100,12 +100,7 @@ describe Puppet::Parser::Interpreter, " when managing parser instances" do @parser = mock('parser') end - it "it should an exception when nothing is there and nil is returned" do - @interp.expects(:create_parser).with(:myenv).returns(nil) - @interp.send(:parser, :myenv).should be_nil - end - - it "should create and return a new parser and use the same parser when the parser does not need reparsing" do + it "should use the same parser when the parser does not need reparsing" do @interp.expects(:create_parser).with(:myenv).returns(@parser) @interp.send(:parser, :myenv).should equal(@parser) @@ -125,7 +120,12 @@ describe Puppet::Parser::Interpreter, " when managing parser instances" do @interp.send(:parser, :myenv).should equal(newparser) end - it "should keep the old parser if create_parser doesn't return anything." do + it "should fail intelligently if a parser cannot be created and one does not already exist" do + @interp.expects(:create_parser).with(:myenv).raises(ArgumentError) + proc { @interp.send(:parser, :myenv) }.should raise_error(ArgumentError) + end + + it "should keep the old parser if a new parser cannot be created" do # Get the first parser in the hash. @interp.expects(:create_parser).with(:myenv).returns(@parser) @interp.send(:parser, :myenv).should equal(@parser) @@ -134,7 +134,7 @@ describe Puppet::Parser::Interpreter, " when managing parser instances" do @parser.expects(:reparse?).returns(true) # But fail to create a new parser - @interp.expects(:create_parser).with(:myenv).returns(nil) + @interp.expects(:create_parser).with(:myenv).raises(ArgumentError) # And make sure we still get the old valid parser @interp.send(:parser, :myenv).should equal(@parser) @@ -154,27 +154,30 @@ end describe Puppet::Parser::Interpreter, " when compiling configurations" do before do @interp = Puppet::Parser::Interpreter.new + @node = stub 'node', :environment => :myenv + @compile = mock 'compile' + @parser = mock 'parser' end - it "should create a configuration with the node, parser, and whether to use ast nodes" do - node = mock('node') - node.expects(:environment).returns(:myenv) - compile = mock 'compile' - compile.expects(:compile).returns(:config) - parser = mock 'parser' - @interp.expects(:parser).with(:myenv).returns(parser) + it "should create a compile with the node, parser, and whether to use ast nodes when ast nodes is true" 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) - @interp.compile(node) + Puppet::Parser::Compile.expects(:new).with(@node, @parser, :ast_nodes => true).returns(@compile) + @interp.compile(@node) + end - # Now try it when usenodes is true - @interp = Puppet::Parser::Interpreter.new :UseNodes => false - node.expects(:environment).returns(:myenv) - compile.expects(:compile).returns(:config) - @interp.expects(:parser).with(:myenv).returns(parser) + 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) + 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) end end diff --git a/spec/unit/util/settings.rb b/spec/unit/util/settings.rb index 8d11737b3..e647ce1cd 100755 --- a/spec/unit/util/settings.rb +++ b/spec/unit/util/settings.rb @@ -395,6 +395,17 @@ describe Puppet::Util::Settings, " when being used to manage the host machine" d @settings.setdefaults :files, :myfile => {:default => "/myfile", :desc => "a", :mode => 0755} end + def stub_transaction + @bucket = mock 'bucket' + @config = mock 'config' + @trans = mock 'transaction' + + @settings.expects(:to_transportable).with(:whatever).returns(@bucket) + @bucket.expects(:to_configuration).returns(@config) + @config.expects(:apply).yields(@trans) + @config.stubs(:host_config=) + end + it "should provide a method that writes files with the correct modes" do pending "Not converted from test/unit yet" end @@ -518,6 +529,7 @@ describe Puppet::Util::Settings, " when being used to manage the host machine" d Puppet::Util::Storage.expects(:store).never Puppet::Util::Storage.expects(:load).never Dir.expects(:mkdir).with("/maindir") + Dir.expects(:mkdir).with("/seconddir") @settings.use(:main) end @@ -532,4 +544,11 @@ describe Puppet::Util::Settings, " when being used to manage the host machine" d @settings.use(:other) @settings.reuse end + + it "should fail if any resources fail" do + stub_transaction + @trans.expects(:any_failed?).returns(true) + + proc { @settings.use(:whatever) }.should raise_error(RuntimeError) + end end |
