summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-11-05 23:04:33 -0600
committerLuke Kanies <luke@madstop.com>2008-11-05 23:04:33 -0600
commit0149e2e125fc09bb5a8c1ff206cd46e06c0593cd (patch)
treea97f8bd6e045ec2aaf9a25682f341425b5d3b481 /test
parent35c623e65b44fed098374288e8c1dfc450a1f9f7 (diff)
downloadpuppet-0149e2e125fc09bb5a8c1ff206cd46e06c0593cd.tar.gz
puppet-0149e2e125fc09bb5a8c1ff206cd46e06c0593cd.tar.xz
puppet-0149e2e125fc09bb5a8c1ff206cd46e06c0593cd.zip
Converting the file 'source' property to a parameter.
This makes a lot of sense because source was always more of a metaparameter than a property -- it affected the 'should' values of other properties, but it shouldn't have done any other work. It will hopefully make everything else much cleaner. This is such a large commit mostly because of the need to fix a lot of tests. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'test')
-rwxr-xr-xtest/other/overrides.rb34
-rwxr-xr-xtest/ral/type/exec.rb2
-rwxr-xr-xtest/ral/type/file.rb41
-rwxr-xr-xtest/ral/type/file/target.rb61
-rwxr-xr-xtest/ral/type/filesources.rb90
5 files changed, 24 insertions, 204 deletions
diff --git a/test/other/overrides.rb b/test/other/overrides.rb
index e0e3fdf5f..b38cb09e8 100755
--- a/test/other/overrides.rb
+++ b/test/other/overrides.rb
@@ -23,33 +23,27 @@ class TestOverrides < Test::Unit::TestCase
basedir = File.join(tmpdir(), "overridetesting")
mksubdirs(basedir, 1)
- baseobj = nil
basefile = File.join(basedir, "file")
- assert_nothing_raised("Could not create base obj") {
- baseobj = Puppet.type(:file).create(
- :title => "base",
- :path => basedir,
- :recurse => true,
- :mode => "755"
- )
- }
+ baseobj = Puppet.type(:file).create(
+ :title => "base",
+ :path => basedir,
+ :recurse => true,
+ :mode => "755"
+ )
- subobj = nil
subdir = File.join(basedir, "0")
subfile = File.join(subdir, "file")
- assert_nothing_raised("Could not create sub obj") {
- subobj = Puppet.type(:file).create(
- :title => "sub",
- :path => subdir,
- :recurse => true,
- :mode => "644"
- )
- }
+ subobj = Puppet.type(:file).create(
+ :title => "sub",
+ :path => subdir,
+ :recurse => true,
+ :mode => "644"
+ )
assert_apply(baseobj, subobj)
- assert(File.stat(basefile).mode & 007777 == 0755)
- assert(File.stat(subfile).mode & 007777 == 0644)
+ assert_equal(0755, File.stat(basefile).mode & 007777, "Did not set base mode")
+ assert_equal(0644, File.stat(subfile).mode & 007777, "Did not set overridden mode")
end
def test_deepoverride
diff --git a/test/ral/type/exec.rb b/test/ral/type/exec.rb
index 8c7c3f69b..5ccfc2475 100755
--- a/test/ral/type/exec.rb
+++ b/test/ral/type/exec.rb
@@ -442,7 +442,7 @@ class TestExec < Test::Unit::TestCase
Puppet.type(:exec).checks.each do |check|
klass = Puppet.type(:exec).paramclass(check)
- next if klass.values.include? :false
+ next if klass.value_collection.values.include? :false
assert_raise(Puppet::Error, "Check '%s' did not fail on false" % check) do
exec[check] = false
end
diff --git a/test/ral/type/file.rb b/test/ral/type/file.rb
index c0c644dc0..348970fd7 100755
--- a/test/ral/type/file.rb
+++ b/test/ral/type/file.rb
@@ -639,46 +639,6 @@ class TestFile < Test::Unit::TestCase
assert_equal(subobj, edge.target, "file did not require its parent dir")
end
- def test_content
- file = tempfile()
- str = "This is some content"
-
- obj = nil
- assert_nothing_raised {
- obj = Puppet.type(:file).create(
- :name => file,
- :content => str
- )
- }
-
- assert(!obj.insync?(obj.retrieve), "Object is incorrectly in sync")
-
- assert_events([:file_created], obj)
-
- currentvalues = obj.retrieve
-
- assert(obj.insync?(currentvalues), "Object is not in sync")
-
- text = File.read(file)
-
- assert_equal(str, text, "Content did not copy correctly")
-
- newstr = "Another string, yo"
-
- obj[:content] = newstr
-
- assert(!obj.insync?(obj.retrieve), "Object is incorrectly in sync")
-
- assert_events([:file_changed], obj)
-
- text = File.read(file)
-
- assert_equal(newstr, text, "Content did not copy correctly")
-
- currentvalues = obj.retrieve
- assert(obj.insync?(currentvalues), "Object is not in sync")
- end
-
# Unfortunately, I know this fails
def disabled_test_recursivemkdir
path = tempfile()
@@ -946,6 +906,7 @@ class TestFile < Test::Unit::TestCase
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"
diff --git a/test/ral/type/file/target.rb b/test/ral/type/file/target.rb
index b6c84df99..4fd5894d7 100755
--- a/test/ral/type/file/target.rb
+++ b/test/ral/type/file/target.rb
@@ -42,54 +42,6 @@ class TestFileTarget < Test::Unit::TestCase
assert_events([], file)
assert_events([], file)
end
-
- def test_linkrecurse
- dest = tempfile()
- link = @file.create :path => tempfile(), :recurse => true, :ensure => dest
- catalog = mk_catalog(link)
-
- ret = nil
-
- # Start with nothing, just to make sure we get nothing back
- assert_nothing_raised { ret = link.linkrecurse(true) }
- assert_nil(ret, "got a return when the dest doesn't exist")
-
- # then with a directory with only one file
- Dir.mkdir(dest)
- one = File.join(dest, "one")
- File.open(one, "w") { |f| f.puts "" }
- link[:ensure] = dest
- assert_nothing_raised { ret = link.linkrecurse(true) }
-
- assert_equal(:directory, link.should(:ensure), "ensure was not set to directory")
- assert_equal([File.join(link.title, "one")], ret.collect { |f| f.title },
- "Did not get linked file")
- oneobj = catalog.resource(:file, File.join(link.title, "one"))
- assert_equal(one, oneobj.should(:target), "target was not set correctly")
-
- oneobj.remove
- File.unlink(one)
-
- # Then make sure we get multiple files
- returns = []
- 5.times do |i|
- path = File.join(dest, i.to_s)
- returns << File.join(link.title, i.to_s)
- File.open(path, "w") { |f| f.puts "" }
- end
- assert_nothing_raised { ret = link.linkrecurse(true) }
-
- assert_equal(returns.sort, ret.collect { |f| f.title }.sort,
- "Did not get links back")
-
- returns.each do |path|
- obj = catalog.resource(:file, path)
- assert(path, "did not get obj for %s" % path)
- sdest = File.join(dest, File.basename(path))
- assert_equal(sdest, obj.should(:target),
- "target was not set correctly for %s" % path)
- end
- end
def test_simplerecursivelinking
source = tempfile()
@@ -116,7 +68,8 @@ class TestFileTarget < Test::Unit::TestCase
assert(File.symlink?(linkpath), "path is not a link")
assert_equal(file, File.readlink(linkpath))
- assert_nil(catalog.resource(:file, sublink), "objects were not removed")
+ # Use classes for comparison, because the resource inspection is so large
+ assert_equal(NilClass, catalog.resource(:file, sublink).class, "dynamically generated resources were not removed")
assert_equal([], link.evaluate, "Link is not in sync")
end
@@ -195,20 +148,20 @@ class TestFileTarget < Test::Unit::TestCase
source = tempfile()
dest = tempfile()
- objects = []
- objects << Puppet.type(:exec).create(
+ resources = []
+ resources << Puppet.type(:exec).create(
:command => "mkdir %s; touch %s/file" % [source, source],
:title => "yay",
:path => ENV["PATH"]
)
- objects << Puppet.type(:file).create(
+ resources << Puppet.type(:file).create(
:ensure => source,
:path => dest,
:recurse => true,
- :require => objects[0]
+ :require => resources[0]
)
- assert_apply(*objects)
+ assert_apply(*resources)
link = File.join(dest, "file")
assert(FileTest.symlink?(link), "Did not make link")
diff --git a/test/ral/type/filesources.rb b/test/ral/type/filesources.rb
index 9dd1d988e..2479eb491 100755
--- a/test/ral/type/filesources.rb
+++ b/test/ral/type/filesources.rb
@@ -53,94 +53,6 @@ class TestFileSources < Test::Unit::TestCase
destfile = File.join(dest, "file")
return source, dest, sourcefile, destfile
end
-
- def test_source_retrieve
- source = tempfile()
- dest = tempfile()
-
- file = Puppet::Type.newfile :path => dest, :source => source,
- :title => "copier"
-
- assert(file.property(:checksum), "source property did not create checksum property")
- property = file.property(:source)
- assert(property, "did not get source property")
-
- # Make sure the munge didn't actually change the source
- assert_equal([source], property.should, "munging changed the source")
-
- currentvalue = nil
- # Now make the dest a directory, and make sure the object sets :ensure
- # up to create a directory
- Dir.mkdir(source)
- assert_nothing_raised do
- currentvalue = property.retrieve
- end
- assert_equal(:directory, file.should(:ensure),
- "Did not set to create directory")
-
- # And make sure the source property won't try to do anything with a
- # remote dir
- assert(property.insync?(currentvalue), "Source was out of sync even tho remote is dir")
-
- # Now remove the source, and make sure :ensure was not modified
- Dir.rmdir(source)
- assert_equal(:directory, file.should(:ensure),
- "Did not keep :ensure setting")
-
- # Now have a remote file and make sure things work correctly
- File.open(source, "w") { |f| f.puts "yay" }
- File.chmod(0755, source)
-
- assert_nothing_raised do
- property.retrieve
- end
- assert_equal(:file, file.should(:ensure),
- "Did not make correct :ensure setting")
- assert_equal(0755, file.should(:mode),
- "Mode was not copied over")
-
- # Now let's make sure that we get the first found source
- fake = tempfile()
- property.should = [fake, source]
- assert_nothing_raised do
- property.retrieve
- end
- assert_equal(Digest::MD5.hexdigest(File.read(source)), property.checksum.sub(/^\{\w+\}/, ''),
- "Did not catch later source")
- end
-
- def test_source_sync
- source = tempfile()
- dest = tempfile()
-
- file = Puppet::Type.newfile :path => dest, :source => source,
- :title => "copier"
- property = file.property(:source)
-
- File.open(source, "w") { |f| f.puts "yay" }
-
- currentvalues = file.retrieve
- assert(! property.insync?(currentvalues[property]), "source thinks it's in sync")
-
- event = nil
- assert_nothing_raised do
- event = property.sync
- end
- assert_equal(:file_created, event)
- assert_equal(File.read(source), File.read(dest),
- "File was not copied correctly")
-
- # Now write something different
- File.open(source, "w") { |f| f.puts "rah" }
- currentvalues = file.retrieve
- assert(! property.insync?(currentvalues[property]), "source should be out of sync")
- assert_nothing_raised do
- event = property.sync
- end
- assert_equal(:file_changed, event)
- assert_equal(File.read(source), File.read(dest),
- "File was not copied correctly")
- end
def recursive_source_test(fromdir, todir)
initstorage
@@ -259,7 +171,7 @@ class TestFileSources < Test::Unit::TestCase
FileUtils.cd(todir) {
%x{find . 2>/dev/null}.chomp.split(/\n/).each { |file|
if file =~ /file[0-9]+/
- File.unlink(file)
+ FileUtils.rm_rf(file)
end
}
}