diff options
| author | Luke Kanies <luke@madstop.com> | 2008-10-28 18:09:55 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-11-04 16:20:45 -0600 |
| commit | 05e1325891b2ab22088dcd34dd54e4afcbf59ddb (patch) | |
| tree | 46f28ce17354bac900ba513402dc94e889ab7b4e | |
| parent | 6f7ccff8bb764dffd1d41d5391dd79f7bd4a387c (diff) | |
| download | puppet-05e1325891b2ab22088dcd34dd54e4afcbf59ddb.tar.gz puppet-05e1325891b2ab22088dcd34dd54e4afcbf59ddb.tar.xz puppet-05e1325891b2ab22088dcd34dd54e4afcbf59ddb.zip | |
Moving a file purging test to rspec
Signed-off-by: Luke Kanies <luke@madstop.com>
| -rwxr-xr-x | spec/integration/type/file.rb | 49 | ||||
| -rwxr-xr-x | test/ral/type/file.rb | 42 |
2 files changed, 49 insertions, 42 deletions
diff --git a/spec/integration/type/file.rb b/spec/integration/type/file.rb index 7f5e9cbac..c9e0d19c6 100755 --- a/spec/integration/type/file.rb +++ b/spec/integration/type/file.rb @@ -213,4 +213,53 @@ describe Puppet::Type.type(:file) do File.should_not be_exist(dest) end + + describe "when purging files" do + before do + @sourcedir = tmpfile("purge_source") + @destdir = tmpfile("purge_dest") + Dir.mkdir(@sourcedir) + Dir.mkdir(@destdir) + @sourcefile = File.join(@sourcedir, "sourcefile") + @copiedfile = File.join(@destdir, "sourcefile") + @localfile = File.join(@destdir, "localfile") + @purgee = File.join(@destdir, "to_be_purged") + File.open(@localfile, "w") { |f| f.puts "rahtest" } + File.open(@sourcefile, "w") { |f| f.puts "funtest" } + # this file should get removed + File.open(@purgee, "w") { |f| f.puts "footest" } + + @lfobj = Puppet::Type.newfile( + :title => "localfile", + :path => @localfile, + :content => "rahtest\n", + :ensure => :file, + :backup => false + ) + + @destobj = Puppet::Type.newfile(:title => "destdir", :path => @destdir, + :source => @sourcedir, + :backup => false, + :purge => true, + :recurse => true) + + @catalog = Puppet::Node::Catalog.new + @catalog.add_resource @lfobj, @destobj + end + + it "should still copy remote files" do + @catalog.apply + FileTest.should be_exist(@copiedfile) + end + + it "should not purge managed, local files" do + @catalog.apply + FileTest.should be_exist(@localfile) + end + + it "should purge files that are neither remote nor otherwise managed" do + @catalog.apply + FileTest.should_not be_exist(@purgee) + end + end end diff --git a/test/ral/type/file.rb b/test/ral/type/file.rb index df0f849f2..c0c644dc0 100755 --- a/test/ral/type/file.rb +++ b/test/ral/type/file.rb @@ -955,48 +955,6 @@ class TestFile < Test::Unit::TestCase assert_equal("yayness", File.read(path), "Content did not get set correctly") end - # Make sure unmanaged files are purged. - def test_purge - sourcedir = tempfile() - destdir = tempfile() - Dir.mkdir(sourcedir) - Dir.mkdir(destdir) - sourcefile = File.join(sourcedir, "sourcefile") - dsourcefile = File.join(destdir, "sourcefile") - localfile = File.join(destdir, "localfile") - purgee = File.join(destdir, "to_be_purged") - File.open(sourcefile, "w") { |f| f.puts "funtest" } - # this file should get removed - File.open(purgee, "w") { |f| f.puts "footest" } - - lfobj = Puppet::Type.newfile( - :title => "localfile", - :path => localfile, - :content => "rahtest", - :ensure => :file, - :backup => false - ) - - destobj = Puppet::Type.newfile(:title => "destdir", :path => destdir, - :source => sourcedir, - :backup => false, - :recurse => true) - - config = mk_catalog(lfobj, destobj) - config.apply - - assert(FileTest.exists?(dsourcefile), "File did not get copied") - assert(FileTest.exists?(localfile), "Local file did not get created") - assert(FileTest.exists?(purgee), "Purge target got prematurely purged") - - assert_nothing_raised { destobj[:purge] = true } - config.apply - - 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 - # Testing #274. Make sure target can be used without 'ensure'. def test_target_without_ensure source = tempfile() |
