diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-07-11 20:23:49 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-07-11 20:23:49 +0000 |
| commit | d104d4b32b34434e42a83078bccaa68890c1b373 (patch) | |
| tree | e11ab0b246ed044c3fd61491e4b3501c9341366e /test/util | |
| parent | 17a830d5421a0ae9d84914a4215010bf4b16253f (diff) | |
| download | puppet-d104d4b32b34434e42a83078bccaa68890c1b373.tar.gz puppet-d104d4b32b34434e42a83078bccaa68890c1b373.tar.xz puppet-d104d4b32b34434e42a83078bccaa68890c1b373.zip | |
Having FileType instances automatically back their contents up to a filebucket, so it is much harder to lose content. This does not yet back up crontab contents, though.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2679 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/util')
| -rwxr-xr-x | test/util/filetype.rb | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/test/util/filetype.rb b/test/util/filetype.rb index 6f026f9f1..2c4a16fc2 100755 --- a/test/util/filetype.rb +++ b/test/util/filetype.rb @@ -2,9 +2,9 @@ $:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ -require 'puppet' -require 'puppet/util/filetype' require 'puppettest' +require 'puppet/util/filetype' +require 'mocha' class TestFileType < Test::Unit::TestCase include PuppetTest @@ -53,6 +53,52 @@ class TestFileType < Test::Unit::TestCase assert_equal(text, newtext, "Text was changed somehow") end + # Make sure that modified files are backed up before they're changed. + def test_backup_is_called + path = tempfile + File.open(path, "w") { |f| f.print 'yay' } + + obj = Puppet::Util::FileType.filetype(:flat).new(path) + + obj.expects(:backup) + + obj.write("something") + + assert_equal("something", File.read(path), "File did not get changed") + end + + def test_backup + path = tempfile + type = Puppet::Type.type(:filebucket) + + obj = Puppet::Util::FileType.filetype(:flat).new(path) + + # First try it when the file does not yet exist. + assert_nothing_raised("Could not call backup when file does not exist") do + obj.backup + end + + # Then create the file + File.open(path, "w") { |f| f.print 'one' } + + # Then try it with no filebucket objects + assert_nothing_raised("Could not call backup with no buckets") do + obj.backup + end + puppet = type["puppet"] + assert(puppet, "Did not create default filebucket") + + assert_equal("one", puppet.bucket.getfile(Digest::MD5.hexdigest(File.read(path))), "Could not get file from backup") + + # Try it again when the default already exists + File.open(path, "w") { |f| f.print 'two' } + assert_nothing_raised("Could not call backup with no buckets") do + obj.backup + end + + assert_equal("two", puppet.bucket.getfile(Digest::MD5.hexdigest(File.read(path))), "Could not get file from backup") + end + if Facter["operatingsystem"].value == "Darwin" def test_ninfotoarray obj = nil |
