diff options
-rw-r--r-- | lib/puppet/transaction.rb | 3 | ||||
-rwxr-xr-x | test/other/transactions.rb | 44 |
2 files changed, 46 insertions, 1 deletions
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index f3d05b5ef..fe86c2595 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -544,7 +544,8 @@ class Transaction # Set an edge to be triggered when we evaluate its target. def set_trigger(edge) - return unless edge.callback + return unless method = edge.callback + return unless edge.target.respond_to?(method) if edge.target.respond_to?(:ref) edge.source.info "Scheduling %s of %s" % [edge.callback, edge.target.ref] end diff --git a/test/other/transactions.rb b/test/other/transactions.rb index 4a5fee9a0..d1ea0ef68 100755 --- a/test/other/transactions.rb +++ b/test/other/transactions.rb @@ -928,6 +928,50 @@ class TestTransactions < Test::Unit::TestCase assert(FileTest.exists?(file), "graph for %s was not created" % name) end end + + def test_set_target + file = Puppet::Type.newfile(:path => tempfile(), :content => "yay") + exec1 = Puppet::Type.type(:exec).create :command => "/bin/echo exec1" + exec2 = Puppet::Type.type(:exec).create :command => "/bin/echo exec2" + trans = Puppet::Transaction.new(newcomp(file, exec1, exec2)) + + # First try it with an edge that has no callback + edge = Puppet::Relationship.new(file, exec1) + assert_nothing_raised { trans.set_trigger(edge) } + assert(! trans.targeted?(exec1), "edge with no callback resulted in a target") + + # Now with an edge that has an unsupported callback + edge = Puppet::Relationship.new(file, exec1, :callback => :nosuchmethod, :event => :ALL_EVENTS) + assert_nothing_raised { trans.set_trigger(edge) } + assert(! trans.targeted?(exec1), "edge with invalid callback resulted in a target") + + # Lastly, with an edge with a supported callback + edge = Puppet::Relationship.new(file, exec1, :callback => :refresh, :event => :ALL_EVENTS) + assert_nothing_raised { trans.set_trigger(edge) } + assert(trans.targeted?(exec1), "edge with valid callback did not result in a target") + end + + # Testing #401 -- transactions are calling refresh() on classes that don't support it. + def test_callback_availability + $called = [] + klass = Puppet::Type.newtype(:norefresh) do + newparam(:name, :namevar => true) {} + def method_missing(method, *args) + $called << method + end + end + cleanup do + $called = nil + Puppet::Type.rmtype(:norefresh) + end + + file = Puppet::Type.newfile :path => tempfile(), :content => "yay" + one = klass.create :name => "one", :subscribe => file + + assert_apply(file, one) + + assert(! $called.include?(:refresh), "Called refresh when it wasn't set as a method") + end end # $Id$ |