diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-19 04:57:57 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-19 04:57:57 +0000 |
| commit | 9f4870637ce57d548d23c0b3330200014327c268 (patch) | |
| tree | b820cfb5a8150dc00d475ffe0cde6316ad210a91 /test/rails | |
| parent | dc5f4dc0d01dc2ccb4679afbf3802a7ab0f3c126 (diff) | |
| download | puppet-9f4870637ce57d548d23c0b3330200014327c268.tar.gz puppet-9f4870637ce57d548d23c0b3330200014327c268.tar.xz puppet-9f4870637ce57d548d23c0b3330200014327c268.zip | |
All rails *and* language tests now pass, with the exception of a language/resource test that passes by itself but fails when run as part of the whole suite. Also, I added deletion where appropriate, so that unspecified resources, parameters, and facts are now deleted, as one would expect.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1951 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/rails')
| -rwxr-xr-x | test/rails/host.rb | 136 | ||||
| -rwxr-xr-x | test/rails/rails.rb | 84 | ||||
| -rwxr-xr-x | test/rails/railsresource.rb | 4 |
3 files changed, 138 insertions, 86 deletions
diff --git a/test/rails/host.rb b/test/rails/host.rb new file mode 100755 index 000000000..38389ac64 --- /dev/null +++ b/test/rails/host.rb @@ -0,0 +1,136 @@ +#!/usr/bin/env ruby + +$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ + +require 'puppet' +require 'puppet/rails' +require 'puppet/parser/interpreter' +require 'puppet/parser/parser' +require 'puppet/client' +require 'puppettest' +require 'puppettest/parsertesting' +require 'puppettest/resourcetesting' +require 'puppettest/railstesting' + +class TestRailsHost < Test::Unit::TestCase + include PuppetTest::ParserTesting + include PuppetTest::ResourceTesting + include PuppetTest::RailsTesting + + def setup + super + railsinit + end + + def teardown + railsteardown + super + end + + def test_includerails + assert_nothing_raised { + require 'puppet/rails' + } + end + + # Don't do any tests w/out this class + if Puppet.features.rails? + def test_store + @interp, @scope, @source = mkclassframing + # First make some objects + resources = [] + 10.times { |i| + # Make a file + resources << mkresource(:type => "file", + :title => "/tmp/file#{i.to_s}", + :params => {:owner => "user#{i}"}) + + # And an exec, so we're checking multiple types + resources << mkresource(:type => "exec", + :title => "/bin/echo file#{i.to_s}", + :params => {:user => "user#{i}"}) + } + + # Now collect our facts + facts = {"hostname" => Facter.value(:hostname), "test1" => "funtest", + "ipaddress" => Facter.value(:ipaddress)} + + # Now try storing our crap + host = nil + assert_nothing_raised { + host = Puppet::Rails::Host.store( + :resources => resources, + :facts => facts, + :name => facts["hostname"], + :classes => ["one", "two::three", "four"] + ) + } + + assert(host, "Did not create host") + + host = nil + assert_nothing_raised { + host = Puppet::Rails::Host.find_by_name(facts["hostname"]) + } + assert(host, "Could not find host object") + + assert(host.resources, "No objects on host") + + facts.each do |fact, value| + assert_equal(value, host.fact(fact), "fact %s is wrong" % fact) + end + assert_equal(facts["ipaddress"], host.ip, "IP did not get set") + + count = 0 + host.resources.each do |resource| + assert_equal(host, resource.host) + count += 1 + i = nil + if resource[:title] =~ /file([0-9]+)/ + i = $1 + else + raise "Got weird resource %s" % resource.inspect + end + assert(resource[:restype] != "", "Did not get a type from the resource") + case resource["restype"] + when "file": + assert_equal("user#{i}", resource.parameter("owner"), + "got no owner for %s" % resource.ref) + when "exec": + assert_equal("user#{i}", resource.parameter("user"), + "got no user for %s" % resource.ref) + else + raise "Unknown type %s" % resource[:restype].inspect + end + end + + assert_equal(20, count, "Did not get enough resources") + + # Now remove a couple of resources and change a fact + resources.reject! { |r| r.title =~ /file9/ } + facts["test2"] = "yaytest" + facts.delete("test1") + host = nil + assert_nothing_raised { + host = Puppet::Rails::Host.store( + :resources => resources, + :facts => facts, + :name => facts["hostname"], + :classes => ["one", "two::three", "four"] + ) + } + + assert_nil(host.fact('test1'), "removed fact was not deleted") + facts.each do |fact, value| + assert_equal(value, host.fact(fact), "fact %s is wrong" % fact) + end + + assert(! host.resources.find(:all).detect { |r| r.title =~ /file9/ }, + "Removed resources are still present") + end + else + $stderr.puts "Install Rails for Rails and Caching tests" + end +end + +# $Id$ diff --git a/test/rails/rails.rb b/test/rails/rails.rb index 69e1fd7b8..c0f902d65 100755 --- a/test/rails/rails.rb +++ b/test/rails/rails.rb @@ -32,90 +32,6 @@ class TestRails < Test::Unit::TestCase require 'puppet/rails' } end - - # Don't do any tests w/out this class - if Puppet.features.rails? - def test_hostcache - @interp, @scope, @source = mkclassframing - # First make some objects - resources = [] - 10.times { |i| - # Make a file - resources << mkresource(:type => "file", - :title => "/tmp/file#{i.to_s}", - :params => {:owner => "user#{i}"}) - - # And an exec, so we're checking multiple types - resources << mkresource(:type => "exec", - :title => "/bin/echo file#{i.to_s}", - :params => {:user => "user#{i}"}) - } - - # Now collect our facts - facts = {"hostname" => Facter.value(:hostname), "test1" => "funtest"} - - # Now try storing our crap - host = nil - assert_nothing_raised { - host = Puppet::Rails::Host.store( - :resources => resources, - :facts => facts, - :name => facts["hostname"], - :classes => ["one", "two::three", "four"] - ) - } - - assert(host, "Did not create host") - - host = nil - assert_nothing_raised { - host = Puppet::Rails::Host.find_by_name(facts["hostname"]) - } - assert(host, "Could not find host object") - - assert(host.resources, "No objects on host") - - assert_equal(facts["hostname"], host.facts("hostname"), - "Did not retrieve facts") - - count = 0 - host.resources.each do |resource| - assert_equal(host, resource.host) - count += 1 - i = nil - if resource[:title] =~ /file([0-9]+)/ - i = $1 - else - raise "Got weird resource %s" % resource.inspect - end - assert(resource[:restype] != "", "Did not get a type from the resource") - case resource["restype"] - when "file": - assert_equal("user#{i}", resource.parameter("owner"), - "got no owner for %s" % resource.ref) - when "exec": - assert_equal("user#{i}", resource.parameter("user"), - "got no user for %s" % resource.ref) - else - raise "Unknown type %s" % resource[:restype].inspect - end - end - - assert_equal(20, count, "Did not get enough resources") - - host = nil - assert_nothing_raised { - host = Puppet::Rails::Host.store( - :resources => resources, - :facts => facts, - :name => facts["hostname"], - :classes => ["one", "two::three", "four"] - ) - } - end - else - $stderr.puts "Install Rails for Rails and Caching tests" - end end # $Id$ diff --git a/test/rails/railsresource.rb b/test/rails/railsresource.rb index 302dd99fb..968e0e1b9 100755 --- a/test/rails/railsresource.rb +++ b/test/rails/railsresource.rb @@ -66,8 +66,8 @@ class TestRailsResource < Test::Unit::TestCase res = resource.to_resource(scope) end assert_instance_of(Puppet::Parser::Resource, res) - assert_equal("root", res[:owner]) - assert_equal("644", res[:mode]) + assert_equal(["root"], res[:owner]) + assert_equal(["644"], res[:mode]) assert_equal("/tmp/to_resource", res.title) assert_equal(source, res.source) end |
