diff options
Diffstat (limited to 'test')
| -rwxr-xr-x | test/language/ast.rb | 56 | ||||
| -rw-r--r-- | test/language/parser.rb | 19 | ||||
| -rwxr-xr-x | test/language/rails.rb | 24 | ||||
| -rw-r--r-- | test/puppettest.rb | 2 |
4 files changed, 97 insertions, 4 deletions
diff --git a/test/language/ast.rb b/test/language/ast.rb index b714fcdea..cb95fdff4 100755 --- a/test/language/ast.rb +++ b/test/language/ast.rb @@ -753,6 +753,62 @@ class TestAST < Test::Unit::TestCase end end + # Verify that our collection stuff works. + def test_collection + collectable = [] + non = [] + # First put some objects into the database. + bucket = mk_transtree do |object, depth, width| + # and mark some of them collectable + if width % 2 == 1 + object.collectable = true + collectable << object + else + non << object + end + end + + # Now collect our facts + facts = {} + Facter.each do |fact, value| facts[fact] = value end + + assert_nothing_raised { + Puppet::Rails.init + } + + # Now try storing our crap + assert_nothing_raised { + host = Puppet::Rails::Host.store( + :objects => bucket, + :facts => facts, + :host => facts["hostname"] + ) + } + + # Now create an ast tree that collects that. They should all be files. + coll = nil + assert_nothing_raised { + coll = AST::Collection.new( + :type => nameobj("file") + ) + } + + top = nil + assert_nothing_raised("Could not create top object") { + top = AST::ASTArray.new( + :children => [coll] + ) + } + + objects = nil + assert_nothing_raised("Could not evaluate") { + scope = Puppet::Parser::Scope.new() + objects = scope.evaluate(:ast => top).flatten + } + + assert(objects.length > 0, "Did not receive any collected objects") + end + # To fix #140. Currently non-functional. def disabled_test_classreuse children = [] diff --git a/test/language/parser.rb b/test/language/parser.rb index e1b6598d4..848f0128e 100644 --- a/test/language/parser.rb +++ b/test/language/parser.rb @@ -335,6 +335,25 @@ class TestParser < Test::Unit::TestCase parser.parse } end + + # Verify that we can parse collections + def test_collecting + Puppet[:storeconfigs] = true + text = "port <| |>" + parser = Puppet::Parser::Parser.new + parser.string = text + + ret = nil + assert_nothing_raised { + ret = parser.parse + } + + assert_instance_of(AST::ASTArray, ret) + + ret.each do |obj| + assert_instance_of(AST::Collection, obj) + end + end end # $Id$ diff --git a/test/language/rails.rb b/test/language/rails.rb index e85652620..13bee4c5b 100755 --- a/test/language/rails.rb +++ b/test/language/rails.rb @@ -62,7 +62,21 @@ class TestRails < Test::Unit::TestCase assert(host.rails_objects, "No objects on host") - collectable = host.rails_objects.find_all do |obj| obj.collectable end + assert_equal(facts["hostname"], host.facts["hostname"], + "Did not retrieve facts") + + inline_test_objectcollection(host) + end + + # This is called from another test, it just makes sense to split it out some + def inline_test_objectcollection(host) + # XXX For some reason, find_all doesn't work here at all. + collectable = [] + host.rails_objects.each do |obj| + if obj.collectable? + collectable << obj + end + end assert(collectable.length > 0, "Found no collectable objects") @@ -76,8 +90,12 @@ class TestRails < Test::Unit::TestCase assert(!trans.collectable, "Object from db was collectable") end - assert_equal(facts["hostname"], host.facts["hostname"], - "Did not retrieve facts") + # Now find all collectable objects directly through database APIs + + list = Puppet::Rails::RailsObject.find_all_by_collectable(true) + + assert_equal(collectable.length, list.length, + "Did not get the right number of objects") end def test_railsinit diff --git a/test/puppettest.rb b/test/puppettest.rb index 53e747fd1..ed0383fd3 100644 --- a/test/puppettest.rb +++ b/test/puppettest.rb @@ -1021,7 +1021,7 @@ module ParserTesting objects = [] width.times do |j| path = tempfile + i.to_s - obj = Puppet::TransObject.new("file", file) + obj = Puppet::TransObject.new("file", path) obj["owner"] = "root" obj["mode"] = "644" |
