diff options
author | Claire McQuin <claire@getchef.com> | 2015-01-14 11:40:48 -0800 |
---|---|---|
committer | Claire McQuin <claire@getchef.com> | 2015-01-15 15:34:33 -0800 |
commit | 4cbc6274889ddedf105ec99200f53b50439df273 (patch) | |
tree | e42d111f7f20f45377f0dbbdeb4e5ef377c9c9f0 | |
parent | d1a70027b68b1ba6d36eea3bc38d5441a61f22f8 (diff) | |
download | chef-4cbc6274889ddedf105ec99200f53b50439df273.tar.gz |
Update DSL method name to controls_group.mcquin/control_group
Update to use control_group.
Unify wording along control_group.
Unify wording along control_group.
Fix typo.
Enable audit mode.
Update to use control_group syntax.
Update for audit DSL changes.
Update for audit DSL change.
20 files changed, 54 insertions, 52 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 43c8f06d93..f457841a3e 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -15,7 +15,7 @@ node. As such the syntax is very similar to a normal RSpec spec. ### Syntax ```ruby -controls "Database Audit" do +control_group "Database Audit" do control "postgres package" do it "should not be installed" do @@ -35,8 +35,8 @@ end Using the example above I will break down the components of an Audit: -* `controls` - This named block contains all the audits to be performed during the audit phase. During Chef convergence - the audits will be collected and ran in a separate phase at the end of the Chef run. Any `controls` block defined in +* `control_group` - This named block contains all the audits to be performed during the audit phase. During Chef convergence + the audits will be collected and ran in a separate phase at the end of the Chef run. Any `control_group` block defined in a recipe that is ran on the node will be performed. * `control` - This keyword describes a section of audits to perform. The name here should either be a string describing the system under test, or a [Serverspec resource](http://serverspec.org/resource_types.html). diff --git a/kitchen-tests/.chef/client.rb b/kitchen-tests/.chef/client.rb index 98f773d691..be46e2e8d7 100644 --- a/kitchen-tests/.chef/client.rb +++ b/kitchen-tests/.chef/client.rb @@ -6,3 +6,5 @@ log_level :info chef_repo_path repo_dir local_mode true cache_path "#{ENV['HOME']}/.cache/chef" + +audit_mode :enabled
\ No newline at end of file diff --git a/kitchen-tests/cookbooks/audit_test/recipes/default.rb b/kitchen-tests/cookbooks/audit_test/recipes/default.rb index 4f634d73c1..833c12064a 100644 --- a/kitchen-tests/cookbooks/audit_test/recipes/default.rb +++ b/kitchen-tests/cookbooks/audit_test/recipes/default.rb @@ -4,7 +4,7 @@ # # Copyright (c) 2014 The Authors, All Rights Reserved. -controls "basic control group" do +control_group "basic control group" do control "basic math" do it "should pass" do expect(2 - 2).to eq(0) @@ -12,15 +12,15 @@ controls "basic control group" do end end -controls "control group without top level control" do +control_group "control group without top level control" do it "should pass" do expect(2 - 2).to eq(0) end end -controls "control group with empty control" do +control_group "control group with empty control" do control "empty" end -controls "empty control group with block" do +control_group "empty control group with block" do end diff --git a/kitchen-tests/cookbooks/audit_test/recipes/error_duplicate_control_groups.rb b/kitchen-tests/cookbooks/audit_test/recipes/error_duplicate_control_groups.rb index 77a4592e9d..82b358d4be 100644 --- a/kitchen-tests/cookbooks/audit_test/recipes/error_duplicate_control_groups.rb +++ b/kitchen-tests/cookbooks/audit_test/recipes/error_duplicate_control_groups.rb @@ -4,13 +4,13 @@ # # Copyright (c) 2014 The Authors, All Rights Reserved. -controls "basic control group" do +control_group "basic control group" do it "should pass" do expect(2 - 2).to eq(0) end end -controls "basic control group" do +control_group "basic control group" do it "should pass" do expect(2 - 2).to eq(0) end diff --git a/kitchen-tests/cookbooks/audit_test/recipes/error_no_block.rb b/kitchen-tests/cookbooks/audit_test/recipes/error_no_block.rb index 76a8817b5d..42da81aa4f 100644 --- a/kitchen-tests/cookbooks/audit_test/recipes/error_no_block.rb +++ b/kitchen-tests/cookbooks/audit_test/recipes/error_no_block.rb @@ -4,4 +4,4 @@ # # Copyright (c) 2014 The Authors, All Rights Reserved. -controls "empty control group without block" +control_group "empty control group without block" diff --git a/kitchen-tests/cookbooks/audit_test/recipes/error_orphan_control.rb b/kitchen-tests/cookbooks/audit_test/recipes/error_orphan_control.rb index d74acd6c6b..4f2a8e6c55 100644 --- a/kitchen-tests/cookbooks/audit_test/recipes/error_orphan_control.rb +++ b/kitchen-tests/cookbooks/audit_test/recipes/error_orphan_control.rb @@ -4,7 +4,7 @@ # # Copyright (c) 2014 The Authors, All Rights Reserved. -controls "basic control group" do +control_group "basic control group" do it "should pass" do expect(2 - 2).to eq(0) end diff --git a/kitchen-tests/cookbooks/audit_test/recipes/failed_specs.rb b/kitchen-tests/cookbooks/audit_test/recipes/failed_specs.rb index 3225d3983e..c5c2c32f0a 100644 --- a/kitchen-tests/cookbooks/audit_test/recipes/failed_specs.rb +++ b/kitchen-tests/cookbooks/audit_test/recipes/failed_specs.rb @@ -4,7 +4,7 @@ # # Copyright (c) 2014 The Authors, All Rights Reserved. -controls "basic control group" do +control_group "basic control group" do control "basic math" do # Can not write a good control :( it "should pass" do diff --git a/kitchen-tests/cookbooks/audit_test/recipes/serverspec_collision.rb b/kitchen-tests/cookbooks/audit_test/recipes/serverspec_collision.rb index 70109d84b8..c433bd1a90 100644 --- a/kitchen-tests/cookbooks/audit_test/recipes/serverspec_collision.rb +++ b/kitchen-tests/cookbooks/audit_test/recipes/serverspec_collision.rb @@ -9,7 +9,7 @@ file "/tmp/audit_test_file" do content "Welcome to audit mode." end -controls "file auditing" do +control_group "file auditing" do describe "test file" do it "says welcome" do expect(file("/tmp/audit_test_file")).to contain("Welcome") @@ -22,7 +22,7 @@ file "/tmp/audit_test_file_2" do content "Bye to audit mode." end -controls "end file auditing" do +control_group "end file auditing" do describe "end file" do it "says bye" do expect(file("/tmp/audit_test_file_2")).to contain("Bye") diff --git a/kitchen-tests/cookbooks/audit_test/recipes/serverspec_support.rb b/kitchen-tests/cookbooks/audit_test/recipes/serverspec_support.rb index 0396cc0de7..8b3c35a6bd 100644 --- a/kitchen-tests/cookbooks/audit_test/recipes/serverspec_support.rb +++ b/kitchen-tests/cookbooks/audit_test/recipes/serverspec_support.rb @@ -13,7 +13,7 @@ end # action :install # end -controls "serverspec helpers with types" do +control_group "serverspec helpers with types" do control "file helper" do it "says welcome" do expect(file("/tmp/audit_test_file")).to contain("Welcome") diff --git a/kitchen-tests/cookbooks/audit_test/recipes/with_include_recipe.rb b/kitchen-tests/cookbooks/audit_test/recipes/with_include_recipe.rb index ff39cde117..f795f7786a 100644 --- a/kitchen-tests/cookbooks/audit_test/recipes/with_include_recipe.rb +++ b/kitchen-tests/cookbooks/audit_test/recipes/with_include_recipe.rb @@ -6,7 +6,7 @@ include_recipe "audit_test::serverspec_collision" -controls "basic example" do +control_group "basic example" do it "should pass" do expect(2 - 2).to eq(0) end diff --git a/lib/chef/audit/audit_event_proxy.rb b/lib/chef/audit/audit_event_proxy.rb index 2512b8bfe2..b9ca39e5dc 100644 --- a/lib/chef/audit/audit_event_proxy.rb +++ b/lib/chef/audit/audit_event_proxy.rb @@ -35,15 +35,15 @@ class Chef def example_group_started(notification) if notification.group.parent_groups.size == 1 - # top level `controls` block + # top level `control_group` block desc = notification.group.description - Chef::Log.debug("Entered `controls` block named #{desc}") + Chef::Log.debug("Entered `control_group` block named #{desc}") events.control_group_started(desc) end end def stop(notification) - Chef::Log.info("Successfully executed all `controls` blocks and contained examples") + Chef::Log.info("Successfully executed all `control_group` blocks and contained examples") notification.examples.each do |example| control_group_name, control_data = build_control_from(example) e = example.exception @@ -75,7 +75,7 @@ class Chef group = group[:parent_example_group] end - # We know all of our examples each live in a top-level `controls` block - get this name now + # We know all of our examples each live in a top-level `control_group` block - get this name now outermost_group_desc = describe_groups.shift return outermost_group_desc, { diff --git a/lib/chef/audit/runner.rb b/lib/chef/audit/runner.rb index 7ef17a4301..e7d1657d69 100644 --- a/lib/chef/audit/runner.rb +++ b/lib/chef/audit/runner.rb @@ -29,7 +29,7 @@ class Chef def run setup - register_controls + register_control_groups do_run end @@ -136,29 +136,29 @@ class Chef Specinfra.configuration.backend = :exec end - # Iterates through the controls registered to this run_context, builds an - # example group (RSpec::Core::ExampleGroup) object per controls, and + # Iterates through the control groups registered to this run_context, builds an + # example group (RSpec::Core::ExampleGroup) object per control group, and # registers the group with the RSpec.world. # # We could just store an array of example groups and not use RSpec.world, # but it may be useful later if we decide to apply our own ordering scheme # or use example group filters. - def register_controls + def register_control_groups add_example_group_methods run_context.audits.each do |name, group| - ctl_grp = RSpec::Core::ExampleGroup.__controls__(*group.args, &group.block) + ctl_grp = RSpec::Core::ExampleGroup.__control_group__(*group.args, &group.block) RSpec.world.register(ctl_grp) end end # Add example group method aliases to RSpec. # - # __controls__: Used internally to create example groups from the controls - # saved in the run_context. - # control: Used within the context of a controls block, like RSpec's + # __control_group__: Used internally to create example groups from the control + # groups saved in the run_context. + # control: Used within the context of a control group block, like RSpec's # describe or context. def add_example_group_methods - RSpec::Core::ExampleGroup.define_example_group_method :__controls__ + RSpec::Core::ExampleGroup.define_example_group_method :__control_group__ RSpec::Core::ExampleGroup.define_example_group_method :control end diff --git a/lib/chef/dsl/audit.rb b/lib/chef/dsl/audit.rb index 022bbcce01..d1bf09b313 100644 --- a/lib/chef/dsl/audit.rb +++ b/lib/chef/dsl/audit.rb @@ -24,7 +24,7 @@ class Chef # Can encompass tests in a `control` block or `describe` block # Adds the controls group and block (containing controls to execute) to the runner's list of pending examples - def controls(*args, &block) + def control_group(*args, &block) raise Chef::Exceptions::NoAuditsProvided unless block name = args[0] diff --git a/lib/chef/event_dispatch/base.rb b/lib/chef/event_dispatch/base.rb index 25dd9fd1b2..7274105802 100644 --- a/lib/chef/event_dispatch/base.rb +++ b/lib/chef/event_dispatch/base.rb @@ -248,15 +248,15 @@ class Chef def audit_phase_failed(exception) end - # Signifies the start of a `controls` block with a defined name + # Signifies the start of a `control_group` block with a defined name def control_group_started(name) end - # An example in a `controls` block completed successfully + # An example in a `control_group` block completed successfully def control_example_success(control_group_name, example_data) end - # An example in a `controls` block failed with the provided error + # An example in a `control_group` block failed with the provided error def control_example_failure(control_group_name, example_data, error) end diff --git a/spec/functional/audit/runner_spec.rb b/spec/functional/audit/runner_spec.rb index aa35548f2f..f5ef37f8f8 100644 --- a/spec/functional/audit/runner_spec.rb +++ b/spec/functional/audit/runner_spec.rb @@ -53,7 +53,7 @@ describe Chef::Audit::Runner do let(:audits) { {} } let(:run_context) { instance_double(Chef::RunContext, :events => events, :audits => audits) } - let(:controls_name) { "controls_name" } + let(:control_group_name) { "control_group_name" } it "Correctly runs an empty controls block" do in_sub_process do @@ -68,7 +68,7 @@ describe Chef::Audit::Runner do expect(2 - 2).to eq(0) end end - { controls_name => Struct.new(:args, :block).new([controls_name], should_pass)} + { control_group_name => Struct.new(:args, :block).new([control_group_name], should_pass)} end end @@ -79,7 +79,7 @@ describe Chef::Audit::Runner do expect(2 - 1).to eq(0) end end - { controls_name => Struct.new(:args, :block).new([controls_name], should_fail)} + { control_group_name => Struct.new(:args, :block).new([control_group_name], should_fail)} end end @@ -102,7 +102,7 @@ describe Chef::Audit::Runner do expect(stdout.string).to match(/Failure\/Error: expect\(2 - 1\)\.to eq\(0\)/) expect(stdout.string).to match(/1 example, 1 failure/) - expect(stdout.string).to match(/# controls_name should fail/) + expect(stdout.string).to match(/# control_group_name should fail/) end end end @@ -126,7 +126,7 @@ describe Chef::Audit::Runner do 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/) + expect(contents).to match(/# control_group_name should fail/) end end end diff --git a/spec/integration/client/client_spec.rb b/spec/integration/client/client_spec.rb index 62660bb852..0d18cfbc3d 100644 --- a/spec/integration/client/client_spec.rb +++ b/spec/integration/client/client_spec.rb @@ -252,7 +252,7 @@ EOM it "should exit with a zero code when there is not an audit failure" do file 'cookbooks/audit_test/recipes/succeed.rb', <<-RECIPE -controls "control group without top level control" do +control_group "control group without top level control" do it "should succeed" do expect(2 - 2).to eq(0) end @@ -261,12 +261,12 @@ end result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'audit_test::succeed'", :cwd => chef_dir) expect(result.error?).to be_falsey - expect(result.stdout).to include("Successfully executed all `controls` blocks and contained examples") + expect(result.stdout).to include("Successfully executed all `control_group` blocks and contained examples") end it "should exit with a non-zero code when there is an audit failure" do file 'cookbooks/audit_test/recipes/fail.rb', <<-RECIPE -controls "control group without top level control" do +control_group "control group without top level control" do it "should fail" do expect(2 - 2).to eq(1) end diff --git a/spec/unit/audit/audit_event_proxy_spec.rb b/spec/unit/audit/audit_event_proxy_spec.rb index 899ba468b1..17a5d3d771 100644 --- a/spec/unit/audit/audit_event_proxy_spec.rb +++ b/spec/unit/audit/audit_event_proxy_spec.rb @@ -44,7 +44,7 @@ describe Chef::Audit::AuditEventProxy do it "notifies control_group_started event" do expect(Chef::Log).to receive(:debug). - with("Entered \`controls\` block named poots") + with("Entered \`control_group\` block named poots") expect(events).to receive(:control_group_started). with(description) audit_event_proxy.example_group_started(notification) @@ -76,7 +76,7 @@ describe Chef::Audit::AuditEventProxy do end it "sends a message that audits completed" do - expect(Chef::Log).to receive(:info).with("Successfully executed all \`controls\` blocks and contained examples") + expect(Chef::Log).to receive(:info).with("Successfully executed all \`control_group\` blocks and contained examples") audit_event_proxy.stop(notification) end diff --git a/spec/unit/audit/runner_spec.rb b/spec/unit/audit/runner_spec.rb index 67590fecf9..250c93b24d 100644 --- a/spec/unit/audit/runner_spec.rb +++ b/spec/unit/audit/runner_spec.rb @@ -76,14 +76,14 @@ describe Chef::Audit::Runner do end end - describe "#register_controls" do + describe "#register_control_groups" do let(:audits) { [] } let(:run_context) { instance_double(Chef::RunContext, :audits => audits) } it "adds the control group aliases" do - runner.send(:register_controls) + runner.send(:register_control_groups) - expect(RSpec::Core::DSL.example_group_aliases).to include(:__controls__) + expect(RSpec::Core::DSL.example_group_aliases).to include(:__control_group__) expect(RSpec::Core::DSL.example_group_aliases).to include(:control) end @@ -92,7 +92,7 @@ describe Chef::Audit::Runner do let(:group) {Struct.new(:args, :block).new(["group_name"], nil)} it "sends the audits to the world" do - runner.send(:register_controls) + runner.send(:register_control_groups) expect(RSpec.world.example_groups.size).to eq(1) # For whatever reason, `kind_of` is not working diff --git a/spec/unit/dsl/audit_spec.rb b/spec/unit/dsl/audit_spec.rb index 38707127f0..28b28e0a7c 100644 --- a/spec/unit/dsl/audit_spec.rb +++ b/spec/unit/dsl/audit_spec.rb @@ -17,18 +17,18 @@ describe Chef::DSL::Audit do let(:cookbook_collection) { {} } it "raises an error when a block of audits is not provided" do - expect{ auditor.controls "name" }.to raise_error(Chef::Exceptions::NoAuditsProvided) + expect{ auditor.control_group "name" }.to raise_error(Chef::Exceptions::NoAuditsProvided) end it "raises an error when no audit name is given" do - expect{ auditor.controls do end }.to raise_error(Chef::Exceptions::AuditNameMissing) + expect{ auditor.control_group do end }.to raise_error(Chef::Exceptions::AuditNameMissing) end context "audits already populated" do let(:audits) { {"unique" => {} } } it "raises an error if the audit name is a duplicate" do - expect { auditor.controls "unique" do end }.to raise_error(Chef::Exceptions::AuditControlGroupDuplicate) + expect { auditor.control_group "unique" do end }.to raise_error(Chef::Exceptions::AuditControlGroupDuplicate) end end @@ -36,7 +36,7 @@ describe Chef::DSL::Audit do let(:auditor) { BadAuditDSLTester.new } it "fails because it relies on the recipe DSL existing" do - expect { auditor.controls "unique" do end }.to raise_error(NoMethodError, /undefined method `cookbook_name'/) + expect { auditor.control_group "unique" do end }.to raise_error(NoMethodError, /undefined method `cookbook_name'/) end end diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb index 22389a1a82..74feb984a5 100644 --- a/spec/unit/recipe_spec.rb +++ b/spec/unit/recipe_spec.rb @@ -563,7 +563,7 @@ describe Chef::Recipe do describe "included DSL" do it "should include features from Chef::DSL::Audit" do expect(recipe.singleton_class.included_modules).to include(Chef::DSL::Audit) - expect(recipe.respond_to?(:controls)).to be true + expect(recipe.respond_to?(:control_group)).to be true end end end |