Skip to content
Browse files

[CHEF-2076] Add integration tests for frozen cookbooks

  • Loading branch information...
1 parent 82e0a8a commit 71c71bd76df051f1f619ff5de0218d947b30b536 @danielsdeleo danielsdeleo committed Mar 25, 2011
View
1 .gitignore
@@ -34,5 +34,6 @@ chef-expander/conf/chef-expander.rb
chef-expander/spec/fixtures/expander.log
features/data/cookbooks/transfer_remote_files/metadata.json
features/data/cookbooks/synchronize_deps/metadata.json
+features/data/cookbooks_not_uploaded_at_feature_start/*/metadata.json
*/tags
*~
View
8 chef/lib/chef/cookbook_uploader.rb
@@ -1,5 +1,6 @@
require 'rest_client'
require 'chef/exceptions'
+require 'chef/knife/cookbook_metadata'
require 'chef/checksum_cache'
require 'chef/sandbox'
require 'chef/cookbook_version'
@@ -12,6 +13,7 @@ class CookbookUploader
attr_reader :cookbook
attr_reader :path
attr_reader :opts
+ attr_reader :rest
# Creates a new CookbookUploader.
# ===Arguments:
@@ -24,15 +26,17 @@ class CookbookUploader
# uploading the cookbook. This allows frozen CookbookVersion
# documents on the server to be overwritten (otherwise a 409 is
# returned by the server)
+ # * :rest A Chef::REST object that you have configured the way you like it.
+ # If you don't provide this, one will be created using the values
+ # in Chef::Config.
def initialize(cookbook, path, opts={})
@cookbook, @path, @opts = cookbook, path, opts
+ @rest = opts[:rest] || Chef::REST.new(Chef::Config[:chef_server_url])
end
def upload_cookbook
Chef::Log.info("Saving #{cookbook.name}")
- rest = Chef::REST.new(Chef::Config[:chef_server_url])
-
# Syntax Check
validate_cookbook
# Generate metadata.json from metadata.rb
View
14 features/api/cookbooks/upload_cookbooks.feature
@@ -141,3 +141,17 @@ Feature: CRUD cookbooks
Then I should not get an exception
When I create a cookbook named 'testcookbook_invalid_empty_except_metadata' with only the metadata file
Then I should get a '400 "Bad Request"' exception
+
+ @freeze_cookbook_version
+ Scenario: Create a frozen Cookbook Version
+ Given I am an administrator
+ And I have uploaded a frozen cookbook named 'testcookbook_valid' at version '0.1.0'
+ When I 'GET' the path '/cookbooks/testcookbook_valid/0.1.0'
+ Then the cookbook version document should be frozen
+
+ @freeze_cookbook_version @overwrite_frozen_version
+ Scenario: Cannot overwrite a frozen Cookbook Version
+ Given I am an administrator
+ And I have uploaded a frozen cookbook named 'testcookbook_valid' at version '0.1.0'
+ When I upload a cookbook named 'testcookbook_valid' at version '0.1.0'
+ Then I should get a '409 "Conflict"' exception
View
24 features/steps/cookbook_steps.rb
@@ -19,6 +19,7 @@
#
require 'chef/cookbook/file_system_file_vendor'
+require 'chef/cookbook_uploader'
def compare_manifests(manifest1, manifest2)
Chef::CookbookVersion::COOKBOOK_SEGMENTS.each do |segment|
@@ -67,6 +68,10 @@ def compare_manifests(manifest1, manifest2)
shell_out!("#{KNIFE_CMD} cookbook upload -c #{KNIFE_CONFIG} -a -o #{INTEGRATION_COOKBOOKS}")
end
+Given "I have uploaded a frozen cookbook named '$cookbook_name' at version '$cookbook_version'" do |name, version|
+ shell_out!("#{KNIFE_CMD} cookbook upload #{name} -c #{KNIFE_CONFIG} -o #{EXTRA_COOKBOOKS} --freeze --force")
+end
+
Given /^I delete the cookbook's on disk checksum files$/ do
#pp :checksums => @last_uploaded_cookbook.checksums.keys
#pending # express the regexp above with the code you wish you had
@@ -103,6 +108,21 @@ def compare_manifests(manifest1, manifest2)
# Cookbook upload/download-specific steps
#####
+When "I upload a cookbook named '$name' at version '$version'" do |name, version|
+
+ # This is total crap :(
+ Chef::Config[:client_key] = rest.auth_credentials.key_file
+ Chef::Config[:node_name] = rest.auth_credentials.client_name
+
+ cookbook = @cookbook_loader_not_uploaded_at_feature_start[name]
+ uploader = Chef::CookbookUploader.new(cookbook, [EXTRA_COOKBOOKS], :rest => rest)
+ begin
+ uploader.upload_cookbook
+ rescue Exception => e
+ @exception = e
+ end
+end
+
When /^I create a versioned cookbook(?: named '(.*?)')?(?: versioned '(.*?)')? with '(.*?)'$/ do |request_name, request_version, cookbook_name|
cookbook = @cookbook_loader_not_uploaded_at_feature_start[cookbook_name]
raise ArgumentError, "no such cookbook in cookbooks_not_uploaded_at_feature_start: #{cookbook_name}" unless cookbook
@@ -329,6 +349,10 @@ def compare_manifests(manifest1, manifest2)
inflated_response.metadata.dependencies.should have_key(key)
end
+Then "the cookbook version document should be frozen" do
+ inflated_response.should be_frozen_version
+end
+
RSpec::Matchers.define :have_been_deleted do
match do |file_name|
! File.exist?(file_name)
View
3 features/support/env.rb
@@ -24,6 +24,7 @@
KNIFE_CMD = File.expand_path(File.join(CHEF_PROJECT_ROOT, "chef", "bin", "knife"))
FEATURES_DATA = File.join(CHEF_PROJECT_ROOT, "features", "data")
INTEGRATION_COOKBOOKS = File.join(FEATURES_DATA, "cookbooks")
+EXTRA_COOKBOOKS = File.join(FEATURES_DATA, "cookbooks_not_uploaded_at_feature_start")
$:.unshift(CHEF_PROJECT_ROOT)
$:.unshift(CHEF_PROJECT_ROOT + '/chef/lib')
@@ -42,6 +43,8 @@
require 'chef/sandbox'
require 'chef/solr_query'
require 'chef/certificate'
+require 'chef/cookbook_version'
+require 'chef/cookbook_loader'
require 'chef/mixin/shell_out'
require 'tmpdir'
require 'chef/streaming_cookbook_uploader'

0 comments on commit 71c71bd

Please sign in to comment.
Something went wrong with that request. Please try again.