summaryrefslogtreecommitdiffstats
path: root/test/ral
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-11-14 19:27:50 -0600
committerLuke Kanies <luke@madstop.com>2008-11-15 02:25:47 -0600
commit053d7bfa678b152c42bf3fcbccaaa86aa578c39b (patch)
tree69904d2ac68767bf680b397d08ed066993e3d67d /test/ral
parenta8d9976d0a11c4dc50b2ef49c63f3f745cb4eccb (diff)
downloadpuppet-053d7bfa678b152c42bf3fcbccaaa86aa578c39b.tar.gz
puppet-053d7bfa678b152c42bf3fcbccaaa86aa578c39b.tar.xz
puppet-053d7bfa678b152c42bf3fcbccaaa86aa578c39b.zip
These changes are all about making sure file data is expired when appropriate.
All file tests now pass. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'test/ral')
-rwxr-xr-xtest/ral/type/file.rb151
-rwxr-xr-xtest/ral/type/filesources.rb6
2 files changed, 8 insertions, 149 deletions
diff --git a/test/ral/type/file.rb b/test/ral/type/file.rb
index 56ae8a285..5d3a9b60b 100755
--- a/test/ral/type/file.rb
+++ b/test/ral/type/file.rb
@@ -355,102 +355,6 @@ class TestFile < Test::Unit::TestCase
}
end
- def test_checksums
- types = %w{md5 md5lite timestamp time}
- exists = "/tmp/sumtest-exists"
- nonexists = "/tmp/sumtest-nonexists"
-
- @@tmpfiles << exists
- @@tmpfiles << nonexists
-
- # try it both with files that exist and ones that don't
- files = [exists, nonexists]
- initstorage
- File.open(exists,File::CREAT|File::TRUNC|File::WRONLY) { |of|
- of.puts "initial text"
- }
- types.each { |type|
- files.each { |path|
- if Puppet[:debug]
- Puppet.warning "Testing %s on %s" % [type,path]
- end
- file = nil
- events = nil
- # okay, we now know that we have a file...
- assert_nothing_raised() {
- file = Puppet.type(:file).create(
- :name => path,
- :ensure => "file",
- :checksum => type
- )
- }
- trans = nil
-
- currentvalues = file.retrieve
-
- if file.title !~ /nonexists/
- sum = file.property(:checksum)
- assert(sum.insync?(currentvalues[sum]), "file is not in sync")
- end
-
- events = assert_apply(file)
-
- assert(events)
-
- assert(! events.include?(:file_changed), "File incorrectly changed")
- assert_events([], file)
-
- # We have to sleep because the time resolution of the time-based
- # mechanisms is greater than one second
- sleep 1 if type =~ /time/
-
- assert_nothing_raised() {
- File.open(path,File::CREAT|File::TRUNC|File::WRONLY) { |of|
- of.puts "some more text, yo"
- }
- }
-
- # now recreate the file
- assert_nothing_raised() {
- file = Puppet.type(:file).create(
- :name => path,
- :checksum => type
- )
- }
- trans = nil
-
- assert_events([:file_changed], file)
-
- # Run it a few times to make sure we aren't getting
- # spurious changes.
- sum = nil
- assert_nothing_raised do
- sum = file.property(:checksum).retrieve
- end
- assert(file.property(:checksum).insync?(sum),
- "checksum is not in sync")
-
- sleep 1.1 if type =~ /time/
- assert_nothing_raised() {
- File.unlink(path)
- File.open(path,File::CREAT|File::TRUNC|File::WRONLY) { |of|
- # We have to put a certain amount of text in here or
- # the md5-lite test fails
- 2.times {
- of.puts rand(100)
- }
- of.flush
- }
- }
- assert_events([:file_changed], file)
-
- if path =~ /nonexists/
- File.unlink(path)
- end
- }
- }
- end
-
def cyclefile(path)
# i had problems with using :name instead of :path
[:name,:path].each { |param|
@@ -820,21 +724,20 @@ class TestFile < Test::Unit::TestCase
500.times { |i| f.puts "line %s" % i }
}
- obj = Puppet::Type.type(:file).create(
+ resource = Puppet::Type.type(:file).create(
:title => dest, :source => source
)
- assert_events([:file_created], obj)
+ assert_events([:file_created], resource)
File.open(source, File::APPEND|File::WRONLY) { |f| f.puts "another line" }
- assert_events([:file_changed], obj)
+ assert_events([:file_changed], resource)
# Now modify the dest file
File.open(dest, File::APPEND|File::WRONLY) { |f| f.puts "one more line" }
- assert_events([:file_changed, :file_changed], obj)
-
+ assert_events([:file_changed, :file_changed], resource)
end
def test_replacefilewithlink
@@ -877,48 +780,6 @@ class TestFile < Test::Unit::TestCase
assert(FileTest.exists?(dest), "File did not get created")
end
- def test_present_matches_anything
- path = tempfile()
-
- file = Puppet::Type.newfile(:path => path, :ensure => :present)
-
- currentvalues = file.retrieve
- assert(! file.insync?(currentvalues), "File incorrectly in sync")
-
- # Now make a file
- File.open(path, "w") { |f| f.puts "yay" }
-
- currentvalues = file.retrieve
- assert(file.insync?(currentvalues), "File not in sync")
-
- # Now make a directory
- File.unlink(path)
- Dir.mkdir(path)
-
- currentvalues = file.retrieve
- assert(file.insync?(currentvalues), "Directory not considered 'present'")
-
- Dir.rmdir(path)
-
- # Now make a link
- file[:links] = :manage
-
- otherfile = tempfile()
- File.symlink(otherfile, path)
-
- currentvalues = file.retrieve
- assert(file.insync?(currentvalues), "Symlink not considered 'present'")
- File.unlink(path)
- file.flush
-
- # Now set some content, and make sure it works
- file[:content] = "yayness"
-
- assert_apply(file)
-
- assert_equal("yayness", File.read(path), "Content did not get set correctly")
- end
-
# Testing #274. Make sure target can be used without 'ensure'.
def test_target_without_ensure
source = tempfile()
@@ -985,7 +846,7 @@ class TestFile < Test::Unit::TestCase
dir = tempfile()
Dir.mkdir(dir)
- bucket = Puppet::Type.newfilebucket :name => "main"
+ bucket = Puppet::Type.type(:filebucket).create :name => "main"
File.symlink(dir, link)
File.open(file, "w") { |f| f.puts "" }
assert_equal(dir, File.readlink(link))
@@ -1036,7 +897,7 @@ class TestFile < Test::Unit::TestCase
:link => proc { File.symlink(linkdest, path) }
}
- bucket = Puppet::Type.newfilebucket :name => "main", :path => tempfile()
+ bucket = Puppet::Type.type(:filebucket).create :name => "main", :path => tempfile()
obj = Puppet::Type.newfile :path => path, :force => true,
:links => :manage
diff --git a/test/ral/type/filesources.rb b/test/ral/type/filesources.rb
index 2479eb491..5b66f0e6f 100755
--- a/test/ral/type/filesources.rb
+++ b/test/ral/type/filesources.rb
@@ -433,12 +433,10 @@ class TestFileSources < Test::Unit::TestCase
"File got replaced when :replace was false")
# Now set it to true and make sure it does change.
- assert_nothing_raised {
- file[:replace] = true
- }
+ file[:replace] = true
assert_apply(file)
- # Make sure it doesn't change.
+ # Make sure it changes.
assert_equal("funtest\n", File.read(dest),
"File was not replaced when :replace was true")
end