diff options
author | Lamont Granquist <lamont@opscode.com> | 2013-03-20 16:20:27 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@opscode.com> | 2013-03-20 16:20:27 -0700 |
commit | 675e0c7cca37a32189fd00cdf421363c7d0d2f46 (patch) | |
tree | 555b0c470b694e0859a8a7a3ef73d0ec3d29952e /spec/unit/provider/file | |
parent | cc81c76ca1e1a233bfe29f2b585f98a37131ad39 (diff) | |
download | chef-675e0c7cca37a32189fd00cdf421363c7d0d2f46.tar.gz |
adding specs for file content
Diffstat (limited to 'spec/unit/provider/file')
-rw-r--r-- | spec/unit/provider/file/content_spec.rb | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/spec/unit/provider/file/content_spec.rb b/spec/unit/provider/file/content_spec.rb new file mode 100644 index 0000000000..6b9cdc748f --- /dev/null +++ b/spec/unit/provider/file/content_spec.rb @@ -0,0 +1,98 @@ +# +# Author:: Lamont Granquist (<lamont@opscode.com>) +# Copyright:: Copyright (c) 2013 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Provider::File::Content do + + before(:all) do + @original_config = Chef::Config.configuration + end + + after(:all) do + Chef::Config.configuration.replace(@original_config) + end + + # + # mock setup + # + + let(:current_resource) 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(:new_resource) do + mock("Chef::Provider::File::Resource (new)", :name => "seattle.txt", :path => resource_path) + end + + let(:run_context) do + mock("Chef::RunContext") + end + + # + # subject + # + let(:content) do + Chef::Provider::File::Content.new(new_resource, current_resource, run_context) + end + + describe "when the resource has a content attribute set" do + + before do + new_resource.stub!(:content).and_return("Do do do do, do do do do, do do do do, do do do do") + end + + it "returns a tempfile" do + content.tempfile.should be_a_kind_of(Tempfile) + end + + it "the tempfile contents should match the resource contents" do + IO.read(content.tempfile.path).should == new_resource.content + end + + it "returns a tempfile in the tempdir when :file_deployment_uses_destdir is not set" do + Chef::Config[:file_deployment_uses_destdir] = false + content.tempfile.path.should match /^#{Dir::tmpdir}/ + content.tempfile.path.should_not match /^#{enclosing_directory}/ + end + + it "returns a tempfile in the destdir when :file_desployment_uses_destdir is not set" do + Chef::Config[:file_deployment_uses_destdir] = true + content.tempfile.path.should_not match /^#{Dir::tmpdir}/ + content.tempfile.path.should match /^#{enclosing_directory}/ + end + + end + + describe "when the resource does not have a content attribute set" do + + before do + new_resource.stub!(:content).and_return(nil) + end + + it "should return nil instead of a tempfile" do + content.tempfile.should be_nil + end + + end +end + |