diff options
Diffstat (limited to 'features/steps/cookbook_steps.rb')
-rw-r--r-- | features/steps/cookbook_steps.rb | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/features/steps/cookbook_steps.rb b/features/steps/cookbook_steps.rb index 1c5c0276ae..521c4546da 100644 --- a/features/steps/cookbook_steps.rb +++ b/features/steps/cookbook_steps.rb @@ -53,3 +53,76 @@ When /^I run the rake task to generate cookbook metadata$/ do end end +##### +# Cookbook tarball-specific steps +##### + +require 'chef/streaming_cookbook_uploader' + +Given /^a cookbook named '(.+?)' is created with '(.*?)'$/ do |cookbook, stash_key| + params = {:name => cookbook}.merge(@stash[stash_key]) + response = Chef::StreamingCookbookUploader.post("#{Chef::Config[:chef_server_url]}/cookbooks", rest.client_name, rest.signing_key_filename, params) + response.status.should == 201 +end + +When /^I delete the cached tarball for '(.*?)'$/ do |cookbook| + path = File.join(server_tmpdir, "cookbook-tarballs", "#{cookbook}.tar.gz") + Chef::Log.debug "Deleting #{path}" + FileUtils.rm_f(path) +end + +When /^I create a cookbook(?: named '(.*?)')? with '(.*?)'$/ do |name, stash_key| + payload = { } + payload[:name] = name if name + payload.merge!(@stash[stash_key]) + url = "#{Chef::Config[:chef_server_url]}/cookbooks" + payload[:file].rewind if payload[:file].kind_of?(File) + response = Chef::StreamingCookbookUploader.post(url, rest.client_name, rest.signing_key_filename, payload) + + store_response response +end + +When /^I upload '(.*?)' to cookbook '(.*?)'$/ do |stash_key, cookbook| + payload = @stash[stash_key] + url = "#{Chef::Config[:chef_server_url]}/cookbooks/#{cookbook}/_content" + payload[:file].rewind if payload[:file].kind_of?(File) + response = Chef::StreamingCookbookUploader.put(url, rest.client_name, rest.signing_key_filename, payload) + + store_response response +end + +When /^I download the '(.*?)' cookbook$/ do |cookbook| + When "I 'GET' the path '/cookbooks/#{cookbook}/_content'" +end + +When /^I delete cookbook '(.*?)'$/ do |cookbook| + When "I 'DELETE' the path '/cookbooks/#{cookbook}'" +end + +Then /^the response should be a valid tarball$/ do + Tempfile.open('tarball') do |tempfile| + tempfile.write(self.response.to_s) + tempfile.flush() + system("tar", "tzf", tempfile.path).should == true + end +end + +Then /^the untarred response should include file '(.+)'$/ do |filepath| + Tempfile.open('tarball') do |tempfile| + tempfile.write(self.response.to_s) + tempfile.flush() + `tar tzf #{tempfile.path}`.split("\n").select{|e| e == filepath}.empty?.should == false + end +end + +def store_response(resp) + self.response = resp + + STDERR.puts "store response: #{resp.inspect}, #{resp.to_s}"# if ENV['DEBUG']=='true' + begin + STDERR.puts resp.to_s + self.inflated_response = JSON.parse(resp.to_s) + rescue + STDERR.puts "failed to convert response to JSON: #{$!.message}" if ENV['DEBUG']=='true' + end +end |