diff options
| author | Luke Kanies <luke@madstop.com> | 2005-07-19 06:10:33 +0000 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2005-07-19 06:10:33 +0000 |
| commit | de91dbdc5c554136437250daa512050f6d46fbc8 (patch) | |
| tree | 745391ccfa27e682f272364ef15e7c092ce2f68e /test | |
| parent | 9ba72f574aba66020913c7ac837634d5ca0fb13e (diff) | |
temp commit before i change the whole way that i am doing source + recursion
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@421 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
| -rw-r--r-- | test/types/tc_file.rb | 140 | ||||
| -rw-r--r-- | test/types/tc_query.rb | 2 |
2 files changed, 124 insertions, 18 deletions
diff --git a/test/types/tc_file.rb b/test/types/tc_file.rb index 32a67cf41..d7df72311 100644 --- a/test/types/tc_file.rb +++ b/test/types/tc_file.rb @@ -14,6 +14,7 @@ class TestFile < Test::Unit::TestCase # this is complicated, because we store references to the created # objects in a central store def setup + @@tmpfiles = [] @file = nil @path = File.join($puppetbase,"examples/root/etc/configfile") Puppet[:loglevel] = :debug if __FILE__ == $0 @@ -27,6 +28,9 @@ class TestFile < Test::Unit::TestCase def teardown Puppet::Type.allclear + @@tmpfiles.each { |file| + system("rm -rf %s" % file) + } system("rm -f %s" % Puppet[:statefile]) end @@ -110,9 +114,32 @@ class TestFile < Test::Unit::TestCase file.evaluate } assert(file.insync?()) + assert(FileTest.file?(path)) + @@tmpfiles.push path + } + end + + def test_create_dir + %w{a b c d}.collect { |name| "/tmp/createst%s" % name }.each { |path| + file = nil + assert_nothing_raised() { + file = Puppet::Type::PFile.new( + :name => path, + :create => "directory" + ) + } + assert_nothing_raised() { + file.evaluate + } assert_nothing_raised() { - system("rm -f %s" % path) + file.sync + } + assert_nothing_raised() { + file.evaluate } + assert(file.insync?()) + assert(FileTest.directory?(path)) + @@tmpfiles.push path } end @@ -167,15 +194,21 @@ class TestFile < Test::Unit::TestCase assert_nothing_raised() { @file.delete(:link) } - system("rm -f %s" % link) + @@tmpfiles.push link end def test_checksums types = %w{md5 md5lite timestamp ctime} - files = %w{/tmp/sumtest} - assert_nothing_raised() { - Puppet::Storage.init - # Puppet::Storage.load + exists = "/tmp/sumtest-exists" + nonexists = "/tmp/sumtest-nonexists" + + # try it both with files that exist and ones that don't + files = [exists, nonexists] + initstorage + File.open(exists,"w") { |of| + 10.times { + of.puts rand(100) + } } types.each { |type| files.each { |path| @@ -184,17 +217,11 @@ class TestFile < Test::Unit::TestCase end file = nil events = nil - assert_nothing_raised() { - File.open(path,"w") { |of| - 10.times { - of.puts rand(100) - } - } - } # okay, we now know that we have a file... assert_nothing_raised() { file = Puppet::Type::PFile.new( :name => path, + :create => true, :checksum => type ) } @@ -238,9 +265,7 @@ class TestFile < Test::Unit::TestCase assert_nothing_raised() { Puppet::Type::PFile.clear } - assert_nothing_raised() { - system("rm -f %s" % path) - } + @@tmpfiles.push path } } # clean up so i don't screw up other tests @@ -294,6 +319,87 @@ class TestFile < Test::Unit::TestCase of.puts "goodness" } cyclefile(path) - system("rm -rf #{path}") + @@tmpfiles.push path + end + + def test_simplelocalsource + path = "/tmp/filesourcetest" + system("mkdir -p #{path}") + frompath = File.join(path,"source") + topath = File.join(path,"dest") + fromfile = nil + tofile = nil + trans = nil + + File.open(frompath, File::WRONLY|File::CREAT|File::APPEND) { |of| + of.puts "yayness" + } + assert_nothing_raised { + tofile = Puppet::Type::PFile.new( + :name => topath, + :source => frompath + ) + } + comp = Puppet::Component.new( + :name => "component" + ) + comp.push tofile + assert_nothing_raised { + trans = comp.evaluate + } + assert_nothing_raised { + trans.evaluate + } + assert_nothing_raised { + comp.sync + } + from = File.open(frompath) { |o| o.read } + to = File.open(topath) { |o| o.read } + assert_equal(from,to) + clearstorage + Puppet::Type.allclear + @@tmpfiles.push path + end + + def test_xcomplicatedlocalsource + path = "/tmp/filesourcetest" + @@tmpfiles.push path + system("mkdir -p #{path}") + fromdir = File.join(path,"fromdir") + frompath = File.join(fromdir,"source") + todir = File.join(path,"todir") + topath = File.join(todir,"source") + fromfile = nil + tofile = nil + trans = nil + + Dir.mkdir(fromdir) + File.open(frompath, File::WRONLY|File::CREAT|File::APPEND) { |of| + of.puts "yayness" + } + + assert_nothing_raised { + tofile = Puppet::Type::PFile.new( + :name => todir, + :recurse => true, + :source => fromdir + ) + } + comp = Puppet::Component.new( + :name => "component" + ) + comp.push tofile + assert_nothing_raised { + trans = comp.evaluate + } + assert_nothing_raised { + trans.evaluate + } + assert(FileTest.file?(topath)) + from = File.open(frompath) { |o| o.read } + to = File.open(topath) { |o| o.read } + assert_equal(from,to) + clearstorage + Puppet::Type.allclear end end diff --git a/test/types/tc_query.rb b/test/types/tc_query.rb index f127d1dfe..fefb76700 100644 --- a/test/types/tc_query.rb +++ b/test/types/tc_query.rb @@ -29,7 +29,7 @@ class TestQuery < Test::Unit::TestCase unless Puppet::Type::PFile.has_key?(cfile) Puppet::Type::PFile.new( :path => cfile, - :check => [:mode, :owner] + :check => [:mode, :owner, :checksum] ) end @configfile = Puppet::Type::PFile[cfile] |
