diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/lib/puppettest/railstesting.rb | 10 | ||||
-rwxr-xr-x | test/rails/rails.rb | 11 | ||||
-rwxr-xr-x | test/rails/railsparameter.rb | 31 | ||||
-rwxr-xr-x | test/rails/railsresource.rb | 27 |
4 files changed, 41 insertions, 38 deletions
diff --git a/test/lib/puppettest/railstesting.rb b/test/lib/puppettest/railstesting.rb index 3a32d0c9e..e3b472b4f 100644 --- a/test/lib/puppettest/railstesting.rb +++ b/test/lib/puppettest/railstesting.rb @@ -14,16 +14,14 @@ module PuppetTest::RailsTesting host = Puppet::Rails::Host.new(:name => Facter.value("hostname")) # Now build a resource - resource = host.rails_resources.build( - :title => title, :restype => type, - :exported => true + resource = host.resources.build( + :title => title, :exported => true ) # Now add some params params.each do |param, value| - resource.rails_parameters.build( - :name => param, :value => value - ) + pvalue = ParamValue.new(:value => value) + resource.param_name.find_or_create_by_name(param).param_values << pvalue end # Now save the whole thing diff --git a/test/rails/rails.rb b/test/rails/rails.rb index 8be1bc66d..699d132a2 100755 --- a/test/rails/rails.rb +++ b/test/rails/rails.rb @@ -60,13 +60,14 @@ class TestRails < Test::Unit::TestCase } assert(host, "Could not find host object") - assert(host.rails_resources, "No objects on host") + assert(host.resources, "No objects on host") - assert_equal(facts["hostname"], host.facts["hostname"], + # This changed from a hash to a method call, hope that doesn't break anything! + assert_equal(facts["hostname"], host.facts("hostname"), "Did not retrieve facts") count = 0 - host.rails_resources.each do |resource| + host.resources.each do |resource| count += 1 i = nil if resource[:title] =~ /file([0-9]+)/ @@ -74,9 +75,7 @@ class TestRails < Test::Unit::TestCase else raise "Got weird resource %s" % resource.inspect end - - assert_equal("user#{i}", - resource.rails_parameters.find_by_name("owner")[:value]) + assert_equal("user#{i}", resource.parameters[:owner]) end assert_equal(20, count, "Did not get enough resources") diff --git a/test/rails/railsparameter.rb b/test/rails/railsparameter.rb index 46a12e57c..f76939ac9 100755 --- a/test/rails/railsparameter.rb +++ b/test/rails/railsparameter.rb @@ -16,32 +16,33 @@ class TestRailsParameter < Test::Unit::TestCase def test_to_resourceparam railsinit # First create our parameter - rparam = nil - hash = { :name => :myparam, :value => "myval", - :file => __FILE__, :line => __LINE__} + #FIXME Need to re-add file/line support + pname = { :name => "myname" } + pvalue = { :value => "myval" } + pn = Puppet::Rails::ParamName.new(:name => pname[:name]) + pv = Puppet::Rails::ParamValue.new(:value => pvalue[:value]) assert_nothing_raised do - rparam = Puppet::Rails::RailsParameter.new(hash) + pn.param_values << pv end - assert(rparam, "Did not create rails parameter") + assert(pn, "Did not create rails parameter") # The id doesn't get assigned until we save - rparam.save + pn.save # Now create a source interp = mkinterp source = interp.newclass "myclass" # And try to convert our parameter - pparam = nil - assert_nothing_raised do - pparam = rparam.to_resourceparam(source) - end - - - assert_instance_of(Puppet::Parser::Resource::Param, pparam) - hash.each do |name, value| - assert_equal(value, pparam.send(name), "%s was not equal" % name) + #FIXME Why does this assert prevent the block from executing? + #assert_nothing_raised do + pp = pn.to_resourceparam(source) + #end + + assert_instance_of(Puppet::Parser::Resource::Param, pp) + pname.each do |name, value| + assert_equal(value.to_sym, pp.send(name), "%s was not equal" % name) end end end diff --git a/test/rails/railsresource.rb b/test/rails/railsresource.rb index 666d26bcf..e109ba7d1 100755 --- a/test/rails/railsresource.rb +++ b/test/rails/railsresource.rb @@ -22,33 +22,38 @@ class TestRailsResource < Test::Unit::TestCase host = Puppet::Rails::Host.new(:name => "myhost") # Now build a resource - resource = host.rails_resources.build( - :title => "/tmp/to_resource", :restype => "file", - :exported => true - ) - + resource = host.resources.create( + :title => "/tmp/to_resource", + :exported => true) + + # For some reason the child class doesn't exist until after the resource is created. + # Probably an issue with the dynamic class generation. + resource.type = "PuppetFile" + resource.save + # Now add some params {"owner" => "root", "mode" => "644"}.each do |param, value| - resource.rails_parameters.build( - :name => param, :value => value - ) + pn = resource.param_names.find_or_create_by_name(param) + pv = pn.param_values.find_or_create_by_value(value) + resource.param_names << pn end # Now save the whole thing host.save - # Now, try to convert our resource to a real resource # We need a scope interp, scope, source = mkclassframing + # Find the new resource and include all it's parameters. + resource = Puppet::Rails::Resource.find_by_id(resource.id, :include => [ :param_names, :param_values ]) + + # Now, try to convert our resource to a real resource res = nil assert_nothing_raised do 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("/tmp/to_resource", res.title) |