summaryrefslogtreecommitdiffstats
path: root/test/rails
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-04-21 00:56:32 -0500
committerJames Turnbull <james@lovedthanlost.net>2009-04-22 14:39:40 +1000
commit93246c0c70796a606fc8c05b51e1feb09c94e377 (patch)
tree8a68d8f18c695469f3be85df1ae24d2c59dde401 /test/rails
parent5cb0f76f3ccb0b179de5f2735749ff91ae7346cc (diff)
downloadpuppet-93246c0c70796a606fc8c05b51e1feb09c94e377.tar.gz
puppet-93246c0c70796a606fc8c05b51e1feb09c94e377.tar.xz
puppet-93246c0c70796a606fc8c05b51e1feb09c94e377.zip
Removing the old rails tests.
They don't work with the modified code, and we rely almost entirely on manual integration testing for this stuff anyway. We definitely need to add tests where we can, but these tests are totally useless. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'test/rails')
-rwxr-xr-xtest/rails/configuration.rb71
-rwxr-xr-xtest/rails/host.rb154
-rwxr-xr-xtest/rails/railsresource.rb251
3 files changed, 0 insertions, 476 deletions
diff --git a/test/rails/configuration.rb b/test/rails/configuration.rb
deleted file mode 100755
index a878d1381..000000000
--- a/test/rails/configuration.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../lib/puppettest'
-
-require 'puppettest'
-require 'puppet/parser/parser'
-require 'puppet/network/client'
-require 'puppet/rails'
-require 'puppettest/resourcetesting'
-require 'puppettest/parsertesting'
-require 'puppettest/servertest'
-require 'puppettest/railstesting'
-
-
-class ConfigurationRailsTests < PuppetTest::TestCase
- include PuppetTest
- include PuppetTest::ServerTest
- include PuppetTest::ParserTesting
- include PuppetTest::ResourceTesting
- include PuppetTest::RailsTesting
- AST = Puppet::Parser::AST
- 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
- compile = mkcompiler
- parser = compile.parser
-
- node = parser.newnode [compile.node.name], :code => AST::ASTArray.new(:children => [
- resourcedef("file", "/tmp/yay", :group => "root"),
- defaultobj("file", :owner => "root")
- ])
-
- # Now do the rails crap
- Puppet[:storeconfigs] = true
-
- Puppet::Rails::Host.expects(:store).with do |node, resources|
- if res = resources.find { |r| r.type == "File" and r.title == "/tmp/yay" }
- assert_equal("root", res["owner"], "Did not set default on resource")
- true
- else
- raise "Resource was not passed to store()"
- end
- end
- compile.compile
- end
-
- def test_hoststorage
- assert_nothing_raised {
- Puppet[:storeconfigs] = true
- }
-
- Puppet[:code] = "file { \"/etc\": owner => root }"
-
- interp = Puppet::Parser::Interpreter.new
-
- facts = {}
- Facter.each { |fact, val| facts[fact] = val }
- node = mknode(facts["hostname"])
- node.parameters = facts
-
- objects = nil
- assert_nothing_raised {
- objects = interp.compile(node)
- }
-
- obj = Puppet::Rails::Host.find_by_name(node.name)
- assert(obj, "Could not find host object")
- end
-end
diff --git a/test/rails/host.rb b/test/rails/host.rb
deleted file mode 100755
index a7b17c3ae..000000000
--- a/test/rails/host.rb
+++ /dev/null
@@ -1,154 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../lib/puppettest'
-
-require 'puppet'
-require 'puppet/rails'
-require 'puppet/parser/interpreter'
-require 'puppet/parser/parser'
-require 'puppet/network/client'
-require 'puppettest'
-require 'puppettest/parsertesting'
-require 'puppettest/resourcetesting'
-require 'puppettest/railstesting'
-
-class TestRailsHost < PuppetTest::TestCase
- confine "Missing ActiveRecord" => Puppet.features.rails?
- include PuppetTest::ParserTesting
- include PuppetTest::ResourceTesting
- include PuppetTest::RailsTesting
-
- def setup
- super
- railsinit if Puppet.features.rails?
- end
-
- def teardown
- railsteardown if Puppet.features.rails?
- super
- end
-
- def test_includerails
- assert_nothing_raised {
- require 'puppet/rails'
- }
- end
-
- def test_store
- @scope = mkscope
- # First make some objects
- resources = []
- 4.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" => "myhost", "test1" => "funtest", "ipaddress" => "192.168.0.1"}
-
- # Now try storing our crap
- host = nil
- node = mknode(facts["hostname"])
- node.parameters = facts
- assert_nothing_raised {
- host = Puppet::Rails::Host.store(node, resources)
- }
-
- 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)[0].value, "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(8, count, "Did not get enough resources")
-
- # Now remove a couple of resources
- resources.reject! { |r| r.title =~ /file3/ }
-
- # Change a few resources
- resources.find_all { |r| r.title =~ /file2/ }.each do |r|
- r.send(:set_parameter, "loglevel", "notice")
- end
-
- # And add a new resource
- resources << mkresource(:type => "file",
- :title => "/tmp/file_added",
- :params => {:owner => "user_added"})
-
- # And change some facts
- facts["test2"] = "yaytest"
- facts["test3"] = "funtest"
- facts["test1"] = "changedfact"
- facts.delete("ipaddress")
- node = mknode(facts["hostname"])
- node.parameters = facts
- newhost = nil
- assert_nothing_raised {
- newhost = Puppet::Rails::Host.store(node, resources)
- }
-
- assert_equal(host.id, newhost.id, "Created new host instance)")
-
- # Make sure it sets the last_compile time
- assert_nothing_raised do
- assert_instance_of(Time, host.last_compile, "did not set last_compile")
- end
-
- assert_equal(0, host.fact('ipaddress').size, "removed fact was not deleted")
- facts.each do |fact, value|
- assert_equal(value, host.fact(fact)[0].value, "fact %s is wrong" % fact)
- end
-
- # And check the changes we made.
- assert(! host.resources.find(:all).detect { |r| r.title =~ /file3/ },
- "Removed resources are still present")
-
- res = host.resources.find_by_title("/tmp/file_added")
- assert(res, "New resource was not added")
- assert_equal("user_added", res.parameter("owner"), "user info was not stored")
-
- host.resources.find(:all, :conditions => [ "title like ?", "%file2%"]).each do |r|
- assert_equal("notice", r.parameter("loglevel"),
- "loglevel was not added")
- end
- end
-end
diff --git a/test/rails/railsresource.rb b/test/rails/railsresource.rb
deleted file mode 100755
index 3df5001be..000000000
--- a/test/rails/railsresource.rb
+++ /dev/null
@@ -1,251 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../lib/puppettest'
-
-require 'puppet'
-require 'puppet/rails'
-require 'puppettest'
-require 'puppettest/railstesting'
-require 'puppettest/resourcetesting'
-require 'puppettest/parsertesting'
-
-# Don't do any tests w/out this class
-if Puppet.features.rails?
-class TestRailsResource < Test::Unit::TestCase
- include PuppetTest::RailsTesting
- include PuppetTest::ResourceTesting
- include PuppetTest::ParserTesting
-
- def setup
- super
- railsinit
- end
-
- def teardown
- railsteardown
- super
- end
-
- def mktest_resource
- # We need a host for resources
- host = Puppet::Rails::Host.new(:name => "myhost")
- host.save
-
- # Now build a resource
- resource = host.resources.create(
- :title => "/tmp/to_resource",
- :restype => "file",
- :exported => true)
-
- # Now add some params
- params.each do |param, value|
- pn = Puppet::Rails::ParamName.find_or_create_by_name(param)
- pv = resource.param_values.create(:value => value,
- :param_name => pn)
- end
-
- host.save
-
- return resource
- end
-
- def params
- {"owner" => "root", "mode" => "644"}
- end
-
- # Create a resource param from a rails parameter
- def test_to_resource
- resource = mktest_resource
-
- # We need a scope
- scope = mkscope
-
- # Find the new resource and include all it's parameters.
- resource = Puppet::Rails::Resource.find_by_id(resource.id)
-
- # 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)
- assert_equal(scope.source, res.source)
- end
-
- def test_parameters
- resource = mktest_resource
- setparams = nil
- assert_nothing_raised do
- setparams = resource.parameters.inject({}) { |h, a|
- h[a[0]] = a[1][0]
- h
- }
- end
- assert_equal(params, setparams,
- "Did not get the right answer from #parameters")
- end
-
- # Make sure we can retrieve individual parameters by name.
- def test_parameter
- resource = mktest_resource
-
- params.each do |p,v|
- assert_equal(v, resource.parameter(p), "%s is not correct" % p)
- end
- end
-end
-else
- $stderr.puts "Install Rails for Rails and Caching tests"
-end
-
-# A separate class for testing rails integration
-class TestExportedResources < PuppetTest::TestCase
- include PuppetTest
- include PuppetTest::ParserTesting
- include PuppetTest::ResourceTesting
- include PuppetTest::RailsTesting
- Parser = Puppet::Parser
- AST = Parser::AST
- Reference = Puppet::Parser::Resource::Reference
-
- def setup
- super
- Puppet[:trace] = false
- @scope = mkscope
- end
-
- confine "Missing rails support" => Puppet.features.rails?
-
- # Compare a parser resource to a rails resource.
- def compare_resources(host, res, updating, options = {})
- newobj = nil
-
- # If the resource is in the db, then use modify_rails, else use to_rails
- if newobj = Puppet::Rails::Resource.find_by_restype_and_title(res.type, res.title)
- assert_nothing_raised("Call to modify_rails failed") do
- res.modify_rails(newobj)
- end
- else
- assert_nothing_raised("Call to to_rails failed") do
- newobj = res.to_rails(host)
- end
- end
-
- assert_instance_of(Puppet::Rails::Resource, newobj)
- newobj.save
-
- if updating
- tail = "on update"
- else
- tail = ""
- end
-
- # Make sure we find our object and only our object
- count = 0
- obj = nil
- Puppet::Rails::Resource.find(:all).each do |obj|
- assert_equal(newobj.id, obj.id, "A new resource was created instead of modifying an existing resource")
- 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 was not set correctly in rails %s" % [param, tail])
- end
- end
- assert_equal(1, count, "Got too many resources %s" % tail)
- # Now make sure we can find it again
- assert_nothing_raised do
- obj = Puppet::Rails::Resource.find_by_restype_and_title(
- res.type, res.title, :include => :param_names
- )
- end
- assert_instance_of(Puppet::Rails::Resource, obj)
-
- # Make sure we get the parameters back
- params = options[: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 %s" % [name, tail])
- else
- assert(! param, "resource did not delete %s %s" % [name, tail])
- end
- if param
- 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 %s" % [param.name, tail])
- end
- end
-
- return obj
- end
-
- def test_to_rails
- railsteardown
- railsinit
- ref1 = Reference.new :type => "exec", :title => "one"
- ref2 = Reference.new :type => "exec", :title => "two"
- res = mkresource :type => "file", :title => "/tmp/testing",
- :source => @source, :scope => @scope,
- :params => {:owner => "root", :source => ["/tmp/A", "/tmp/B"],
- :mode => "755", :require => [ref1, ref2], :subscribe => ref1}
-
- res.line = 50
-
- # We also need a Rails Host to store under
- host = Puppet::Rails::Host.new(:name => Facter.hostname)
-
- railsres = compare_resources(host, res, false, :params => %w{owner source mode})
-
- # Now make sure our parameters did not change
- assert_instance_of(Array, res[:require], "Parameter array changed")
- res[:require].each do |ref|
- assert_instance_of(Reference, ref, "Resource reference changed")
- end
- assert_instance_of(Reference, res[:subscribe], "Resource reference changed")
-
- # And make sure that the rails resource actually has resource references
- params = railsres.parameters
- [params["subscribe"], params["require"]].flatten.each do |ref|
- assert_instance_of(Reference, ref, "Resource reference is no longer a reference")
- end
-
- # Now make some changes to our resource. We're removing the mode,
- # changing the source, and adding 'check'.
- res = mkresource :type => "file", :title => "/tmp/testing",
- :source => @source, :scope => @scope,
- :params => {:owner => "bin", :source => ["/tmp/A", "/tmp/C"],
- :check => "checksum", :require => [ref1, ref2], :subscribe => ref2}
-
- res.line = 75
- res.exported = true
-
- railsres = compare_resources(host, res, true, :params => %w{owner source mode check})
-
- # Again make sure our parameters did not change
- assert_instance_of(Array, res[:require], "Parameter array changed")
- res[:require].each do |ref|
- assert_instance_of(Reference, ref, "Resource reference changed")
- end
-
- # Again with the serialization checks
- params = railsres.parameters
- [params["subscribe"], params["require"]].flatten.each do |ref|
- assert_instance_of(Reference, ref, "Resource reference is no longer a reference")
- end
-
- end
-end
-
-