diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-05-20 07:55:44 -0700 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-05-21 10:13:07 -0500 |
commit | 8d969503cdb5805807aeec8d06629116c28e5877 (patch) | |
tree | 87d429c955787ec7f38c63081c624ef4b48ed3ab | |
parent | 6ba819dd88383a9ad7ef7af5b013cbf6a4da2c84 (diff) | |
download | chef-8d969503cdb5805807aeec8d06629116c28e5877.tar.gz |
Update specs for remote local file + spaces
-rw-r--r-- | lib/chef/provider/remote_file/local_file.rb | 8 | ||||
-rw-r--r-- | spec/unit/provider/remote_file/local_file_spec.rb | 31 | ||||
-rw-r--r-- | spec/unit/resource/remote_file_spec.rb | 5 |
3 files changed, 35 insertions, 9 deletions
diff --git a/lib/chef/provider/remote_file/local_file.rb b/lib/chef/provider/remote_file/local_file.rb index d3fdcab24a..026206b64e 100644 --- a/lib/chef/provider/remote_file/local_file.rb +++ b/lib/chef/provider/remote_file/local_file.rb @@ -38,13 +38,15 @@ class Chef path.gsub(/^\/([a-zA-Z]:)/,'\1') end - def uri_path - URI.unescape(uri.path) + def source_path + @source_path ||= begin + path = URI.unescape(uri.path) + Chef::Platform.windows? ? fix_windows_path(path) : path + end end # Fetches the file at uri, returning a Tempfile-like File handle def fetch - source_path = Chef::Platform.windows? ? fix_windows_path(uri_path) : uri_path tempfile = Chef::FileContentManagement::Tempfile.new(new_resource).tempfile Chef::Log.debug("#{new_resource} staging #{source_path} to #{tempfile.path}") FileUtils.cp(source_path, tempfile.path) diff --git a/spec/unit/provider/remote_file/local_file_spec.rb b/spec/unit/provider/remote_file/local_file_spec.rb index b33d82f624..575996a540 100644 --- a/spec/unit/provider/remote_file/local_file_spec.rb +++ b/spec/unit/provider/remote_file/local_file_spec.rb @@ -25,26 +25,45 @@ describe Chef::Provider::RemoteFile::LocalFile do let(:new_resource) { Chef::Resource::RemoteFile.new("local file backend test (new_resource)") } let(:current_resource) { Chef::Resource::RemoteFile.new("local file backend test (current_resource)") } subject(:fetcher) { Chef::Provider::RemoteFile::LocalFile.new(uri, new_resource, current_resource) } - - context "when parsing source path" do + + context "when parsing source path on windows" do + + before do + allow(Chef::Platform).to receive(:windows?).and_return(true) + end + describe "when given local unix path" do let(:uri) { URI.parse("file:///nyan_cat.png") } it "returns a correct unix path" do - expect(fetcher.fix_windows_path(uri.path)).to eq("/nyan_cat.png") + expect(fetcher.source_path).to eq("/nyan_cat.png") end end describe "when given local windows path" do let(:uri) { URI.parse("file:///z:/windows/path/file.txt") } it "returns a valid windows local path" do - expect(fetcher.fix_windows_path(uri.path)).to eq("z:/windows/path/file.txt") + expect(fetcher.source_path).to eq("z:/windows/path/file.txt") + end + end + + describe "when given local windows path with spaces" do + let(:uri) { URI.parse(URI.escape("file:///z:/windows/path/foo & bar.txt")) } + it "returns a valid windows local path" do + expect(fetcher.source_path).to eq("z:/windows/path/foo & bar.txt") end end describe "when given unc windows path" do let(:uri) { URI.parse("file:////server/share/windows/path/file.txt") } it "returns a valid windows unc path" do - expect(fetcher.fix_windows_path(uri.path)).to eq("//server/share/windows/path/file.txt") + expect(fetcher.source_path).to eq("//server/share/windows/path/file.txt") + end + end + + describe "when given unc windows path with spaces" do + let(:uri) { URI.parse(URI.escape("file:////server/share/windows/path/foo & bar.txt")) } + it "returns a valid windows unc path" do + expect(fetcher.source_path).to eq("//server/share/windows/path/foo & bar.txt") end end end @@ -73,7 +92,7 @@ describe Chef::Provider::RemoteFile::LocalFile do it "stages the local file to a temporary file" do expect(Chef::FileContentManagement::Tempfile).to receive(:new).with(new_resource).and_return(chef_tempfile) expect(::FileUtils).to receive(:cp).with(uri.path, tempfile.path) - expect(tempfile).to receive(:close) + expect(tempfile).to receive(:close) result = fetcher.fetch expect(result).to eq(tempfile) diff --git a/spec/unit/resource/remote_file_spec.rb b/spec/unit/resource/remote_file_spec.rb index 0b3df4eb2c..0a379ff574 100644 --- a/spec/unit/resource/remote_file_spec.rb +++ b/spec/unit/resource/remote_file_spec.rb @@ -60,6 +60,11 @@ describe Chef::Resource::RemoteFile do expect(@resource.source).to eql([ "\\\\fakey\\fakerton\\fake.txt" ]) end + it 'should accept file URIs with spaces' do + @resource.source("file:///C:/foo bar") + expect(@resource.source).to eql(["file:///C:/foo bar"]) + end + it "should accept a delayed evalutator (string) for the remote file source" do @resource.source Chef::DelayedEvaluator.new {"http://opscode.com/"} expect(@resource.source).to eql([ "http://opscode.com/" ]) |