diff options
author | Lamont Granquist <lamont@opscode.com> | 2013-03-22 16:01:08 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@opscode.com> | 2013-03-22 16:01:08 -0700 |
commit | db72ae9f28a3eaf27c8e8af5815f7b030186ef07 (patch) | |
tree | 055e49530c404d70ac4b998999630797722ef0dc /spec/unit/provider/cookbook_file_spec.rb | |
parent | 675e0c7cca37a32189fd00cdf421363c7d0d2f46 (diff) | |
download | chef-db72ae9f28a3eaf27c8e8af5815f7b030186ef07.tar.gz |
more spec test work
Diffstat (limited to 'spec/unit/provider/cookbook_file_spec.rb')
-rw-r--r-- | spec/unit/provider/cookbook_file_spec.rb | 156 |
1 files changed, 15 insertions, 141 deletions
diff --git a/spec/unit/provider/cookbook_file_spec.rb b/spec/unit/provider/cookbook_file_spec.rb index 66fdd9871d..35025ee970 100644 --- a/spec/unit/provider/cookbook_file_spec.rb +++ b/spec/unit/provider/cookbook_file_spec.rb @@ -61,39 +61,22 @@ describe Chef::Provider::CookbookFile do # # end - it "prefers the explicit cookbook name on the resource to the implicit one" do - @new_resource.cookbook('nginx') - @provider.resource_cookbook.should == 'nginx' - end - - it "falls back to the implicit cookbook name on the resource" do - @provider.resource_cookbook.should == 'apache2' - end - - describe "when loading the current file state" do - - it "converts windows-y filenames to unix-y ones" do - @new_resource.path('windows\stuff') - @provider.load_current_resource - @new_resource.path.should == 'windows/stuff' - end - - it "sets the current resources path to the same as the new resource" do - @new_resource.path('/tmp/file') - @provider.load_current_resource - @provider.current_resource.path.should == '/tmp/file' - end - end - - describe "when the enclosing directory of the target file location doesn't exist" do - before do - @new_resource.path("/tmp/no/such/intermediate/path/file.txt") - end +# FIXME: move to Chef::Provider::File +# describe "when loading the current file state" do +# +# it "converts windows-y filenames to unix-y ones" do +# @new_resource.path('windows\stuff') +# @provider.load_current_resource +# @new_resource.path.should == 'windows/stuff' +# end +# +# it "sets the current resources path to the same as the new resource" do +# @new_resource.path('/tmp/file') +# @provider.load_current_resource +# @provider.current_resource.path.should == '/tmp/file' +# end +# end - it "raises a specific error alerting the user to the problem" do - lambda {@provider.run_action(:create)}.should raise_error(Chef::Exceptions::EnclosingDirectoryDoesNotExist) - end - end describe "when the file doesn't yet exist" do before do @install_to = Dir.tmpdir + '/apache2_modconf.pl' @@ -104,11 +87,6 @@ describe Chef::Provider::CookbookFile do after { ::File.exist?(File.dirname(@install_to)) && FileUtils.rm_rf(@install_to) } - it "loads the current file state" do - @provider.load_current_resource - @provider.current_resource.checksum.should be_nil - end - it "looks up a file from the cookbook cache" do expected = CHEF_SPEC_DATA + "/cookbooks/apache2/files/default/apache2_module_conf_generate.pl" @provider.file_cache_location.should == expected @@ -122,110 +100,6 @@ describe Chef::Provider::CookbookFile do actual = IO.read(@install_to) actual.should == @file_content end - - it "installs the file for create_if_missing --> from Provider::File" do - @new_resource.path(@install_to) - @provider.should_receive(:backup_new_resource) - @provider.stub!(:update_new_file_state) - @provider.run_action(:create_if_missing) - actual = IO.read(@install_to) - actual.should == @file_content - end - - it "marks the resource as updated by the last action --> being tested in the converge framework" do - @new_resource.path(@install_to) - @provider.stub!(:backup_new_resource) - @provider.stub!(:set_file_access_controls) - @provider.stub!(:update_new_file_state) - @provider.run_action(:create) - @new_resource.should be_updated - @new_resource.should be_updated_by_last_action - end - - end - - describe "when the file exists but has incorrect content" do - before do - @tempfile = Tempfile.open('cookbook_file_spec') - @new_resource.path(@target_file = @tempfile.path) - @tempfile.puts "the wrong content" - @tempfile.close - @current_resource = @new_resource.dup - @provider.current_resource = @current_resource - end - - it "stages the cookbook to a temporary file" do - # prevents file backups where we might not have write access - @provider.should_receive(:backup_new_resource) - @new_resource.path(@install_to) - @provider.should_receive(:deploy_tempfile) - @provider.run_action(:create) - end - - it "overwrites it when the create action is called" do - @provider.should_receive(:backup_new_resource) - @provider.run_action(:create) - actual = IO.read(@target_file) - actual.should == @file_content - end - - it "marks the resource as updated by the last action" do - @provider.should_receive(:backup_new_resource) - @provider.run_action(:create) - @new_resource.should be_updated - @new_resource.should be_updated_by_last_action - end - - it "doesn't overwrite when the create if missing action is called" do - @provider.should_not_receive(:set_file_access_controls) - @provider.run_action(:create_if_missing) - actual = IO.read(@target_file) - actual.should == "the wrong content\n" - end - - it "doesn't mark the resource as updated by the action for create_if_missing" do - @provider.run_action(:create_if_missing) - @new_resource.should_not be_updated - @new_resource.should_not be_updated_by_last_action - end - - after { @tempfile && @tempfile.close! } end - describe "when the file has the correct content" do - before do - Chef::FileAccessControl.any_instance.stub(:modified?).and_return(false) - @tempfile = Tempfile.open('cookbook_file_spec') - # CHEF-2991: We handle CRLF very poorly and we don't know what line endings - # our source file is going to have, so we use binary mode to preserve CRLF if needed. - source_file = CHEF_SPEC_DATA + "/cookbooks/apache2/files/default/apache2_module_conf_generate.pl" - @tempfile.binmode unless File.open(source_file, "rb") { |f| f.read =~ /\r/ } - @new_resource.path(@target_file = @tempfile.path) - @tempfile.write(@file_content) - @tempfile.close - @current_resource = @new_resource.dup - @provider.current_resource = @current_resource - end - - after { @tempfile && @tempfile.unlink} - - it "checks access control but does not alter content when action is create" do - @provider.should_receive(:set_all_access_controls) - @provider.should_not_receive(:stage_file_to_tmpdir) - @provider.run_action(:create) - end - - it "does not mark the resource as updated by the last action" do - @provider.run_action(:create) - @new_resource.should_not be_updated - @new_resource.should_not be_updated_by_last_action - end - - it "does not alter content or access control when action is create if missing" do - @provider.should_not_receive(:set_all_access_controls) - @provider.should_not_receive(:stage_file_to_tmpdir) - @provider.run_action(:create_if_missing) - end - - end end |