summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsersut <serdar@opscode.com>2013-05-23 09:57:51 -0700
committersersut <serdar@opscode.com>2013-05-23 09:57:51 -0700
commitaa13ddee5a7ada2dba8b624ad5325d0132ce883f (patch)
tree2e5d39ee7e5e866a24331ecd70f8153bb62fb85c
parent67eb0c2bae18ee50a585140873b93ea6ec0ded2d (diff)
downloadchef-aa13ddee5a7ada2dba8b624ad5325d0132ce883f.tar.gz
Fix specs on windows.
-rw-r--r--lib/chef/provider/file.rb13
-rw-r--r--spec/support/chef_helpers.rb6
-rw-r--r--spec/support/shared/functional/file_resource.rb20
-rw-r--r--spec/support/shared/unit/provider/file.rb82
-rw-r--r--spec/unit/provider/cookbook_file_spec.rb8
-rw-r--r--spec/unit/provider/file/content_spec.rb17
-rw-r--r--spec/unit/provider/file_spec.rb8
-rw-r--r--spec/unit/provider/remote_file/ftp_spec.rb8
-rw-r--r--spec/unit/provider/remote_file_spec.rb8
-rw-r--r--spec/unit/provider/template_spec.rb16
10 files changed, 121 insertions, 65 deletions
diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb
index 7f63475c95..71ed2bb088 100644
--- a/lib/chef/provider/file.rb
+++ b/lib/chef/provider/file.rb
@@ -26,6 +26,7 @@ require 'fileutils'
require 'chef/scan_access_control'
require 'chef/mixin/checksum'
require 'chef/mixin/shell_out'
+require 'chef/mixin/file_class'
require 'chef/util/backup'
require 'chef/util/diff'
require 'chef/deprecation/provider/file'
@@ -49,6 +50,7 @@ class Chef
include Chef::Mixin::Checksum
include Chef::Mixin::ShellOut
include Chef::Util::Selinux
+ include Chef::Mixin::FileClass
extend Chef::Deprecation::Warnings
include Chef::Deprecation::Provider::File
@@ -136,7 +138,7 @@ class Chef
def action_delete
if ::File.exists?(@new_resource.path)
converge_by("delete file #{@new_resource.path}") do
- do_backup unless ::File.symlink?(@new_resource.path)
+ do_backup unless file_class.symlink?(@new_resource.path)
::File.delete(@new_resource.path)
Chef::Log.info("#{@new_resource} deleted file at #{@new_resource.path}")
end
@@ -173,7 +175,7 @@ class Chef
"pipe"
when ::File.socket?(path)
"socket"
- when ::File.symlink?(path)
+ when file_class.symlink?(path)
"symlink"
else
"unknown filetype"
@@ -181,7 +183,7 @@ class Chef
end
def real_file?(path)
- !::File.symlink?(path) && ::File.file?(path)
+ !file_class.symlink?(path) && ::File.file?(path)
end
def unlink(path)
@@ -313,11 +315,6 @@ class Chef
acl_scanner.set_all!
end
- # File.exists? always follows symlinks, i want true if there's a symlink there
- # def exists_or_symlink?(path)
- # ::File.symlink?(path) || ::File.exists?(path)
- # end
-
end
end
end
diff --git a/spec/support/chef_helpers.rb b/spec/support/chef_helpers.rb
index 8315108122..11fec106c4 100644
--- a/spec/support/chef_helpers.rb
+++ b/spec/support/chef_helpers.rb
@@ -77,3 +77,9 @@ def system_windows_service_gem?
system windows_service_gem_check_command
end
end
+
+# This is a helper to canonicalize paths that we're using in the file
+# tests.
+def canonicalize_path(path)
+ windows? ? path.gsub('/', '\\') : path
+end
diff --git a/spec/support/shared/functional/file_resource.rb b/spec/support/shared/functional/file_resource.rb
index 7ca889d314..fb65b902b4 100644
--- a/spec/support/shared/functional/file_resource.rb
+++ b/spec/support/shared/functional/file_resource.rb
@@ -233,8 +233,16 @@ shared_examples_for "a file resource" do
end
shared_examples_for "file resource not pointing to a real file" do
+ def symlink?(file_path)
+ if windows?
+ Chef::ReservedNames::Win32::File.symlink?(file_path)
+ else
+ File.symlink?(file_path)
+ end
+ end
+
def real_file?(file_path)
- !File.symlink?(file_path) && File.file?(file_path)
+ !symlink?(file_path) && File.file?(file_path)
end
describe "when force_unlink is set to true" do
@@ -301,7 +309,11 @@ shared_examples_for "a configured file resource" do
end
before(:each) do
- File.symlink(symlink_target, path)
+ if windows?
+ Chef::ReservedNames::Win32::File.symlink(symlink_target, path)
+ else
+ File.symlink(symlink_target, path)
+ end
end
after(:each) do
@@ -548,6 +560,10 @@ shared_examples_for "a configured file resource" do
end
shared_context Chef::Resource::File do
+ if windows?
+ require 'chef/win32/file'
+ end
+
# We create the files in a different directory than tmp to exercise
# different file deployment strategies more completely.
let(:test_file_dir) do
diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb
index a7a7164eb5..4c44b23533 100644
--- a/spec/support/shared/unit/provider/file.rb
+++ b/spec/support/shared/unit/provider/file.rb
@@ -18,48 +18,58 @@
require 'spec_helper'
require 'tmpdir'
+if windows?
+ require 'chef/win32/file'
+end
- # Filesystem stubs
-
- def setup_normal_file
- File.stub!(:exists?).with(resource_path).and_return(true)
- File.stub!(:directory?).with(resource_path).and_return(false)
- File.stub!(:directory?).with(enclosing_directory).and_return(true)
- File.stub!(:writable?).with(resource_path).and_return(true)
- File.stub!(:symlink?).with(resource_path).and_return(false)
+# Filesystem stubs
+def file_symlink_class
+ if windows?
+ Chef::ReservedNames::Win32::File
+ else
+ File
end
+end
- def setup_missing_file
- File.stub!(:exists?).with(resource_path).and_return(false)
- File.stub!(:directory?).with(resource_path).and_return(false)
- File.stub!(:directory?).with(enclosing_directory).and_return(true)
- File.stub!(:writable?).with(resource_path).and_return(false)
- File.stub!(:symlink?).with(resource_path).and_return(false)
- end
+def setup_normal_file
+ File.stub!(:exists?).with(resource_path).and_return(true)
+ File.stub!(:directory?).with(resource_path).and_return(false)
+ File.stub!(:directory?).with(enclosing_directory).and_return(true)
+ File.stub!(:writable?).with(resource_path).and_return(true)
+ file_symlink_class.stub!(:symlink?).with(resource_path).and_return(false)
+end
- def setup_symlink
- File.stub!(:exists?).with(resource_path).and_return(true)
- File.stub!(:directory?).with(resource_path).and_return(false)
- File.stub!(:directory?).with(enclosing_directory).and_return(true)
- File.stub!(:writable?).with(resource_path).and_return(true)
- File.stub!(:symlink?).with(resource_path).and_return(true)
- end
+def setup_missing_file
+ File.stub!(:exists?).with(resource_path).and_return(false)
+ File.stub!(:directory?).with(resource_path).and_return(false)
+ File.stub!(:directory?).with(enclosing_directory).and_return(true)
+ File.stub!(:writable?).with(resource_path).and_return(false)
+ file_symlink_class.stub!(:symlink?).with(resource_path).and_return(false)
+end
- def setup_unwritable_file
- File.stub!(:exists?).with(resource_path).and_return(true)
- File.stub!(:directory?).with(resource_path).and_return(false)
- File.stub!(:directory?).with(enclosing_directory).and_return(true)
- File.stub!(:writable?).with(resource_path).and_return(false)
- File.stub!(:symlink?).with(resource_path).and_return(false)
- end
+def setup_symlink
+ File.stub!(:exists?).with(resource_path).and_return(true)
+ File.stub!(:directory?).with(resource_path).and_return(false)
+ File.stub!(:directory?).with(enclosing_directory).and_return(true)
+ File.stub!(:writable?).with(resource_path).and_return(true)
+ file_symlink_class.stub!(:symlink?).with(resource_path).and_return(true)
+end
- def setup_missing_enclosing_directory
- File.stub!(:exists?).with(resource_path).and_return(false)
- File.stub!(:directory?).with(resource_path).and_return(false)
- File.stub!(:directory?).with(enclosing_directory).and_return(false)
- File.stub!(:writable?).with(resource_path).and_return(false)
- File.stub!(:symlink?).with(resource_path).and_return(false)
- end
+def setup_unwritable_file
+ File.stub!(:exists?).with(resource_path).and_return(true)
+ File.stub!(:directory?).with(resource_path).and_return(false)
+ File.stub!(:directory?).with(enclosing_directory).and_return(true)
+ File.stub!(:writable?).with(resource_path).and_return(false)
+ file_symlink_class.stub!(:symlink?).with(resource_path).and_return(false)
+end
+
+def setup_missing_enclosing_directory
+ File.stub!(:exists?).with(resource_path).and_return(false)
+ File.stub!(:directory?).with(resource_path).and_return(false)
+ File.stub!(:directory?).with(enclosing_directory).and_return(false)
+ File.stub!(:writable?).with(resource_path).and_return(false)
+ file_symlink_class.stub!(:symlink?).with(resource_path).and_return(false)
+end
shared_examples_for Chef::Provider::File do
diff --git a/spec/unit/provider/cookbook_file_spec.rb b/spec/unit/provider/cookbook_file_spec.rb
index 6938bb93b6..44569075de 100644
--- a/spec/unit/provider/cookbook_file_spec.rb
+++ b/spec/unit/provider/cookbook_file_spec.rb
@@ -26,8 +26,12 @@ describe Chef::Provider::CookbookFile do
let(:node) { double('Chef::Node') }
let(:events) { double('Chef::Events').as_null_object } # mock all the methods
let(:run_context) { double('Chef::RunContext', :node => node, :events => events) }
- let(:enclosing_directory) { File.expand_path(File.join(CHEF_SPEC_DATA, "templates")) }
- let(:resource_path) { File.expand_path(File.join(enclosing_directory, "seattle.txt")) }
+ let(:enclosing_directory) {
+ canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates")))
+ }
+ let(:resource_path) {
+ canonicalize_path(File.expand_path(File.join(enclosing_directory, "seattle.txt")))
+ }
# Subject
diff --git a/spec/unit/provider/file/content_spec.rb b/spec/unit/provider/file/content_spec.rb
index 771c889cf1..1e681d5c15 100644
--- a/spec/unit/provider/file/content_spec.rb
+++ b/spec/unit/provider/file/content_spec.rb
@@ -36,9 +36,12 @@ describe Chef::Provider::File::Content do
mock("Chef::Provider::File::Resource (current)")
end
- let(:enclosing_directory) { File.expand_path(File.join(CHEF_SPEC_DATA, "templates")) }
-
- let(:resource_path) { File.expand_path(File.join(enclosing_directory, "seattle.txt")) }
+ let(:enclosing_directory) {
+ canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates")))
+ }
+ let(:resource_path) {
+ canonicalize_path(File.expand_path(File.join(enclosing_directory, "seattle.txt")))
+ }
let(:new_resource) do
mock("Chef::Provider::File::Resource (new)", :name => "seattle.txt", :path => resource_path, :binmode => true)
@@ -71,14 +74,14 @@ describe Chef::Provider::File::Content do
it "returns a tempfile in the tempdir when :file_staging_uses_destdir is not set" do
Chef::Config[:file_staging_uses_destdir] = false
- content.tempfile.path.should match /^#{Dir::tmpdir}/
- content.tempfile.path.should_not match /^#{enclosing_directory}/
+ content.tempfile.path.start_with?(Dir::tmpdir).should be_true
+ canonicalize_path(content.tempfile.path).start_with?(enclosing_directory).should be_false
end
it "returns a tempfile in the destdir when :file_desployment_uses_destdir is not set" do
Chef::Config[:file_staging_uses_destdir] = true
- content.tempfile.path.should_not match /^#{Dir::tmpdir}/
- content.tempfile.path.should match /^#{enclosing_directory}/
+ content.tempfile.path.start_with?(Dir::tmpdir).should be_false
+ canonicalize_path(content.tempfile.path).start_with?(enclosing_directory).should be_true
end
end
diff --git a/spec/unit/provider/file_spec.rb b/spec/unit/provider/file_spec.rb
index 6ad60437b1..291f510067 100644
--- a/spec/unit/provider/file_spec.rb
+++ b/spec/unit/provider/file_spec.rb
@@ -35,8 +35,12 @@ describe Chef::Provider::File do
let(:node) { double('Chef::Node') }
let(:events) { double('Chef::Events').as_null_object } # mock all the methods
let(:run_context) { double('Chef::RunContext', :node => node, :events => events) }
- let(:enclosing_directory) { File.expand_path(File.join(CHEF_SPEC_DATA, "templates")) }
- let(:resource_path) { File.expand_path(File.join(enclosing_directory, "seattle.txt")) }
+ let(:enclosing_directory) {
+ canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates")))
+ }
+ let(:resource_path) {
+ canonicalize_path(File.expand_path(File.join(enclosing_directory, "seattle.txt")))
+ }
# Subject
diff --git a/spec/unit/provider/remote_file/ftp_spec.rb b/spec/unit/provider/remote_file/ftp_spec.rb
index 60b708d9f8..f9e3331b6f 100644
--- a/spec/unit/provider/remote_file/ftp_spec.rb
+++ b/spec/unit/provider/remote_file/ftp_spec.rb
@@ -19,8 +19,12 @@
require 'spec_helper'
describe Chef::Provider::RemoteFile::FTP do
- let(:enclosing_directory) { File.expand_path(File.join(CHEF_SPEC_DATA, "templates")) }
- let(:resource_path) { File.expand_path(File.join(enclosing_directory, "seattle.txt")) }
+ let(:enclosing_directory) {
+ canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates")))
+ }
+ let(:resource_path) {
+ canonicalize_path(File.expand_path(File.join(enclosing_directory, "seattle.txt")))
+ }
before(:each) do
@ftp = mock(Net::FTP, { })
diff --git a/spec/unit/provider/remote_file_spec.rb b/spec/unit/provider/remote_file_spec.rb
index a0fe9da8e1..3b01b45983 100644
--- a/spec/unit/provider/remote_file_spec.rb
+++ b/spec/unit/provider/remote_file_spec.rb
@@ -38,8 +38,12 @@ describe Chef::Provider::RemoteFile do
let(:node) { double('Chef::Node') }
let(:events) { double('Chef::Events').as_null_object } # mock all the methods
let(:run_context) { double('Chef::RunContext', :node => node, :events => events) }
- let(:enclosing_directory) { File.expand_path(File.join(CHEF_SPEC_DATA, "templates")) }
- let(:resource_path) { File.expand_path(File.join(enclosing_directory, "seattle.txt")) }
+ let(:enclosing_directory) {
+ canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates")))
+ }
+ let(:resource_path) {
+ canonicalize_path(File.expand_path(File.join(enclosing_directory, "seattle.txt")))
+ }
subject(:provider) do
provider = described_class.new(resource, run_context)
diff --git a/spec/unit/provider/template_spec.rb b/spec/unit/provider/template_spec.rb
index e3add8cdd2..ca8f1db5e2 100644
--- a/spec/unit/provider/template_spec.rb
+++ b/spec/unit/provider/template_spec.rb
@@ -28,8 +28,12 @@ describe Chef::Provider::Template do
let(:node) { double('Chef::Node') }
let(:events) { double('Chef::Events').as_null_object } # mock all the methods
let(:run_context) { double('Chef::RunContext', :node => node, :events => events) }
- let(:enclosing_directory) { File.expand_path(File.join(CHEF_SPEC_DATA, "templates")) }
- let(:resource_path) { File.expand_path(File.join(enclosing_directory, "seattle.txt")) }
+ let(:enclosing_directory) {
+ canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates")))
+ }
+ let(:resource_path) {
+ canonicalize_path(File.expand_path(File.join(enclosing_directory, "seattle.txt")))
+ }
# Subject
@@ -58,8 +62,12 @@ describe Chef::Provider::Template do
let(:node) { double('Chef::Node') }
let(:events) { double('Chef::Events').as_null_object } # mock all the methods
let(:run_context) { double('Chef::RunContext', :node => node, :events => events) }
- let(:enclosing_directory) { File.expand_path(File.join(CHEF_SPEC_DATA, "templates")) }
- let(:resource_path) { File.expand_path(File.join(enclosing_directory, "seattle.txt")) }
+ let(:enclosing_directory) {
+ canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates")))
+ }
+ let(:resource_path) {
+ canonicalize_path(File.expand_path(File.join(enclosing_directory, "seattle.txt")))
+ }
# Subject