diff options
author | Claire McQuin <claire@getchef.com> | 2014-12-16 13:03:53 -0800 |
---|---|---|
committer | tyler-ball <tyleraball@gmail.com> | 2014-12-17 18:52:25 -0800 |
commit | 19f7b0f1668e5801f44570f52285f8a1bde516c0 (patch) | |
tree | d53a3cf4d9ae3eeb923054ab1f6799887e8de796 /spec/functional/audit | |
parent | 5531cabf5640607874fd24c5e9c6006d848ec69b (diff) | |
download | chef-19f7b0f1668e5801f44570f52285f8a1bde516c0.tar.gz |
Unit tests for audit-mode in chef-solo.
* Audits are disabled by default.
* Also, updated spec file to use RSpec :let.
Diffstat (limited to 'spec/functional/audit')
-rw-r--r-- | spec/functional/audit/runner_spec.rb | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/spec/functional/audit/runner_spec.rb b/spec/functional/audit/runner_spec.rb index 89c62ae2e8..aa35548f2f 100644 --- a/spec/functional/audit/runner_spec.rb +++ b/spec/functional/audit/runner_spec.rb @@ -20,6 +20,7 @@ require 'spec_helper' require 'spec/support/audit_helper' require 'chef/audit/runner' require 'rspec/support/spec/in_sub_process' +require 'tempfile' ## # This functional test ensures that our runner can be setup to not interfere with existing RSpec @@ -60,7 +61,7 @@ describe Chef::Audit::Runner do end end - context "there is a single successful control" do + shared_context "passing audit" do let(:audits) do should_pass = lambda do it "should pass" do @@ -69,17 +70,9 @@ describe Chef::Audit::Runner do end { controls_name => Struct.new(:args, :block).new([controls_name], should_pass)} end - - it "correctly runs" do - in_sub_process do - runner.run - - expect(stdout.string).to match(/1 example, 0 failures/) - end - end end - context "there is a single failing control" do + shared_context "failing audit" do let(:audits) do should_fail = lambda do it "should fail" do @@ -88,7 +81,21 @@ describe Chef::Audit::Runner do end { controls_name => Struct.new(:args, :block).new([controls_name], should_fail)} end + end + + context "there is a single successful control" do + include_context "passing audit" + it "correctly runs" do + in_sub_process do + runner.run + + expect(stdout.string).to match(/1 example, 0 failures/) + end + end + end + context "there is a single failing control" do + include_context "failing audit" it "correctly runs" do in_sub_process do runner.run @@ -100,6 +107,30 @@ describe Chef::Audit::Runner do end end + describe "log location is a file" do + let(:tmpfile) { Tempfile.new("audit") } + before do + Chef::Config[:log_location] = tmpfile.path + end + + after do + tmpfile.close + tmpfile.unlink + end + + include_context "failing audit" + it "correctly runs" do + in_sub_process do + runner.run + + contents = tmpfile.read + expect(contents).to match(/Failure\/Error: expect\(2 - 1\)\.to eq\(0\)/) + expect(contents).to match(/1 example, 1 failure/) + expect(contents).to match(/# controls_name should fail/) + end + end + end + end end |