diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2005-10-01 19:57:07 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2005-10-01 19:57:07 +0000 |
| commit | 0d6241ca97ded8e003338c6cf316e280530ea8ee (patch) | |
| tree | d66e60c1a77eacf0a894d0976f6c9f5216104c90 /test | |
| parent | a96bdac66ba703736afa7155f4d31cbe3e9fc0ef (diff) | |
switching all relationships to be centrally maintained and to use symbolic references, rather than literal ones; also going through and making all tests pass again after mucking with services
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@710 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
| -rwxr-xr-x | test/other/tc_events.rb | 18 | ||||
| -rwxr-xr-x | test/other/tc_relationships.rb | 120 | ||||
| -rw-r--r-- | test/other/tc_transactions.rb | 1 | ||||
| -rw-r--r-- | test/server/tc_bucket.rb | 2 | ||||
| -rw-r--r-- | test/types/tc_basic.rb | 3 | ||||
| -rw-r--r-- | test/types/tc_file.rb | 114 | ||||
| -rw-r--r-- | test/types/tc_query.rb | 3 | ||||
| -rw-r--r-- | test/types/tc_service.rb | 18 |
8 files changed, 183 insertions, 96 deletions
diff --git a/test/other/tc_events.rb b/test/other/tc_events.rb index 5f3ddcd67..c555e17f0 100755 --- a/test/other/tc_events.rb +++ b/test/other/tc_events.rb @@ -11,9 +11,9 @@ require 'test/unit' # $Id$ class TestEvents < TestPuppet - def setup - Puppet[:loglevel] = :debug if __FILE__ == $0 + def teardown super + Puppet::Event::Subscription.clear end def test_simplesubscribe @@ -30,17 +30,9 @@ class TestEvents < TestPuppet @@tmpfiles << "/tmp/eventtestingA" - comp = Puppet::Type::Component.create( - :name => "eventtesting" - ) - comp.push exec - trans = comp.evaluate - events = nil - assert_nothing_raised { - events = trans.evaluate - } + comp = newcomp("eventtesting", file, exec) - assert_equal(1, events.length) + trans = assert_events(comp, [:file_created], "events") assert_equal(1, trans.triggered?(exec, :refresh)) end @@ -74,7 +66,7 @@ class TestEvents < TestPuppet assert_equal(0, trans.triggered?(exec, :refresh)) end - def test_ladderrequire + def test_zladderrequire comps = {} objects = {} fname = "/tmp/eventtestfuntest" diff --git a/test/other/tc_relationships.rb b/test/other/tc_relationships.rb index c8927972b..d2544ffa4 100755 --- a/test/other/tc_relationships.rb +++ b/test/other/tc_relationships.rb @@ -9,57 +9,103 @@ require 'puppettest' require 'test/unit' class TestRelationships < TestPuppet - def setup - super - @groups = %x{groups}.chomp.split(/ /) - unless @groups.length > 1 - p @groups - raise "You must be a member of more than one group to test this" - end - end - def newfile assert_nothing_raised() { - cfile = File.join($puppetbase,"examples/root/etc/configfile") - unless Puppet::Type::PFile.has_key?(cfile) - Puppet::Type::PFile.create( - :path => cfile, - :check => [:mode, :owner, :group] - ) - end - return Puppet::Type::PFile[cfile] + return Puppet::Type::PFile.create( + :path => tempfile, + :check => [:mode, :owner, :group] + ) } end - def newservice - assert_nothing_raised() { - unless Puppet::Type::Service.has_key?("sleeper") - Puppet::Type::Service.create( - :name => "sleeper", - :path => File.join($puppetbase,"examples/root/etc/init.d"), - :check => [:running] - ) - end - return Puppet::Type::Service["sleeper"] + def test_simplerel + file1 = newfile() + file2 = newfile() + assert_nothing_raised { + file1[:require] = [file2.class.name, file2.name] } - end - def newcomp(name,*args) - comp = nil - assert_nothing_raised() { - comp = Puppet::Component.new(:name => name) + deps = [] + assert_nothing_raised { + file1.eachdependency { |obj| + deps << obj + } } - args.each { |arg| - assert_nothing_raised() { - comp.push arg + assert_equal(1, deps.length, "Did not get dependency") + + assert_nothing_raised { + file1.unsubscribe(file2) + } + + deps = [] + assert_nothing_raised { + file1.eachdependency { |obj| + deps << obj } } - return comp + assert_equal(0, deps.length, "Still have dependency") end - def test_simplerel + def test_newsub + file1 = newfile() + file2 = newfile() + + sub = nil + assert_nothing_raised("Could not create subscription") { + sub = Puppet::Event::Subscription.new( + :source => file1, + :target => file2, + :event => :ALL_EVENTS, + :callback => :refresh + ) + } + + subs = nil + + assert_nothing_raised { + subs = Puppet::Event::Subscription.subscribers(file1) + } + assert_equal(1, subs.length, "Got incorrect number of subs") + assert_equal(sub.target, subs[0], "Got incorrect sub") + + deps = nil + assert_nothing_raised { + deps = Puppet::Event::Subscription.dependencies(file2) + } + assert_equal(1, deps.length, "Got incorrect number of deps") + assert_equal(sub, deps[0], "Got incorrect dep") + end + + def test_eventmatch + file1 = newfile() + file2 = newfile() + + sub = nil + assert_nothing_raised("Could not create subscription") { + sub = Puppet::Event::Subscription.new( + :source => file1, + :target => file2, + :event => :ALL_EVENTS, + :callback => :refresh + ) + } + + assert(sub.match?(:anything), "ALL_EVENTS did not match") + assert(! sub.match?(:NONE), "ALL_EVENTS matched :NONE") + + sub.event = :file_created + + assert(sub.match?(:file_created), "event did not match") + assert(sub.match?(:ALL_EVENTS), "ALL_EVENTS did not match") + assert(! sub.match?(:NONE), "ALL_EVENTS matched :NONE") + + sub.event = :NONE + + assert(! sub.match?(:file_created), "Invalid match") + assert(! sub.match?(:ALL_EVENTS), "ALL_EVENTS matched") + assert(! sub.match?(:NONE), "matched :NONE") end end diff --git a/test/other/tc_transactions.rb b/test/other/tc_transactions.rb index 946d53279..6b6213b81 100644 --- a/test/other/tc_transactions.rb +++ b/test/other/tc_transactions.rb @@ -74,6 +74,7 @@ class TestTransactions < FileTesting return Puppet::Type::Service.create( :name => "sleeper", :path => File.join($puppetbase,"examples/root/etc/init.d"), + :hasstatus => true, :check => [:running] ) } diff --git a/test/server/tc_bucket.rb b/test/server/tc_bucket.rb index 264a8da13..8a7e71511 100644 --- a/test/server/tc_bucket.rb +++ b/test/server/tc_bucket.rb @@ -22,6 +22,7 @@ class TestBucket < ServerTest spin name = File.basename(file) tmppath = File.join(tmpdir,name) + @@tmpfiles << tmppath # copy the files to our tmp directory so we can modify them... File.open(tmppath,File::WRONLY|File::TRUNC|File::CREAT) { |wf| @@ -167,6 +168,7 @@ class TestBucket < ServerTest files = filelist() tmpdir = File.join(tmpdir(),"tmpfiledir") + @@tmpfiles << tmpdir FileUtils.mkdir_p(tmpdir) bucket = nil diff --git a/test/types/tc_basic.rb b/test/types/tc_basic.rb index 585caaa95..f0257fef0 100644 --- a/test/types/tc_basic.rb +++ b/test/types/tc_basic.rb @@ -1,7 +1,7 @@ if __FILE__ == $0 $:.unshift '..' $:.unshift '../../lib' - $puppetbase = "../../../../language/trunk" + $puppetbase = "../.." end require 'puppet' @@ -40,6 +40,7 @@ class TestBasic < Test::Unit::TestCase @sleeper = Puppet::Type::Service.create( :name => "sleeper", :path => File.join($puppetbase,"examples/root/etc/init.d"), + :hasstatus => true, :running => 1 ) } diff --git a/test/types/tc_file.rb b/test/types/tc_file.rb index 169b32995..8b19dc670 100644 --- a/test/types/tc_file.rb +++ b/test/types/tc_file.rb @@ -86,8 +86,66 @@ class TestFile < FileTesting end end - # we can really only test changing ownership if we're root - if Process.uid == 0 + uid, name = users.shift + us = {} + us[uid] = name + users.each { |uid, name| + # just make sure we don't try to manage users + assert_nothing_raised() { + file.sync + } + assert_nothing_raised() { + file[:owner] = name + } + assert_nothing_raised() { + file.retrieve + } + assert_nothing_raised() { + file.sync + } + } + end + + def test_zgroup + file = mktestfile() + [%x{groups}.chomp.split(/ /), Process.groups].flatten.each { |group| + assert_nothing_raised() { + file[:group] = group + } + assert(file.state(:group)) + assert(file.state(:group).should) + } + end + + if Process.uid == 0 + def test_ownerasroot + file = mktestfile() + + users = {} + count = 0 + + # collect five users + Etc.passwd { |passwd| + if count > 5 + break + else + count += 1 + end + users[passwd.uid] = passwd.name + } + + fake = {} + # find a fake user + while true + a = rand(1000) + begin + Etc.getpwuid(a) + rescue + fake[a] = "fakeuser" + break + end + end + users.each { |uid, name| assert_nothing_raised() { file[:owner] = name @@ -122,51 +180,33 @@ class TestFile < FileTesting file[:owner] = uid } } - else - uid, name = users.shift - us = {} - us[uid] = name - users.each { |uid, name| - # just make sure we don't try to manage users + end + + def test_groupasroot + file = mktestfile() + [%x{groups}.chomp.split(/ /), Process.groups].flatten.each { |group| assert_nothing_raised() { - file.sync + file[:group] = group } + assert(file.state(:group)) + assert(file.state(:group).should) assert_nothing_raised() { - file[:owner] = name + file.evaluate } assert_nothing_raised() { - file.retrieve + file.sync + } + assert_nothing_raised() { + file.evaluate } assert(file.insync?()) assert_nothing_raised() { - file.sync + file.delete(:group) } } end - end - - def test_group - file = mktestfile() - [%x{groups}.chomp.split(/ /), Process.groups].flatten.each { |group| - assert_nothing_raised() { - file[:group] = group - } - assert(file.state(:group)) - assert(file.state(:group).should) - assert_nothing_raised() { - file.evaluate - } - assert_nothing_raised() { - file.sync - } - assert_nothing_raised() { - file.evaluate - } - assert(file.insync?()) - assert_nothing_raised() { - file.delete(:group) - } - } + else + $stderr.puts "Run as root for complete owner and group testing" end def test_create @@ -371,6 +411,7 @@ class TestFile < FileTesting def test_recursion path = "/tmp/filerecursetest" + @@tmpfiles.push path tmpfile = File.join(path,"testing") system("mkdir -p #{path}") cyclefile(path) @@ -382,7 +423,6 @@ class TestFile < FileTesting of.puts "goodness" } cyclefile(path) - @@tmpfiles.push path end =begin diff --git a/test/types/tc_query.rb b/test/types/tc_query.rb index 5ba0e0c64..31e0d23a9 100644 --- a/test/types/tc_query.rb +++ b/test/types/tc_query.rb @@ -1,7 +1,7 @@ if __FILE__ == $0 $:.unshift '..' $:.unshift '../../lib' - $puppetbase = "../../../../language/trunk" + $puppetbase = "../.." end require 'puppet' @@ -43,6 +43,7 @@ class TestQuery < Test::Unit::TestCase Puppet::Type::Service.create( :name => "sleeper", :path => File.join($puppetbase,"examples/root/etc/init.d"), + :hasstatus => true, :check => [:running] ) end diff --git a/test/types/tc_service.rb b/test/types/tc_service.rb index c0df3419f..82827c734 100644 --- a/test/types/tc_service.rb +++ b/test/types/tc_service.rb @@ -74,14 +74,18 @@ class TestService < TestPuppet assert(sleeper.insync?) end - def test_processStartWithPattern - sleeper = mksleeper(:pattern => "bin/sleeper") + case Puppet::Type::Service.svctype + when Puppet::ServiceTypes::InitSvc + def test_processStartWithPattern + sleeper = mksleeper(:pattern => "bin/sleeper") - cyclesleeper(sleeper) - end + cyclesleeper(sleeper) + end - def test_processStartWithStatus - sleeper = mksleeper(:hasstatus => true) - cyclesleeper(sleeper) + def test_processStartWithStatus + sleeper = mksleeper(:hasstatus => true) + cyclesleeper(sleeper) + end + #when Puppet::ServiceTypes::SMFSvc end end |
