diff options
Diffstat (limited to 'spec/unit/transaction_spec.rb')
-rwxr-xr-x | spec/unit/transaction_spec.rb | 78 |
1 files changed, 32 insertions, 46 deletions
diff --git a/spec/unit/transaction_spec.rb b/spec/unit/transaction_spec.rb index 9e85390eb..f5720e75a 100755 --- a/spec/unit/transaction_spec.rb +++ b/spec/unit/transaction_spec.rb @@ -436,6 +436,10 @@ describe Puppet::Transaction do @transaction.catalog.add_resource(dependent, dependent2) + # We enqueue them here just so we can check their blockers. This is done + # again in traverse. + graph.enqueue_roots + graph.blockers[dependent].should == 1 graph.blockers[dependent2].should == 1 @@ -453,6 +457,8 @@ describe Puppet::Transaction do @transaction.catalog.add_resource(dependent, dependent2) + graph.enqueue_roots + graph.blockers[dependent].should == 1 graph.blockers[dependent2].should == 1 @@ -510,70 +516,50 @@ describe Puppet::Transaction do end end - describe "when generating resources" do - it "should call 'generate' on all created resources" do - first = Puppet::Type.type(:notify).new(:name => "first") - second = Puppet::Type.type(:notify).new(:name => "second") - third = Puppet::Type.type(:notify).new(:name => "third") + describe "when generating resources before traversal" do + let(:catalog) { Puppet::Resource::Catalog.new } + let(:transaction) { Puppet::Transaction.new(catalog) } + let(:generator) { Puppet::Type.type(:notify).create :title => "generator" } + let(:generated) do + %w[a b c].map { |name| Puppet::Type.type(:notify).new(:name => name) } + end - @catalog = Puppet::Resource::Catalog.new - @transaction = Puppet::Transaction.new(@catalog) + before :each do + catalog.add_resource generator + generator.stubs(:generate).returns generated + end - first.expects(:generate).returns [second] - second.expects(:generate).returns [third] - third.expects(:generate) + it "should call 'generate' on all created resources" do + generated.each { |res| res.expects(:generate) } - @transaction.generate_additional_resources(first) + transaction.add_dynamically_generated_resources end it "should finish all resources" do - generator = stub 'generator', :depthfirst? => true, :tags => [], :ref => "Some[resource]" - resource = stub 'resource', :tag => nil - - @catalog = Puppet::Resource::Catalog.new - @transaction = Puppet::Transaction.new(@catalog) - - generator.expects(:generate).returns [resource] - - @catalog.expects(:add_resource).yields(resource) - - resource.expects(:finish) + generated.each { |res| res.expects(:finish) } - @transaction.generate_additional_resources(generator) + transaction.add_dynamically_generated_resources end it "should skip generated resources that conflict with existing resources" do - generator = mock 'generator', :tags => [] - resource = stub 'resource', :tag => nil - - @catalog = Puppet::Resource::Catalog.new - @transaction = Puppet::Transaction.new(@catalog) + duplicate = generated.first + catalog.add_resource(duplicate) - generator.expects(:generate).returns [resource] + duplicate.expects(:finish).never - @catalog.expects(:add_resource).raises(Puppet::Resource::Catalog::DuplicateResourceError.new("foo")) + duplicate.expects(:info).with { |msg| msg =~ /Duplicate generated resource/ } - resource.expects(:finish).never - resource.expects(:info) # log that it's skipped - - @transaction.generate_additional_resources(generator) + transaction.add_dynamically_generated_resources end it "should copy all tags to the newly generated resources" do - child = stub 'child', :ref => "Some[child_resource]" - generator = stub 'resource', :tags => ["one", "two"], :ref => "Some[resource]" - - @catalog = Puppet::Resource::Catalog.new - @transaction = Puppet::Transaction.new(@catalog) - - generator.stubs(:generate).returns [child] - @catalog.stubs(:add_resource) + generator.tag('one', 'two') - child.expects(:tag).with("one", "two") - child.expects(:finish) - generator.expects(:depthfirst?) + transaction.add_dynamically_generated_resources - @transaction.generate_additional_resources(generator) + generated.each do |res| + res.should be_tagged(generator.tags) + end end end |