summaryrefslogtreecommitdiffstats
path: root/test/language/collector.rb
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-10-04 18:24:24 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-10-04 18:24:24 +0000
commit28cee40689440388994a4768bd301ae32c8ecc05 (patch)
treec865ab44f4c9247052cf83de16ffc8ebe8b15e54 /test/language/collector.rb
parente0e291332bd4676962a28c7b220ae5c5e9651c0a (diff)
downloadpuppet-28cee40689440388994a4768bd301ae32c8ecc05.tar.gz
puppet-28cee40689440388994a4768bd301ae32c8ecc05.tar.xz
puppet-28cee40689440388994a4768bd301ae32c8ecc05.zip
Merging the changes from the override-refactor branch. This is a significant rewrite of the parser, but it has little affect on the rest of the code tree.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1726 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/language/collector.rb')
-rwxr-xr-xtest/language/collector.rb206
1 files changed, 206 insertions, 0 deletions
diff --git a/test/language/collector.rb b/test/language/collector.rb
new file mode 100755
index 000000000..d7ac059fa
--- /dev/null
+++ b/test/language/collector.rb
@@ -0,0 +1,206 @@
+#!/usr/bin/ruby
+
+require 'puppet/rails'
+require 'puppettest'
+require 'puppettest/parsertesting'
+require 'puppettest/resourcetesting'
+require 'puppettest/railstesting'
+
+class TestCollector < Test::Unit::TestCase
+ include PuppetTest
+ include PuppetTest::ParserTesting
+ include PuppetTest::ResourceTesting
+ include PuppetTest::RailsTesting
+ Parser = Puppet::Parser
+ AST = Parser::AST
+
+ def setup
+ super
+ Puppet[:trace] = false
+ @interp, @scope, @source = mkclassframing
+ end
+
+ def test_virtual
+ # Make a virtual resource
+ virtual = mkresource(:type => "file", :title => "/tmp/virtual",
+ :virtual => true, :params => {:owner => "root"})
+ @scope.setresource virtual
+
+ # And a non-virtual
+ real = mkresource(:type => "file", :title => "/tmp/real",
+ :params => {:owner => "root"})
+ @scope.setresource real
+
+ # Now make a collector
+ coll = nil
+ assert_nothing_raised do
+ coll = Puppet::Parser::Collector.new(@scope, "file", nil, :virtual)
+ end
+
+ # Set it in our scope
+ @scope.newcollection(coll)
+
+ # Make sure it's in the collections
+ assert_equal([coll], @scope.collections)
+
+ # And try to collect the virtual resources.
+ ret = nil
+ assert_nothing_raised do
+ ret = coll.collect_virtual
+ end
+
+ assert_equal([virtual], ret)
+
+ # Now make sure evaluate does the right thing.
+ assert_nothing_raised do
+ ret = coll.evaluate
+ end
+
+ # Make sure it got deleted from the collection list
+ assert_equal([], @scope.collections)
+
+ # And make sure our virtual object is no longer virtual
+ assert(! virtual.virtual?, "Virtual object did not get realized")
+
+ # Now make a new collector of a different type and make sure it
+ # finds nothing.
+ assert_nothing_raised do
+ coll = Puppet::Parser::Collector.new(@scope, "exec", nil, :virtual)
+ end
+
+ # Remark this as virtual
+ virtual.virtual = true
+
+ assert_nothing_raised do
+ ret = coll.evaluate
+ end
+
+ assert_equal([], ret)
+ end
+
+ if defined? ActiveRecord::Base
+ def test_collect_exported
+ railsinit
+ # make an exported resource
+ exported = mkresource(:type => "file", :title => "/tmp/exported",
+ :exported => true, :params => {:owner => "root"})
+ @scope.setresource exported
+
+ assert(exported.exported?, "Object was not marked exported")
+ assert(exported.virtual?, "Object was not marked virtual")
+
+ # And a non-exported
+ real = mkresource(:type => "file", :title => "/tmp/real",
+ :params => {:owner => "root"})
+ @scope.setresource real
+
+ # Now make a collector
+ coll = nil
+ assert_nothing_raised do
+ coll = Puppet::Parser::Collector.new(@scope, "file", nil, :exported)
+ end
+
+ # Set it in our scope
+ @scope.newcollection(coll)
+
+ # Make sure it's in the collections
+ assert_equal([coll], @scope.collections)
+
+ # And try to collect the virtual resources.
+ ret = nil
+ assert_nothing_raised do
+ ret = coll.collect_exported
+ end
+
+ assert_equal([exported], ret)
+
+ # Now make sure evaluate does the right thing.
+ assert_nothing_raised do
+ ret = coll.evaluate
+ end
+
+ # Make sure it got deleted from the collection list
+ assert_equal([], @scope.collections)
+
+ # And make sure our exported object is no longer exported
+ assert(! exported.virtual?, "Virtual object did not get realized")
+
+ # But it should still be marked exported.
+ assert(exported.exported?, "Resource got un-exported")
+
+ # Now make a new collector of a different type and make sure it
+ # finds nothing.
+ assert_nothing_raised do
+ coll = Puppet::Parser::Collector.new(@scope, "exec", nil, :exported)
+ end
+
+ # Remark this as virtual
+ exported.virtual = true
+
+ assert_nothing_raised do
+ ret = coll.evaluate
+ end
+
+ assert_equal([], ret)
+ end
+
+ def test_collection_conflicts
+ railsinit
+
+ # First make a railshost we can conflict with
+ host = Puppet::Rails::Host.new(:name => "myhost")
+
+ host.rails_resources.build(:title => "/tmp/conflicttest", :restype => "file",
+ :exported => true)
+
+ host.save
+
+ # Now make a normal resource
+ normal = mkresource(:type => "file", :title => "/tmp/conflicttest",
+ :params => {:owner => "root"})
+ @scope.setresource normal
+
+ # Now make a collector
+ coll = nil
+ assert_nothing_raised do
+ coll = Puppet::Parser::Collector.new(@scope, "file", nil, :exported)
+ end
+
+ # And try to collect the virtual resources.
+ assert_raise(Puppet::ParseError) do
+ ret = coll.collect_exported
+ end
+ end
+
+ # Make sure we do not collect resources from the host we're on
+ def test_no_resources_from_me
+ railsinit
+
+ # Make our configuration
+ host = Puppet::Rails::Host.new(:name => "myhost")
+
+ host.rails_resources.build(:title => "/tmp/hosttest", :restype => "file",
+ :exported => true)
+
+ host.save
+
+ @scope.host = "myhost"
+
+ # Now make a collector
+ coll = nil
+ assert_nothing_raised do
+ coll = Puppet::Parser::Collector.new(@scope, "file", nil, :exported)
+ end
+
+ # And make sure we get nada back
+ ret = nil
+ assert_nothing_raised do
+ ret = coll.collect_exported
+ end
+
+ assert(ret.empty?, "Found exports from our own host")
+ end
+ end
+end
+
+# $Id$