From 46252b5bb858a1f2b87cc8646f3a59f935c58061 Mon Sep 17 00:00:00 2001 From: luke Date: Sun, 17 Jun 2007 21:41:50 +0000 Subject: All rails and language tests now pass again. All of the rails tests should now be in the rails/ directory, and I have modified resource translation so that it always converts single-member arrays to singe values, which means the rails collection does not need to worry about it. git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2597 980ebf18-57e1-0310-9a29-db15c13687c0 --- test/language/ast.rb | 150 +------------------------------------------ test/language/collector.rb | 3 - test/language/interpreter.rb | 84 ------------------------ test/language/resource.rb | 19 ++++-- 4 files changed, 16 insertions(+), 240 deletions(-) (limited to 'test/language') diff --git a/test/language/ast.rb b/test/language/ast.rb index 29b8004dc..9e00c610d 100755 --- a/test/language/ast.rb +++ b/test/language/ast.rb @@ -2,80 +2,17 @@ $:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ -require 'puppet' -require 'puppet/rails' +require 'puppettest' require 'puppet/parser/interpreter' require 'puppet/parser/parser' -require 'puppet/network/client' -require 'puppettest' require 'puppettest/resourcetesting' require 'puppettest/parsertesting' -require 'puppettest/railstesting' +require 'puppettest/support/collection' class TestAST < Test::Unit::TestCase - include PuppetTest::RailsTesting include PuppetTest::ParserTesting include PuppetTest::ResourceTesting - - if defined? ActiveRecord - # 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 = mkscope - objects = scope.evaluate(:ast => top).flatten - } - - assert(objects.length > 0, "Did not receive any collected objects") - end - else - $stderr.puts "No ActiveRecord -- skipping collection tests" - end + include PuppetTest::Support::Collection def test_if astif = nil @@ -251,87 +188,6 @@ class TestAST < Test::Unit::TestCase end end end - - if defined? ActiveRecord::Base - def test_exported_collexp - railsinit - Puppet[:storeconfigs] = true - @interp, @scope, @source = mkclassframing - - # make a rails resource - railsresource "file", "/tmp/testing", :owner => "root", :group => "bin", - :mode => "644" - - run_collection_queries(:exported) do |string, result, query| - code = nil - str = nil - - # We don't support anything but the title in rails right now - retval = nil - bad = false - # Figure out if the search is for anything rails will ignore - string.scan(/(\w+) [!=]= \w+/) do |s| - unless s[0] == "title" - bad = true - break - end - end - - # And if it is, make sure we throw an error. - if bad - assert_raise(Puppet::ParseError, "Evaluated '#{string}'") do - str, code = query.evaluate :scope => @scope - end - next - else - assert_nothing_raised("Could not evaluate '#{string}'") do - str, code = query.evaluate :scope => @scope - end - end - assert_nothing_raised("Could not find resource") do - retval = Puppet::Rails::Resource.find(:all, - :include => :param_values, - :conditions => str) - end - - if result - assert_equal(1, retval.length, "Did not find resource with '#{string}'") - res = retval.shift - - assert_equal("file", res.restype) - assert_equal("/tmp/testing", res.title) - else - assert_equal(0, retval.length, "found a resource with '#{string}'") - end - end - end - end - - def run_collection_queries(form) - {true => [%{title == "/tmp/testing"}, %{(title == "/tmp/testing")}, - %{title == "/tmp/testing" and group == bin}, %{title == bin or group == bin}, - %{title == "/tmp/testing" or title == bin}, %{title == "/tmp/testing"}, - %{(title == "/tmp/testing" or title == bin) and group == bin}], - false => [%{title == bin}, %{title == bin or (title == bin and group == bin)}, - %{title != "/tmp/testing"}, %{title != "/tmp/testing" and group != bin}] - }.each do |res, ary| - ary.each do |str| - if form == :virtual - code = "File <| #{str} |>" - else - code = "File <<| #{str} |>>" - end - parser = mkparser - query = nil - - assert_nothing_raised("Could not parse '#{str}'") do - query = parser.parse(code)[0].query - end - - yield str, res, query - end - end - end end # $Id$ diff --git a/test/language/collector.rb b/test/language/collector.rb index e3a2db98c..bdcaf4aec 100755 --- a/test/language/collector.rb +++ b/test/language/collector.rb @@ -2,17 +2,14 @@ $:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ -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 diff --git a/test/language/interpreter.rb b/test/language/interpreter.rb index cf2cba854..aababc1d0 100755 --- a/test/language/interpreter.rb +++ b/test/language/interpreter.rb @@ -8,12 +8,10 @@ require 'puppet' require 'puppet/parser/interpreter' require 'puppet/parser/parser' require 'puppet/network/client' -require 'puppet/rails' require 'puppettest' require 'puppettest/resourcetesting' require 'puppettest/parsertesting' require 'puppettest/servertest' -require 'puppettest/railstesting' require 'timeout' class TestInterpreter < PuppetTest::TestCase @@ -21,7 +19,6 @@ class TestInterpreter < PuppetTest::TestCase include PuppetTest::ServerTest include PuppetTest::ParserTesting include PuppetTest::ResourceTesting - include PuppetTest::RailsTesting AST = Puppet::Parser::AST NodeDef = Puppet::Parser::Interpreter::NodeDef @@ -920,7 +917,6 @@ class LdapNodeTest < PuppetTest::TestCase include PuppetTest::ServerTest include PuppetTest::ParserTesting include PuppetTest::ResourceTesting - include PuppetTest::RailsTesting AST = Puppet::Parser::AST NodeDef = Puppet::Parser::Interpreter::NodeDef confine "LDAP is not available" => Puppet.features.ldap? @@ -1004,7 +1000,6 @@ class LdapReconnectTests < PuppetTest::TestCase include PuppetTest::ServerTest include PuppetTest::ParserTesting include PuppetTest::ResourceTesting - include PuppetTest::RailsTesting AST = Puppet::Parser::AST NodeDef = Puppet::Parser::Interpreter::NodeDef confine "Not running on culain as root" => (Puppet::Util::SUIDManager.uid == 0 and Facter.value("hostname") == "culain") @@ -1048,83 +1043,4 @@ class LdapReconnectTests < PuppetTest::TestCase end end -class InterpreterRailsTests < PuppetTest::TestCase - include PuppetTest - include PuppetTest::ServerTest - include PuppetTest::ParserTesting - include PuppetTest::ResourceTesting - include PuppetTest::RailsTesting - AST = Puppet::Parser::AST - NodeDef = Puppet::Parser::Interpreter::NodeDef - confine "No rails support" => Puppet.features.rails? - - # We need to make sure finished objects are stored in the db. - def test_finish_before_store - railsinit - interp = mkinterp - - node = interp.newnode ["myhost"], :code => AST::ASTArray.new(:children => [ - resourcedef("file", "/tmp/yay", :group => "root"), - defaultobj("file", :owner => "root") - ]) - - interp.newclass "myclass", :code => AST::ASTArray.new(:children => [ - ]) - - interp.newclass "sub", :parent => "myclass", - :code => AST::ASTArray.new(:children => [ - resourceoverride("file", "/tmp/yay", :owner => "root") - ] - ) - - # Now do the rails crap - Puppet[:storeconfigs] = true - - interp.evaluate("myhost", {}) - - # And then retrieve the object from rails - res = Puppet::Rails::Resource.find_by_restype_and_title("file", "/tmp/yay") - - assert(res, "Did not get resource from rails") - - param = res.param_names.find_by_name("owner", :include => :param_values) - - assert(param, "Did not find owner param") - - pvalue = param.param_values.find_by_value("root") - assert_equal("root", pvalue[:value]) - end - - def test_hoststorage - assert_nothing_raised { - Puppet[:storeconfigs] = true - } - - file = tempfile() - File.open(file, "w") { |f| - f.puts "file { \"/etc\": owner => root }" - } - - interp = nil - assert_nothing_raised { - interp = Puppet::Parser::Interpreter.new( - :Manifest => file, - :UseNodes => false, - :ForkSave => false - ) - } - - facts = {} - Facter.each { |fact, val| facts[fact] = val } - - objects = nil - assert_nothing_raised { - objects = interp.run(facts["hostname"], facts) - } - - obj = Puppet::Rails::Host.find_by_name(facts["hostname"]) - assert(obj, "Could not find host object") - end -end - # $Id$ diff --git a/test/language/resource.rb b/test/language/resource.rb index 47978eda9..d2fdd0967 100755 --- a/test/language/resource.rb +++ b/test/language/resource.rb @@ -4,13 +4,11 @@ $:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ require 'puppettest' require 'puppettest/resourcetesting' -require 'puppettest/railstesting' class TestResource < PuppetTest::TestCase include PuppetTest include PuppetTest::ParserTesting include PuppetTest::ResourceTesting - include PuppetTest::RailsTesting Parser = Puppet::Parser AST = Parser::AST Reference = Puppet::Parser::Resource::Reference @@ -134,10 +132,15 @@ class TestResource < PuppetTest::TestCase end def test_to_trans - # First try translating a builtin resource + # First try translating a builtin resource. Make sure we use some references + # and arrays, to make sure they translate correctly. + refs = [] + 4.times { |i| refs << Puppet::Parser::Resource::Reference.new(:title => "file%s" % i, :type => "file") } res = Parser::Resource.new :type => "file", :title => "/tmp", :source => @source, :scope => @scope, - :params => paramify(@source, :owner => "nobody", :mode => "644") + :params => paramify(@source, :owner => "nobody", :group => %w{you me}, + :require => refs[0], :ignore => %w{svn}, + :subscribe => [refs[1], refs[2]], :notify => [refs[3]]) obj = nil assert_nothing_raised do @@ -150,8 +153,12 @@ class TestResource < PuppetTest::TestCase assert_equal(obj.name, res.title) # TransObjects use strings, resources use symbols - hash = obj.to_hash.inject({}) { |h,a| h[a[0].intern] = a[1]; h } - assert_equal(hash, res.to_hash) + assert_equal("nobody", obj["owner"], "Single-value string was not passed correctly") + assert_equal(%w{you me}, obj["group"], "Array of strings was not passed correctly") + assert_equal("svn", obj["ignore"], "Array with single string was not turned into single value") + assert_equal(["file", refs[0].title], obj["require"], "Resource reference was not passed correctly") + assert_equal([["file", refs[1].title], ["file", refs[2].title]], obj["subscribe"], "Array of resource references was not passed correctly") + assert_equal(["file", refs[3].title], obj["notify"], "Array with single resource reference was not turned into single value") end def test_adddefaults -- cgit