diff options
author | David Schmitt <david@dasz.at> | 2010-05-17 14:38:41 +0200 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | 6a928940a43001f62cbd62d6c760c7d287bad855 (patch) | |
tree | 9aacb1f3dfd9d3f7c618463ae8c4bf06215bbb25 /spec | |
parent | 47c9dd16df3a31dddb486bc4d583ff3b86b0ac01 (diff) | |
download | puppet-6a928940a43001f62cbd62d6c760c7d287bad855.tar.gz |
Avoid trying to symlink() on windows
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/unit/type/file.rb | 309 |
1 files changed, 191 insertions, 118 deletions
diff --git a/spec/unit/type/file.rb b/spec/unit/type/file.rb index 4ce627549..548fc1b8f 100755 --- a/spec/unit/type/file.rb +++ b/spec/unit/type/file.rb @@ -5,6 +5,8 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe Puppet::Type.type(:file) do before do Puppet.settings.stubs(:use) + @real_posix = Puppet.features.posix? + Puppet.features.stubs("posix?").returns(true) @path = Tempfile.new("puppetspec") pathname = @path.path @@ -151,127 +153,181 @@ describe Puppet::Type.type(:file) do end describe "when using POSIX filenames" do - it "should autorequire its parent directory" do - file = Puppet::Type::File.new(:path => "/foo/bar") - dir = Puppet::Type::File.new(:path => "/foo") - @catalog.add_resource file - @catalog.add_resource dir - reqs = file.autorequire - reqs[0].source.must == dir - reqs[0].target.must == file - end + describe "on POSIX systems" do + before do + Puppet.features.stubs(:posix?).returns(true) + Puppet.features.stubs(:win32?).returns(false) + end - it "should not autorequire its parent dir if its parent dir is itself" do - file = Puppet::Type::File.new(:path => "/") - @catalog.add_resource file - file.autorequire.should be_empty - end + it "should autorequire its parent directory" do + file = Puppet::Type::File.new(:path => "/foo/bar") + dir = Puppet::Type::File.new(:path => "/foo") + @catalog.add_resource file + @catalog.add_resource dir + reqs = file.autorequire + reqs[0].source.must == dir + reqs[0].target.must == file + end - it "should remove trailing slashes" do - file = Puppet::Type::File.new(:path => "/foo/bar/baz/") - file[:path].should == "/foo/bar/baz" - end + it "should not autorequire its parent dir if its parent dir is itself" do + file = Puppet::Type::File.new(:path => "/") + @catalog.add_resource file + file.autorequire.should be_empty + end - it "should remove double slashes" do - file = Puppet::Type::File.new(:path => "/foo/bar//baz") - file[:path].should == "/foo/bar/baz" - end + it "should remove trailing slashes" do + file = Puppet::Type::File.new(:path => "/foo/bar/baz/") + file[:path].should == "/foo/bar/baz" + end - it "should remove trailing double slashes" do - file = Puppet::Type::File.new(:path => "/foo/bar/baz//") - file[:path].should == "/foo/bar/baz" + it "should remove double slashes" do + file = Puppet::Type::File.new(:path => "/foo/bar//baz") + file[:path].should == "/foo/bar/baz" + end + + it "should remove trailing double slashes" do + file = Puppet::Type::File.new(:path => "/foo/bar/baz//") + file[:path].should == "/foo/bar/baz" + end + + it "should leave a single slash alone" do + file = Puppet::Type::File.new(:path => "/") + file[:path].should == "/" + end end + + describe "on Win32 systems" do + before do + Puppet.features.stubs(:posix?).returns(false) + Puppet.features.stubs(:win32?).returns(true) + end - it "should leave a single slash alone" do - file = Puppet::Type::File.new(:path => "/") - file[:path].should == "/" + it "should refuse to work" do + lambda { Puppet::Type::File.new(:path => "/foo/bar") }.should raise_error(Puppet::Error) + end end end describe "when using Win32 filenames" do - it "should autorequire its parent directory" do - file = Puppet::Type::File.new(:path => "X:/foo/bar") - dir = Puppet::Type::File.new(:path => "X:/foo") - @catalog.add_resource file - @catalog.add_resource dir - reqs = file.autorequire - reqs[0].source.must == dir - reqs[0].target.must == file - end + describe "on Win32 systems" do + before do + Puppet.features.stubs(:posix?).returns(false) + Puppet.features.stubs(:win32?).returns(true) + end - it "should not autorequire its parent dir if its parent dir is itself" do - file = Puppet::Type::File.new(:path => "X:/") - @catalog.add_resource file - file.autorequire.should be_empty - end + it "should autorequire its parent directory" do + file = Puppet::Type::File.new(:path => "X:/foo/bar") + dir = Puppet::Type::File.new(:path => "X:/foo") + @catalog.add_resource file + @catalog.add_resource dir + reqs = file.autorequire + reqs[0].source.must == dir + reqs[0].target.must == file + end - it "should remove trailing slashes" do - file = Puppet::Type::File.new(:path => "X:/foo/bar/baz/") - file[:path].should == "X:/foo/bar/baz" - end + it "should not autorequire its parent dir if its parent dir is itself" do + file = Puppet::Type::File.new(:path => "X:/") + @catalog.add_resource file + file.autorequire.should be_empty + end - it "should remove double slashes" do - file = Puppet::Type::File.new(:path => "X:/foo/bar//baz") - file[:path].should == "X:/foo/bar/baz" - end + it "should remove trailing slashes" do + file = Puppet::Type::File.new(:path => "X:/foo/bar/baz/") + file[:path].should == "X:/foo/bar/baz" + end - it "should remove trailing double slashes" do - file = Puppet::Type::File.new(:path => "X:/foo/bar/baz//") - file[:path].should == "X:/foo/bar/baz" - end + it "should remove double slashes" do + file = Puppet::Type::File.new(:path => "X:/foo/bar//baz") + file[:path].should == "X:/foo/bar/baz" + end + + it "should remove trailing double slashes" do + file = Puppet::Type::File.new(:path => "X:/foo/bar/baz//") + file[:path].should == "X:/foo/bar/baz" + end + + it "should leave a drive letter with a slash alone" do + file = Puppet::Type::File.new(:path => "X:/") + file[:path].should == "X:/" + end - it "should leave a drive letter with a slash alone" do - file = Puppet::Type::File.new(:path => "X:/") - file[:path].should == "X:/" + it "should add a slash to a drive letter" do + file = Puppet::Type::File.new(:path => "X:") + file[:path].should == "X:/" + end end - it "should add a slash to a drive letter" do - file = Puppet::Type::File.new(:path => "X:") - file[:path].should == "X:/" + describe "on POSIX systems" do + before do + Puppet.features.stubs(:posix?).returns(true) + Puppet.features.stubs(:win32?).returns(false) + end + + it "should refuse to work" do + lambda { Puppet::Type::File.new(:path => "X:/foo/bar") }.should raise_error(Puppet::Error) + end end end describe "when using UNC filenames" do - it "should autorequire its parent directory" do - file = Puppet::Type::File.new(:path => "//server/foo/bar") - dir = Puppet::Type::File.new(:path => "//server/foo") - @catalog.add_resource file - @catalog.add_resource dir - reqs = file.autorequire - reqs[0].source.must == dir - reqs[0].target.must == file - end + describe "on Win32 systems" do + before do + Puppet.features.stubs(:posix?).returns(false) + Puppet.features.stubs(:win32?).returns(true) + end - it "should not autorequire its parent dir if its parent dir is itself" do - file = Puppet::Type::File.new(:path => "//server/foo") - @catalog.add_resource file - puts file.autorequire - file.autorequire.should be_empty - end + it "should autorequire its parent directory" do + file = Puppet::Type::File.new(:path => "//server/foo/bar") + dir = Puppet::Type::File.new(:path => "//server/foo") + @catalog.add_resource file + @catalog.add_resource dir + reqs = file.autorequire + reqs[0].source.must == dir + reqs[0].target.must == file + end - it "should remove trailing slashes" do - file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/") - file[:path].should == "//server/foo/bar/baz" - end + it "should not autorequire its parent dir if its parent dir is itself" do + file = Puppet::Type::File.new(:path => "//server/foo") + @catalog.add_resource file + puts file.autorequire + file.autorequire.should be_empty + end - it "should remove double slashes" do - file = Puppet::Type::File.new(:path => "//server/foo/bar//baz") - file[:path].should == "//server/foo/bar/baz" - end + it "should remove trailing slashes" do + file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/") + file[:path].should == "//server/foo/bar/baz" + end - it "should remove trailing double slashes" do - file = Puppet::Type::File.new(:path => "//server/foo/bar/baz//") - file[:path].should == "//server/foo/bar/baz" - end + it "should remove double slashes" do + file = Puppet::Type::File.new(:path => "//server/foo/bar//baz") + file[:path].should == "//server/foo/bar/baz" + end + + it "should remove trailing double slashes" do + file = Puppet::Type::File.new(:path => "//server/foo/bar/baz//") + file[:path].should == "//server/foo/bar/baz" + end - it "should remove a trailing slash from a sharename" do - file = Puppet::Type::File.new(:path => "//server/foo/") - file[:path].should == "//server/foo" + it "should remove a trailing slash from a sharename" do + file = Puppet::Type::File.new(:path => "//server/foo/") + file[:path].should == "//server/foo" + end + + it "should not modify a sharename" do + file = Puppet::Type::File.new(:path => "//server/foo") + file[:path].should == "//server/foo" + end end - it "should not modify a sharename" do - file = Puppet::Type::File.new(:path => "//server/foo") - file[:path].should == "//server/foo" + describe "on POSIX systems" do + before do + Puppet.features.stubs(:posix?).returns(true) + Puppet.features.stubs(:win32?).returns(false) + end + + it "should refuse to work" do + lambda { Puppet::Type::File.new(:path => "X:/foo/bar") }.should raise_error(Puppet::Error) + end end end @@ -310,37 +366,54 @@ describe Puppet::Type.type(:file) do include PuppetTest require 'tempfile' - before do - @basedir = tempfile - Dir.mkdir(@basedir) - @file = File.join(@basedir, "file") - @link = File.join(@basedir, "link") + if @real_posix + describe "on POSIX systems" do + before do + @basedir = tempfile + Dir.mkdir(@basedir) + @file = File.join(@basedir, "file") + @link = File.join(@basedir, "link") + + File.open(@file, "w", 0644) { |f| f.puts "yayness"; f.flush } + File.symlink(@file, @link) + + @resource = Puppet::Type.type(:file).new( + :path => @link, + :mode => "755" + ) + @catalog.add_resource @resource + end - File.open(@file, "w", 0644) { |f| f.puts "yayness"; f.flush } - File.symlink(@file, @link) + after do + remove_tmp_files + end - @resource = Puppet::Type.type(:file).new( - :path => @link, - :mode => "755" - ) - @catalog.add_resource @resource - end + it "should default to managing the link" do + @catalog.apply + # I convert them to strings so they display correctly if there's an error. + ("%o" % (File.stat(@file).mode & 007777)).should == "%o" % 0644 + end - after do - remove_tmp_files - end + it "should be able to follow links" do + @resource[:links] = :follow + @catalog.apply - it "should default to managing the link" do - @catalog.apply - # I convert them to strings so they display correctly if there's an error. - ("%o" % (File.stat(@file).mode & 007777)).should == "%o" % 0644 + ("%o" % (File.stat(@file).mode & 007777)).should == "%o" % 0755 + end + end + else # @real_posix + # should recode tests using expectations instead of using the filesystem end + + describe "on Win32 systems" do + before do + Puppet.features.stubs(:posix?).returns(false) + Puppet.features.stubs(:win32?).returns(true) + end - it "should be able to follow links" do - @resource[:links] = :follow - @catalog.apply - - ("%o" % (File.stat(@file).mode & 007777)).should == "%o" % 0755 + it "should refuse to work with links" do + lambda { Puppet::Type.type(:file).new(:path => @link, :mode => "755") }.should raise_error(Puppet::Error) + end end end |