From 3a6683ea720a53bd2ddb34b9215bdc676bdcdb2c Mon Sep 17 00:00:00 2001 From: luke Date: Wed, 18 Oct 2006 06:01:18 +0000 Subject: Changing the realize() function to be just syntactic sugar for a collection -- it literally creates a collector object now. The benefit of this is that it is late-binding, so file order does not affect whether a resource is available. git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1810 980ebf18-57e1-0310-9a29-db15c13687c0 --- test/language/collector.rb | 36 ++++++++++++++++++++++++++++++++++++ test/language/functions.rb | 22 ++++++++++++++++++++-- 2 files changed, 56 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/language/collector.rb b/test/language/collector.rb index 0204778de..ceab76ccc 100755 --- a/test/language/collector.rb +++ b/test/language/collector.rb @@ -22,6 +22,42 @@ class TestCollector < Test::Unit::TestCase @interp, @scope, @source = mkclassframing end + # Test just collecting a specific resource. This is used by the 'realize' + # function, and it's much faster than iterating over all of the resources. + def test_collect_resource + # Make a couple of virtual resources + one = mkresource(:type => "file", :title => "/tmp/virtual1", + :virtual => true, :params => {:owner => "root"}) + two = mkresource(:type => "file", :title => "/tmp/virtual2", + :virtual => true, :params => {:owner => "root"}) + @scope.setresource one + @scope.setresource two + + # Now make a collector + coll = nil + assert_nothing_raised do + coll = Puppet::Parser::Collector.new(@scope, "file", nil, nil, :virtual) + end + + # Now set the resource in the collector + assert_nothing_raised do + coll.resources = one.ref + end + + # Now run the collector + assert_nothing_raised do + coll.evaluate + end + + # And make sure the resource is no longer virtual + assert(! one.virtual?, + "Resource is still virtual") + + # But the other still is + assert(two.virtual?, + "Resource got realized") + end + def test_virtual # Make a virtual resource virtual = mkresource(:type => "file", :title => "/tmp/virtual", diff --git a/test/language/functions.rb b/test/language/functions.rb index 21af606db..bd7143db6 100755 --- a/test/language/functions.rb +++ b/test/language/functions.rb @@ -321,19 +321,37 @@ class TestLangFunctions < Test::Unit::TestCase @scope.function_realize(ref) end + # Make sure it created a collection + assert_equal(1, @scope.collections.length, + "Did not set collection") + + assert_nothing_raised do + @scope.collections.each do |coll| coll.evaluate end + end + @scope.collections.clear + # Now make sure the virtual resource is no longer virtual assert(! virtual.virtual?, "Did not make virtual resource real") # Make sure we puke on any resource that doesn't exist - none = Puppet::Parser::Resource::Reference.new( :type => "file", :title => "/tmp/nosuchfile", :scope => @scope ) - assert_raise(Puppet::ParseError) do + # The function works + assert_nothing_raised do @scope.function_realize(none) end + + # Make sure it created a collection + assert_equal(1, @scope.collections.length, + "Did not set collection") + + # But the collection fails + assert_raise(Puppet::ParseError) do + @scope.collections.each do |coll| coll.evaluate end + end end end -- cgit