diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-04-20 19:38:48 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-04-20 19:38:48 +0000 |
| commit | d91b7df7befbd9e7877c97c2266b94864d55440f (patch) | |
| tree | 94af7888852c643096d1c5fb2efd1b21da1152c9 /test/server | |
| parent | a9b67cce5ad2a22e916d20b39363b6c2c182e923 (diff) | |
Added a list class method to just about all types, and it seems to actually work for everyone. Now just to add a list method to the pelement server.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1125 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/server')
| -rw-r--r-- | test/server/pelement.rb | 115 |
1 files changed, 100 insertions, 15 deletions
diff --git a/test/server/pelement.rb b/test/server/pelement.rb index fd92e750f..40d5f7ea1 100644 --- a/test/server/pelement.rb +++ b/test/server/pelement.rb @@ -25,15 +25,95 @@ class TestPElementServer < Test::Unit::TestCase server = Puppet::Server::PElementServer.new() end + # The first run we create the file on the copy, the second run + # the file is already there so the object should be in sync + 2.times do |i| + [ [nil], + [[:content, :mode], []], + [[], [:content]], + [[:content], [:mode]] + ].each do |ary| + retrieve = ary[0] || [] + ignore = ary[1] || [] + + File.open(file, "w") { |f| f.print str } + + result = nil + assert_nothing_raised do + result = server.describe("file", file, *ary) + end + + assert(result, "Could not retrieve file information") + + assert_instance_of(Puppet::TransObject, result) + + # Now we have to clear, so that the server's object gets removed + Puppet::Type.type(:file).clear + + # And remove the file, so we can verify it gets recreated + if i == 0 + File.unlink(file) + end + + object = nil + assert_nothing_raised do + object = result.to_type + end + + assert(object, "Could not create type") + + retrieve.each do |state| + assert(object.should(state), "Did not retrieve %s" % state) + end + + ignore.each do |state| + assert(! object.should(state), "Incorrectly retrieved %s" % state) + end + + if i == 0 + assert_events([:file_created], object) + else + assert_nothing_raised { + object.retrieve + } + assert(object.insync?, "Object was not in sync") + end + + assert(FileTest.exists?(file), "File did not get recreated") + + if i == 0 + if object.should(:content) + assert_equal(str, File.read(file), "File contents are not the same") + else + assert_equal("", File.read(file), "File content was incorrectly made") + end + end + if FileTest.exists? file + File.unlink(file) + end + end + end + end + + def test_describe_directory + # Make a file to describe + file = tempfile() + + server = nil + + assert_nothing_raised do + server = Puppet::Server::PElementServer.new() + end + [ [nil], - [[:content, :mode], []], - [[], [:content]], - [[:content], [:mode]] + [[:ensure, :checksum, :mode], []], + [[], [:checksum]], + [[:ensure, :checksum], [:mode]] ].each do |ary| retrieve = ary[0] || [] ignore = ary[1] || [] - File.open(file, "w") { |f| f.print str } + Dir.mkdir(file) result = nil assert_nothing_raised do @@ -48,7 +128,7 @@ class TestPElementServer < Test::Unit::TestCase Puppet::Type.type(:file).clear # And remove the file, so we can verify it gets recreated - File.unlink(file) + Dir.rmdir(file) object = nil assert_nothing_raised do @@ -65,15 +145,10 @@ class TestPElementServer < Test::Unit::TestCase assert(! object.should(state), "Incorrectly retrieved %s" % state) end - assert_events([:file_created], object) + assert_events([:directory_created], object) - assert(FileTest.exists?(file), "File did not get recreated") - - if object.should(:content) - assert_equal(str, File.read(file), "File contents are not the same") - else - assert_equal("", File.read(file), "File content was incorrectly made") - end + assert(FileTest.directory?(file), "Directory did not get recreated") + Dir.rmdir(file) end end @@ -85,20 +160,27 @@ class TestPElementServer < Test::Unit::TestCase require 'etc' + # Make the example schedules, for testing + Puppet::Type.type(:schedule).mkdefaultschedules + Puppet::Type.eachtype do |type| unless type.respond_to? :list Puppet.warning "%s does not respond to :list" % type.name next end + #next unless type.name == :file Puppet.info "Describing each %s" % type.name + count = 0 described = {} - type.list.each do |name| + type.list.each do |obj| + assert_instance_of(type, obj) + break if count > 5 trans = nil assert_nothing_raised do - described[name] = server.describe(type.name, name) + described[obj.name] = server.describe(type.name, obj.name) end count += 1 @@ -118,6 +200,7 @@ class TestPElementServer < Test::Unit::TestCase obj = trans.to_type end + assert(obj, "Could not create object") assert_nothing_raised do obj.retrieve end @@ -129,6 +212,8 @@ class TestPElementServer < Test::Unit::TestCase assert_equal(Puppet::Type.type(:package).default, obj[:type]) end end + + type.clear end end end |
