summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Helwig <jacob@puppetlabs.com>2011-08-02 17:05:10 -0700
committerJacob Helwig <jacob@puppetlabs.com>2011-08-02 17:05:10 -0700
commit11b4d2ddcc240e1d3ea4106c984ef98e6de9b653 (patch)
treeaccb62eb82b2dfda19f386b57bf0c267f9c993bb
parente9233b67a5d73852d89eb2e14dcf5255fe082a6a (diff)
parent447c1171845d8d17e4e684c9508fddecc003d15e (diff)
downloadpuppet-11b4d2ddcc240e1d3ea4106c984ef98e6de9b653.tar.gz
puppet-11b4d2ddcc240e1d3ea4106c984ef98e6de9b653.tar.xz
puppet-11b4d2ddcc240e1d3ea4106c984ef98e6de9b653.zip
Merge branch 'file-test-on-windows'
* file-test-on-windows: Check for the appropriate permissions in File type tests on Windows Remove :fails_on_windows from file type tests that no longer fail on Windows Disable file bucket diffing tests on Windows Always put a slash between the checksum and path in filebucket URLs Treat Windows absolute paths as absolute paths Consolidate test logic determining if a registered file is in the temp directory Clarify logic and error messages when initializing Puppet::FileBucket::File Disable symlink related file tests on Windows
-rw-r--r--lib/puppet/file_bucket/dipper.rb5
-rw-r--r--lib/puppet/file_bucket/file.rb6
-rw-r--r--lib/puppet/file_serving/base.rb5
-rw-r--r--lib/puppet/file_serving/indirection_hooks.rb1
-rw-r--r--lib/puppet/indirector/request.rb4
-rw-r--r--lib/puppet/type/file.rb20
-rwxr-xr-xlib/puppet/type/file/source.rb4
-rwxr-xr-xspec/integration/type/file_spec.rb30
-rwxr-xr-xspec/lib/puppet_spec/files.rb18
-rwxr-xr-xspec/unit/file_bucket/dipper_spec.rb2
-rwxr-xr-xspec/unit/file_bucket/file_spec.rb12
-rwxr-xr-xspec/unit/indirector/file_bucket_file/file_spec.rb2
-rwxr-xr-xspec/unit/type/file_spec.rb380
13 files changed, 232 insertions, 257 deletions
diff --git a/lib/puppet/file_bucket/dipper.rb b/lib/puppet/file_bucket/dipper.rb
index d6f6a3747..870c50eec 100644
--- a/lib/puppet/file_bucket/dipper.rb
+++ b/lib/puppet/file_bucket/dipper.rb
@@ -35,11 +35,12 @@ class Puppet::FileBucket::Dipper
begin
file_bucket_file = Puppet::FileBucket::File.new(contents, :bucket_path => @local_path)
files_original_path = absolutize_path(file)
- dest_path = "#{@rest_path}#{file_bucket_file.name}#{files_original_path}"
+ dest_path = "#{@rest_path}#{file_bucket_file.name}/#{files_original_path}"
+ file_bucket_path = "#{@rest_path}#{file_bucket_file.checksum_type}/#{file_bucket_file.checksum_data}/#{files_original_path}"
# Make a HEAD request for the file so that we don't waste time
# uploading it if it already exists in the bucket.
- unless Puppet::FileBucket::File.indirection.head("#{@rest_path}#{file_bucket_file.checksum_type}/#{file_bucket_file.checksum_data}#{files_original_path}")
+ unless Puppet::FileBucket::File.indirection.head(file_bucket_path)
Puppet::FileBucket::File.indirection.save(file_bucket_file, dest_path)
end
diff --git a/lib/puppet/file_bucket/file.rb b/lib/puppet/file_bucket/file.rb
index 08c0329f1..2a0558fde 100644
--- a/lib/puppet/file_bucket/file.rb
+++ b/lib/puppet/file_bucket/file.rb
@@ -15,11 +15,11 @@ class Puppet::FileBucket::File
attr :bucket_path
def initialize( contents, options = {} )
- raise ArgumentError if !contents.is_a?(String)
- @contents = contents
+ raise ArgumentError.new("contents must be a String, got a #{contents.class}") unless contents.is_a?(String)
+ @contents = contents
@bucket_path = options.delete(:bucket_path)
- raise ArgumentError if options != {}
+ raise ArgumentError.new("Unknown option(s): #{options.keys.join(', ')}") unless options.empty?
end
def checksum_type
diff --git a/lib/puppet/file_serving/base.rb b/lib/puppet/file_serving/base.rb
index 09cab97d9..706f67af9 100644
--- a/lib/puppet/file_serving/base.rb
+++ b/lib/puppet/file_serving/base.rb
@@ -53,7 +53,10 @@ class Puppet::FileServing::Base
# Set our base path.
attr_reader :path
def path=(path)
- raise ArgumentError.new("Paths must be fully qualified") unless path =~ /^#{::File::SEPARATOR}/
+ unless path =~ /^#{::File::SEPARATOR}/ or path =~ /^[a-z]:[\/\\]/i
+ raise ArgumentError.new("Paths must be fully qualified")
+ end
+
@path = path
end
diff --git a/lib/puppet/file_serving/indirection_hooks.rb b/lib/puppet/file_serving/indirection_hooks.rb
index a85e90ef1..2a0dc1792 100644
--- a/lib/puppet/file_serving/indirection_hooks.rb
+++ b/lib/puppet/file_serving/indirection_hooks.rb
@@ -17,6 +17,7 @@ module Puppet::FileServing::IndirectionHooks
# Short-circuit to :file if it's a fully-qualified path or specifies a 'file' protocol.
return PROTOCOL_MAP["file"] if request.key =~ /^#{::File::SEPARATOR}/
+ return PROTOCOL_MAP["file"] if request.key =~ /^[a-z]:[\/\\]/i
return PROTOCOL_MAP["file"] if request.protocol == "file"
# We're heading over the wire the protocol is 'puppet' and we've got a server name or we're not named 'apply' or 'puppet'
diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb
index 697d9df47..4dfbac9ab 100644
--- a/lib/puppet/indirector/request.rb
+++ b/lib/puppet/indirector/request.rb
@@ -127,7 +127,9 @@ class Puppet::Indirector::Request
# because it rewrites the key. We could otherwise strip server/port/etc
# info out in the REST class, but it seemed bad design for the REST
# class to rewrite the key.
- if key.to_s =~ /^\w+:\/\// # it's a URI
+ if key.to_s =~ /^[a-z]:[\/\\]/i # It's an absolute path for Windows.
+ @key = key
+ elsif key.to_s =~ /^\w+:\/\// # it's a URI
set_uri_key(key)
else
@key = key
diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb
index 988416ab5..07409a108 100644
--- a/lib/puppet/type/file.rb
+++ b/lib/puppet/type/file.rb
@@ -23,7 +23,7 @@ Puppet::Type.newtype(:file) do
location, rather than using native resources, please contact
Puppet Labs and we can hopefully work with you to develop a
native resource to support what you are doing.
-
+
**Autorequires:** If Puppet is managing the user or group that owns a file, the file resource will autorequire them. If Puppet is managing any parent directories of a file, the file resource will autorequire them."
def self.title_patterns
@@ -36,7 +36,7 @@ Puppet::Type.newtype(:file) do
validate do |value|
# accept various path syntaxes: lone slash, posix, win32, unc
- unless (Puppet.features.posix? and value =~ /^\//) or (Puppet.features.microsoft_windows? and (value =~ /^[A-Za-z]:\// or value =~ /^\/\/[^\/]+\/[^\/]+/))
+ unless (Puppet.features.posix? and value =~ /^\//) or (value =~ /^[A-Za-z]:\// or value =~ /^\/\/[^\/]+\/[^\/]+/)
fail Puppet::Error, "File paths must be fully qualified, not '#{value}'"
end
end
@@ -44,7 +44,21 @@ Puppet::Type.newtype(:file) do
# convert the current path in an index into the collection and the last
# path name. The aim is to use less storage for all common paths in a hierarchy
munge do |value|
- path, name = ::File.split(value.gsub(/\/+/,'/'))
+ # We need to save off, and remove the volume designator in the
+ # path if it is there, since File.split does not handle paths
+ # with volume designators properly, except when run on Windows.
+ # Since we are potentially compiling a catalog for a Windows
+ # machine on a non-Windows master, we need to handle this
+ # ourselves.
+ optional_volume_designator = value.match(/^([a-z]:)[\/\\].*/i)
+ value_without_designator = value.sub(/^(?:[a-z]:)?(.*)/i, '\1')
+
+ path, name = ::File.split(value_without_designator.gsub(/\/+/,'/'))
+
+ if optional_volume_designator
+ path = optional_volume_designator[1] + path
+ end
+
{ :index => Puppet::FileCollection.collection.index(path), :name => name }
end
diff --git a/lib/puppet/type/file/source.rb b/lib/puppet/type/file/source.rb
index 39f85e2ad..8653a8f7a 100755
--- a/lib/puppet/type/file/source.rb
+++ b/lib/puppet/type/file/source.rb
@@ -72,7 +72,7 @@ module Puppet
self.fail "Could not understand source #{source}: #{detail}"
end
- self.fail "Cannot use URLs of type '#{uri.scheme}' as source for fileserving" unless uri.scheme.nil? or %w{file puppet}.include?(uri.scheme)
+ self.fail "Cannot use URLs of type '#{uri.scheme}' as source for fileserving" unless uri.scheme.nil? or %w{file puppet}.include?(uri.scheme) or (Puppet.features.microsoft_windows? and uri.scheme =~ /^[a-z]$/i)
end
end
@@ -180,6 +180,8 @@ module Puppet
private
def uri
+ return nil if metadata.source =~ /^[a-z]:[\/\\]/i # Abspath for Windows
+
@uri ||= URI.parse(URI.escape(metadata.source))
end
end
diff --git a/spec/integration/type/file_spec.rb b/spec/integration/type/file_spec.rb
index 241861cc5..9814c4539 100755
--- a/spec/integration/type/file_spec.rb
+++ b/spec/integration/type/file_spec.rb
@@ -73,7 +73,7 @@ describe Puppet::Type.type(:file) do
File.read(file[:path]).should == "bar\n"
end
- it "should not backup symlinks", :fails_on_windows => true do
+ it "should not backup symlinks", :unless => Puppet.features.microsoft_windows? do
link = tmpfile("link")
dest1 = tmpfile("dest1")
dest2 = tmpfile("dest2")
@@ -214,7 +214,7 @@ describe Puppet::Type.type(:file) do
end
end
- it "should be able to recursively make links to other files", :fails_on_windows => true do
+ it "should be able to recursively make links to other files", :unless => Puppet.features.microsoft_windows? do
source = tmpfile("file_link_integration_source")
build_path(source)
@@ -289,23 +289,24 @@ describe Puppet::Type.type(:file) do
(File.stat(file).mode & 007777).should == 0644
end
- it "should recursively manage files even if there is an explicit file whose name is a prefix of the managed file", :fails_on_windows => true do
+ it "should recursively manage files even if there is an explicit file whose name is a prefix of the managed file" do
dir = tmpfile("recursion_vs_explicit_2")
- managed = File.join(dir, "file")
- generated = File.join(dir, "file_with_a_name_starting_with_the_word_file")
+ managed = File.join(dir, "file")
+ generated = File.join(dir, "file_with_a_name_starting_with_the_word_file")
+ managed_mode = Puppet.features.microsoft_windows? ? 0444 : 0700
FileUtils.mkdir_p(dir)
File.open(managed, "w") { |f| f.puts "" }
File.open(generated, "w") { |f| f.puts "" }
@catalog = Puppet::Resource::Catalog.new
- @catalog.add_resource Puppet::Type::File.new(:name => dir, :recurse => true, :backup => false, :mode => "755")
+ @catalog.add_resource Puppet::Type::File.new(:name => dir, :recurse => true, :backup => false, :mode => managed_mode)
@catalog.add_resource Puppet::Type::File.new(:name => managed, :recurse => true, :backup => false, :mode => "644")
@catalog.apply
- (File.stat(generated).mode & 007777).should == 0755
+ (File.stat(generated).mode & 007777).should == managed_mode
end
end
@@ -349,7 +350,7 @@ describe Puppet::Type.type(:file) do
describe "when copying files" do
# Ticket #285.
- it "should be able to copy files with pound signs in their names", :fails_on_windows => true do
+ it "should be able to copy files with pound signs in their names" do
source = tmpfile("filewith#signs")
dest = tmpfile("destwith#signs")
@@ -366,7 +367,7 @@ describe Puppet::Type.type(:file) do
File.read(dest).should == "foo"
end
- it "should be able to copy files with spaces in their names", :fails_on_windows => true do
+ it "should be able to copy files with spaces in their names" do
source = tmpfile("filewith spaces")
dest = tmpfile("destwith spaces")
@@ -381,11 +382,12 @@ describe Puppet::Type.type(:file) do
catalog.apply
+ expected_mode = Puppet.features.microsoft_windows? ? 0644 : 0755
File.read(dest).should == "foo"
- (File.stat(dest).mode & 007777).should == 0755
+ (File.stat(dest).mode & 007777).should == expected_mode
end
- it "should be able to copy individual files even if recurse has been specified", :fails_on_windows => true do
+ it "should be able to copy individual files even if recurse has been specified" do
source = tmpfile("source")
dest = tmpfile("dest")
@@ -434,7 +436,7 @@ describe Puppet::Type.type(:file) do
File.read(dest).should == "this is some content, yo"
end
- it "should delete files with sources but that are set for deletion", :fails_on_windows => true do
+ it "should delete files with sources but that are set for deletion" do
dest = tmpfile("dest_source_with_ensure")
source = tmpfile("source_source_with_ensure")
File.open(source, "w") { |f| f.puts "yay" }
@@ -455,7 +457,7 @@ describe Puppet::Type.type(:file) do
File.should_not be_exist(dest)
end
- describe "when purging files", :fails_on_windows => true do
+ describe "when purging files" do
before do
@sourcedir = tmpfile("purge_source")
@destdir = tmpfile("purge_dest")
@@ -470,7 +472,6 @@ describe Puppet::Type.type(:file) do
# this file should get removed
File.open(@purgee, "w") { |f| f.puts "footest" }
-
@lfobj = Puppet::Type.newfile(
:title => "localfile",
:path => @localfile,
@@ -479,7 +480,6 @@ describe Puppet::Type.type(:file) do
:backup => false
)
-
@destobj = Puppet::Type.newfile(
:title => "destdir",
:path => @destdir,
diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb
index 9e75d3142..725bf2af9 100755
--- a/spec/lib/puppet_spec/files.rb
+++ b/spec/lib/puppet_spec/files.rb
@@ -1,21 +1,19 @@
require 'fileutils'
require 'tempfile'
+require 'pathname'
# A support module for testing files.
module PuppetSpec::Files
# This code exists only to support tests that run as root, pretty much.
# Once they have finally been eliminated this can all go... --daniel 2011-04-08
- if Puppet.features.posix? then
- def self.in_tmp(path)
- path =~ /^\/tmp/ or path =~ /^\/var\/folders/
- end
- elsif Puppet.features.microsoft_windows?
- def self.in_tmp(path)
- tempdir = File.expand_path(File.join(Dir::LOCAL_APPDATA, "Temp"))
- path =~ /^#{tempdir}/
+ def self.in_tmp(path)
+ tempdir = Dir.tmpdir
+
+ Pathname.new(path).ascend do |dir|
+ return true if File.identical?(tempdir, dir)
end
- else
- fail "Help! Can't find in_tmp for this platform"
+
+ false
end
def self.cleanup
diff --git a/spec/unit/file_bucket/dipper_spec.rb b/spec/unit/file_bucket/dipper_spec.rb
index 431b12371..605719324 100755
--- a/spec/unit/file_bucket/dipper_spec.rb
+++ b/spec/unit/file_bucket/dipper_spec.rb
@@ -91,7 +91,7 @@ describe Puppet::FileBucket::Dipper do
[request1, request2].each do |r|
r.server.should == 'puppetmaster'
r.port.should == 31337
- r.key.should == "md5/#{checksum}#{real_path}"
+ r.key.should == "md5/#{checksum}/#{real_path}"
end
end
diff --git a/spec/unit/file_bucket/file_spec.rb b/spec/unit/file_bucket/file_spec.rb
index c4444ae77..ebf02438c 100755
--- a/spec/unit/file_bucket/file_spec.rb
+++ b/spec/unit/file_bucket/file_spec.rb
@@ -26,11 +26,17 @@ describe Puppet::FileBucket::File do
it "should raise an error if changing content" do
x = Puppet::FileBucket::File.new("first")
- proc { x.contents = "new" }.should raise_error
+ expect { x.contents = "new" }.to raise_error(NoMethodError, /undefined method .contents=/)
end
it "should require contents to be a string" do
- proc { Puppet::FileBucket::File.new(5) }.should raise_error(ArgumentError)
+ expect { Puppet::FileBucket::File.new(5) }.to raise_error(ArgumentError, /contents must be a String, got a Fixnum$/)
+ end
+
+ it "should complain about options other than :bucket_path" do
+ expect {
+ Puppet::FileBucket::File.new('5', :crazy_option => 'should not be passed')
+ }.to raise_error(ArgumentError, /Unknown option\(s\): crazy_option/)
end
it "should set the contents appropriately" do
@@ -61,7 +67,7 @@ describe Puppet::FileBucket::File do
it "should reject a url-ish name with an invalid checksum" do
bucket = Puppet::FileBucket::File.new(@contents)
- lambda { bucket.name = "sha1/4a8ec4fa5f01b4ab1a0ab8cbccb709f0/new/path" }.should raise_error
+ expect { bucket.name = "sha1/4a8ec4fa5f01b4ab1a0ab8cbccb709f0/new/path" }.to raise_error(NoMethodError, /undefined method .name=/)
end
it "should convert the contents to PSON" do
diff --git a/spec/unit/indirector/file_bucket_file/file_spec.rb b/spec/unit/indirector/file_bucket_file/file_spec.rb
index eb86eee85..808da17d8 100755
--- a/spec/unit/indirector/file_bucket_file/file_spec.rb
+++ b/spec/unit/indirector/file_bucket_file/file_spec.rb
@@ -111,7 +111,7 @@ describe Puppet::FileBucketFile::File do
end
end
- describe "when diffing files" do
+ describe "when diffing files", :unless => Puppet.features.microsoft_windows? do
it "should generate an empty string if there is no diff" do
checksum = save_bucket_file("I'm the contents of a file")
Puppet::FileBucket::File.indirection.find("md5/#{checksum}", :diff_with => checksum).should == ''
diff --git a/spec/unit/type/file_spec.rb b/spec/unit/type/file_spec.rb
index 6be8acfca..65c7a091c 100755
--- a/spec/unit/type/file_spec.rb
+++ b/spec/unit/type/file_spec.rb
@@ -37,7 +37,6 @@ describe Puppet::Type.type(:file) do
end
describe "#write" do
-
it "should propagate failures encountered when renaming the temporary file" do
File.stubs(:open)
@@ -92,7 +91,6 @@ describe Puppet::Type.type(:file) do
lambda { @file.write :NOTUSED }.should_not raise_error(Puppet::Error)
end
-
end
end
@@ -152,254 +150,204 @@ describe Puppet::Type.type(:file) do
end
describe "when using POSIX filenames" do
- describe "on POSIX systems" do
- before do
- Puppet.features.stubs(:posix?).returns(true)
- Puppet.features.stubs(:microsoft_windows?).returns(false)
- 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 autorequire its nearest ancestor directory" do
- file = Puppet::Type::File.new(:path => "/foo/bar/baz")
- dir = Puppet::Type::File.new(:path => "/foo")
- root = Puppet::Type::File.new(:path => "/")
- @catalog.add_resource file
- @catalog.add_resource dir
- @catalog.add_resource root
- reqs = file.autorequire
- reqs.length.must == 1
- reqs[0].source.must == dir
- reqs[0].target.must == file
- end
-
- it "should not autorequire anything when there is no nearest ancestor directory" do
- file = Puppet::Type::File.new(:path => "/foo/bar/baz")
- @catalog.add_resource file
- file.autorequire.should be_empty
- 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 trailing slashes" do
- file = Puppet::Type::File.new(:path => "/foo/bar/baz/")
- file[:path].should == "/foo/bar/baz"
- 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 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 double slashes" do
- file = Puppet::Type::File.new(:path => "/foo/bar/baz//")
- file[:path].should == "/foo/bar/baz"
- end
+ it "should autorequire its nearest ancestor directory" do
+ file = Puppet::Type::File.new(:path => "/foo/bar/baz")
+ dir = Puppet::Type::File.new(:path => "/foo")
+ root = Puppet::Type::File.new(:path => "/")
+ @catalog.add_resource file
+ @catalog.add_resource dir
+ @catalog.add_resource root
+ reqs = file.autorequire
+ reqs.length.must == 1
+ reqs[0].source.must == dir
+ reqs[0].target.must == file
+ end
- it "should leave a single slash alone" do
- file = Puppet::Type::File.new(:path => "/")
- file[:path].should == "/"
- end
+ it "should not autorequire anything when there is no nearest ancestor directory" do
+ file = Puppet::Type::File.new(:path => "/foo/bar/baz")
+ @catalog.add_resource file
+ file.autorequire.should be_empty
+ end
- it "should accept a double-slash at the start of the path" do
- expect {
- file = Puppet::Type::File.new(:path => "//tmp/xxx")
- # REVISIT: This should be wrong, later. See the next test.
- # --daniel 2011-01-31
- file[:path].should == '/tmp/xxx'
- }.should_not raise_error
- 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
- # REVISIT: This is pending, because I don't want to try and audit the
- # entire codebase to make sure we get this right. POSIX treats two (and
- # exactly two) '/' characters at the start of the path specially.
- #
- # See sections 3.2 and 4.11, which allow DomainOS to be all special like
- # and still have the POSIX branding and all. --daniel 2011-01-31
- it "should preserve the double-slash at the start of the path"
+ it "should remove trailing slashes" do
+ file = Puppet::Type::File.new(:path => "/foo/bar/baz/")
+ file[:path].should == "/foo/bar/baz"
end
- describe "on Microsoft Windows systems" do
- before do
- Puppet.features.stubs(:posix?).returns(false)
- Puppet.features.stubs(:microsoft_windows?).returns(true)
- 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 refuse to work" do
- lambda { Puppet::Type::File.new(:path => "/foo/bar") }.should raise_error(Puppet::Error)
- end
+ it "should remove trailing double slashes" do
+ file = Puppet::Type::File.new(:path => "/foo/bar/baz//")
+ file[:path].should == "/foo/bar/baz"
end
- end
- describe "when using Microsoft Windows filenames", :if => Puppet.features.microsoft_windows? do
- describe "on Microsoft Windows systems" do
- before do
- Puppet.features.stubs(:posix?).returns(false)
- Puppet.features.stubs(:microsoft_windows?).returns(true)
- end
+ it "should leave a single slash alone" do
+ file = Puppet::Type::File.new(:path => "/")
+ file[:path].should == "/"
+ 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 accept a double-slash at the start of the path" do
+ expect {
+ file = Puppet::Type::File.new(:path => "//tmp/xxx")
+ # REVISIT: This should be wrong, later. See the next test.
+ # --daniel 2011-01-31
+ file[:path].should == '/tmp/xxx'
+ }.should_not raise_error
+ end
- it "should autorequire its nearest ancestor directory" do
- file = Puppet::Type::File.new(:path => "X:/foo/bar/baz")
- dir = Puppet::Type::File.new(:path => "X:/foo")
- root = Puppet::Type::File.new(:path => "X:/")
- @catalog.add_resource file
- @catalog.add_resource dir
- @catalog.add_resource root
- reqs = file.autorequire
- reqs.length.must == 1
- reqs[0].source.must == dir
- reqs[0].target.must == file
- end
+ # REVISIT: This is pending, because I don't want to try and audit the
+ # entire codebase to make sure we get this right. POSIX treats two (and
+ # exactly two) '/' characters at the start of the path specially.
+ #
+ # See sections 3.2 and 4.11, which allow DomainOS to be all special like
+ # and still have the POSIX branding and all. --daniel 2011-01-31
+ it "should preserve the double-slash at the start of the path"
+ end
- it "should not autorequire anything when there is no nearest ancestor directory" do
- file = Puppet::Type::File.new(:path => "X:/foo/bar/baz")
- @catalog.add_resource file
- file.autorequire.should be_empty
- end
+ describe "when using Microsoft Windows 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
- 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 nearest ancestor directory" do
+ file = Puppet::Type::File.new(:path => "X:/foo/bar/baz")
+ dir = Puppet::Type::File.new(:path => "X:/foo")
+ root = Puppet::Type::File.new(:path => "X:/")
+ @catalog.add_resource file
+ @catalog.add_resource dir
+ @catalog.add_resource root
+ reqs = file.autorequire
+ reqs.length.must == 1
+ 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 anything when there is no nearest ancestor directory" do
+ file = Puppet::Type::File.new(:path => "X:/foo/bar/baz")
+ @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 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 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 trailing 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", :'fails_on_ruby_1.9.2' => true do
- file = Puppet::Type::File.new(:path => "X:/")
- file[:path].should == "X:/"
- 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 not accept a drive letter without a slash", :'fails_on_ruby_1.9.2' => true do
- lambda { Puppet::Type::File.new(:path => "X:") }.should raise_error(/File paths must be fully qualified/)
- 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
- describe "on POSIX systems" do
- before do
- Puppet.features.stubs(:posix?).returns(true)
- Puppet.features.stubs(:microsoft_windows?).returns(false)
- end
+ it "should leave a drive letter with a slash alone", :'fails_on_ruby_1.9.2' => true do
+ file = Puppet::Type::File.new(:path => "X:/")
+ file[:path].should == "X:/"
+ end
- it "should refuse to work" do
- lambda { Puppet::Type::File.new(:path => "X:/foo/bar") }.should raise_error(Puppet::Error)
- end
+ it "should not accept a drive letter without a slash", :'fails_on_ruby_1.9.2' => true do
+ lambda { Puppet::Type::File.new(:path => "X:") }.should raise_error(/File paths must be fully qualified/)
end
end
- describe "when using UNC filenames" do
- describe "on Microsoft Windows systems", :if => Puppet.features.microsoft_windows?, :'fails_on_ruby_1.9.2' => true do
- before do
- Puppet.features.stubs(:posix?).returns(false)
- Puppet.features.stubs(:microsoft_windows?).returns(true)
- 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 autorequire its nearest ancestor directory" do
- file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/qux")
- dir = Puppet::Type::File.new(:path => "//server/foo/bar")
- root = Puppet::Type::File.new(:path => "//server/foo")
- @catalog.add_resource file
- @catalog.add_resource dir
- @catalog.add_resource root
- reqs = file.autorequire
- reqs.length.must == 1
- reqs[0].source.must == dir
- reqs[0].target.must == file
- end
+ describe "when using UNC filenames", :'fails_on_ruby_1.9.2' => true do
+ before :each do
+ pending("UNC file paths not yet supported")
+ end
- it "should not autorequire anything when there is no nearest ancestor directory" do
- file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/qux")
- @catalog.add_resource file
- 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 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 nearest ancestor directory" do
+ file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/qux")
+ dir = Puppet::Type::File.new(:path => "//server/foo/bar")
+ root = Puppet::Type::File.new(:path => "//server/foo")
+ @catalog.add_resource file
+ @catalog.add_resource dir
+ @catalog.add_resource root
+ reqs = file.autorequire
+ reqs.length.must == 1
+ 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 anything when there is no nearest ancestor directory" do
+ file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/qux")
+ @catalog.add_resource file
+ 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 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 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 trailing 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"
- 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 not modify a sharename" do
- file = Puppet::Type::File.new(:path => "//server/foo")
- file[:path].should == "//server/foo"
- 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
- describe "on POSIX systems" do
- before do
- Puppet.features.stubs(:posix?).returns(true)
- Puppet.features.stubs(:microsoft_windows?).returns(false)
- end
+ 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 refuse to work" do
- lambda { Puppet::Type::File.new(:path => "X:/foo/bar") }.should raise_error(Puppet::Error)
- end
+ it "should not modify a sharename" do
+ file = Puppet::Type::File.new(:path => "//server/foo")
+ file[:path].should == "//server/foo"
end
end