Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[KITCHEN-23] - add feature test for metadata naming

* Update chef_cookbook helper method to support a new directory
* Create helper predicate method using check_file_content to check
that the project name is correct
* Needed to pass output_dir in get_cookbook_name method in
TestKitchen::Scaffold.
  • Loading branch information...
commit ea7965269910f9371407a5589cd0bc2834d1dd1c 1 parent 9172584
@jtimberman jtimberman authored
View
5 features/scaffold_existing_cookbook.feature
@@ -9,3 +9,8 @@ I want to be able to quickly setup my existing cookbook for integration testing
When I scaffold the integration tests
And I run the integration tests with test kitchen
Then the existing cookbook will have been converged
+
+ Scenario: Existing cookbook in different directory
+ Given an existing Chef cookbook named in metadata but not the directory
+ When I scaffold the integration tests in its directory
+ Then The generated Kitchenfile will contain the name from the metadata
View
12 features/step_definitions/integration_test_steps.rb
@@ -90,6 +90,10 @@
chef_cookbook(:type => :real_world_testless)
end
+Given 'an existing Chef cookbook named in metadata but not the directory' do
+ chef_cookbook(:type => :real_world_testless_dir)
+end
+
Given /^the integration tests are defined in a (malformed )?Kitchenfile included with the (cookbook|project)$/ do |malformed, project_type|
define_integration_tests(:malformed => malformed, :project_type => project_type)
end
@@ -110,6 +114,10 @@
scaffold_tests('vim')
end
+When /^I scaffold the integration tests in its directory$/ do
+ scaffold_tests('cookbook-vim')
+end
+
When 'I run the command line tool from the bundle with no options' do
run_simple(unescape("bundle exec kitchen"), false)
end
@@ -184,6 +192,10 @@
all_output.must_match /Chef Run complete in/
end
+Then 'The generated Kitchenfile will contain the name from the metadata' do
+ assert cookbook_project_name_metadata?
+end
+
Then 'the expected platforms will be available' do
available_platforms.must_equal(["centos-5.8", "centos-6.3", "ubuntu-10.04", "ubuntu-12.04"])
end
View
14 features/support/integration_test_helpers.rb
@@ -58,6 +58,8 @@ def chef_cookbook(options = {})
end
when :real_world_testless
clone_cookbook_repository('opscode-cookbooks', 'vim', '88e8d01')
+ when :real_world_testless_dir
+ clone_cookbook_repository('opscode-cookbooks', 'vim', '88e8d01', 'cookbook-vim')
when :newly_generated
generate_new_cookbook(options[:name], options[:path], options[:recipes])
add_platform_metadata(options[:name], options[:supports_type], options[:path]) if options[:supports_type]
@@ -170,6 +172,11 @@ def scaffold_tests(cookbook_name)
run_simple(unescape("bundle exec kitchen init"))
end
+ def cookbook_project_name_metadata?
+ kf = File.join(File.expand_path(current_dir), 'test', 'kitchen', 'Kitchenfile')
+ check_file_content(kf, 'cookbook "vim" do', true)
+ end
+
def kitchenfile_error_shown?
!! (all_output =~ /Your Kitchenfile could not be loaded. Please check it for errors./)
end
@@ -192,9 +199,10 @@ def unrecognized_platform_warning_shown?(platform_name)
private
- def clone_cookbook_repository(organization, cookbook_name, sha)
- run_simple("git clone --quiet git://github.com/#{organization}/#{cookbook_name}.git")
- cd(cookbook_name)
+ def clone_cookbook_repository(organization, cookbook_name, sha, dirname = '')
+ run_simple("git clone --quiet git://github.com/#{organization}/#{cookbook_name}.git #{dirname}")
+ working_dir = dirname.length > 0 ? dirname : cookbook_name
+ cd(working_dir)
run_simple("git checkout --quiet #{sha}")
cd '..'
end
View
4 lib/test-kitchen/scaffold.rb
@@ -52,13 +52,13 @@ def generate(output_dir)
def project_name(output_dir)
if project_type(output_dir) =~ /cookbook/
- get_cookbook_name
+ get_cookbook_name(output_dir)
else
File.basename(output_dir)
end
end
- def get_cookbook_name()
+ def get_cookbook_name(output_dir)
md = Chef::Cookbook::Metadata.new
md.from_file(File.join(output_dir, 'metadata.rb'))
md.name
Please sign in to comment.
Something went wrong with that request. Please try again.