diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-03-10 05:41:01 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-03-10 05:41:01 +0000 |
| commit | 02f91fcd55aefe63a11a29c5608c0738867b8130 (patch) | |
| tree | c0904874ea0a7535f8b3d3d226583004493153ef /test | |
| parent | b336e7e59d3497b96dd42b6dbc1855176e6e830d (diff) | |
Merging symlinks back into files. Symlinks still exist but with a warning about deprecation. Fixes #93. Also the first time I have run any tests on OS X, so there are some bug fixes related to that.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1000 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
| -rw-r--r-- | test/types/file.rb | 143 | ||||
| -rw-r--r-- | test/types/parameter.rb | 2 | ||||
| -rw-r--r-- | test/types/state.rb | 6 | ||||
| -rwxr-xr-x | test/types/symlink.rb | 3 |
4 files changed, 149 insertions, 5 deletions
diff --git a/test/types/file.rb b/test/types/file.rb index a92b62a5c..7951a623c 100644 --- a/test/types/file.rb +++ b/test/types/file.rb @@ -929,6 +929,149 @@ class TestFile < Test::Unit::TestCase assert_apply(file) assert_equal("%o" % 0755, "%o" % (File.stat(path).mode & 007777)) end + + # Make sure we can create symlinks + def test_symlinks + path = tempfile() + link = tempfile() + + File.open(path, "w") { |f| f.puts "yay" } + + file = nil + assert_nothing_raised { + file = Puppet.type(:file).create( + :ensure => path, + :path => link + ) + } + + assert_events([:link_created], file) + + assert(FileTest.symlink?(link), "Link was not created") + + assert_equal(path, File.readlink(link), "Link was created incorrectly") + end + + def test_simplerecursivelinking + source = tempfile() + dest = tempfile() + subdir = File.join(source, "subdir") + file = File.join(subdir, "file") + + system("mkdir -p %s" % subdir) + system("touch %s" % file) + + link = nil + assert_nothing_raised { + link = Puppet.type(:file).create( + :ensure => source, + :path => dest, + :recurse => true + ) + } + + assert_apply(link) + + subdest = File.join(dest, "subdir") + linkpath = File.join(subdest, "file") + assert(File.directory?(dest), "dest is not a dir") + assert(File.directory?(subdest), "subdest is not a dir") + assert(File.symlink?(linkpath), "path is not a link") + assert_equal(file, File.readlink(linkpath)) + end + + def test_recursivelinking + source = tempfile() + dest = tempfile() + + files = [] + dirs = [] + + # Make a bunch of files and dirs + Dir.mkdir(source) + Dir.chdir(source) do + system("mkdir -p %s" % "some/path/of/dirs") + system("mkdir -p %s" % "other/path/of/dirs") + system("touch %s" % "file") + system("touch %s" % "other/file") + system("touch %s" % "some/path/of/file") + system("touch %s" % "some/path/of/dirs/file") + system("touch %s" % "other/path/of/file") + + files = %x{find . -type f}.chomp.split(/\n/) + dirs = %x{find . -type d}.chomp.split(/\n/).reject{|d| d =~ /^\.+$/ } + end + + link = nil + assert_nothing_raised { + link = Puppet.type(:file).create( + :ensure => source, + :path => dest, + :recurse => true + ) + } + + assert_apply(link) + + files.each do |f| + f.sub!(/^\.#{File::SEPARATOR}/, '') + path = File.join(dest, f) + assert(FileTest.exists?(path), "Link %s was not created" % path) + assert(FileTest.symlink?(path), "%s is not a link" % f) + target = File.readlink(path) + assert_equal(File.join(source, f), target) + end + + dirs.each do |d| + d.sub!(/^\.#{File::SEPARATOR}/, '') + path = File.join(dest, d) + assert(FileTest.exists?(path), "Dir %s was not created" % path) + assert(FileTest.directory?(path), "%s is not a directory" % d) + end + end + + def test_localrelativelinks + dir = tempfile() + Dir.mkdir(dir) + source = File.join(dir, "source") + File.open(source, "w") { |f| f.puts "yay" } + dest = File.join(dir, "link") + + link = nil + assert_nothing_raised { + link = Puppet.type(:file).create( + :path => dest, + :ensure => "source" + ) + } + + assert_events([:link_created], link) + assert(FileTest.symlink?(dest), "Did not create link") + assert_equal("source", File.readlink(dest)) + assert_equal("yay\n", File.read(dest)) + end + + def test_recursivelinkingmissingtarget + source = tempfile() + dest = tempfile() + + objects = [] + objects << Puppet.type(:exec).create( + :command => "mkdir %s; touch %s/file" % [source, source], + :path => ENV["PATH"] + ) + objects << Puppet.type(:file).create( + :ensure => source, + :path => dest, + :recurse => true + ) + + assert_apply(*objects) + + link = File.join(dest, "file") + assert(FileTest.symlink?(link), "Did not make link") + assert_equal(File.join(source, "file"), File.readlink(link)) + end end # $Id$ diff --git a/test/types/parameter.rb b/test/types/parameter.rb index d95ef461d..902f1398e 100644 --- a/test/types/parameter.rb +++ b/test/types/parameter.rb @@ -8,7 +8,7 @@ require 'puppet/type' require 'puppettest' require 'test/unit' -class TestState < Test::Unit::TestCase +class TestParameter < Test::Unit::TestCase include TestPuppet def newparam(name = :fakeparam) diff --git a/test/types/state.rb b/test/types/state.rb index 88df6575d..406b9af6b 100644 --- a/test/types/state.rb +++ b/test/types/state.rb @@ -63,12 +63,12 @@ class TestState < Test::Unit::TestCase assert_equal(2, inst.is) end - def test_newvaluewithregexes + def test_newstatevaluewithregexes state = newstate() assert_nothing_raised { - state.newvalue(/^\w+$/) do |value| - @is = value.upcase + state.newvalue(/^\w+$/) do + @is = self.should.upcase return :regex_matched end } diff --git a/test/types/symlink.rb b/test/types/symlink.rb index 21b1e865b..eb6b9a04d 100755 --- a/test/types/symlink.rb +++ b/test/types/symlink.rb @@ -77,6 +77,7 @@ class TestSymlink < Test::Unit::TestCase cycle(comp) path = link.name + assert(FileTest.directory?(path), "Did not make %s" % path) list = file_list(path) FileUtils.cd(path) { list.each { |file| @@ -89,7 +90,7 @@ class TestSymlink < Test::Unit::TestCase } end - def test_createdrecursion + def disabled_test_createdrecursion source = tempfile() file = File.join(source, "file") dest = tempfile() |
