summaryrefslogtreecommitdiffstats
path: root/test
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
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')
-rw-r--r--test/data/snippets/failmissingexecpath.pp14
-rwxr-xr-xtest/language/snippets.rb15
-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
-rwxr-xr-xtest/network/client/master.rb52
-rwxr-xr-xtest/network/handler/master.rb9
-rwxr-xr-xtest/other/dsl.rb2
-rwxr-xr-xtest/other/events.rb67
-rwxr-xr-xtest/other/overrides.rb6
-rwxr-xr-xtest/other/relationships.rb13
-rwxr-xr-xtest/other/report.rb14
-rwxr-xr-xtest/other/transactions.rb270
-rwxr-xr-xtest/ral/manager/type.rb94
-rwxr-xr-xtest/ral/providers/service.rb4
-rwxr-xr-xtest/ral/types/basic.rb11
-rwxr-xr-xtest/ral/types/component.rb113
-rwxr-xr-xtest/ral/types/cron.rb4
-rwxr-xr-xtest/ral/types/exec.rb10
-rwxr-xr-xtest/ral/types/file.rb38
-rwxr-xr-xtest/ral/types/file/target.rb6
-rwxr-xr-xtest/ral/types/fileignoresource.rb48
-rwxr-xr-xtest/ral/types/filesources.rb63
-rwxr-xr-xtest/ral/types/group.rb4
-rwxr-xr-xtest/ral/types/tidy.rb2
-rwxr-xr-xtest/ral/types/user.rb18
-rwxr-xr-xtest/util/config.rb148
-rwxr-xr-xtest/util/fact_store.rb67
-rwxr-xr-xtest/util/graph.rb108
30 files changed, 298 insertions, 1036 deletions
diff --git a/test/data/snippets/failmissingexecpath.pp b/test/data/snippets/failmissingexecpath.pp
deleted file mode 100644
index b03875547..000000000
--- a/test/data/snippets/failmissingexecpath.pp
+++ /dev/null
@@ -1,14 +0,0 @@
-define distloc($path) {
- file { "/tmp/exectesting1":
- ensure => file
- }
- exec { "exectest":
- command => "touch $path",
- subscribe => File["/tmp/exectesting1"],
- refreshonly => true
- }
-}
-
-distloc { yay:
- path => "/tmp/execdisttesting",
-}
diff --git a/test/language/snippets.rb b/test/language/snippets.rb
index ff8a09881..7168a81d8 100755
--- a/test/language/snippets.rb
+++ b/test/language/snippets.rb
@@ -197,7 +197,7 @@ class TestSnippets < Test::Unit::TestCase
def snippet_classpathtest
path = "/tmp/classtest"
- file = @file[path]
+ file = @configuration.resource(:file, path)
assert(file, "did not create file %s" % path)
assert_nothing_raised {
@@ -271,14 +271,6 @@ class TestSnippets < Test::Unit::TestCase
assert_mode_equal(0755, file)
end
- def snippet_failmissingexecpath
- file = "/tmp/exectesting1"
- execfile = "/tmp/execdisttesting"
- assert_file(file)
-
- assert_nil(Puppet::Type.type(:exec)["exectest"], "invalid exec was created")
- end
-
def snippet_selectorvalues
nums = %w{1 2 3 4 5}
files = nums.collect { |n|
@@ -473,8 +465,8 @@ class TestSnippets < Test::Unit::TestCase
:Local => true
)
facts = Puppet::Node::Facts.new("testhost", facts)
- Puppet::Node::Facts.stubs(:post)
- Puppet::Node::Facts.stubs(:get).returns(facts)
+ Puppet::Node::Facts.stubs(:save)
+ Puppet::Node::Facts.stubs(:find).returns(facts)
client = Puppet::Network::Client.master.new(
:Master => server,
:Cache => false
@@ -508,6 +500,7 @@ class TestSnippets < Test::Unit::TestCase
assert(obj.name)
}
}
+ @configuration = client.configuration
assert_nothing_raised {
self.send(mname)
}
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
diff --git a/test/network/client/master.rb b/test/network/client/master.rb
index a29254d16..2e9ed2752 100755
--- a/test/network/client/master.rb
+++ b/test/network/client/master.rb
@@ -88,51 +88,6 @@ class TestMasterClient < Test::Unit::TestCase
return master, objects
end
- def test_apply
- master, objects = mk_fake_client
-
- check = Proc.new do |hash|
- assert(objects.trans, "transaction was not created")
- trans = objects.trans
- hash[:yes].each do |m|
- assert_equal(1, trans.send(m.to_s + "?"), "did not call #{m} enough times")
- end
- hash[:no].each do |m|
- assert_equal(0, trans.send(m.to_s + "?"), "called #{m} too many times")
- end
- end
-
- # First try it with no arguments
- assert_nothing_raised do
- master.apply
- end
- check.call :yes => %w{evaluate cleanup addtimes}, :no => %w{report tags ignoreschedules}
- assert_equal(0, master.reported, "master sent report with reports disabled")
-
-
- # Now enable reporting and make sure the report method gets called
- Puppet[:report] = true
- assert_nothing_raised do
- master.apply
- end
- check.call :yes => %w{evaluate cleanup addtimes}, :no => %w{tags ignoreschedules}
- assert_equal(1, master.reported, "master did not send report")
-
- # Now try it with tags enabled
- assert_nothing_raised do
- master.apply("tags")
- end
- check.call :yes => %w{evaluate cleanup tags addtimes}, :no => %w{ignoreschedules}
- assert_equal(2, master.reported, "master did not send report")
-
- # and ignoreschedules
- assert_nothing_raised do
- master.apply("tags", true)
- end
- check.call :yes => %w{evaluate cleanup tags ignoreschedules addtimes}, :no => %w{}
- assert_equal(3, master.reported, "master did not send report")
- end
-
def test_getconfig
client = mkclient
@@ -167,9 +122,8 @@ class TestMasterClient < Test::Unit::TestCase
[:getplugins, :get_actual_config].each do |method|
assert($methodsrun.include?(method), "method %s was not run" % method)
end
-
- objects = client.objects
- assert(objects.finalized?, "objects were not finalized")
+
+ assert_instance_of(Puppet::Node::Configuration, client.configuration, "Configuration was not created")
end
def test_disable
@@ -233,7 +187,7 @@ class TestMasterClient < Test::Unit::TestCase
}
end
- # This method is supposed
+ # This method downloads files, and yields each file object if a block is given.
def test_download
source = tempfile()
dest = tempfile()
diff --git a/test/network/handler/master.rb b/test/network/handler/master.rb
index 9749c7bdf..df946fa33 100755
--- a/test/network/handler/master.rb
+++ b/test/network/handler/master.rb
@@ -76,9 +76,10 @@ class TestMaster < Test::Unit::TestCase
"Client is incorrectly up to date")
Puppet.config.use(:main)
+ config = nil
assert_nothing_raised {
- client.getconfig
- client.apply
+ config = client.getconfig
+ config.apply
}
# Now it should be up to date
@@ -113,8 +114,8 @@ class TestMaster < Test::Unit::TestCase
# Retrieve and apply the new config
assert_nothing_raised {
- client.getconfig
- client.apply
+ config = client.getconfig
+ config.apply
}
assert(client.fresh?(facts), "Client is not up to date")
diff --git a/test/other/dsl.rb b/test/other/dsl.rb
index f1fd1a1e9..59610cd0f 100755
--- a/test/other/dsl.rb
+++ b/test/other/dsl.rb
@@ -214,5 +214,3 @@ class TestDSL < Test::Unit::TestCase
assert_instance_of(Puppet::Parser::Resource, file)
end
end
-
-# $Id$
diff --git a/test/other/events.rb b/test/other/events.rb
index 802a701a3..b67ea05a1 100755
--- a/test/other/events.rb
+++ b/test/other/events.rb
@@ -23,7 +23,7 @@ class TestEvents < Test::Unit::TestCase
:subscribe => [[file.class.name, file.name]]
)
- comp = newcomp("eventtesting", file, exec)
+ comp = mk_configuration("eventtesting", file, exec)
trans = assert_events([:file_created, :triggered], comp)
@@ -44,56 +44,16 @@ class TestEvents < Test::Unit::TestCase
)
- comp = Puppet.type(:component).create(
- :name => "eventtesting"
- )
- comp.push exec
- trans = comp.evaluate
- events = nil
- assert_nothing_raised {
- events = trans.evaluate
- }
+ config = mk_configuration
+ config.add_resource file
+ config.add_resource exec
+ trans = config.apply
- assert_equal(1, events.length)
+ assert_equal(1, trans.events.length)
assert_equal(0, trans.triggered?(exec, :refresh))
end
- # Verify that one component can subscribe to another component and the "right"
- # thing happens
- def test_ladderrequire
- comps = {}
- objects = {}
- fname = tempfile()
- file = Puppet.type(:file).create(
- :name => tempfile(),
- :ensure => "file"
- )
-
- exec = Puppet.type(:exec).create(
- :name => "touch %s" % fname,
- :path => "/usr/bin:/bin",
- :refreshonly => true
- )
-
- fcomp = newcomp(file)
- ecomp = newcomp(exec)
- comp = newcomp("laddercomp", fcomp, ecomp)
-
- ecomp[:subscribe] = [[fcomp.class.name, fcomp.name]]
-
- comp.finalize
-
- trans = comp.evaluate
- events = nil
- assert_nothing_raised {
- events = trans.evaluate
- }
-
- assert(FileTest.exists?(fname), "#{fname} does not exist")
- #assert_equal(events.length, trans.triggered?(objects[:b], :refresh))
- end
-
def test_multiplerefreshes
files = []
@@ -115,7 +75,7 @@ class TestEvents < Test::Unit::TestCase
["file", f.name]
}
- comp = newcomp(exec, *files)
+ comp = mk_configuration(exec, *files)
assert_apply(comp)
assert(FileTest.exists?(fname), "Exec file did not get created")
@@ -147,17 +107,16 @@ class TestEvents < Test::Unit::TestCase
)
execs = [exec1, exec2, exec3]
- comp = newcomp(exec1,exec2,exec3)
+ config = mk_configuration(exec1,exec2,exec3)
- trans = comp.evaluate
- execs.each do |e| assert(trans.resources.vertex?(e), "%s is not in graph" % e.title) end
+ trans = Puppet::Transaction.new(config)
+ execs.each do |e| assert(config.vertex?(e), "%s is not in graph" % e.title) end
trans.prepare
- execs.each do |e| assert(trans.relgraph.vertex?(e), "%s is not in relgraph" % e.title) end
- reverse = trans.relgraph.reversal
+ execs.each do |e| assert(config.vertex?(e), "%s is not in relgraph" % e.title) end
+ reverse = trans.relationship_graph.reversal
execs.each do |e| assert(reverse.vertex?(e), "%s is not in reversed graph" % e.title) end
-
- assert_apply(comp)
+ config.apply
assert(FileTest.exists?(file), "File does not exist")
diff --git a/test/other/overrides.rb b/test/other/overrides.rb
index 2bc443980..9a7c4b8ba 100755
--- a/test/other/overrides.rb
+++ b/test/other/overrides.rb
@@ -90,12 +90,10 @@ class TestOverrides < Test::Unit::TestCase
}
}
- comp = newcomp("overrides", baseobj)
- children.each { |child| comp.push child }
+ config = mk_configuration(baseobj, *children)
assert_nothing_raised("Could not eval component") {
- trans = comp.evaluate
- trans.evaluate
+ config.apply
}
files.each { |path, mode|
diff --git a/test/other/relationships.rb b/test/other/relationships.rb
index a5c9db5dc..771b119ee 100755
--- a/test/other/relationships.rb
+++ b/test/other/relationships.rb
@@ -172,15 +172,12 @@ class TestRelationships < Test::Unit::TestCase
end
assert_equal([Puppet::Relationship[file, exec]], reqs)
- # Now make sure that these relationships are added to the transaction's
- # relgraph
- trans = Puppet::Transaction.new(newcomp(file, exec))
- assert_nothing_raised do
- trans.evaluate
+ # Now make sure that these relationships are added to the
+ # relationship graph
+ config = mk_configuration(file, exec)
+ config.apply do |trans|
+ assert(config.relationship_graph.edge?(file, exec), "autorequire edge was not created")
end
-
- graph = trans.relgraph
- assert(graph.edge?(file, exec), "autorequire edge was not created")
end
def test_requires?
diff --git a/test/other/report.rb b/test/other/report.rb
index c59881f72..7499c51e2 100755
--- a/test/other/report.rb
+++ b/test/other/report.rb
@@ -26,16 +26,10 @@ class TestReports < Test::Unit::TestCase
)
end
- comp = newcomp(*objects)
-
- trans = nil
- assert_nothing_raised("Failed to create transaction") {
- trans = comp.evaluate
- }
-
- assert_nothing_raised("Failed to evaluate transaction") {
- trans.evaluate
- }
+ config = mk_configuration(*objects)
+ # So the report works out.
+ config.retrieval_duration = 0.001
+ trans = config.apply
return trans.generate_report
end
diff --git a/test/other/transactions.rb b/test/other/transactions.rb
index bf5f65084..7d17a92e7 100755
--- a/test/other/transactions.rb
+++ b/test/other/transactions.rb
@@ -7,8 +7,6 @@ require 'puppettest'
require 'mocha'
require 'puppettest/support/resources'
-# $Id$
-
class TestTransactions < Test::Unit::TestCase
include PuppetTest::FileTesting
include PuppetTest::Support::Resources
@@ -133,7 +131,7 @@ class TestTransactions < Test::Unit::TestCase
inst = type.create :name => "yay"
# Create a transaction
- trans = Puppet::Transaction.new(newcomp(inst))
+ trans = Puppet::Transaction.new(mk_configuration(inst))
# Make sure prefetch works
assert_nothing_raised do
@@ -255,7 +253,7 @@ class TestTransactions < Test::Unit::TestCase
}
- component = newcomp("file",file)
+ component = mk_configuration("file",file)
require 'etc'
groupname = Etc.getgrgid(File.stat(file.name).gid).name
assert_nothing_raised() {
@@ -295,12 +293,11 @@ class TestTransactions < Test::Unit::TestCase
file[:check] = check
file[:group] = @groups[0]
- assert_apply(file)
+ config = mk_configuration(file)
+ config.apply
@@tmpfiles << execfile
- component = newcomp("both",file,exec)
-
# 'subscribe' expects an array of arrays
exec[:subscribe] = [[file.class.name,file.name]]
exec[:refreshonly] = true
@@ -317,7 +314,11 @@ class TestTransactions < Test::Unit::TestCase
file[:mode] = "755"
}
- trans = assert_events([:file_changed, :triggered], component)
+ # Make a new configuration so the resource relationships get
+ # set up.
+ config = mk_configuration(file, exec)
+
+ trans = assert_events([:file_changed, :triggered], config)
assert(FileTest.exists?(execfile), "Execfile does not exist")
File.unlink(execfile)
@@ -325,7 +326,7 @@ class TestTransactions < Test::Unit::TestCase
file[:group] = @groups[1]
}
- trans = assert_events([:file_changed, :triggered], component)
+ trans = assert_events([:file_changed, :triggered], config)
assert(FileTest.exists?(execfile), "Execfile does not exist")
end
@@ -343,24 +344,30 @@ class TestTransactions < Test::Unit::TestCase
file[:group] = @groups[0]
assert_apply(file)
- fcomp = newcomp("file",file)
- ecomp = newcomp("exec",exec)
+ config = Puppet::Node::Configuration.new
+ fcomp = Puppet::Type.type(:component).create(:name => "file")
+ config.add_resource fcomp
+ config.add_resource file
+ config.add_edge!(fcomp, file)
- component = newcomp("both",fcomp,ecomp)
+ ecomp = Puppet::Type.type(:component).create(:name => "exec")
+ config.add_resource ecomp
+ config.add_resource exec
+ config.add_edge!(ecomp, exec)
# 'subscribe' expects an array of arrays
#component[:require] = [[file.class.name,file.name]]
ecomp[:subscribe] = fcomp
exec[:refreshonly] = true
- trans = assert_events([], component)
+ trans = assert_events([], config)
assert_nothing_raised() {
file[:group] = @groups[1]
file[:mode] = "755"
}
- trans = assert_events([:file_changed, :file_changed, :triggered], component)
+ trans = assert_events([:file_changed, :file_changed, :triggered], config)
end
# Make sure that multiple subscriptions get triggered.
@@ -426,7 +433,8 @@ class TestTransactions < Test::Unit::TestCase
Puppet[:ignoreschedules] = false
file = Puppet.type(:file).create(
:name => tempfile(),
- :ensure => "file"
+ :ensure => "file",
+ :backup => false
)
fname = tempfile()
@@ -437,11 +445,10 @@ class TestTransactions < Test::Unit::TestCase
:subscribe => ["file", file.name]
)
- comp = newcomp(file,exec)
- comp.finalize
+ config = mk_configuration(file, exec)
# Run it once
- assert_apply(comp)
+ assert_apply(config)
assert(FileTest.exists?(fname), "File did not get created")
assert(!exec.scheduled?, "Exec is somehow scheduled")
@@ -451,7 +458,8 @@ class TestTransactions < Test::Unit::TestCase
file[:content] = "some content"
- assert_events([:file_changed, :triggered], comp)
+ assert_events([:file_changed, :triggered], config)
+
assert(FileTest.exists?(fname), "File did not get recreated")
# Now remove it, so it can get created again
@@ -469,7 +477,7 @@ class TestTransactions < Test::Unit::TestCase
assert(! file.insync?(file.retrieve), "Uh, file is in sync?")
- assert_events([:file_changed, :triggered], comp)
+ assert_events([:file_changed, :triggered], config)
assert(FileTest.exists?(fname), "File did not get recreated")
end
@@ -493,11 +501,9 @@ class TestTransactions < Test::Unit::TestCase
:ensure => :file
)
- comp = newcomp(exec, file1, file2)
-
- comp.finalize
+ config = mk_configuration(exec, file1, file2)
- assert_apply(comp)
+ assert_apply(config)
assert(! FileTest.exists?(file1[:path]),
"File got created even tho its dependency failed")
@@ -506,31 +512,27 @@ class TestTransactions < Test::Unit::TestCase
end
end
- def f(n)
- Puppet::Type.type(:file)["/tmp/#{n.to_s}"]
- end
-
def test_relationship_graph
- one, two, middle, top = mktree
+ config = mktree
+
+ config.meta_def(:f) do |name|
+ self.resource("File[%s]" % name)
+ end
- {one => two, "f" => "c", "h" => middle}.each do |source, target|
- if source.is_a?(String)
- source = f(source)
- end
- if target.is_a?(String)
- target = f(target)
- end
+ {"one" => "two", "File[f]" => "File[c]", "File[h]" => "middle"}.each do |source_ref, target_ref|
+ source = config.resource(source_ref) or raise "Missing %s" % source_ref
+ target = config.resource(target_ref) or raise "Missing %s" % target_ref
target[:require] = source
end
- trans = Puppet::Transaction.new(top)
+ trans = Puppet::Transaction.new(config)
graph = nil
assert_nothing_raised do
graph = trans.relationship_graph
end
-
- assert_instance_of(Puppet::PGraph, graph,
+
+ assert_instance_of(Puppet::Node::Configuration, graph,
"Did not get relationship graph")
# Make sure all of the components are gone
@@ -544,13 +546,13 @@ class TestTransactions < Test::Unit::TestCase
sorted = graph.topsort.reverse
# Now make sure the appropriate edges are there and are in the right order
- assert(graph.dependents(f(:f)).include?(f(:c)),
+ assert(graph.dependents(config.f(:f)).include?(config.f(:c)),
"c not marked a dep of f")
- assert(sorted.index(f(:c)) < sorted.index(f(:f)),
+ assert(sorted.index(config.f(:c)) < sorted.index(config.f(:f)),
"c is not before f")
- one.each do |o|
- two.each do |t|
+ config.resource("one").each do |o|
+ config.resource("two").each do |t|
assert(graph.dependents(o).include?(t),
"%s not marked a dep of %s" % [t.ref, o.ref])
assert(sorted.index(t) < sorted.index(o),
@@ -558,22 +560,22 @@ class TestTransactions < Test::Unit::TestCase
end
end
- trans.resources.leaves(middle).each do |child|
- assert(graph.dependents(f(:h)).include?(child),
+ trans.configuration.leaves(config.resource("middle")).each do |child|
+ assert(graph.dependents(config.f(:h)).include?(child),
"%s not marked a dep of h" % [child.ref])
- assert(sorted.index(child) < sorted.index(f(:h)),
+ assert(sorted.index(child) < sorted.index(config.f(:h)),
"%s is not before h" % child.ref)
end
# Lastly, make sure our 'g' vertex made it into the relationship
# graph, since it's not involved in any relationships.
- assert(graph.vertex?(f(:g)),
+ assert(graph.vertex?(config.f(:g)),
"Lost vertexes with no relations")
# Now make the reversal graph and make sure all of the vertices made it into that
reverse = graph.reversal
%w{a b c d e f g h}.each do |letter|
- file = f(letter)
+ file = config.f(letter)
assert(reverse.vertex?(file), "%s did not make it into reversal" % letter)
end
end
@@ -594,15 +596,15 @@ class TestTransactions < Test::Unit::TestCase
yay = Puppet::Type.newgenerator :title => "yay"
rah = Puppet::Type.newgenerator :title => "rah"
- comp = newcomp(yay, rah)
- trans = comp.evaluate
+ config = mk_configuration(yay, rah)
+ trans = Puppet::Transaction.new(config)
assert_nothing_raised do
trans.generate
end
%w{ya ra y r}.each do |name|
- assert(trans.resources.vertex?(Puppet::Type.type(:generator)[name]),
+ assert(trans.configuration.vertex?(Puppet::Type.type(:generator)[name]),
"Generated %s was not a vertex" % name)
assert($finished.include?(name), "%s was not finished" % name)
end
@@ -613,7 +615,7 @@ class TestTransactions < Test::Unit::TestCase
end
%w{ya ra y r}.each do |name|
- assert(!trans.resources.vertex?(Puppet::Type.type(:generator)[name]),
+ assert(!trans.configuration.vertex?(Puppet::Type.type(:generator)[name]),
"Generated vertex %s was not removed from graph" % name)
assert_nil(Puppet::Type.type(:generator)[name],
"Generated vertex %s was not removed from class" % name)
@@ -633,8 +635,8 @@ class TestTransactions < Test::Unit::TestCase
yay = Puppet::Type.newgenerator :title => "yay"
rah = Puppet::Type.newgenerator :title => "rah", :subscribe => yay
- comp = newcomp(yay, rah)
- trans = comp.evaluate
+ config = mk_configuration(yay, rah)
+ trans = Puppet::Transaction.new(config)
trans.prepare
@@ -645,13 +647,13 @@ class TestTransactions < Test::Unit::TestCase
end
ya = type["ya"]
assert(ya, "Did not generate ya")
- assert(trans.relgraph.vertex?(ya),
+ assert(trans.relationship_graph.vertex?(ya),
"Did not add ya to rel_graph")
# Now make sure the appropriate relationships were added
- assert(trans.relgraph.edge?(yay, ya),
+ assert(trans.relationship_graph.edge?(yay, ya),
"parent was not required by child")
- assert(! trans.relgraph.edge?(ya, rah),
+ assert(! trans.relationship_graph.edge?(ya, rah),
"generated child ya inherited depencency on rah")
# Now make sure it in turn eval_generates appropriately
@@ -662,7 +664,7 @@ class TestTransactions < Test::Unit::TestCase
%w{y}.each do |name|
res = type[name]
assert(res, "Did not generate %s" % name)
- assert(trans.relgraph.vertex?(res),
+ assert(trans.relationship_graph.vertex?(res),
"Did not add %s to rel_graph" % name)
assert($finished.include?("y"), "y was not finished")
end
@@ -670,7 +672,7 @@ class TestTransactions < Test::Unit::TestCase
assert_nothing_raised("failed to eval_generate with nil response") do
trans.eval_resource(type["y"])
end
- assert(trans.relgraph.edge?(yay, ya), "no edge was created for ya => yay")
+ assert(trans.relationship_graph.edge?(yay, ya), "no edge was created for ya => yay")
assert_nothing_raised("failed to apply rah") do
trans.eval_resource(rah)
@@ -678,15 +680,15 @@ class TestTransactions < Test::Unit::TestCase
ra = type["ra"]
assert(ra, "Did not generate ra")
- assert(trans.relgraph.vertex?(ra),
+ assert(trans.relationship_graph.vertex?(ra),
"Did not add ra to rel_graph" % name)
assert($finished.include?("ra"), "y was not finished")
# Now make sure this generated resource has the same relationships as
# the generating resource
- assert(! trans.relgraph.edge?(yay, ra),
+ assert(! trans.relationship_graph.edge?(yay, ra),
"rah passed its dependencies on to its children")
- assert(! trans.relgraph.edge?(ya, ra),
+ assert(! trans.relationship_graph.edge?(ya, ra),
"children have a direct relationship")
# Now make sure that cleanup gets rid of those generated types.
@@ -695,14 +697,14 @@ class TestTransactions < Test::Unit::TestCase
end
%w{ya ra y r}.each do |name|
- assert(!trans.relgraph.vertex?(type[name]),
+ assert(!trans.relationship_graph.vertex?(type[name]),
"Generated vertex %s was not removed from graph" % name)
assert_nil(type[name],
"Generated vertex %s was not removed from class" % name)
end
# Now, start over and make sure that everything gets evaluated.
- trans = comp.evaluate
+ trans = Puppet::Transaction.new(config)
$evaluated.clear
assert_nothing_raised do
trans.evaluate
@@ -711,54 +713,41 @@ class TestTransactions < Test::Unit::TestCase
assert_equal(%w{yay ya y rah ra r}, $evaluated,
"Not all resources were evaluated or not in the right order")
end
-
- def test_tags
- res = Puppet::Type.newfile :path => tempfile()
- comp = newcomp(res)
-
- # Make sure they default to none
- assert_equal([], comp.evaluate.tags)
-
- # Make sure we get the main tags
- Puppet[:tags] = %w{this is some tags}
- assert_equal(%w{this is some tags}, comp.evaluate.tags)
-
- # And make sure they get processed correctly
- Puppet[:tags] = ["one", "two,three", "four"]
- assert_equal(%w{one two three four}, comp.evaluate.tags)
-
- # lastly, make sure we can override them
- trans = comp.evaluate
- trans.tags = ["one", "two,three", "four"]
- assert_equal(%w{one two three four}, comp.evaluate.tags)
+
+ def test_ignore_tags?
+ config = Puppet::Node::Configuration.new
+ config.host_config = true
+ transaction = Puppet::Transaction.new(config)
+ assert(! transaction.ignore_tags?, "Ignoring tags when applying a host configuration")
+
+ config.host_config = false
+ transaction = Puppet::Transaction.new(config)
+ assert(transaction.ignore_tags?, "Not ignoring tags when applying a non-host configuration")
end
- def test_tagged?
- res = Puppet::Type.newfile :path => tempfile()
- comp = newcomp(res)
- trans = comp.evaluate
-
- assert(trans.tagged?(res), "tagged? defaulted to false")
-
- # Now set some tags
- trans.tags = %w{some tags}
-
- # And make sure it's false
- assert(! trans.tagged?(res), "matched invalid tags")
-
- # Set ignoretags and make sure it sticks
- trans.ignoretags = true
- assert(trans.tagged?(res), "tags were not ignored")
-
- # Now make sure we actually correctly match tags
- res[:tag] = "mytag"
- trans.ignoretags = false
- trans.tags = %w{notag}
-
- assert(! trans.tagged?(res), "tags incorrectly matched")
-
- trans.tags = %w{mytag yaytag}
- assert(trans.tagged?(res), "tags should have matched")
+ def test_missing_tags?
+ resource = stub 'resource', :tagged? => true
+ config = Puppet::Node::Configuration.new
+
+ # Mark it as a host config so we don't care which test is first
+ config.host_config = true
+ transaction = Puppet::Transaction.new(config)
+ assert(! transaction.missing_tags?(resource), "Considered a resource to be missing tags when none are set")
+
+ # host configurations pay attention to tags, no one else does.
+ Puppet[:tags] = "three,four"
+ config.host_config = false
+ transaction = Puppet::Transaction.new(config)
+ assert(! transaction.missing_tags?(resource), "Considered a resource to be missing tags when not running a host configuration")
+
+ #
+ config.host_config = true
+ transaction = Puppet::Transaction.new(config)
+ assert(! transaction.missing_tags?(resource), "Considered a resource to be missing tags when running a host configuration and all tags are present")
+
+ transaction = Puppet::Transaction.new(config)
+ resource.stubs :tagged? => false
+ assert(transaction.missing_tags?(resource), "Considered a resource not to be missing tags when running a host configuration and tags are missing")
end
# Make sure changes generated by eval_generated resources have proxies
@@ -772,8 +761,8 @@ class TestTransactions < Test::Unit::TestCase
end
resource = type.create :name => "test"
- comp = newcomp(resource)
- trans = comp.evaluate
+ config = mk_configuration(resource)
+ trans = Puppet::Transaction.new(config)
trans.prepare
assert_nothing_raised do
@@ -831,7 +820,7 @@ class TestTransactions < Test::Unit::TestCase
end
# Make a graph with some stuff in it.
- graph = Puppet::PGraph.new
+ graph = Puppet::Node::Configuration.new
# Add a non-triggering edge.
a = trigger.new(:a)
@@ -883,52 +872,12 @@ class TestTransactions < Test::Unit::TestCase
assert(trans.triggered?(c, :refresh),
"Transaction did not store the trigger")
end
-
- def test_graph
- Puppet.config.use(:main)
- # Make a graph
- graph = Puppet::PGraph.new
- graph.add_edge!("a", "b")
-
- # Create our transaction
- trans = Puppet::Transaction.new(graph)
-
- assert_nothing_raised do
- trans.graph(graph, :testing)
- end
-
- dotfile = File.join(Puppet[:graphdir], "testing.dot")
- assert(! FileTest.exists?(dotfile), "Enabled graphing even tho disabled")
-
- # Now enable graphing
- Puppet[:graph] = true
-
- assert_nothing_raised do
- trans.graph(graph, :testing)
- end
- assert(FileTest.exists?(dotfile), "Did not create graph.")
- end
-
- def test_created_graphs
- FileUtils.mkdir_p(Puppet[:graphdir])
- file = Puppet::Type.newfile(:path => tempfile, :content => "yay")
- exec = Puppet::Type.type(:exec).create(:command => "echo yay", :path => ENV['PATH'],
- :require => file)
-
- Puppet[:graph] = true
- assert_apply(file, exec)
-
- %w{resources relationships expanded_relationships}.each do |name|
- file = File.join(Puppet[:graphdir], "%s.dot" % name)
- assert(FileTest.exists?(file), "graph for %s was not created" % name)
- end
- end
def test_set_target
file = Puppet::Type.newfile(:path => tempfile(), :content => "yay")
exec1 = Puppet::Type.type(:exec).create :command => "/bin/echo exec1"
exec2 = Puppet::Type.type(:exec).create :command => "/bin/echo exec2"
- trans = Puppet::Transaction.new(newcomp(file, exec1, exec2))
+ trans = Puppet::Transaction.new(mk_configuration(file, exec1, exec2))
# First try it with an edge that has no callback
edge = Puppet::Relationship.new(file, exec1)
@@ -975,7 +924,8 @@ class TestTransactions < Test::Unit::TestCase
one[:require] = two
two[:require] = one
- trans = newcomp(one, two).evaluate
+ config = mk_configuration(one, two)
+ trans = Puppet::Transaction.new(config)
assert_raise(Puppet::Error) do
trans.prepare
end
@@ -1042,15 +992,15 @@ class TestTransactions < Test::Unit::TestCase
rels[dir] = file
rels.each do |after, before|
- comp = newcomp(before, after)
- trans = comp.evaluate
+ config = mk_configuration(before, after)
+ trans = Puppet::Transaction.new(config)
str = "from %s to %s" % [before, after]
assert_nothing_raised("Failed to create graph %s" % str) do
trans.prepare
end
- graph = trans.relgraph
+ graph = trans.relationship_graph
assert(graph.edge?(before, after), "did not create manual relationship %s" % str)
assert(! graph.edge?(after, before), "created automatic relationship %s" % str)
end
@@ -1063,7 +1013,7 @@ class TestTransactions < Test::Unit::TestCase
one[:require] = two
one[:subscribe] = two
- comp = newcomp(one, two)
+ comp = mk_configuration(one, two)
trans = Puppet::Transaction.new(comp)
graph = trans.relationship_graph
@@ -1188,5 +1138,3 @@ class TestTransactions < Test::Unit::TestCase
assert_equal(1, $flushed, "object was flushed in noop")
end
end
-
-# $Id$
diff --git a/test/ral/manager/type.rb b/test/ral/manager/type.rb
index 534c35759..b2c111e60 100755
--- a/test/ral/manager/type.rb
+++ b/test/ral/manager/type.rb
@@ -174,7 +174,7 @@ class TestType < Test::Unit::TestCase
)
}
- comp = newcomp(twoobj, oneobj)
+ comp = mk_configuration(twoobj, oneobj)
assert_nothing_raised {
comp.finalize
@@ -246,76 +246,6 @@ class TestType < Test::Unit::TestCase
# and make sure managed objects start with them
assert(user.property(:ensure), "User did not get an ensure property")
end
-
- # Make sure removal works
- def test_remove
- objects = {}
- top = Puppet.type(:component).create(:name => "top")
- objects[top.class] = top
-
- base = tempfile()
-
- # now make a two-tier, 5 piece tree
- %w{a b}.each do |letter|
- name = "comp%s" % letter
- comp = Puppet.type(:component).create(:name => name)
- top.push comp
- objects[comp.class] = comp
-
- 5.times do |i|
- file = base + letter + i.to_s
-
- obj = Puppet.type(:file).create(:name => file, :ensure => "file")
-
- comp.push obj
- objects[obj.class] = obj
- end
- end
-
- assert_nothing_raised do
- top.remove
- end
-
- objects.each do |klass, obj|
- assert_nil(klass[obj.name], "object %s was not removed" % obj.name)
- end
- end
-
- # Verify that objects can't be their own children.
- def test_object_recursion
- comp = Puppet.type(:component).create(:name => "top")
-
- file = Puppet.type(:component).create(:name => "middle")
-
- assert_raise(Puppet::DevError) do
- comp.push(comp)
- end
-
- assert_raise(Puppet::DevError) do
- file.push(file)
- end
-
- assert_raise(Puppet::DevError) do
- comp.parent = comp
- end
-
- assert_raise(Puppet::DevError) do
- file.parent = file
- end
-
- assert_nothing_raised {
- comp.push(file)
- }
-
- assert_raise(Puppet::DevError) do
- file.push(comp)
- end
-
- assert_raise(Puppet::DevError) do
- comp.parent = file
- end
- end
-
def test_newtype_methods
assert_nothing_raised {
Puppet::Type.newtype(:mytype) do
@@ -732,12 +662,22 @@ class TestType < Test::Unit::TestCase
end
def test_path
+ config = mk_configuration
+
# Check that our paths are built correctly. Just pick a random, "normal" type.
type = Puppet::Type.type(:exec)
mk = Proc.new do |i, hash|
hash[:title] = "exec%s" % i
hash[:command] = "/bin/echo"
- type.create(hash)
+ if parent = hash[:parent]
+ hash.delete(:parent)
+ end
+ res = type.create(hash)
+ config.add_resource res
+ if parent
+ config.add_edge!(parent, res)
+ end
+ res
end
exec = mk.call(1, {})
@@ -745,25 +685,31 @@ class TestType < Test::Unit::TestCase
assert_equal("/Exec[exec1]", exec.path)
comp = Puppet::Type.newcomponent :title => "My[component]", :type => "Yay"
+ config.add_resource comp
exec = mk.call(2, :parent => comp)
assert_equal("/My[component]/Exec[exec2]", exec.path)
comp = Puppet::Type.newcomponent :name => "Other[thing]"
+ config.add_resource comp
exec = mk.call(3, :parent => comp)
assert_equal("/Other[thing]/Exec[exec3]", exec.path)
comp = Puppet::Type.newcomponent :type => "server", :name => "server"
+ config.add_resource comp
exec = mk.call(4, :parent => comp)
assert_equal("/server/Exec[exec4]", exec.path)
comp = Puppet::Type.newcomponent :type => "whatever", :name => "class[main]"
+ config.add_resource comp
exec = mk.call(5, :parent => comp)
assert_equal("//Exec[exec5]", exec.path)
- comp = Puppet::Type.newcomponent :type => "yay", :name => "Good[bad]", :parent => comp
- exec = mk.call(6, :parent => comp)
+ newcomp = Puppet::Type.newcomponent :type => "yay", :name => "Good[bad]"
+ config.add_resource newcomp
+ config.add_edge! comp, newcomp
+ exec = mk.call(6, :parent => newcomp)
assert_equal("//Good[bad]/Exec[exec6]", exec.path)
end
diff --git a/test/ral/providers/service.rb b/test/ral/providers/service.rb
index d21298162..5a4a6c1c2 100755
--- a/test/ral/providers/service.rb
+++ b/test/ral/providers/service.rb
@@ -54,7 +54,7 @@ class TestLocalService < Test::Unit::TestCase
service.retrieve
}
- comp = newcomp("servicetst", service)
+ comp = mk_configuration("servicetst", service)
service[:ensure] = :running
Puppet.info "Starting %s" % service.name
@@ -105,7 +105,7 @@ class TestLocalService < Test::Unit::TestCase
service.retrieve
}
- comp = newcomp("servicetst", service)
+ comp = mk_configuration("servicetst", service)
service[:enable] = true
Puppet.info "Enabling %s" % service.name
diff --git a/test/ral/types/basic.rb b/test/ral/types/basic.rb
index 5d09a5183..2802f3440 100755
--- a/test/ral/types/basic.rb
+++ b/test/ral/types/basic.rb
@@ -35,12 +35,9 @@ class TestBasic < Test::Unit::TestCase
:path => ENV["PATH"]
)
}
- assert_nothing_raised() {
- @component.push(
- @configfile,
- @command
- )
- }
+ @config = mk_configuration(@component, @configfile, @command)
+ @config.add_edge! @component, @configfile
+ @config.add_edge! @component, @command
end
def teardown
@@ -86,5 +83,3 @@ class TestBasic < Test::Unit::TestCase
}
end
end
-
-# $Id$
diff --git a/test/ral/types/component.rb b/test/ral/types/component.rb
deleted file mode 100755
index 06c32dd01..000000000
--- a/test/ral/types/component.rb
+++ /dev/null
@@ -1,113 +0,0 @@
-#!/usr/bin/env ruby
-
-$:.unshift("../../lib") if __FILE__ =~ /\.rb$/
-
-require 'puppettest'
-require 'puppettest/support/resources'
-
-# $Id$
-
-class TestComponent < Test::Unit::TestCase
- include PuppetTest
- include PuppetTest::Support::Resources
- def setup
- super
- @@used = {}
- @type = Puppet::Type::Component
- @file = Puppet::Type.type(:file)
- end
-
- def randnum(limit)
- num = nil
- looped = 0
- loop do
- looped += 1
- if looped > 2000
- raise "Reached limit of looping"
- break
- end
- num = rand(limit)
- unless @@used.include?(num)
- @@used[num] = true
- break
- end
- end
-
- num
- end
-
- def mkfile(num = nil)
- unless num
- num = randnum(1000)
- end
- name = tempfile() + num.to_s
-
- file = Puppet.type(:file).create(
- :path => name,
- :checksum => "md5"
- )
- @@tmpfiles << name
- file
- end
-
- def mkcomp
- Puppet.type(:component).create(:name => "component_" + randnum(1000).to_s)
- end
-
- def mkrandcomp(numfiles, numdivs)
- comp = mkcomp
- hash = {}
- found = 0
-
- divs = {}
-
- numdivs.times { |i|
- num = i + 2
- divs[num] = nil
- }
- while found < numfiles
- num = randnum(numfiles)
- found += 1
- f = mkfile(num)
- hash[f.name] = f
- reqd = []
- divs.each { |n,obj|
- if rand(50) % n == 0
- if obj
- unless reqd.include?(obj.object_id)
- f[:require] = [[obj.class.name, obj.name]]
- reqd << obj.object_id
- end
- end
- end
-
- divs[n] = f
- }
- end
-
- hash.each { |name, obj|
- comp.push obj
- }
-
- comp.finalize
- comp
- end
-
- def test_to_graph
- one, two, middle, top = mktree
-
- graph = nil
- assert_nothing_raised do
- graph = top.to_graph
- end
-
- assert(graph.is_a?(Puppet::PGraph), "result is not a pgraph")
-
- [one, two, middle, top].each do |comp|
- comp.each do |child|
- assert(graph.edge?(comp, child),
- "Did not create edge from %s => %s" % [comp.name, child.name])
- end
- end
- end
-end
diff --git a/test/ral/types/cron.rb b/test/ral/types/cron.rb
index 7b2e770f0..1695befac 100755
--- a/test/ral/types/cron.rb
+++ b/test/ral/types/cron.rb
@@ -94,7 +94,7 @@ class TestCron < Test::Unit::TestCase
text = obj.read
name = cron.name
- comp = newcomp(name, cron)
+ comp = mk_configuration(name, cron)
assert_events([:cron_created], comp)
cron.provider.class.prefetch
@@ -157,7 +157,7 @@ class TestCron < Test::Unit::TestCase
def test_makeandretrievecron
%w{storeandretrieve a-name another-name more_naming SomeName}.each do |name|
cron = mkcron(name)
- comp = newcomp(name, cron)
+ comp = mk_configuration(name, cron)
trans = assert_events([:cron_created], comp, name)
cron.provider.class.prefetch
diff --git a/test/ral/types/exec.rb b/test/ral/types/exec.rb
index ede6361cd..0c7cc1d90 100755
--- a/test/ral/types/exec.rb
+++ b/test/ral/types/exec.rb
@@ -179,7 +179,7 @@ class TestExec < Test::Unit::TestCase
)
}
- comp = newcomp("createstest", exec)
+ comp = mk_configuration("createstest", exec)
assert_events([:executed_command], comp, "creates")
assert_events([], comp, "creates")
end
@@ -202,7 +202,7 @@ class TestExec < Test::Unit::TestCase
:require => [:file, oexe]
)
- comp = newcomp("Testing", file, exec)
+ comp = mk_configuration("Testing", file, exec)
assert_events([:file_created, :executed_command], comp)
end
@@ -299,7 +299,7 @@ class TestExec < Test::Unit::TestCase
:path => ENV['PATH']
)
}
- comp = newcomp(exec)
+ comp = mk_configuration(exec)
assert_events([:executed_command], comp)
assert_events([:executed_command], comp)
@@ -344,7 +344,7 @@ class TestExec < Test::Unit::TestCase
exec = Puppet.type(:exec).create(args)
}
- comp = newcomp("usertest", exec)
+ comp = mk_configuration("usertest", exec)
assert_events([:executed_command], comp, "usertest")
assert(FileTest.exists?(file), "File does not exist")
@@ -425,7 +425,7 @@ class TestExec < Test::Unit::TestCase
)
}
- comp = newcomp(file, exec)
+ comp = mk_configuration(file, exec)
comp.finalize
assert_events([:executed_command, :file_changed], comp)
diff --git a/test/ral/types/file.rb b/test/ral/types/file.rb
index f3e1a562d..0c16d6dff 100755
--- a/test/ral/types/file.rb
+++ b/test/ral/types/file.rb
@@ -122,7 +122,7 @@ class TestFile < Test::Unit::TestCase
)
}
- comp = newcomp("createusertest", file)
+ comp = mk_configuration("createusertest", file)
assert_events([:file_created], comp)
end
@@ -397,6 +397,8 @@ class TestFile < Test::Unit::TestCase
events = assert_apply(file)
+ assert(events)
+
assert(! events.include?(:file_changed),
"File incorrectly changed")
assert_events([], file)
@@ -493,6 +495,7 @@ class TestFile < Test::Unit::TestCase
# Create a test directory
path = tempfile()
dir = @file.create :path => path, :mode => 0755, :recurse => true
+ config = mk_configuration(dir)
Dir.mkdir(path)
@@ -673,6 +676,7 @@ class TestFile < Test::Unit::TestCase
:check => %w{owner mode group}
)
}
+ config = mk_configuration dir
children = nil
@@ -683,19 +687,22 @@ class TestFile < Test::Unit::TestCase
assert_equal([subdir], children.collect {|c| c.title },
"Incorrect generated children")
- dir.class[subdir].remove
+ # Remove our subdir resource,
+ subdir_resource = config.resource(:file, subdir)
+ config.remove_resource(subdir_resource)
+ # Create the test file
File.open(tmpfile, "w") { |f| f.puts "yayness" }
assert_nothing_raised {
children = dir.eval_generate
}
+ # And make sure we get both resources back.
assert_equal([subdir, tmpfile].sort, children.collect {|c| c.title }.sort,
- "Incorrect generated children")
+ "Incorrect generated children when recurse == %s" % value.inspect)
File.unlink(tmpfile)
- #system("rm -rf %s" % basedir)
Puppet.type(:file).clear
end
end
@@ -754,6 +761,7 @@ class TestFile < Test::Unit::TestCase
:check => %w{owner mode group}
)
}
+ mk_configuration dir
assert_nothing_raised {
dir.eval_generate
@@ -796,6 +804,7 @@ class TestFile < Test::Unit::TestCase
:check => %w{mode owner group}
)
}
+ mk_configuration dirobj
assert_nothing_raised {
dirobj.eval_generate
@@ -884,7 +893,7 @@ class TestFile < Test::Unit::TestCase
)
}
- comp = newcomp("yay", file)
+ comp = mk_configuration("yay", file)
comp.finalize
assert_apply(comp)
#assert_events([:directory_created], comp)
@@ -1274,26 +1283,27 @@ class TestFile < Test::Unit::TestCase
lfobj = Puppet::Type.newfile(
:title => "localfile",
:path => localfile,
- :content => "rahtest"
+ :content => "rahtest",
+ :backup => false
)
-
destobj = Puppet::Type.newfile(:title => "destdir", :path => destdir,
:source => sourcedir,
+ :backup => false,
:recurse => true)
- comp = newcomp(lfobj, destobj)
- assert_apply(comp)
+ config = mk_configuration(lfobj, destobj)
+ config.apply
assert(FileTest.exists?(dsourcefile), "File did not get copied")
assert(FileTest.exists?(localfile), "File did not get created")
assert(FileTest.exists?(purgee), "File got prematurely purged")
assert_nothing_raised { destobj[:purge] = true }
- assert_apply(comp)
+ config.apply
- assert(FileTest.exists?(dsourcefile), "Source file got purged")
assert(FileTest.exists?(localfile), "Local file got purged")
+ assert(FileTest.exists?(dsourcefile), "Source file got purged")
assert(! FileTest.exists?(purgee), "File did not get purged")
end
@@ -1333,7 +1343,7 @@ class TestFile < Test::Unit::TestCase
group = Puppet.type(:group).create(
:name => "pptestg"
)
- comp = newcomp(user, group, home)
+ comp = mk_configuration(user, group, home)
}
# Now make sure we get a relationship for each of these
@@ -1629,6 +1639,7 @@ class TestFile < Test::Unit::TestCase
file = File.join(dir, "file")
File.open(file, "w") { |f| f.puts "" }
obj = Puppet::Type.newfile :path => dir, :recurse => true, :mode => 0755
+ mk_configuration obj
assert_equal("/%s" % obj.ref, obj.path)
@@ -1739,6 +1750,7 @@ class TestFile < Test::Unit::TestCase
File.open(file, "w") { |f| f.puts "yay" }
File.chmod(0644, file)
obj = Puppet::Type.newfile(:path => dir, :mode => 0750, :recurse => "2")
+ config = mk_configuration(obj)
children = nil
assert_nothing_raised("Failure when recursing") do
@@ -1747,6 +1759,7 @@ class TestFile < Test::Unit::TestCase
assert(obj.class[subdir], "did not create subdir object")
children.each do |c|
assert_nothing_raised("Failure when recursing on %s" % c) do
+ c.configuration = config
others = c.eval_generate
end
end
@@ -1780,6 +1793,7 @@ class TestFile < Test::Unit::TestCase
obj = Puppet::Type.newfile(:path => dir, :ensure => :directory,
:recurse => true)
+ config = mk_configuration(obj)
children = nil
assert_nothing_raised do
children = obj.eval_generate
diff --git a/test/ral/types/file/target.rb b/test/ral/types/file/target.rb
index 1e62f07ac..c4597cedf 100755
--- a/test/ral/types/file/target.rb
+++ b/test/ral/types/file/target.rb
@@ -44,6 +44,7 @@ class TestFileTarget < Test::Unit::TestCase
def test_linkrecurse
dest = tempfile()
link = @file.create :path => tempfile(), :recurse => true, :ensure => dest
+ mk_configuration link
ret = nil
@@ -317,9 +318,8 @@ class TestFileTarget < Test::Unit::TestCase
:source => dirs["source"],
:recurse => true
)
-
-
- trans = assert_apply(obj)
+ config = mk_configuration obj
+ config.apply
newfile = File.join(dirs["target"], "sourcefile")
diff --git a/test/ral/types/fileignoresource.rb b/test/ral/types/fileignoresource.rb
index fa01aecdc..153946770 100755
--- a/test/ral/types/fileignoresource.rb
+++ b/test/ral/types/fileignoresource.rb
@@ -73,19 +73,8 @@ class TestFileIgnoreSources < Test::Unit::TestCase
)
}
- #make a component and adds the file
- comp = Puppet.type(:component).create(
- :name => "component"
- )
- comp.push tofile
-
- #make, evaluate transaction and sync the component
- assert_nothing_raised {
- trans = comp.evaluate
- }
- assert_nothing_raised {
- trans.evaluate
- }
+ config = mk_configuration(tofile)
+ config.apply
#topath should exist as a directory with sourcedir as a directory
@@ -150,19 +139,8 @@ class TestFileIgnoreSources < Test::Unit::TestCase
)
}
- #make a component and adds the file
- comp = Puppet.type(:component).create(
- :name => "component"
- )
- comp.push tofile
-
- #make, evaluate transaction and sync the component
- assert_nothing_raised {
- trans = comp.evaluate
- }
- assert_nothing_raised {
- trans.evaluate
- }
+ config = mk_configuration(tofile)
+ config.apply
#topath should exist as a directory with sourcedir as a directory
@@ -170,6 +148,7 @@ class TestFileIgnoreSources < Test::Unit::TestCase
assert(FileTest.exists?(File.join(topath,sourcefile1)))
assert(FileTest.exists?(File.join(topath,subdir)))
assert(FileTest.exists?(File.join(File.join(topath,subdir),sourcefile1)))
+
#This file should not
assert(!(FileTest.exists?(File.join(topath,sourcefile2))))
assert(!(FileTest.exists?(File.join(topath,subdir2))))
@@ -235,19 +214,8 @@ class TestFileIgnoreSources < Test::Unit::TestCase
)
}
- #make a component and adds the file
- comp = Puppet.type(:component).create(
- :name => "component"
- )
- comp.push tofile
-
- #make, evaluate transaction and sync the component
- assert_nothing_raised {
- trans = comp.evaluate
- }
- assert_nothing_raised {
- trans.evaluate
- }
+ config = mk_configuration(tofile)
+ config.apply
#topath should exist as a directory with sourcedir as a directory
@@ -273,5 +241,3 @@ class TestFileIgnoreSources < Test::Unit::TestCase
end
end
-
-# $Id$
diff --git a/test/ral/types/filesources.rb b/test/ral/types/filesources.rb
index b257fd935..01d9766db 100755
--- a/test/ral/types/filesources.rb
+++ b/test/ral/types/filesources.rb
@@ -62,6 +62,7 @@ class TestFileSources < Test::Unit::TestCase
:name => path
)
}
+ config = mk_configuration(file)
child = nil
assert_nothing_raised {
child = file.newchild("childtest", true)
@@ -275,6 +276,7 @@ class TestFileSources < Test::Unit::TestCase
# The sourcerecurse method will only ever get called when we're
# recursing, so we go ahead and set it.
obj = Puppet::Type.newfile :source => source, :path => dest, :recurse => true
+ config = mk_configuration(obj)
result = nil
sourced = nil
@@ -288,7 +290,7 @@ class TestFileSources < Test::Unit::TestCase
assert_equal([dfileobj], result)
# Clean this up so it can be recreated
- dfileobj.remove
+ config.remove_resource(dfileobj)
# Make sure we correctly iterate over the sources
nosource = tempfile()
@@ -577,51 +579,6 @@ class TestFileSources < Test::Unit::TestCase
}
end
- def test_networkSourcesWithoutService
- server = nil
-
- Puppet[:autosign] = true
- Puppet[:masterport] = 8765
-
- serverpid = nil
- assert_nothing_raised() {
- server = Puppet::Network::Server::WEBrick.new(
- :Handlers => {
- :CA => {}, # so that certs autogenerate
- }
- )
-
- }
- serverpid = fork {
- assert_nothing_raised() {
- #trap(:INT) { server.shutdown; Kernel.exit! }
- trap(:INT) { server.shutdown }
- server.start
- }
- }
- @@tmppids << serverpid
-
- sleep(1)
-
- name = File.join(tmpdir(), "nosourcefile")
- file = Puppet.type(:file).create(
- :source => "puppet://localhost/dist/file",
- :name => name
- )
-
- assert_nothing_raised {
- file.retrieve
- }
-
- comp = newcomp("nosource", file)
-
- assert_nothing_raised {
- comp.evaluate
- }
-
- assert(!FileTest.exists?(name), "File with no source exists anyway")
- end
-
def test_unmountedNetworkSources
server = nil
mounts = {
@@ -669,11 +626,8 @@ class TestFileSources < Test::Unit::TestCase
file.retrieve
}
- comp = newcomp("nosource", file)
-
- assert_nothing_raised {
- comp.evaluate
- }
+ comp = mk_configuration(file)
+ comp.apply
assert(!FileTest.exists?(name), "File with no source exists anyway")
end
@@ -722,7 +676,7 @@ class TestFileSources < Test::Unit::TestCase
)
}
- comp = newcomp(file)
+ comp = mk_configuration(file)
assert_events([:file_created], comp)
assert(File.exists?(to), "File does not exist")
@@ -808,9 +762,8 @@ class TestFileSources < Test::Unit::TestCase
trans = nil
assert_nothing_raised {
file[:links] = :manage
- comp = newcomp(file)
- trans = comp.evaluate
- trans.evaluate
+ comp = mk_configuration(file)
+ trans = comp.apply
}
assert(trans.failed?(file), "Object did not fail to copy links")
diff --git a/test/ral/types/group.rb b/test/ral/types/group.rb
index 9870d533a..5189c63a1 100755
--- a/test/ral/types/group.rb
+++ b/test/ral/types/group.rb
@@ -65,7 +65,7 @@ class TestGroup < Test::Unit::TestCase
def attrtest_ensure(group)
group[:ensure] = :absent
- comp = newcomp("ensuretest", group)
+ comp = mk_configuration("ensuretest", group)
assert_apply(comp)
assert_equal(:absent, group.provider.ensure, "Group is still present")
group[:ensure] = :present
@@ -91,7 +91,7 @@ class TestGroup < Test::Unit::TestCase
assert_equal(15, group.should(:gid),
"Did not convert gid to number")
- comp = newcomp(group)
+ comp = mk_configuration(group)
trans = assert_events([:group_modified], comp, "group")
assert_equal(15, group.provider.gid, "GID was not changed")
diff --git a/test/ral/types/tidy.rb b/test/ral/types/tidy.rb
index b8d576b9a..8fada1adb 100755
--- a/test/ral/types/tidy.rb
+++ b/test/ral/types/tidy.rb
@@ -55,7 +55,7 @@ class TestTidy < Test::Unit::TestCase
assert_nothing_raised {
link = newlink(:target => source, :recurse => true)
}
- comp = newcomp("linktest",link)
+ comp = mk_configuration("linktest",link)
cycle(comp)
path = link.name
diff --git a/test/ral/types/user.rb b/test/ral/types/user.rb
index 121ac9cf0..9b24cc74a 100755
--- a/test/ral/types/user.rb
+++ b/test/ral/types/user.rb
@@ -82,7 +82,7 @@ class TestUser < Test::Unit::TestCase
old = user.provider.ensure
user[:ensure] = :absent
- comp = newcomp("ensuretest", user)
+ comp = mk_configuration("ensuretest", user)
assert_apply(user)
assert(!user.provider.exists?, "User is still present")
user[:ensure] = :present
@@ -102,7 +102,7 @@ class TestUser < Test::Unit::TestCase
old = user.provider.comment
user[:comment] = "A different comment"
- comp = newcomp("commenttest", user)
+ comp = mk_configuration("commenttest", user)
trans = assert_events([:user_changed], comp, "user")
@@ -117,7 +117,7 @@ class TestUser < Test::Unit::TestCase
def attrtest_home(user)
obj = nil
- comp = newcomp("hometest", user)
+ comp = mk_configuration("hometest", user)
old = user.provider.home
user[:home] = old
@@ -137,7 +137,7 @@ class TestUser < Test::Unit::TestCase
def attrtest_shell(user)
old = user.provider.shell
- comp = newcomp("shelltest", user)
+ comp = mk_configuration("shelltest", user)
user[:shell] = old
@@ -167,7 +167,7 @@ class TestUser < Test::Unit::TestCase
def attrtest_gid(user)
obj = nil
old = user.provider.gid
- comp = newcomp("gidtest", user)
+ comp = mk_configuration("gidtest", user)
user.retrieve
@@ -216,7 +216,7 @@ class TestUser < Test::Unit::TestCase
def attrtest_uid(user)
obj = nil
- comp = newcomp("uidtest", user)
+ comp = mk_configuration("uidtest", user)
user.provider.uid = 1
@@ -387,7 +387,7 @@ class TestUser < Test::Unit::TestCase
ogroup = Puppet.type(:group).create(
:name => "yayness"
)
- comp = newcomp(user, group, home, ogroup)
+ comp = mk_configuration(user, group, home, ogroup)
}
rels = nil
@@ -404,7 +404,7 @@ class TestUser < Test::Unit::TestCase
user = mkuser(name)
- comp = newcomp("usercomp", user)
+ comp = mk_configuration("usercomp", user)
trans = assert_events([:user_created], comp, "user")
@@ -424,7 +424,7 @@ class TestUser < Test::Unit::TestCase
assert(! user.provider.exists?, "User %s is present" % name)
- comp = newcomp("usercomp", user)
+ comp = mk_configuration("usercomp", user)
trans = assert_events([:user_created], comp, "user")
diff --git a/test/util/config.rb b/test/util/config.rb
index f99ad54b4..cbd02b4f9 100755
--- a/test/util/config.rb
+++ b/test/util/config.rb
@@ -59,57 +59,6 @@ class TestConfig < Test::Unit::TestCase
}
end
- # #795 - when --config=relative, we want to fully expand file paths.
- def test_relative_paths_when_to_transportable
- config = mkconfig
- config.setdefaults :yay, :transtest => ["/what/ever", "yo"]
- file = config.element(:transtest)
-
- # Now override it with a relative path name
- config[:transtest] = "here"
-
- should = File.join(Dir.getwd, "here")
-
- object = file.to_transportable[0]
- assert_equal(should, object.name, "Did not translate relative pathnames to full path names")
- end
-
- def test_to_manifest
- set_configs
- manifest = nil
- assert_nothing_raised("Could not convert to a manifest") {
- manifest = @config.to_manifest
- }
-
- Puppet[:parseonly] = true
-
- interp = nil
- assert_nothing_raised do
- interp = mkinterp :Code => manifest, :UseNodes => false
- end
-
- trans = nil
- node = Puppet::Node.new("node")
- assert_nothing_raised do
- trans = interp.compile(node)
- end
- assert_nothing_raised("Could not instantiate objects") {
- trans.extract.to_type
- }
- end
-
- def test_to_comp
- set_configs
- comp = nil
- assert_nothing_raised("Could not convert to a component") {
- comp = @config.to_component
- }
-
- assert_nothing_raised("Could not retrieve component") {
- comp.retrieve
- }
- end
-
def test_to_config
set_configs
@@ -668,91 +617,6 @@ yay = /a/path
assert_equal("/my/file", @config[:b], "Values are not equal")
end
- def test_reuse
- c = mkconfig
-
- file = tempfile()
- section = "testing"
- assert_nothing_raised {
- @config.setdefaults(section,
- :myfile => {:default => file, :create => true, :desc => "yay"}
- )
- }
-
- assert_nothing_raised("Could not use a section") {
- @config.use(section)
- }
-
- assert(FileTest.exists?(file), "Did not create file")
-
- assert(! Puppet::Type.type(:file)[file], "File obj still exists")
-
- File.unlink(file)
-
- @config.reuse
- assert(FileTest.exists?(file), "Did not create file")
- end
-
- def test_mkusers
- c = mkconfig
-
- file = tempfile()
- section = "testing"
- assert_nothing_raised {
- @config.setdefaults(section,
- :mkusers => [false, "yay"],
- :myfile => {
- :default => file,
- :owner => "pptest",
- :group => "pptest",
- :desc => "yay",
- :create => true
- }
- )
- }
-
- comp = nil
- assert_nothing_raised {
- comp = @config.to_component
- }
-
- [:user, :group].each do |type|
- # The objects might get created internally by Puppet::Util; just
- # make sure they're not being managed
- if obj = Puppet.type(type)["pptest"]
- assert(! obj.managed?, "%s objectis managed" % type)
- end
- end
- comp.each { |o| o.remove }
-
- @config[:mkusers] = true
-
- assert_nothing_raised {
- @config.to_component
- }
-
- user = Puppet.type(:user)["pptest"]
- assert(user, "User object did not get created")
- assert(user.managed?, "User object is not managed.")
- assert(user.should(:comment), "user does not have a comment set")
-
- group = Puppet.type(:group)["pptest"]
- assert(group, "Group object did not get created")
- assert(group.managed?,
- "Group object is not managed."
- )
-
- if Process.uid == 0
- cleanup do
- user[:ensure] = :absent
- group[:ensure] = :absent
- assert_apply(user, group)
- end
-
- assert_apply(user, group)
- end
- end
-
def test_notmanagingdev
c = mkconfig
path = "/dev/testing"
@@ -764,11 +628,9 @@ yay = /a/path
}
)
- assert_nothing_raised {
- @config.to_component
- }
+ config = @config.to_configuration
- assert(! Puppet.type(:file)["/dev/testing"], "Created dev file")
+ assert(! config.resource(:file, "/dev/testing"), "Created dev file")
end
def test_groupsetting
@@ -1119,12 +981,12 @@ yay = /a/path
# Now enable it so they'll be added
config[:mkusers] = true
- comp = config.to_component
+ comp = config.to_configuration
- Puppet::Type.type(:user).each do |u|
+ comp.vertices.find_all { |r| r.class.name == :user }.each do |u|
assert(u.name != "root", "Tried to manage root user")
end
- Puppet::Type.type(:group).each do |u|
+ comp.vertices.find_all { |r| r.class.name == :group }.each do |u|
assert(u.name != "root", "Tried to manage root group")
assert(u.name != "wheel", "Tried to manage wheel group")
end
diff --git a/test/util/fact_store.rb b/test/util/fact_store.rb
deleted file mode 100755
index 5b04d1374..000000000
--- a/test/util/fact_store.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/usr/bin/env ruby
-#
-# Created by Luke Kanies on 2007-05-02.
-# Copyright (c) 2007. All rights reserved.
-
-$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
-
-require 'puppettest'
-require 'puppet/util/fact_store'
-
-class TestFactStore < Test::Unit::TestCase
- include PuppetTest
-
- def test_new_fact_store
- klass = nil
- assert_nothing_raised("Could not create fact store") do
- klass = Puppet::Util::FactStore.newstore(:yay) do
- end
- end
-
- assert_equal(klass, Puppet::Util::FactStore.store(:yay), "Did not get created store back by name")
- end
-
- def test_yaml_store
- yaml = Puppet::Util::FactStore.store(:yaml)
- assert(yaml, "Could not retrieve yaml store")
-
- name = "node"
- facts = {"a" => :b, :c => "d", :e => :f, "g" => "h"}
-
- store = nil
- assert_nothing_raised("Could not create YAML store instance") do
- store = yaml.new
- end
-
- assert_nothing_raised("Could not store host facts") do
- store.set(name, facts)
- end
-
- dir = Puppet[:yamlfactdir]
-
- file = File.join(dir, name + ".yaml")
- assert(FileTest.exists?(file), "Did not create yaml file for node")
-
- text = File.read(file)
- newfacts = nil
- assert_nothing_raised("Could not deserialize yaml") do
- newfacts = YAML::load(text)
- end
-
- # Don't directly compare the hashes, because there might be extra
- # data stored in the client hash
- facts.each do |var, value|
- assert_equal(value, newfacts[var], "Value for %s changed during storage" % var)
- end
-
- # Now make sure the facts get retrieved correctly
- assert_nothing_raised("Could not retrieve facts") do
- newfacts = store.get(name)
- end
-
- # Now make sure the hashes are equal, since internal facts should not be returned.
- assert_equal(facts, newfacts, "Retrieved facts are not equal")
- end
-end
-
-# $Id$
diff --git a/test/util/graph.rb b/test/util/graph.rb
deleted file mode 100755
index 875fd0ec3..000000000
--- a/test/util/graph.rb
+++ /dev/null
@@ -1,108 +0,0 @@
-#!/usr/bin/env ruby
-#
-# Created by Luke Kanies on 2006-11-16.
-# Copyright (c) 2006. All rights reserved.
-
-$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
-
-require 'puppettest'
-require 'puppettest/graph'
-require 'puppet/util/graph'
-
-class TestUtilGraph < Test::Unit::TestCase
- include PuppetTest
- include PuppetTest::Graph
-
- def test_to_graph
- children = %w{a b c d}
- list = Container.new("yay", children)
-
- graph = nil
- assert_nothing_raised do
- graph = list.to_graph
- end
-
- assert(graph.vertices.include?(list), "wtf?")
-
- ([list] + children).each do |thing|
- assert(graph.vertex?(thing), "%s is not a vertex" % thing)
- end
- children.each do |child|
- assert(graph.edge?(list, child),
- "%s/%s was not added as an edge" % ["yay", child])
- end
- end
-
- def test_recursive_to_graph
- one, two, three, middle, top = build_tree
-
- graph = nil
- assert_nothing_raised do
- graph = top.to_graph
- end
-
- (%w{a b c d e f g h} + [one, two, middle, top]).each do |v|
- assert(graph.vertex?(v), "%s is not a vertex" % v)
- end
-
- [one, two, middle, top].each do |con|
- con.each do |child|
- assert(graph.edge?(con, child), "%s/%s is not an edge" % [con, child])
- end
- end
-
- # Now make sure we correctly retrieve the leaves from each container
- {top => %w{a b c d e f g h i j},
- one => %w{a b},
- two => %w{c d},
- three => %w{i j},
- middle => %w{c d e f}}.each do |cont, list|
- leaves = nil
- assert_nothing_raised do
- leaves = graph.leaves(cont)
- end
- leaves = leaves.sort
- assert_equal(list.sort, leaves.sort,
- "Got incorrect leaf list for %s" % cont.name)
- %w{a b c d e f g h}.each do |letter|
- unless list.include?(letter)
- assert(!leaves.include?(letter),
- "incorrectly got %s as a leaf of %s" %
- [letter, cont.to_s])
- end
- end
- end
- end
-
- def test_to_graph_with_block
- middle = Container.new "middle", ["c", "d", 3, 4]
- top = Container.new "top", ["a", "b", middle, 1, 2]
-
- graph = nil
- assert_nothing_raised() {
- graph = top.to_graph { |c| c.is_a?(String) or c.is_a?(Container) }
- }
-
- %w{a b c d}.each do |child|
- assert(graph.vertex?(child), "%s was not added as a vertex" % child)
- end
-
- [1, 2, 3, 4].each do |child|
- assert(! graph.vertex?(child), "%s is a vertex" % child)
- end
- end
-
- def test_cyclic_graphs
- one = Container.new "one", %w{a b}
- two = Container.new "two", %w{c d}
-
- one.push(two)
- two.push(one)
-
- assert_raise(Puppet::Error, "did not fail on cyclic graph") do
- one.to_graph
- end
- end
-end
-
-# $Id$