Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

chef: Use test/smoke/default instead of test/recipes for generated cookbooks/recipes #1096

Merged
merged 4 commits into from
Dec 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# ChefDK 1.1 Release notes

## New Inspec Test Location
To address bugs and confusion with the previous `test/recipes` location, all newly generated
cookbooks and recipes will place their Inspec tests in `test/smoke/default`. This
placement creates the association of the `smoke` Workflow phase and the `default` Kitchen suite
where the tests are run.
2 changes: 1 addition & 1 deletion lib/chef-dk/command/generator_commands/cookbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def emit_post_create_message
msg("\nThere are several commands you can run to get started locally developing and testing your cookbook.")
msg("Type `delivery local --help` to see a full list.")
msg("\nWhy not start by writing a test? Tests for the default recipe are stored at:\n")
msg("test/recipes/default_test.rb")
msg("test/smoke/default/default_test.rb")
msg("\nIf you'd prefer to dive right in, the default recipe can be found at:")
msg("\nrecipes/default.rb\n")
end
Expand Down
4 changes: 2 additions & 2 deletions lib/chef-dk/skeletons/code_generator/recipes/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
end

# Inspec
directory "#{app_dir}/test/recipes" do
directory "#{app_dir}/test/smoke/default" do
recursive true
end

template "#{app_dir}/test/recipes/default_test.rb" do
template "#{app_dir}/test/smoke/default/default_test.rb" do
source 'inspec_default_test.rb.erb'
helpers(ChefDK::Generator::TemplateHelper)
action :create_if_missing
Expand Down
4 changes: 2 additions & 2 deletions lib/chef-dk/skeletons/code_generator/recipes/cookbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
end

# Inspec
directory "#{cookbook_dir}/test/recipes" do
directory "#{cookbook_dir}/test/smoke/default" do
recursive true
end

template "#{cookbook_dir}/test/recipes/default_test.rb" do
template "#{cookbook_dir}/test/smoke/default/default_test.rb" do
source 'inspec_default_test.rb.erb'
helpers(ChefDK::Generator::TemplateHelper)
action :create_if_missing
Expand Down
21 changes: 16 additions & 5 deletions lib/chef-dk/skeletons/code_generator/recipes/recipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@
cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
recipe_path = File.join(cookbook_dir, "recipes", "#{context.new_file_basename}.rb")
spec_helper_path = File.join(cookbook_dir, "spec", "spec_helper.rb")
spec_path = File.join(cookbook_dir, "spec", "unit", "recipes", "#{context.new_file_basename}_spec.rb")
inspec_path = File.join(cookbook_dir, "test", "recipes", "#{context.new_file_basename}.rb")
spec_dir = File.join(cookbook_dir, "spec", "unit", "recipes")
spec_path = File.join(spec_dir, "#{context.new_file_basename}_spec.rb")
inspec_dir = File.join(cookbook_dir, "test", "smoke", "default")
inspec_path = File.join(inspec_dir, "#{context.new_file_basename}.rb")

if File.directory?(File.join(cookbook_dir, "test", "recipes"))
Chef::Log.deprecation <<-EOH
It appears that you have Inspec tests located at "test/recipes". This location can
cause issues with Foodcritic and has been deprecated in favor of "test/smoke/default".
Please move your existing Inspec tests to the newly created "test/smoke/default"
directory, and update the 'inspec_tests' value in your .kitchen.yml file(s) to
point to "test/smoke/default".
EOH
end

# Chefspec
directory "#{cookbook_dir}/spec/unit/recipes" do
directory spec_dir do
recursive true
end

Expand All @@ -22,7 +34,7 @@
end

# Inspec
directory "#{cookbook_dir}/test/recipes" do
directory inspec_dir do
recursive true
end

Expand All @@ -37,4 +49,3 @@
source "recipe.rb.erb"
helpers(ChefDK::Generator::TemplateHelper)
end

Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ suites:
- recipe[<%= cookbook_name %>::default]
verifier:
inspec_tests:
- test/recipes
- test/smoke/default
attributes:
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ suites:
- name: default
verifier:
inspec_tests:
- test/recipes
- test/smoke/default
attributes:
10 changes: 5 additions & 5 deletions spec/unit/command/generator_commands/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
.gitignore
.kitchen.yml
test
test/recipes
test/recipes/default_test.rb
test/smoke
test/smoke/default
test/smoke/default/default_test.rb
README.md
cookbooks/new_app/Berksfile
cookbooks/new_app/chefignore
Expand Down Expand Up @@ -128,8 +129,8 @@ def generator_context
end
end

describe "test/recipes/default_test.rb" do
let(:file) { File.join(tempdir, "new_app", "test", "recipes", "default_test.rb") }
describe "test/smoke/default/default_test.rb" do
let(:file) { File.join(tempdir, "new_app", "test", "smoke", "default", "default_test.rb") }

include_examples "a generated file", :cookbook_name do
let(:line) { "describe port" }
Expand Down Expand Up @@ -163,4 +164,3 @@ def generator_context
end
end
end

14 changes: 7 additions & 7 deletions spec/unit/command/generator_commands/cookbook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
.gitignore
.kitchen.yml
test
test/recipes
test/recipes/default_test.rb
test/smoke
test/smoke/default/default_test.rb
Berksfile
chefignore
metadata.rb
Expand Down Expand Up @@ -65,7 +65,7 @@

Why not start by writing a test? Tests for the default recipe are stored at:

test/recipes/default_test.rb
test/smoke/default/default_test.rb

If you'd prefer to dive right in, the default recipe can be found at:

Expand Down Expand Up @@ -460,8 +460,8 @@ def with_argv(argv)

end

describe "test/recipes/default_test.rb" do
let(:file) { File.join(tempdir, "new_cookbook", "test", "recipes", "default_test.rb") }
describe "test/smoke/default/default_test.rb" do
let(:file) { File.join(tempdir, "new_cookbook", "test", "smoke", "default", "default_test.rb") }

include_examples "a generated file", :cookbook_name do
let(:line) { "describe port" }
Expand Down Expand Up @@ -570,7 +570,7 @@ def with_argv(argv)
- name: default
verifier:
inspec_tests:
- test/recipes
- test/smoke/default
attributes:
KITCHEN_YML
end
Expand Down Expand Up @@ -647,7 +647,7 @@ def with_argv(argv)
- recipe[new_cookbook::default]
verifier:
inspec_tests:
- test/recipes
- test/smoke/default
attributes:
KITCHEN_YML
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/command/generator_commands/recipe_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
let(:generated_files) { [ "recipes/new_recipe.rb",
"spec/spec_helper.rb",
"spec/unit/recipes/new_recipe_spec.rb",
"test/recipes/new_recipe.rb"
"test/smoke/default/new_recipe.rb"
] }
let(:new_file_name) { "new_recipe" }

Expand Down