summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-05-13 14:53:56 -0500
committerJay Mundrawala <jdmundrawala@gmail.com>2015-05-13 14:53:56 -0500
commitd17941dd949fd1730912abc6b76cb124e1655b4d (patch)
treeef3ca37b9131c3020982e3c8144f522576ed9310 /spec
parenta96d24d6817ed20b6c418b620892d1421cbf7f84 (diff)
parent03a8b4cc50f02d588e55b2d69e362512170076ac (diff)
downloadchef-d17941dd949fd1730912abc6b76cb124e1655b4d.tar.gz
Merge pull request #3336 from chef/jdm/smb
remote_file support for windows network shares
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/provider/remote_file/fetcher_spec.rb21
-rw-r--r--spec/unit/provider/remote_file/network_file_spec.rb45
-rw-r--r--spec/unit/resource/remote_file_spec.rb10
3 files changed, 75 insertions, 1 deletions
diff --git a/spec/unit/provider/remote_file/fetcher_spec.rb b/spec/unit/provider/remote_file/fetcher_spec.rb
index c049848fbf..8bd3b7c625 100644
--- a/spec/unit/provider/remote_file/fetcher_spec.rb
+++ b/spec/unit/provider/remote_file/fetcher_spec.rb
@@ -24,6 +24,26 @@ describe Chef::Provider::RemoteFile::Fetcher do
let(:new_resource) { double("new resource") }
let(:fetcher_instance) { double("fetcher") }
+ describe "when passed a network share" do
+ before do
+ expect(Chef::Provider::RemoteFile::NetworkFile).to receive(:new).and_return(fetcher_instance)
+ end
+
+ context "when host is a name" do
+ let(:source) { "\\\\foohost\\fooshare\\Foo.tar.gz" }
+ it "returns a network file fetcher" do
+ expect(described_class.for_resource(source, new_resource, current_resource)).to eq(fetcher_instance)
+ end
+ end
+
+ context "when host is an ip" do
+ let(:source) { "\\\\127.0.0.1\\fooshare\\Foo.tar.gz" }
+ it "returns a network file fetcher" do
+ expect(described_class.for_resource(source, new_resource, current_resource)).to eq(fetcher_instance)
+ end
+ end
+ end
+
describe "when passed an http url" do
let(:uri) { double("uri", :scheme => "http" ) }
before do
@@ -72,4 +92,3 @@ describe Chef::Provider::RemoteFile::Fetcher do
end
end
-
diff --git a/spec/unit/provider/remote_file/network_file_spec.rb b/spec/unit/provider/remote_file/network_file_spec.rb
new file mode 100644
index 0000000000..3666a47468
--- /dev/null
+++ b/spec/unit/provider/remote_file/network_file_spec.rb
@@ -0,0 +1,45 @@
+#
+# Author:: Jay Mundrawala (<jdm@chef.io>)
+# Copyright:: Copyright (c) 2015 Chef Software
+# 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::RemoteFile::NetworkFile do
+
+ let(:source) { "\\\\foohost\\fooshare\\Foo.tar.gz" }
+
+ let(:new_resource) { Chef::Resource::RemoteFile.new("network file (new_resource)") }
+ let(:current_resource) { Chef::Resource::RemoteFile.new("network file (current_resource)") }
+ subject(:fetcher) { Chef::Provider::RemoteFile::NetworkFile.new(source, new_resource, current_resource) }
+
+ describe "when fetching the object" do
+
+ let(:tempfile) { double("Tempfile", :path => "/tmp/foo/bar/Foo.tar.gz", :close => nil) }
+ let(:chef_tempfile) { double("Chef::FileContentManagement::Tempfile", :tempfile => tempfile) }
+
+ 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(source, tempfile.path)
+ expect(tempfile).to receive(:close)
+
+ result = fetcher.fetch
+ expect(result).to eq(tempfile)
+ end
+
+ end
+
+end
diff --git a/spec/unit/resource/remote_file_spec.rb b/spec/unit/resource/remote_file_spec.rb
index 3731d1aee2..0b3df4eb2c 100644
--- a/spec/unit/resource/remote_file_spec.rb
+++ b/spec/unit/resource/remote_file_spec.rb
@@ -39,6 +39,11 @@ describe Chef::Resource::RemoteFile do
expect(Chef::Platform.find_provider(:noplatform, 'noversion', @resource)).to eq(Chef::Provider::RemoteFile)
end
+ it "says its provider is RemoteFile when the source is a network share" do
+ @resource.source("\\\\fakey\\fakerton\\fake.txt")
+ expect(@resource.provider).to eq(Chef::Provider::RemoteFile)
+ expect(Chef::Platform.find_provider(:noplatform, 'noversion', @resource)).to eq(Chef::Provider::RemoteFile)
+ end
describe "source" do
it "does not have a default value for 'source'" do
@@ -50,6 +55,11 @@ describe Chef::Resource::RemoteFile do
expect(@resource.source).to eql([ "http://opscode.com/" ])
end
+ it "should accept a windows network share source" do
+ @resource.source "\\\\fakey\\fakerton\\fake.txt"
+ expect(@resource.source).to eql([ "\\\\fakey\\fakerton\\fake.txt" ])
+ 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/" ])