diff options
author | Thom May <thom@may.lt> | 2017-12-19 09:45:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-19 09:45:43 +0000 |
commit | f13388dca743d20cbae5051ba2b7a4a182ed8e5b (patch) | |
tree | 848c20c17586e8e4e2bf0181e9f3b842ae64a117 /spec | |
parent | f61f8bb75fcc0ba934b688c34f8d018bfcb3ca81 (diff) | |
parent | b4690c58ae034207ddcbb8625e066f5327930f97 (diff) | |
download | chef-f13388dca743d20cbae5051ba2b7a4a182ed8e5b.tar.gz |
Merge pull request #6690 from chef/tm+nk/verify-command
Slight improvements to validation failures
Diffstat (limited to 'spec')
-rw-r--r-- | spec/support/shared/unit/provider/file.rb | 10 | ||||
-rw-r--r-- | spec/unit/resource/file/verification_spec.rb | 22 |
2 files changed, 27 insertions, 5 deletions
diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb index b58159fcc9..d508e76b24 100644 --- a/spec/support/shared/unit/provider/file.rb +++ b/spec/support/shared/unit/provider/file.rb @@ -476,7 +476,15 @@ 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) + 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"}") + end + + it "does not show verification for sensitive resources" 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" + 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]") end end end diff --git a/spec/unit/resource/file/verification_spec.rb b/spec/unit/resource/file/verification_spec.rb index feacd715a4..e46040268a 100644 --- a/spec/unit/resource/file/verification_spec.rb +++ b/spec/unit/resource/file/verification_spec.rb @@ -66,6 +66,11 @@ describe Chef::Resource::File::Verification do v = Chef::Resource::File::Verification.new(parent_resource, nil, {}, &f_block) expect(v.verify(temp_path)).to eq(false) end + + it "responds to to_s" do + v = Chef::Resource::File::Verification.new(parent_resource, nil, {}) {} + expect(v.to_s).to eq("<Proc>") + end end context "with a verification command(String)" do @@ -110,23 +115,32 @@ describe Chef::Resource::File::Verification do v = Chef::Resource::File::Verification.new(parent_resource, "true", {}) expect(v.verify(temp_path)).to eq(true) end + + it "responds to to_s" do + v = Chef::Resource::File::Verification.new(parent_resource, "some command --here", {}) + expect(v.to_s).to eq("some command --here") + end end context "with a named verification(Symbol)" do + let(:registered_verification) { double("registered_verification") } + subject { described_class.new(parent_resource, :cats, {}) } before(:each) do class Chef::Resource::File::Verification::Turtle < Chef::Resource::File::Verification provides :cats def verify(path, opts) end end + allow(Chef::Resource::File::Verification::Turtle).to receive(:new).and_return(registered_verification) end it "delegates to the registered verification" do - registered_verification = double() - allow(Chef::Resource::File::Verification::Turtle).to receive(:new).and_return(registered_verification) - v = Chef::Resource::File::Verification.new(parent_resource, :cats, {}) expect(registered_verification).to receive(:verify).with(temp_path, {}) - v.verify(temp_path, {}) + subject.verify(temp_path, {}) + end + + it "responds to to_s" do + expect(subject.to_s).to eq(":cats (Chef::Resource::File::Verification::Turtle)") end end end |