From c5f8e7ab80b9cf69ee02589ee776b848c0f2e356 Mon Sep 17 00:00:00 2001 From: Michael Leinartas Date: Sat, 24 Jul 2010 15:39:40 -0500 Subject: Updated unit tests --- chef/lib/chef/resource/remote_directory.rb | 8 ++++++++ chef/spec/unit/provider/remote_directory_spec.rb | 25 ++++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/chef/lib/chef/resource/remote_directory.rb b/chef/lib/chef/resource/remote_directory.rb index ef7f52e51c..d74ce2d97a 100644 --- a/chef/lib/chef/resource/remote_directory.rb +++ b/chef/lib/chef/resource/remote_directory.rb @@ -88,6 +88,14 @@ class Chef ) end + def overwrite(arg=nil) + set_or_return( + :overwrite, + arg, + :kind_of => [ TrueClass, FalseClass ] + ) + end + def cookbook(args=nil) set_or_return( :cookbook, diff --git a/chef/spec/unit/provider/remote_directory_spec.rb b/chef/spec/unit/provider/remote_directory_spec.rb index a1b1eec50d..089b24a4dc 100644 --- a/chef/spec/unit/provider/remote_directory_spec.rb +++ b/chef/spec/unit/provider/remote_directory_spec.rb @@ -17,6 +17,7 @@ # require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) +require 'digest/md5' describe Chef::Provider::RemoteDirectory do before do @@ -36,10 +37,6 @@ describe Chef::Provider::RemoteDirectory do @provider.current_resource = @resource.clone end - it "doesn't support create_if_missing and explodes if you try to use it" do - lambda {@provider.send :action_create_if_missing}.should raise_error(Chef::Exceptions::UnsupportedAction) - end - describe "when access control is configured on the resource" do before do @resource.mode "0750" @@ -131,5 +128,25 @@ describe Chef::Provider::RemoteDirectory do end end + describe "with overwrite disabled" do + before {@resource.purge(false)} + before {@resource.overwrite(false)} + + it "leaves modifications alone" do + @provider.action_create + file1 = File.open(@destination_dir + '/remote_dir_file1.txt', 'a') + file1.puts "blah blah blah" + file1.close + subdirfile1 = File.open(@destination_dir + '/remotesubdir/remote_subdir_file1.txt', 'a') + subdirfile1.puts "blah blah blah" + subdirfile1.close + file1md5 = Digest::MD5.hexdigest(File.read(@destination_dir + '/remote_dir_file1.txt')) + subdirfile1md5 = Digest::MD5.hexdigest(File.read(@destination_dir + '/remotesubdir/remote_subdir_file1.txt')) + @provider.action_create + file1md5.eql?(Digest::MD5.hexdigest(File.read(@destination_dir + '/remote_dir_file1.txt'))).should be_true + subdirfile1md5.eql?(Digest::MD5.hexdigest(File.read(@destination_dir + '/remotesubdir/remote_subdir_file1.txt'))).should be_true + end + end + end end -- cgit v1.2.1