summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVivek Singh <vivek.singh@msystechnologies.com>2019-12-02 15:47:32 +0530
committerVivek Singh <vivek.singh@msystechnologies.com>2019-12-02 15:47:32 +0530
commit52871d2c8d8bc8ed526b8e3eda9aadb5fa0f93e5 (patch)
treee82909630080293ed9b2a829cd9d77d904125712
parent6deede271dd01f0aad393d1264aba45a0a22d6f0 (diff)
downloadchef-lcg/file-verifier-output.tar.gz
Fix undefined method `dirname' for Chef::Provider::File:Classlcg/file-verifier-output
 - Fix failing specs.  - Fix long strings getting truncated for RSpec expectations. Signed-off-by: Vivek Singh <vivek.singh@msystechnologies.com>
-rw-r--r--lib/chef/provider/file.rb2
-rw-r--r--spec/spec_helper.rb2
-rw-r--r--spec/support/shared/unit/provider/file.rb20
3 files changed, 19 insertions, 5 deletions
diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb
index 158c1b686b..1b1f73b9d5 100644
--- a/lib/chef/provider/file.rb
+++ b/lib/chef/provider/file.rb
@@ -342,7 +342,7 @@ class Chef
new_resource.verify.each do |v|
unless v.verify(tempfile.path)
backupfile = "#{Chef::Config[:file_cache_path]}/failed_validations/#{::File.basename(tempfile.path)}"
- FileUtils.mkdir_p File.dirname(backupfile)
+ FileUtils.mkdir_p ::File.dirname(backupfile)
FileUtils.cp tempfile.path, backupfile
raise Chef::Exceptions::ValidationFailed.new "Proposed content for #{new_resource.path} failed verification #{new_resource.sensitive ? "[sensitive]" : "#{v}\n#{v.output}"}\nTemporary file moved to #{backupfile}"
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 27cf301d67..3154e2f255 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -123,8 +123,10 @@ RSpec.configure do |config|
config.filter_run_excluding external: true
# Explicitly disable :should syntax
+ # And set max_formatted_output_length to nil to prevent RSpec from doing truncation.
config.expect_with :rspec do |c|
c.syntax = :expect
+ c.max_formatted_output_length = nil
end
config.mock_with :rspec do |c|
c.syntax = :expect
diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb
index 36b19675c2..3df8eecc6f 100644
--- a/spec/support/shared/unit/provider/file.rb
+++ b/spec/support/shared/unit/provider/file.rb
@@ -458,14 +458,24 @@ shared_examples_for Chef::Provider::File do
end
context "do_validate_content" do
- before { setup_normal_file }
+ let(:tempfile_name) { "foo-bar-baz" }
+ let(:backupfile) { "/tmp/failed_validations/#{tempfile_name}" }
let(:tempfile) do
- t = double("Tempfile", path: "/tmp/foo-bar-baz", closed?: true)
+ t = double("Tempfile", path: "/tmp/#{tempfile_name}", closed?: true)
allow(content).to receive(:tempfile).and_return(t)
t
end
+ before do
+ Chef::Config[:file_cache_path] = "/tmp"
+ allow(File).to receive(:dirname).and_return(tempfile)
+ allow(File).to receive(:basename).and_return(tempfile_name)
+ allow(FileUtils).to receive(:mkdir_p).and_return(true)
+ allow(FileUtils).to receive(:cp).and_return(true)
+ setup_normal_file
+ end
+
context "with user-supplied verifications" do
it "calls #verify on each verification with tempfile path" do
provider.new_resource.verify windows? ? "REM" : "true"
@@ -477,7 +487,8 @@ shared_examples_for Chef::Provider::File do
allow(File).to receive(:directory?).with("C:\\Windows\\system32/cmd.exe").and_return(false)
provider.new_resource.verify windows? ? "REM" : "true"
provider.new_resource.verify windows? ? "cmd.exe /c exit 1" : "false"
- expect { provider.send(:do_validate_content) }.to raise_error(Chef::Exceptions::ValidationFailed, "Proposed content for #{provider.new_resource.path} failed verification #{windows? ? "cmd.exe /c exit 1" : "false"}")
+ msg = "Proposed content for #{provider.new_resource.path} failed verification #{windows? ? "cmd.exe /c exit 1" : "false"}"
+ expect { provider.send(:do_validate_content) }.to raise_error(Chef::Exceptions::ValidationFailed, /#{msg}/)
end
it "does not show verification for sensitive resources" do
@@ -485,7 +496,8 @@ shared_examples_for Chef::Provider::File do
provider.new_resource.verify windows? ? "REM" : "true"
provider.new_resource.verify windows? ? "cmd.exe /c exit 1" : "false"
provider.new_resource.sensitive true
- expect { provider.send(:do_validate_content) }.to raise_error(Chef::Exceptions::ValidationFailed, "Proposed content for #{provider.new_resource.path} failed verification [sensitive]")
+ msg = "Proposed content for #{provider.new_resource.path} failed verification [sensitive]\nTemporary file moved to #{backupfile}"
+ expect { provider.send(:do_validate_content) }.to raise_error(Chef::Exceptions::ValidationFailed, msg)
end
end
end