diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-19 02:08:11 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-19 02:08:11 +0000 |
| commit | dc5f4dc0d01dc2ccb4679afbf3802a7ab0f3c126 (patch) | |
| tree | 6082433e05ad445aa4323a05de7d5820c5c023d6 /test/language | |
| parent | 5a52855c1da2cb4716587bf0223c6d20eddaf00a (diff) | |
Fixing most of the rails stuff. I think everything basically works now, and now I am just going through and making sure things get deleted when they are supposed (i.e., you remove a resource and it gets deleted from the host's config).
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1950 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/language')
| -rwxr-xr-x | test/language/collector.rb | 38 | ||||
| -rwxr-xr-x | test/language/resource.rb | 77 |
2 files changed, 84 insertions, 31 deletions
diff --git a/test/language/collector.rb b/test/language/collector.rb index 0292fac3e..41ce12f66 100755 --- a/test/language/collector.rb +++ b/test/language/collector.rb @@ -121,9 +121,13 @@ class TestCollector < Test::Unit::TestCase assert_equal([], ret) end - if defined? ActiveRecord::Base + if Puppet.features.rails? def test_collect_exported railsinit + + # Set a hostname + @scope.host = Facter.value(:hostname) + # make an exported resource exported = mkresource(:type => "file", :title => "/tmp/exported", :exported => true, :params => {:owner => "root"}) @@ -189,26 +193,27 @@ class TestCollector < Test::Unit::TestCase # Now create a whole new scope and make sure we can actually retrieve # the resource from the database, not just from the scope. # First create a host object and store our resource in it. - # Now collect our facts - facts = {} - Facter.each do |fact, value| facts[fact] = value end - - - # Now try storing our crap - resources = [] - resources << exported - host = Puppet::Rails::Host.store( - :resources => resources, - :facts => facts, - :name => facts["hostname"] - ) + + # Now collect our facts + facts = {} + Facter.each do |fact, value| facts[fact] = value end + + # Now try storing our crap + # Remark this as exported + exported.exported = true + host = Puppet::Rails::Host.store( + :resources => [exported], + :facts => facts, + :name => facts["hostname"] + ) assert(host, "did not get rails host") host.save # And make sure it's in there - newres = host.resources.find_by_title("/tmp/exported") + newres = host.resources.find_by_restype_and_title_and_exported("file", "/tmp/exported", true) assert(newres, "Did not find resource in db") interp, scope, source = mkclassframing + scope.host = "two" # Now make a collector coll = nil @@ -246,7 +251,7 @@ class TestCollector < Test::Unit::TestCase # First make a railshost we can conflict with host = Puppet::Rails::Host.new(:name => "myhost") - host.resources.build(:title => "/tmp/conflicttest", :type => "PuppetFile", + host.resources.build(:title => "/tmp/conflicttest", :restype => "file", :exported => true) host.save @@ -255,6 +260,7 @@ class TestCollector < Test::Unit::TestCase normal = mkresource(:type => "file", :title => "/tmp/conflicttest", :params => {:owner => "root"}) @scope.setresource normal + @scope.host = "otherhost" # Now make a collector coll = nil diff --git a/test/language/resource.rb b/test/language/resource.rb index eb8d2e9aa..872d7b39f 100755 --- a/test/language/resource.rb +++ b/test/language/resource.rb @@ -360,19 +360,13 @@ class TestResource < Test::Unit::TestCase assert_nil(ref.builtintype, "Component was considered builtin") end - if defined? ActiveRecord::Base - def test_store - railsinit - res = mkresource :type => "file", :title => "/tmp/testing", - :source => @source, :scope => @scope, - :params => {:owner => "root", :mode => "755"} - - # We also need a Rails Host to store under - host = Puppet::Rails::Host.new(:name => Facter.hostname) + if Puppet.features.rails? + # Compare a parser resource to a rails resource. + def compare_resources(host, res) obj = nil assert_nothing_raised do - obj = res.store(host) + obj = res.to_rails(host) end assert_instance_of(Puppet::Rails::Resource, obj) @@ -383,20 +377,73 @@ class TestResource < Test::Unit::TestCase end end + # Make sure we find our object and only our object + count = 0 + Puppet::Rails::Resource.find(:all).each do |obj| + count += 1 + [:title, :restype, :line, :exported].each do |param| + if param == :restype + method = :type + else + method = param + end + assert_equal(res.send(method), obj[param], + "attribute %s is incorrect" % param) + end + end + assert_equal(1, count, "Got too many resources") # Now make sure we can find it again assert_nothing_raised do - obj = Puppet::Rails::Resource.find_by_host_id_and_title( - host.id, res.title + obj = Puppet::Rails::Resource.find_by_restype_and_title( + res.type, res.title ) end assert_instance_of(Puppet::Rails::Resource, obj) # Make sure we get the parameters back - obj.parameters.each do |param| - assert_equal(res[param[:name]], param[:value], - "%s was different" % param[:name]) + params = [obj.param_names.collect { |p| p.name }, + res.to_hash.keys].flatten.collect { |n| n.to_s }.uniq + + params.each do |name| + param = obj.param_names.find_by_name(name) + if res[name] + assert(param, "resource did not keep %s" % name) + else + assert(! param, "resource did not delete %s" % name) + end + values = param.param_values.collect { |pv| pv.value } + should = res[param.name] + should = [should] unless should.is_a?(Array) + assert_equal(should, values, + "%s was different" % param.name) end end + + def test_to_rails + railsinit + res = mkresource :type => "file", :title => "/tmp/testing", + :source => @source, :scope => @scope, + :params => {:owner => "root", :source => ["/tmp/A", "/tmp/B"], + :mode => "755"} + + res.line = 50 + + # We also need a Rails Host to store under + host = Puppet::Rails::Host.new(:name => Facter.hostname) + + compare_resources(host, res) + + # Now make some changes to our resource. + res = mkresource :type => "file", :title => "/tmp/testing", + :source => @source, :scope => @scope, + :params => {:owner => "bin", :source => ["/tmp/A", "/tmp/C"], + :check => "checksum"} + + res.line = 75 + res.exported = true + + compare_resources(host, res) + end end end |
