diff options
Diffstat (limited to 'features/steps')
-rw-r--r-- | features/steps/deploy_steps.rb | 2 | ||||
-rw-r--r-- | features/steps/fixture_steps.rb | 22 | ||||
-rw-r--r-- | features/steps/packages.rb | 28 | ||||
-rw-r--r-- | features/steps/request_steps.rb | 59 | ||||
-rw-r--r-- | features/steps/response_steps.rb | 38 |
5 files changed, 81 insertions, 68 deletions
diff --git a/features/steps/deploy_steps.rb b/features/steps/deploy_steps.rb index 2a3906f5ad..ace9b0b173 100644 --- a/features/steps/deploy_steps.rb +++ b/features/steps/deploy_steps.rb @@ -72,7 +72,7 @@ Then /^the callback named <callback> should have run$/ do |callback_files| hook_name = file.first.gsub(/\.rb$/, "") evidence_file = "deploy/current/app/" + hook_name expected_contents = {"hook_name" => hook_name, "env" => "production"} - actual_contents = JSON.parse(IO.read(File.join(tmpdir, evidence_file))) + actual_contents = Chef::JSON.from_json(IO.read(File.join(tmpdir, evidence_file))) expected_contents.should == actual_contents end end diff --git a/features/steps/fixture_steps.rb b/features/steps/fixture_steps.rb index 433826b1b5..fb1b6a2cbb 100644 --- a/features/steps/fixture_steps.rb +++ b/features/steps/fixture_steps.rb @@ -191,6 +191,24 @@ Before do n.name 'paradise' n.run_list << "version_test" n + end, + 'really_deep_node' => Proc.new do + array = [] + hash = {} + max_levels = 50 + + max_levels.times do |num_level| + array = [num_level, "really_deep_string_in_array", array] + hash = {"really_deep_string_in_hash_#{num_level}" => hash} + num_level += 1 + end + + n = Chef::Node.new + n.name 'really_deep_node' + n.run_list << "deep_node_recipe" + n.deep_array = array + n.deep_hash = hash + n end }, 'hash' => { @@ -264,14 +282,14 @@ Given /^an? '(.+)' named '(.+)' exists$/ do |stash_name, stash_key| :method => "POST", "HTTP_ACCEPT" => 'application/json', "CONTENT_TYPE" => 'application/json', - :input => @stash[stash_name].to_json + :input => Chef::JSON.to_json(@stash[stash_name]) }.merge(sign_request("POST", request_path, OpenSSL::PKey::RSA.new(IO.read("#{tmpdir}/client.pem")), "bobo"))) end end end Given /^sending the method '(.+)' to the '(.+)' with '(.+)'/ do |method, stash_name, update_value| - update_value = JSON.parse(update_value) if update_value =~ /^\[|\{/ + update_value = Chef::JSON.from_json(update_value) if update_value =~ /^\[|\{/ @stash[stash_name].send(method.to_sym, update_value) end diff --git a/features/steps/packages.rb b/features/steps/packages.rb index 2d349f0894..cd057bd5a1 100644 --- a/features/steps/packages.rb +++ b/features/steps/packages.rb @@ -27,13 +27,20 @@ end After("@apt") do remove_integration_test_apt_source + purge_chef_integration_debs + shell_out! "apt-get clean" +end + +Before('@dpkg') do + purge_chef_integration_debs end -Before('@dpkg,@apt') do +Before('@apt') do purge_chef_integration_debs + shell_out! "apt-get clean" end -After('@dpkg,@apt') do +After('@dpkg') do purge_chef_integration_debs end @@ -64,6 +71,13 @@ Given "the apt server is running" do apt_server.start end + + Chef::Log.debug "Waiting for apt server to start" + until tcp_test_port("localhost", 9000) do + Chef::Log.debug "." + sleep 1 + end + Chef::Log.debug "done" end Given "I have updated my apt cache" do @@ -119,3 +133,13 @@ Then "the dpkg package '$package_name' should be installed" do |package_name| dpkg_should_be_installed(package_name) end +def tcp_test_port(hostname, port) + tcp_socket = TCPSocket.new(hostname, port) + true +rescue Errno::ETIMEDOUT + false +rescue Errno::ECONNREFUSED + false +ensure + tcp_socket && tcp_socket.close +end diff --git a/features/steps/request_steps.rb b/features/steps/request_steps.rb index 92a57af280..199ff8d6c1 100644 --- a/features/steps/request_steps.rb +++ b/features/steps/request_steps.rb @@ -96,62 +96,3 @@ def call_as_admin(&block) Chef::Config[:client_key] = orig_client_key end end - -#When /^I dump the contents of the search index$/ do -# Given "I dump the contents of the search index" -#end -# - -# When /^I '(.+)' the path '(.+)'$/ do |http_method, request_uri| -# begin -# #if http_method.downcase == 'get' -# # self.api_response = @rest.get_rest(request_uri) -# #else -# #puts "test test test \n\n\n\n\n\n\n" -# @response = @rest.send("#{http_method}_rest".downcase.to_sym, request_uri) -# #end -# puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" -# puts @response -# puts @response['content-type'] -# #puts self.api_response -# #puts self.api_response.inspect -# #self.inflated_response = self.api_response -# @inflated_response = @response#JSON.parse(response.body.to_s) -# puts "~~~~~~~~INFLATED RESPONSE~~~~~~~~~~~~" -# puts @inflated_response -# rescue -# self.exception = $! -# end -# end -# -# When /^I '(.+)' the '(.+)' to the path '(.+)'$/ do |http_method, stash_key, request_uri| -# begin -# #if http_method.downcase == 'post' -# # puts "post request" -# # self.api_response = @rest.post_rest(request_uri, @stash[stash_key]) -# # puts self.api_response -# #else -# puts "This is the request -- @stash[stash_key]:" -# puts @stash[stash_key].to_s -# @response = @rest.send("#{http_method}_rest".downcase.to_sym, request_uri, @stash[stash_key]) -# #end -# puts "This is the response:" -# #puts self.api_response.body.to_s -# puts @response -# #self.inflated_response = response -# @inflated_response = @response#JSON.parse(self.api_response.body.to_s) -# puts "~~~~~~~~INFLATED RESPONSE~~~~~~~~~~~~" -# puts @inflated_response -# rescue -# self.exception = $! -# end -# end -# -# When /^I authenticate as '(.+)'$/ do |reg| -# begin -# rest.authenticate(reg, 'tclown') -# rescue -# self.exception = $! -# end -# end -# diff --git a/features/steps/response_steps.rb b/features/steps/response_steps.rb index 37480b7108..989099d78d 100644 --- a/features/steps/response_steps.rb +++ b/features/steps/response_steps.rb @@ -1,3 +1,28 @@ + +# Walk array/hash to determine maximum depth. A scalar (anything but an +# Array or Hash) has depth 0. +def count_structure_levels(obj) + if obj.respond_to?(:keys) + # empty hash also has depth 0. + max_depth = 0 + obj.keys.each do |key| + child_levels = 1 + count_structure_levels(obj[key]) + max_depth = [max_depth, child_levels].max + end + max_depth + elsif obj.is_a?(Array) + # empty array also has depth 0. + max_depth = 0 + obj.each do |child| + child_levels = 1 + count_structure_levels(child) + max_depth = [max_depth, child_levels].max + end + max_depth + else + 0 + end +end + Then /^I should get a '(.+)' exception$/ do |exception| self.exception.message.to_s.should == exception end @@ -40,12 +65,12 @@ end Then /^the inflated response should match '(.+)' as json$/ do |regex| puts self.inflated_response.inspect if ENV["DEBUG"] - self.inflated_response.to_json.should =~ /#{regex}/m + Chef::JSON.to_json(self.inflated_response).should =~ /#{regex}/m end Then /^the inflated responses key '(.+)' should match '(.+)' as json$/ do |key, regex| puts self.inflated_response.inspect if ENV["DEBUG"] - self.inflated_response[key].to_json.should =~ /#{regex}/m + Chef::JSON.to_json(self.inflated_response[key]).should =~ /#{regex}/m end Then /^the inflated responses key '(.+)' item '(\d+)' should be '(.+)'$/ do |key, index, to_equal| @@ -135,7 +160,7 @@ Then /^the inflated response should be a kind of '(.+)'$/ do |thing| end Then /^the inflated response should respond to '(.+)' with '(.+)'$/ do |method, to_match| - to_match = JSON.parse(to_match) if to_match =~ /^\[|\{/ + to_match = Chef::JSON.from_json(to_match) if to_match =~ /^\[|\{/ to_match = true if to_match == 'true' to_match = false if to_match == 'false' self.inflated_response.to_hash[method].should == to_match @@ -146,7 +171,12 @@ Then /^the inflated response should respond to '(.+)' and match '(.+)'$/ do |met end Then /^the inflated response should respond to '(.+)' and match '(.+)' as json$/ do |method, regex| - self.inflated_response.to_hash[method].to_json.should =~ /#{regex}/m + Chef::JSON.to_json(self.inflated_response.to_hash[method]).should =~ /#{regex}/m +end + +#And the 'deep_array' component has depth of '50' levels +Then /^the '(.+)' component has depth of '(.+)' levels$/ do |method, levels| + count_structure_levels(self.inflated_response.to_hash[method]).should == levels.to_i end Then /^the fields in the inflated response should match the '(.+)'$/ do |stash_name| |