diff options
| author | Luke Kanies <luke@madstop.com> | 2005-08-18 19:36:47 +0000 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2005-08-18 19:36:47 +0000 |
| commit | 4741eeff6bae987c9dfa9e06e2908ae91daa4d16 (patch) | |
| tree | bd7ec692c4c2f429f03176cc9e8cfb34f30453cb /test | |
| parent | 63309c3b40b7e7f6f46692e0b4b2c780fc806737 (diff) | |
| download | puppet-4741eeff6bae987c9dfa9e06e2908ae91daa4d16.tar.gz puppet-4741eeff6bae987c9dfa9e06e2908ae91daa4d16.tar.xz puppet-4741eeff6bae987c9dfa9e06e2908ae91daa4d16.zip | |
Execution order is now based on dependency relationships, and those relationships correctly propagate up and descend into components. There is also an event test suite now, along with a (currently simple) component test suite.
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@565 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
| -rwxr-xr-x | test/other/tc_events.rb | 89 | ||||
| -rw-r--r-- | test/other/tc_transactions.rb | 2 | ||||
| -rw-r--r-- | test/puppettest.rb | 4 | ||||
| -rw-r--r-- | test/types/tc_basic.rb | 2 | ||||
| -rwxr-xr-x | test/types/tc_component.rb | 107 | ||||
| -rwxr-xr-x | test/types/tc_exec.rb | 2 | ||||
| -rw-r--r-- | test/types/tc_file.rb | 6 | ||||
| -rw-r--r-- | test/types/tc_query.rb | 2 |
8 files changed, 205 insertions, 9 deletions
diff --git a/test/other/tc_events.rb b/test/other/tc_events.rb new file mode 100755 index 000000000..d30f59437 --- /dev/null +++ b/test/other/tc_events.rb @@ -0,0 +1,89 @@ +if __FILE__ == $0 + $:.unshift '..' + $:.unshift '../../lib' + $puppetbase = "../../../../language/trunk" +end + +require 'puppet' +require 'puppettest' +require 'test/unit' + +# $Id$ + +class TestEvents < TestPuppet + def setup + Puppet[:loglevel] = :debug if __FILE__ == $0 + super + end + + def test_simplerequire + file = Puppet::Type::PFile.new( + :name => "/tmp/eventtestingA", + :create => true + ) + exec = Puppet::Type::Exec.new( + :name => "echo true", + :path => "/usr/bin:/bin", + :refreshonly => true, + :subscribe => [[file.class.name, file.name]] + ) + + @@tmpfiles << "/tmp/eventtestingA" + + comp = Puppet::Type::Component.new( + :name => "eventtesting" + ) + comp.push exec + trans = comp.evaluate + events = nil + assert_nothing_raised { + events = trans.evaluate + } + + assert_equal(1, events.length) + + assert_equal(1, trans.triggered?(exec, :refresh)) + end + + def test_zladderrequire + comps = {} + objects = {} + fname = "/tmp/eventtestfuntest" + [:a, :b].each { |l| + case l + when :a + name = "/tmp/eventtesting%s" % l + objects[l] = Puppet::Type::PFile.new( + :name => name, + :create => true + ) + @@tmpfiles << name + when :b + objects[l] = Puppet::Type::Exec.new( + :name => "touch %s" % fname, + :path => "/usr/bin:/bin", + :refreshonly => true + ) + @@tmpfiles << fname + end + + + comps[l] = Puppet::Type::Component.new( + :name => "eventtesting%s" % l + ) + + comps[l].push objects[l] + } + + comps[:b][:subscribe] = [[comps[:a].class.name, comps[:a].name]] + + trans = comps[:a].evaluate + events = nil + assert_nothing_raised { + events = trans.evaluate + } + + assert(FileTest.exists?(fname)) + #assert_equal(events.length, trans.triggered?(objects[:b], :refresh)) + end +end diff --git a/test/other/tc_transactions.rb b/test/other/tc_transactions.rb index 737622c26..5a275a899 100644 --- a/test/other/tc_transactions.rb +++ b/test/other/tc_transactions.rb @@ -102,7 +102,7 @@ class TestTransactions < Test::Unit::TestCase def newcomp(name,*args) comp = nil assert_nothing_raised() { - comp = Puppet::Component.new(:name => name) + comp = Puppet::Type::Component.new(:name => name) } args.each { |arg| diff --git a/test/puppettest.rb b/test/puppettest.rb index 95a99c767..d7c3077f8 100644 --- a/test/puppettest.rb +++ b/test/puppettest.rb @@ -5,7 +5,6 @@ class TestPuppet < Test::Unit::TestCase def setup @@tmpfiles = [] Puppet[:loglevel] = :debug if __FILE__ == $0 - Puppet::Type.allclear end def teardown @@ -16,6 +15,7 @@ class TestPuppet < Test::Unit::TestCase end } @@tmpfiles.clear + Puppet::Type.allclear end def test_nothing @@ -81,7 +81,7 @@ unless defined? PuppetTestSuite module FileTesting def newcomp(name,*ary) - comp = Puppet::Component.new( + comp = Puppet::Type::Component.new( :name => name ) ary.each { |item| comp.push item } diff --git a/test/types/tc_basic.rb b/test/types/tc_basic.rb index a283c3e04..6910485ae 100644 --- a/test/types/tc_basic.rb +++ b/test/types/tc_basic.rb @@ -21,7 +21,7 @@ class TestBasic < Test::Unit::TestCase Puppet[:loglevel] = :debug if __FILE__ == $0 assert_nothing_raised() { - @component = Puppet::Component.new( + @component = Puppet::Type::Component.new( :name => "yaytest", :type => "testing" ) diff --git a/test/types/tc_component.rb b/test/types/tc_component.rb new file mode 100755 index 000000000..bd8b21a40 --- /dev/null +++ b/test/types/tc_component.rb @@ -0,0 +1,107 @@ +if __FILE__ == $0 + $:.unshift '..' + $:.unshift '../../lib' + $puppetbase = "../../../../language/trunk" +end + +require 'puppet' +require 'puppettest' +require 'test/unit' + +# $Id$ + +class TestComponent < TestPuppet + def setup + @@used = {} + super + end + + def teardown + assert_nothing_raised() { + Puppet::Type.allclear + } + super + end + + def randnum(limit) + num = nil + loop do + 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 = "/tmp/componentrandfile" + num.to_s + + file = Puppet::Type::PFile.new( + :path => name, + :checksum => "md5" + ) + @@tmpfiles << name + file + end + + def mkcomp + comp = Puppet::Type::Component.new(: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 + end + + def test_ordering + list = nil + comp = mkrandcomp(30,5) + assert_nothing_raised { + list = comp.flatten + } + + list.each_with_index { |obj, index| + obj.eachdependency { |dep| + assert(list.index(dep) < index) + } + } + end +end diff --git a/test/types/tc_exec.rb b/test/types/tc_exec.rb index f9f59de24..cfd06d495 100755 --- a/test/types/tc_exec.rb +++ b/test/types/tc_exec.rb @@ -170,7 +170,7 @@ class TestExec < Test::Unit::TestCase :refreshonly => true ) } - comp = Puppet::Component.new(:name => "RefreshTest") + comp = Puppet::Type::Component.new(:name => "RefreshTest") [file,cmd].each { |obj| comp.push obj } diff --git a/test/types/tc_file.rb b/test/types/tc_file.rb index 85f6723e1..8c7316403 100644 --- a/test/types/tc_file.rb +++ b/test/types/tc_file.rb @@ -336,7 +336,7 @@ class TestFile < Test::Unit::TestCase :checksum => "md5" ) } - comp = Puppet::Component.new( + comp = Puppet::Type::Component.new( :name => "component" ) comp.push file @@ -447,7 +447,7 @@ class TestFile < Test::Unit::TestCase :source => frompath ) } - comp = Puppet::Component.new( + comp = Puppet::Type::Component.new( :name => "component" ) comp.push tofile @@ -482,7 +482,7 @@ class TestFile < Test::Unit::TestCase "source" => fromdir ) } - comp = Puppet::Component.new( + comp = Puppet::Type::Component.new( :name => "component" ) comp.push tofile diff --git a/test/types/tc_query.rb b/test/types/tc_query.rb index fefb76700..52d641e4c 100644 --- a/test/types/tc_query.rb +++ b/test/types/tc_query.rb @@ -54,7 +54,7 @@ class TestQuery < Test::Unit::TestCase def component(name,*args) assert_nothing_raised() { - @component = Puppet::Component.new(:name => name) + @component = Puppet::Type::Component.new(:name => name) } args.each { |arg| |
