summaryrefslogtreecommitdiffstats
path: root/test/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-09-22 15:04:34 -0500
committerLuke Kanies <luke@madstop.com>2007-09-22 15:04:34 -0500
commitd6e91ae78698bdbec818d383574f4c279735e172 (patch)
tree7072c2a71ef1c05c6a46b6050f52bf3d01ae2843 /test/lib
parenta66699596452f88d2bc467af4cff3f9a1aec3d1e (diff)
parent86dde63473d29c45d8698ce4edd53c820a621362 (diff)
Merge branch 'configurations' into indirection
Conflicts: lib/puppet/defaults.rb lib/puppet/indirector/facts/yaml.rb spec/unit/indirector/indirection.rb spec/unit/indirector/indirector.rb
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/puppettest/parsertesting.rb10
-rw-r--r--test/lib/puppettest/support/assertions.rb52
-rwxr-xr-xtest/lib/puppettest/support/resources.rb34
-rw-r--r--test/lib/puppettest/support/utils.rb38
4 files changed, 60 insertions, 74 deletions
diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb
index c4bd7dc2b..62fa7213e 100644
--- a/test/lib/puppettest/parsertesting.rb
+++ b/test/lib/puppettest/parsertesting.rb
@@ -308,17 +308,17 @@ module PuppetTest::ParserTesting
)
}
- config = nil
+ trans = nil
assert_nothing_raised {
- config = interp.compile(mknode)
+ trans = interp.compile(mknode)
}
- comp = nil
+ config = nil
assert_nothing_raised {
- comp = config.extract.to_type
+ config = trans.extract.to_configuration
}
- assert_apply(comp)
+ config.apply
files.each do |file|
assert(FileTest.exists?(file), "Did not create %s" % file)
diff --git a/test/lib/puppettest/support/assertions.rb b/test/lib/puppettest/support/assertions.rb
index 9369f17e7..7e3e5ca2b 100644
--- a/test/lib/puppettest/support/assertions.rb
+++ b/test/lib/puppettest/support/assertions.rb
@@ -38,7 +38,7 @@ module PuppetTest
run_events(:rollback, trans, events, msg)
end
- def assert_events(events, *items)
+ def assert_events(events, *resources)
trans = nil
comp = nil
msg = nil
@@ -46,56 +46,26 @@ module PuppetTest
unless events.is_a? Array
raise Puppet::DevError, "Incorrect call of assert_events"
end
- if items[-1].is_a? String
- msg = items.pop
+ if resources[-1].is_a? String
+ msg = resources.pop
end
- remove_comp = false
- # They either passed a comp or a list of items.
- if items[0].is_a? Puppet.type(:component)
- comp = items.shift
- else
- comp = newcomp(items[0].title, *items)
- remove_comp = true
- end
- msg ||= comp.title
- assert_nothing_raised("Component %s failed" % [msg]) {
- trans = comp.evaluate
- }
+ config = resources2config(*resources)
+ transaction = Puppet::Transaction.new(config)
- run_events(:evaluate, trans, events, msg)
+ run_events(:evaluate, transaction, events, msg)
- if remove_comp
- Puppet.type(:component).delete(comp)
- end
-
- return trans
+ return transaction
end
# A simpler method that just applies what we have.
- def assert_apply(*objects)
- if objects[0].is_a?(Puppet.type(:component))
- comp = objects.shift
- unless objects.empty?
- objects.each { |o| comp.push o }
- end
- else
- comp = newcomp(*objects)
- end
- trans = nil
-
- assert_nothing_raised("Failed to create transaction") {
- trans = comp.evaluate
- }
+ def assert_apply(*resources)
+ config = resources2config(*resources)
events = nil
- assert_nothing_raised("Failed to evaluate transaction") {
- events = trans.evaluate.collect { |e| e.event }
+ assert_nothing_raised("Failed to evaluate") {
+ events = config.apply.events
}
- trans.cleanup
- Puppet.type(:component).delete(comp)
events
end
end
-
-# $Id$
diff --git a/test/lib/puppettest/support/resources.rb b/test/lib/puppettest/support/resources.rb
index 45d89c5fb..18d7caa77 100755
--- a/test/lib/puppettest/support/resources.rb
+++ b/test/lib/puppettest/support/resources.rb
@@ -4,34 +4,34 @@
# Copyright (c) 2006. All rights reserved.
module PuppetTest::Support::Resources
- def treefile(name)
- Puppet::Type.type(:file).create :path => "/tmp/#{name}", :mode => 0755
+ def tree_resource(name)
+ Puppet::Type.type(:file).create :title => name, :path => "/tmp/#{name}", :mode => 0755
end
- def treecomp(name)
+ def tree_container(name)
Puppet::Type::Component.create :name => name, :type => "yay"
end
- def treenode(name, *children)
- comp = treecomp name
- children.each do |c|
- if c.is_a?(String)
- comp.push treefile(c)
- else
- comp.push c
+ def treenode(config, name, *resources)
+ comp = tree_container name
+ resources.each do |resource|
+ if resource.is_a?(String)
+ resource = tree_resource(resource)
end
+ config.add_edge!(comp, resource)
+ config.add_resource resource unless config.resource(resource.ref)
end
return comp
end
def mktree
- one = treenode("one", "a", "b")
- two = treenode("two", "c", "d")
- middle = treenode("middle", "e", "f", two)
- top = treenode("top", "g", "h", middle, one)
+ configuration = Puppet::Node::Configuration.new do |config|
+ one = treenode(config, "one", "a", "b")
+ two = treenode(config, "two", "c", "d")
+ middle = treenode(config, "middle", "e", "f", two)
+ top = treenode(config, "top", "g", "h", middle, one)
+ end
- return one, two, middle, top
+ return configuration
end
end
-
-# $Id$ \ No newline at end of file
diff --git a/test/lib/puppettest/support/utils.rb b/test/lib/puppettest/support/utils.rb
index c7d54d5e6..7f4260e31 100644
--- a/test/lib/puppettest/support/utils.rb
+++ b/test/lib/puppettest/support/utils.rb
@@ -19,6 +19,25 @@ module PuppetTest
}
end
+ # Turn a list of resources, or possibly a configuration and some resources,
+ # into a configuration object.
+ def resources2config(*resources)
+ if resources[0].is_a?(Puppet::Node::Configuration)
+ config = resources.shift
+ unless resources.empty?
+ resources.each { |r| config.add_resource r }
+ end
+ elsif resources[0].is_a?(Puppet.type(:component))
+ raise ArgumentError, "resource2config() no longer accpts components"
+ comp = resources.shift
+ comp.delve
+ else
+ config = Puppet::Node::Configuration.new
+ resources.each { |res| config.add_resource res }
+ end
+ return config
+ end
+
# stop any services that might be hanging around
def stopservices
if stype = Puppet::Type.type(:service)
@@ -127,20 +146,17 @@ module PuppetTest
}
end
- def newcomp(*ary)
- name = nil
- if ary[0].is_a?(String)
- name = ary.shift
+ def mk_configuration(*resources)
+ if resources[0].is_a?(String)
+ name = resources.shift
else
- name = ary[0].title
+ name = :testing
+ end
+ config = Puppet::Node::Configuration.new :testing do |conf|
+ resources.each { |resource| conf.add_resource resource }
end
- comp = Puppet.type(:component).create(:name => name)
- ary.each { |item|
- comp.push item
- }
-
- return comp
+ return config
end
def setme