microwave 1.0.4 → 11.400.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (249) hide show
  1. data/CONTRIBUTING.md +155 -0
  2. data/README.md +89 -0
  3. data/Rakefile +2 -2
  4. data/bin/chef-apply +25 -0
  5. data/bin/chef-shell +34 -0
  6. data/bin/chef-solo +0 -2
  7. data/bin/shef +6 -5
  8. data/lib/chef.rb +2 -4
  9. data/spec/data/big_json.json +2 -1
  10. data/spec/data/big_json_plus_one.json +2 -1
  11. data/spec/data/cookbooks/chefignore +2 -0
  12. data/spec/data/cookbooks/openldap/attributes/default.rb +10 -9
  13. data/spec/data/cookbooks/openldap/attributes/smokey.rb +1 -1
  14. data/spec/data/git_bundles/sinatra-test-app-with-callback-files.gitbundle +0 -0
  15. data/spec/data/git_bundles/sinatra-test-app-with-symlinks.gitbundle +0 -0
  16. data/spec/data/git_bundles/sinatra-test-app.gitbundle +0 -0
  17. data/spec/data/lwrp/providers/inline_compiler.rb +26 -0
  18. data/spec/data/nodes/default.rb +3 -3
  19. data/spec/data/nodes/test.example.com.rb +3 -3
  20. data/spec/data/nodes/test.rb +3 -3
  21. data/spec/data/partial_one.erb +1 -0
  22. data/spec/data/run_context/cookbooks/circular-dep1/attributes/default.rb +4 -0
  23. data/spec/data/run_context/cookbooks/circular-dep1/definitions/circular_dep1_res.rb +1 -0
  24. data/spec/data/run_context/cookbooks/circular-dep1/libraries/lib.rb +2 -0
  25. data/spec/data/run_context/cookbooks/circular-dep1/metadata.rb +2 -0
  26. data/spec/data/run_context/cookbooks/circular-dep1/providers/provider.rb +1 -0
  27. data/spec/data/run_context/cookbooks/circular-dep1/recipes/default.rb +0 -0
  28. data/spec/data/run_context/cookbooks/circular-dep1/resources/resource.rb +1 -0
  29. data/spec/data/run_context/cookbooks/circular-dep2/attributes/default.rb +3 -0
  30. data/spec/data/run_context/cookbooks/circular-dep2/definitions/circular_dep2_res.rb +1 -0
  31. data/spec/data/run_context/cookbooks/circular-dep2/libraries/lib.rb +2 -0
  32. data/spec/data/run_context/cookbooks/circular-dep2/metadata.rb +2 -0
  33. data/spec/data/run_context/cookbooks/circular-dep2/providers/provider.rb +1 -0
  34. data/spec/data/run_context/cookbooks/circular-dep2/recipes/default.rb +0 -0
  35. data/spec/data/run_context/cookbooks/circular-dep2/resources/resource.rb +1 -0
  36. data/spec/data/run_context/cookbooks/dependency1/attributes/aa_first.rb +2 -0
  37. data/spec/data/run_context/cookbooks/dependency1/attributes/default.rb +2 -0
  38. data/spec/data/run_context/cookbooks/dependency1/attributes/zz_last.rb +3 -0
  39. data/spec/data/run_context/cookbooks/dependency1/definitions/dependency1_res.rb +1 -0
  40. data/spec/data/run_context/cookbooks/dependency1/libraries/lib.rb +2 -0
  41. data/spec/data/run_context/cookbooks/dependency1/providers/provider.rb +1 -0
  42. data/spec/data/run_context/cookbooks/dependency1/recipes/default.rb +0 -0
  43. data/spec/data/run_context/cookbooks/dependency1/resources/resource.rb +1 -0
  44. data/spec/data/run_context/cookbooks/dependency2/attributes/default.rb +3 -0
  45. data/spec/data/run_context/cookbooks/dependency2/definitions/dependency2_res.rb +1 -0
  46. data/spec/data/run_context/cookbooks/dependency2/libraries/lib.rb +2 -0
  47. data/spec/data/run_context/cookbooks/dependency2/providers/provider.rb +1 -0
  48. data/spec/data/run_context/cookbooks/dependency2/recipes/default.rb +0 -0
  49. data/spec/data/run_context/cookbooks/dependency2/resources/resource.rb +1 -0
  50. data/spec/data/run_context/cookbooks/no-default-attr/attributes/server.rb +3 -0
  51. data/spec/data/run_context/cookbooks/no-default-attr/definitions/no_default-attr_res.rb +1 -0
  52. data/spec/data/run_context/cookbooks/no-default-attr/providers/provider.rb +1 -0
  53. data/spec/data/run_context/cookbooks/no-default-attr/recipes/default.rb +0 -0
  54. data/spec/data/run_context/cookbooks/no-default-attr/resources/resource.rb +1 -0
  55. data/spec/data/run_context/cookbooks/test-with-circular-deps/attributes/default.rb +3 -0
  56. data/spec/data/run_context/cookbooks/test-with-circular-deps/definitions/test_with-circular-deps_res.rb +1 -0
  57. data/spec/data/run_context/cookbooks/test-with-circular-deps/libraries/lib.rb +2 -0
  58. data/spec/data/run_context/cookbooks/test-with-circular-deps/metadata.rb +2 -0
  59. data/spec/data/run_context/cookbooks/test-with-circular-deps/providers/provider.rb +1 -0
  60. data/spec/data/run_context/cookbooks/test-with-circular-deps/recipes/default.rb +0 -0
  61. data/spec/data/run_context/cookbooks/test-with-circular-deps/resources/resource.rb +1 -0
  62. data/spec/data/run_context/cookbooks/test-with-deps/attributes/default.rb +3 -0
  63. data/spec/data/run_context/cookbooks/test-with-deps/definitions/test_with-deps_res.rb +1 -0
  64. data/spec/data/run_context/cookbooks/test-with-deps/libraries/lib.rb +1 -0
  65. data/spec/data/run_context/cookbooks/test-with-deps/metadata.rb +3 -0
  66. data/spec/data/run_context/cookbooks/test-with-deps/providers/provider.rb +1 -0
  67. data/spec/data/run_context/cookbooks/test-with-deps/recipes/default.rb +0 -0
  68. data/spec/data/run_context/cookbooks/test-with-deps/recipes/server.rb +0 -0
  69. data/spec/data/run_context/cookbooks/test-with-deps/resources/resource.rb +1 -0
  70. data/spec/data/run_context/cookbooks/test/attributes/default.rb +0 -0
  71. data/spec/data/run_context/cookbooks/test/attributes/george.rb +1 -1
  72. data/spec/data/run_context/cookbooks/test/definitions/test_res.rb +1 -0
  73. data/spec/data/run_context/cookbooks/test/providers/provider.rb +1 -0
  74. data/spec/data/run_context/cookbooks/test/resources/resource.rb +1 -0
  75. data/spec/data/shef-config.rb +10 -0
  76. data/spec/functional/dsl/registry_helper_spec.rb +63 -0
  77. data/spec/functional/knife/cookbook_delete_spec.rb +0 -2
  78. data/spec/functional/knife/exec_spec.rb +4 -6
  79. data/spec/functional/knife/smoke_test.rb +34 -0
  80. data/spec/functional/knife/ssh_spec.rb +64 -3
  81. data/spec/functional/resource/cookbook_file_spec.rb +33 -2
  82. data/spec/functional/resource/deploy_revision_spec.rb +515 -0
  83. data/spec/functional/resource/directory_spec.rb +4 -0
  84. data/spec/functional/resource/file_spec.rb +56 -22
  85. data/spec/functional/resource/link_spec.rb +12 -10
  86. data/spec/functional/resource/registry_spec.rb +572 -0
  87. data/spec/functional/resource/remote_directory_spec.rb +142 -36
  88. data/spec/functional/resource/remote_file_spec.rb +28 -3
  89. data/spec/functional/resource/template_spec.rb +23 -2
  90. data/spec/functional/run_lock_spec.rb +238 -0
  91. data/spec/functional/shell_spec.rb +101 -0
  92. data/spec/functional/tiny_server_spec.rb +5 -4
  93. data/spec/functional/win32/registry_helper_spec.rb +632 -0
  94. data/spec/functional/win32/security_spec.rb +37 -0
  95. data/spec/spec_helper.rb +15 -3
  96. data/spec/stress/win32/security_spec.rb +5 -5
  97. data/spec/support/chef_helpers.rb +14 -3
  98. data/spec/support/lib/chef/resource/cat.rb +3 -5
  99. data/spec/support/lib/chef/resource/one_two_three_four.rb +8 -10
  100. data/spec/support/lib/chef/resource/zen_master.rb +8 -10
  101. data/spec/support/matchers/leak.rb +1 -1
  102. data/spec/support/platform_helpers.rb +18 -0
  103. data/spec/support/shared/functional/directory_resource.rb +85 -23
  104. data/spec/support/shared/functional/file_resource.rb +198 -53
  105. data/spec/support/shared/functional/securable_resource.rb +140 -105
  106. data/spec/support/shared/functional/securable_resource_with_reporting.rb +375 -0
  107. data/spec/support/shared/unit/file_system_support.rb +110 -0
  108. data/spec/support/shared/unit/platform_introspector.rb +162 -0
  109. data/spec/tiny_server.rb +29 -10
  110. data/spec/unit/api_client/registration_spec.rb +172 -0
  111. data/spec/unit/api_client_spec.rb +156 -103
  112. data/spec/unit/application/apply.rb +84 -0
  113. data/spec/unit/application/knife_spec.rb +5 -0
  114. data/spec/unit/application_spec.rb +57 -2
  115. data/spec/unit/chef_fs/diff_spec.rb +329 -0
  116. data/spec/unit/chef_fs/file_pattern_spec.rb +526 -0
  117. data/spec/unit/chef_fs/file_system/chef_server_root_dir_spec.rb +237 -0
  118. data/spec/unit/chef_fs/file_system/cookbooks_dir_spec.rb +568 -0
  119. data/spec/unit/chef_fs/file_system/data_bags_dir_spec.rb +220 -0
  120. data/spec/unit/chef_fs/file_system_spec.rb +136 -0
  121. data/spec/unit/client_spec.rb +188 -16
  122. data/spec/unit/config_spec.rb +54 -4
  123. data/spec/unit/cookbook/chefignore_spec.rb +2 -1
  124. data/spec/unit/cookbook/syntax_check_spec.rb +48 -109
  125. data/spec/unit/cookbook_loader_spec.rb +153 -91
  126. data/spec/unit/cookbook_manifest_spec.rb +81 -81
  127. data/spec/unit/cookbook_spec.rb +3 -20
  128. data/spec/unit/cookbook_version_spec.rb +23 -122
  129. data/spec/unit/digester_spec.rb +50 -0
  130. data/spec/unit/dsl/data_query_spec.rb +66 -0
  131. data/spec/unit/dsl/platform_introspection_spec.rb +130 -0
  132. data/spec/unit/dsl/regsitry_helper_spec.rb +55 -0
  133. data/spec/unit/encrypted_data_bag_item_spec.rb +126 -10
  134. data/spec/unit/environment_spec.rb +0 -130
  135. data/spec/unit/exceptions_spec.rb +2 -3
  136. data/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +23 -3
  137. data/spec/unit/json_compat_spec.rb +69 -0
  138. data/spec/unit/knife/bootstrap_spec.rb +81 -28
  139. data/spec/unit/knife/client_reregister_spec.rb +23 -22
  140. data/spec/unit/knife/configure_spec.rb +29 -26
  141. data/spec/unit/knife/cookbook_metadata_spec.rb +11 -4
  142. data/spec/unit/knife/cookbook_site_install_spec.rb +12 -2
  143. data/spec/unit/knife/cookbook_test_spec.rb +1 -0
  144. data/spec/unit/knife/cookbook_upload_spec.rb +41 -2
  145. data/spec/unit/knife/core/bootstrap_context_spec.rb +8 -1
  146. data/spec/unit/knife/core/ui_spec.rb +156 -7
  147. data/spec/unit/knife/data_bag_create_spec.rb +14 -0
  148. data/spec/unit/knife/data_bag_edit_spec.rb +14 -4
  149. data/spec/unit/knife/data_bag_from_file_spec.rb +17 -5
  150. data/spec/unit/knife/data_bag_show_spec.rb +11 -4
  151. data/spec/unit/knife/index_rebuild_spec.rb +96 -33
  152. data/spec/unit/knife/knife_help.rb +7 -7
  153. data/spec/unit/knife/node_run_list_remove_spec.rb +2 -1
  154. data/spec/unit/knife/ssh_spec.rb +121 -15
  155. data/spec/unit/knife/status_spec.rb +2 -2
  156. data/spec/unit/knife/user_create_spec.rb +86 -0
  157. data/spec/unit/knife/user_delete_spec.rb +39 -0
  158. data/spec/unit/knife/user_edit_spec.rb +42 -0
  159. data/spec/unit/knife/user_list_spec.rb +32 -0
  160. data/spec/unit/knife/user_reregister_spec.rb +53 -0
  161. data/spec/unit/knife/user_show_spec.rb +41 -0
  162. data/spec/unit/knife_spec.rb +53 -0
  163. data/spec/unit/lwrp_spec.rb +59 -17
  164. data/spec/unit/mixin/checksum_spec.rb +2 -2
  165. data/spec/unit/mixin/deep_merge_spec.rb +56 -491
  166. data/spec/unit/mixin/deprecation_spec.rb +23 -0
  167. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +6 -1
  168. data/spec/unit/mixin/params_validate_spec.rb +4 -2
  169. data/spec/unit/mixin/securable_spec.rb +5 -3
  170. data/spec/unit/mixin/template_spec.rb +119 -0
  171. data/spec/unit/node/attribute_spec.rb +272 -137
  172. data/spec/unit/node/immutable_collections_spec.rb +139 -0
  173. data/spec/unit/node_spec.rb +411 -339
  174. data/spec/unit/platform_spec.rb +8 -8
  175. data/spec/unit/provider/breakpoint_spec.rb +8 -8
  176. data/spec/unit/provider/cookbook_file_spec.rb +4 -8
  177. data/spec/unit/provider/deploy/revision_spec.rb +2 -8
  178. data/spec/unit/provider/deploy_spec.rb +6 -40
  179. data/spec/unit/provider/directory_spec.rb +103 -68
  180. data/spec/unit/provider/erl_call_spec.rb +0 -2
  181. data/spec/unit/provider/file_spec.rb +69 -59
  182. data/spec/unit/provider/git_spec.rb +0 -10
  183. data/spec/unit/provider/group/groupadd_spec.rb +1 -1
  184. data/spec/unit/provider/group/usermod_spec.rb +2 -2
  185. data/spec/unit/provider/http_request_spec.rb +28 -69
  186. data/spec/unit/provider/ifconfig_spec.rb +2 -2
  187. data/spec/unit/provider/link_spec.rb +1 -1
  188. data/spec/unit/provider/ohai_spec.rb +4 -4
  189. data/spec/unit/provider/package/apt_spec.rb +0 -1
  190. data/spec/unit/provider/package/ips_spec.rb +0 -1
  191. data/spec/unit/provider/package/rubygems_spec.rb +0 -18
  192. data/spec/unit/provider/package/yum_spec.rb +79 -15
  193. data/spec/unit/provider/package_spec.rb +7 -5
  194. data/spec/unit/provider/registry_key_spec.rb +269 -0
  195. data/spec/unit/provider/remote_directory_spec.rb +24 -7
  196. data/spec/unit/provider/remote_file_spec.rb +36 -0
  197. data/spec/unit/provider/route_spec.rb +3 -6
  198. data/spec/unit/provider/ruby_block_spec.rb +8 -0
  199. data/spec/unit/provider/service/arch_service_spec.rb +4 -4
  200. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  201. data/spec/unit/provider/service/freebsd_service_spec.rb +4 -4
  202. data/spec/unit/provider/service/init_service_spec.rb +26 -3
  203. data/spec/unit/provider/service/insserv_service_spec.rb +1 -1
  204. data/spec/unit/provider/service/invokercd_service_spec.rb +3 -3
  205. data/spec/unit/provider/service/redhat_spec.rb +1 -1
  206. data/spec/unit/provider/service/simple_service_spec.rb +3 -3
  207. data/spec/unit/provider/service/upstart_service_spec.rb +7 -7
  208. data/spec/unit/provider/service_spec.rb +2 -2
  209. data/spec/unit/provider/subversion_spec.rb +1 -1
  210. data/spec/unit/provider/template_spec.rb +35 -11
  211. data/spec/unit/provider/user/dscl_spec.rb +57 -31
  212. data/spec/unit/provider/user_spec.rb +7 -16
  213. data/spec/unit/provider_spec.rb +4 -3
  214. data/spec/unit/recipe_spec.rb +10 -8
  215. data/spec/unit/registry_helper_spec.rb +376 -0
  216. data/spec/unit/resource/log_spec.rb +9 -0
  217. data/spec/unit/resource/registry_key_spec.rb +171 -0
  218. data/spec/unit/resource/remote_file_spec.rb +21 -23
  219. data/spec/unit/resource/ruby_block_spec.rb +7 -3
  220. data/spec/unit/resource/service_spec.rb +11 -0
  221. data/spec/unit/resource_spec.rb +27 -4
  222. data/spec/unit/rest/auth_credentials_spec.rb +2 -14
  223. data/spec/unit/rest_spec.rb +122 -187
  224. data/spec/unit/run_context/cookbook_compiler_spec.rb +181 -0
  225. data/spec/unit/run_context_spec.rb +18 -4
  226. data/spec/unit/run_list_spec.rb +0 -209
  227. data/spec/unit/run_lock_spec.rb +37 -0
  228. data/spec/unit/runner_spec.rb +101 -2
  229. data/spec/unit/scan_access_control_spec.rb +4 -4
  230. data/spec/unit/{shef → shell}/model_wrapper_spec.rb +5 -5
  231. data/spec/unit/{shef/shef_ext_spec.rb → shell/shell_ext_spec.rb} +21 -21
  232. data/spec/unit/{shef/shef_session_spec.rb → shell/shell_session_spec.rb} +12 -12
  233. data/spec/unit/shell_out_spec.rb +18 -0
  234. data/spec/unit/{shef_spec.rb → shell_spec.rb} +20 -20
  235. data/spec/unit/user_spec.rb +255 -0
  236. metadata +162 -157
  237. data/README.rdoc +0 -177
  238. data/spec/unit/certificate_spec.rb +0 -76
  239. data/spec/unit/checksum_cache_spec.rb +0 -209
  240. data/spec/unit/checksum_spec.rb +0 -94
  241. data/spec/unit/couchdb_spec.rb +0 -274
  242. data/spec/unit/index_queue_spec.rb +0 -391
  243. data/spec/unit/json_compat_spect.rb +0 -53
  244. data/spec/unit/mixin/language_spec.rb +0 -305
  245. data/spec/unit/openid_registration_spec.rb +0 -153
  246. data/spec/unit/solr_query/query_transform_spec.rb +0 -454
  247. data/spec/unit/solr_query/solr_http_request_spec.rb +0 -244
  248. data/spec/unit/solr_query_spec.rb +0 -203
  249. data/spec/unit/webui_user_spec.rb +0 -238
@@ -38,6 +38,15 @@ describe Chef::Resource::Log do
38
38
  it "should allow you to set a log string" do
39
39
  @resource.name.should == @log_str
40
40
  end
41
+
42
+ it "should set the message to the first argument to new" do
43
+ @resource.message.should == @log_str
44
+ end
45
+
46
+ it "should accept a string for the log message" do
47
+ @resource.message "this is different"
48
+ @resource.message.should == "this is different"
49
+ end
41
50
 
42
51
  it "should accept a vaild level option" do
43
52
  @resource.level :debug
@@ -0,0 +1,171 @@
1
+ #
2
+ # Author:: Lamont Granquist (<lamont@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 OpsCode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+
21
+ describe Chef::Resource::RegistryKey, "initialize" do
22
+ before(:each) do
23
+ @resource = Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius')
24
+ end
25
+
26
+ it "should create a new Chef::Resource::RegistryKey" do
27
+ @resource.should be_a_kind_of(Chef::Resource)
28
+ @resource.should be_a_kind_of(Chef::Resource::RegistryKey)
29
+ end
30
+
31
+ it "should set the resource_name to :registry_key" do
32
+ @resource.resource_name.should eql(:registry_key)
33
+ end
34
+
35
+ it "should set the key equal to the argument to initialize" do
36
+ @resource.key.should eql('HKCU\Software\Raxicoricofallapatorius')
37
+ end
38
+
39
+ it "should default recursive to false" do
40
+ @resource.recursive.should eql(false)
41
+ end
42
+
43
+ it "should default architecture to :machine" do
44
+ @resource.architecture.should eql(:machine)
45
+ end
46
+
47
+ it "should set action to :create" do
48
+ @resource.action.should eql(:create)
49
+ end
50
+
51
+ %w{create create_if_missing delete delete_key}.each do |action|
52
+ it "should allow action #{action}" do
53
+ @resource.allowed_actions.detect { |a| a == action.to_sym }.should eql(action.to_sym)
54
+ end
55
+ end
56
+ end
57
+
58
+ describe Chef::Resource::RegistryKey, "key" do
59
+ before(:each) do
60
+ @resource = Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius')
61
+ end
62
+
63
+ it "should allow a string" do
64
+ @resource.key 'HKCU\Software\Poosh'
65
+ @resource.key.should eql('HKCU\Software\Poosh')
66
+ end
67
+
68
+ it "should not allow an integer" do
69
+ lambda { @resource.send(:key, 100) }.should raise_error(ArgumentError)
70
+ end
71
+
72
+ it "should not allow a hash" do
73
+ lambda { @resource.send(:key, { :sonic => "screwdriver" }) }.should raise_error(ArgumentError)
74
+ end
75
+ end
76
+
77
+ describe Chef::Resource::RegistryKey, "values" do
78
+ before(:each) do
79
+ @resource = Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius')
80
+ end
81
+
82
+ it "should allow a single proper hash of registry values" do
83
+ @resource.values( { :name => 'poosh', :type => :string, :data => 'carmen' } )
84
+ @resource.values.should eql([ { :name => 'poosh', :type => :string, :data => 'carmen' } ])
85
+ end
86
+
87
+ it "should allow an array of proper hashes of registry values" do
88
+ @resource.values [ { :name => 'poosh', :type => :string, :data => 'carmen' } ]
89
+ @resource.values.should eql([ { :name => 'poosh', :type => :string, :data => 'carmen' } ])
90
+ end
91
+
92
+ it "should throw an exception if the name field is missing" do
93
+ lambda { @resource.values [ { :type => :string, :data => 'carmen' } ] }.should raise_error(ArgumentError)
94
+ end
95
+
96
+ it "should throw an exception if the type field is missing" do
97
+ lambda { @resource.values [ { :name => 'poosh', :data => 'carmen' } ] }.should raise_error(ArgumentError)
98
+ end
99
+
100
+ it "should throw an exception if the data field is missing" do
101
+ lambda { @resource.values [ { :name => 'poosh', :type => :string } ] }.should raise_error(ArgumentError)
102
+ end
103
+
104
+ it "should throw an exception if extra fields are present" do
105
+ lambda { @resource.values [ { :name => 'poosh', :type => :string, :data => 'carmen', :screwdriver => 'sonic' } ] }.should raise_error(ArgumentError)
106
+ end
107
+
108
+ it "should not allow a string" do
109
+ lambda { @resource.send(:values, 'souffle') }.should raise_error(ArgumentError)
110
+ end
111
+
112
+ it "should not allow an integer" do
113
+ lambda { @resource.send(:values, 100) }.should raise_error(ArgumentError)
114
+ end
115
+ end
116
+
117
+ describe Chef::Resource::RegistryKey, "recursive" do
118
+ before(:each) do
119
+ @resource = Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius')
120
+ end
121
+
122
+ it "should allow a boolean" do
123
+ @resource.recursive(true)
124
+ @resource.recursive.should eql(true)
125
+ end
126
+
127
+ it "should not allow a hash" do
128
+ lambda { @resource.recursive({:sonic => :screwdriver}) }.should raise_error(ArgumentError)
129
+ end
130
+
131
+ it "should not allow an array" do
132
+ lambda { @resource.recursive([:nose, :chin]) }.should raise_error(ArgumentError)
133
+ end
134
+
135
+ it "should not allow a string" do
136
+ lambda { @resource.recursive('souffle') }.should raise_error(ArgumentError)
137
+ end
138
+
139
+ it "should not allow an integer" do
140
+ lambda { @resource.recursive(100) }.should raise_error(ArgumentError)
141
+ end
142
+ end
143
+
144
+ describe Chef::Resource::RegistryKey, "architecture" do
145
+ before(:each) do
146
+ @resource = Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius')
147
+ end
148
+
149
+ [ :i386, :x86_64, :machine ].each do |arch|
150
+ it "should allow #{arch} as a symbol" do
151
+ @resource.architecture(arch)
152
+ @resource.architecture.should eql(arch)
153
+ end
154
+ end
155
+
156
+ it "should not allow a hash" do
157
+ lambda { @resource.architecture({:sonic => :screwdriver}) }.should raise_error(ArgumentError)
158
+ end
159
+
160
+ it "should not allow an array" do
161
+ lambda { @resource.architecture([:nose, :chin]) }.should raise_error(ArgumentError)
162
+ end
163
+
164
+ it "should not allow a string" do
165
+ lambda { @resource.architecture('souffle') }.should raise_error(ArgumentError)
166
+ end
167
+
168
+ it "should not allow an integer" do
169
+ lambda { @resource.architecture(100) }.should raise_error(ArgumentError)
170
+ end
171
+ end
@@ -39,37 +39,35 @@ describe Chef::Resource::RemoteFile do
39
39
  Chef::Platform.find_provider(:noplatform, 'noversion', @resource).should == Chef::Provider::RemoteFile
40
40
  end
41
41
 
42
- it "says its provider is CookbookFile when the source is a relative URI" do
43
- @resource.source('seattle.txt')
44
- @resource.provider.should == Chef::Provider::CookbookFile
45
- Chef::Platform.find_provider(:noplatform, 'noversion', @resource).should == Chef::Provider::CookbookFile
46
- end
47
-
42
+
48
43
  describe "source" do
49
- it "should accept a string for the remote file source" do
50
- @resource.source "something"
51
- @resource.source.should eql("something")
44
+ it "does not have a default value for 'source'" do
45
+ @resource.source.should be_nil
52
46
  end
53
47
 
54
- it "should have a default based on the param name" do
55
- @resource.source.should eql("fakey_fakerton")
48
+ it "should accept a URI for the remote file source" do
49
+ @resource.source "http://opscode.com/"
50
+ @resource.source.should eql([ "http://opscode.com/" ])
56
51
  end
57
52
 
58
- it "should use only the basename of the file as the default" do
59
- r = Chef::Resource::RemoteFile.new("/tmp/obit/fakey_fakerton")
60
- r.source.should eql("fakey_fakerton")
53
+ it "should accept an array of URIs for the remote file source" do
54
+ @resource.source([ "http://opscode.com/", "http://puppetlabs.com/" ])
55
+ @resource.source.should eql([ "http://opscode.com/", "http://puppetlabs.com/" ])
61
56
  end
62
- end
63
-
64
- describe "cookbook" do
65
- it "should accept a string for the cookbook name" do
66
- @resource.cookbook "something"
67
- @resource.cookbook.should eql("something")
57
+
58
+ it "should accept an multiple URIs as arguments for the remote file source" do
59
+ @resource.source("http://opscode.com/", "http://puppetlabs.com/")
60
+ @resource.source.should eql([ "http://opscode.com/", "http://puppetlabs.com/" ])
68
61
  end
69
-
70
- it "should default to nil" do
71
- @resource.cookbook.should == nil
62
+
63
+ it "does not accept a non-URI as the source" do
64
+ lambda { @resource.source("not-a-uri") }.should raise_error(Chef::Exceptions::InvalidRemoteFileURI)
72
65
  end
66
+
67
+ it "should raise and exception when source is an empty array" do
68
+ lambda { @resource.source([]) }.should raise_error(ArgumentError)
69
+ end
70
+
73
71
  end
74
72
 
75
73
  describe "checksum" do
@@ -23,7 +23,7 @@ describe Chef::Resource::RubyBlock do
23
23
 
24
24
  before(:each) do
25
25
  @resource = Chef::Resource::RubyBlock.new("fakey_fakerton")
26
- end
26
+ end
27
27
 
28
28
  it "should create a new Chef::Resource::RubyBlock" do
29
29
  @resource.should be_a_kind_of(Chef::Resource)
@@ -31,7 +31,7 @@ describe Chef::Resource::RubyBlock do
31
31
  end
32
32
 
33
33
  it "should have a default action of 'create'" do
34
- @resource.action.should eql("create")
34
+ @resource.action.should eql("run")
35
35
  end
36
36
 
37
37
  it "should have a resource name of :ruby_block" do
@@ -44,6 +44,11 @@ describe Chef::Resource::RubyBlock do
44
44
  end.call.should eql("foo")
45
45
  end
46
46
 
47
+ it "allows the action to be 'create'" do
48
+ @resource.action :create
49
+ @resource.action.should == [:create]
50
+ end
51
+
47
52
  describe "when it has been initialized with block code" do
48
53
  before do
49
54
  @resource.block_name("puts 'harrrr'")
@@ -53,5 +58,4 @@ describe Chef::Resource::RubyBlock do
53
58
  @resource.identity.should == "puts 'harrrr'"
54
59
  end
55
60
  end
56
-
57
61
  end
@@ -109,6 +109,17 @@ describe Chef::Resource::Service do
109
109
  }.should raise_error(ArgumentError)
110
110
  end
111
111
 
112
+ it "should accept a string for the service init command" do
113
+ @resource.init_command "/etc/init.d/chef"
114
+ @resource.init_command.should eql("/etc/init.d/chef")
115
+ end
116
+
117
+ it "should not accept a regexp for the service init command" do
118
+ lambda {
119
+ @resource.init_command /.*/
120
+ }.should raise_error(ArgumentError)
121
+ end
122
+
112
123
  %w{enabled running}.each do |attrib|
113
124
  it "should accept true for #{attrib}" do
114
125
  @resource.send(attrib, true)
@@ -273,6 +273,29 @@ describe Chef::Resource do
273
273
  end
274
274
  end
275
275
 
276
+ describe "defined_at" do
277
+ it "should correctly parse source_line on unix-like operating systems" do
278
+ @resource.source_line = "/some/path/to/file.rb:80:in `wombat_tears'"
279
+ @resource.defined_at.should == "/some/path/to/file.rb line 80"
280
+ end
281
+
282
+ it "should correctly parse source_line on Windows" do
283
+ @resource.source_line = "C:/some/path/to/file.rb:80 in 1`wombat_tears'"
284
+ @resource.defined_at.should == "C:/some/path/to/file.rb line 80"
285
+ end
286
+
287
+ it "should include the cookbook and recipe when it knows it" do
288
+ @resource.source_line = "/some/path/to/file.rb:80:in `wombat_tears'"
289
+ @resource.recipe_name = "wombats"
290
+ @resource.cookbook_name = "animals"
291
+ @resource.defined_at.should == "animals::wombats line 80"
292
+ end
293
+
294
+ it "should recognize dynamically defined resources" do
295
+ @resource.defined_at.should == "dynamically defined"
296
+ end
297
+ end
298
+
276
299
  describe "to_s" do
277
300
  it "should become a string like resource_name[name]" do
278
301
  zm = Chef::Resource::ZenMaster.new("coffee")
@@ -425,8 +448,8 @@ describe Chef::Resource do
425
448
  before do
426
449
  @resource = Chef::Resource.new("provided", @run_context)
427
450
  @resource.provider = Chef::Provider::SnakeOil
428
- @node[:platform] = "fubuntu"
429
- @node[:platform_version] = '10.04'
451
+ @node.automatic_attrs[:platform] = "fubuntu"
452
+ @node.automatic_attrs[:platform_version] = '10.04'
430
453
  end
431
454
 
432
455
  it "does not run only_if if no only_if command is given" do
@@ -522,8 +545,8 @@ describe Chef::Resource do
522
545
  before(:each) do
523
546
  @node = Chef::Node.new
524
547
  @node.name("bumblebee")
525
- @node.platform("autobots")
526
- @node.platform_version("6.1")
548
+ @node.automatic[:platform] = "autobots"
549
+ @node.automatic[:platform_version] = "6.1"
527
550
  Object.const_set('Soundwave', Class.new(Chef::Resource))
528
551
  Object.const_set('Grimlock', Class.new(Chef::Resource){ provides :dinobot, :on_platforms => ['autobots'] })
529
552
  end
@@ -57,11 +57,8 @@ Y6S6MeZ69Rp89ma4ttMZ+kwi1+XyHqC/dlcVRW42Zl5Dc7BALRlJjQ==
57
57
  describe Chef::REST::AuthCredentials do
58
58
  before do
59
59
  @key_file_fixture = CHEF_SPEC_DATA + '/ssl/private_key.pem'
60
- @auth_credentials = Chef::REST::AuthCredentials.new("client-name", @key_file_fixture)
61
- end
62
-
63
- it "has a key file value" do
64
- @auth_credentials.key_file.should == @key_file_fixture
60
+ @key = OpenSSL::PKey::RSA.new(IO.read(@key_file_fixture).strip)
61
+ @auth_credentials = Chef::REST::AuthCredentials.new("client-name", @key)
65
62
  end
66
63
 
67
64
  it "has a client name" do
@@ -74,15 +71,6 @@ describe Chef::REST::AuthCredentials do
74
71
  end
75
72
 
76
73
  describe "when loading the private key" do
77
- it "raises PrivateKeyMissing when the key file doesn't exist" do
78
- lambda {Chef::REST::AuthCredentials.new("client-name", "/dev/null/nothing_here")}.should raise_error(Chef::Exceptions::PrivateKeyMissing)
79
- end
80
-
81
- it "raises InvalidPrivateKey when the key file doesnt' look like a key" do
82
- invalid_key_file = CHEF_SPEC_DATA + "/bad-config.rb"
83
- lambda {Chef::REST::AuthCredentials.new("client-name", invalid_key_file)}.should raise_error(Chef::Exceptions::InvalidPrivateKey)
84
- end
85
-
86
74
  it "strips extra whitespace before checking the key" do
87
75
  key_file_fixture = CHEF_SPEC_DATA + '/ssl/private_key_with_whitespace.pem'
88
76
  lambda {Chef::REST::AuthCredentials.new("client-name", @key_file_fixture)}.should_not raise_error
@@ -130,6 +130,23 @@ describe Chef::REST do
130
130
  @rest.sign_requests?.should be_false
131
131
  end
132
132
 
133
+ it "raises PrivateKeyMissing when the key file doesn't exist" do
134
+ lambda {Chef::REST.new(@url, "client-name", "/dev/null/nothing_here")}.should raise_error(Chef::Exceptions::PrivateKeyMissing)
135
+ end
136
+
137
+ it "raises InvalidPrivateKey when the key file doesnt' look like a key" do
138
+ invalid_key_file = CHEF_SPEC_DATA + "/bad-config.rb"
139
+ lambda {Chef::REST.new(@url, "client-name", invalid_key_file)}.should raise_error(Chef::Exceptions::InvalidPrivateKey)
140
+ end
141
+
142
+ it "can take private key as a sting :raw_key in options during initializaton" do
143
+ Chef::REST.new(@url, "client-name", nil, :raw_key => SIGNING_KEY_DOT_PEM).signing_key.should == SIGNING_KEY_DOT_PEM
144
+ end
145
+
146
+ it "raises InvalidPrivateKey when the key passed as string :raw_key in options doesnt' look like a key" do
147
+ lambda {Chef::REST.new(@url, "client-name", nil, :raw_key => "bad key string")}.should raise_error(Chef::Exceptions::InvalidPrivateKey)
148
+ end
149
+
133
150
  end
134
151
 
135
152
  context "when making REST requests" do
@@ -153,184 +170,59 @@ describe Chef::REST do
153
170
  @req_with_body_headers = @base_headers.merge("Content-Type" => "application/json", "Content-Length" => '13')
154
171
  end
155
172
 
156
- describe "using the run_request API" do
157
- it "should build a new HTTP GET request" do
158
- request = Net::HTTP::Get.new(@url.path)
159
- Net::HTTP::Get.should_receive(:new).with("/?foo=bar", @base_headers).and_return(request)
160
- @rest.run_request(:GET, @url, {})
161
- end
162
-
163
- it "should build a new HTTP POST request" do
164
- request = Net::HTTP::Post.new(@url.path)
165
-
166
- Net::HTTP::Post.should_receive(:new).with("/?foo=bar", @req_with_body_headers).and_return(request)
167
- @rest.run_request(:POST, @url, {}, {:one=>:two})
168
- request.body.should == '{"one":"two"}'
169
- end
170
-
171
- it "should build a new HTTP PUT request" do
172
- request = Net::HTTP::Put.new(@url.path)
173
- expected_headers = @base_headers.merge("Content-Length" => '13')
174
- Net::HTTP::Put.should_receive(:new).with("/?foo=bar", @req_with_body_headers).and_return(request)
175
- @rest.run_request(:PUT, @url, {}, {:one=>:two})
176
- request.body.should == '{"one":"two"}'
177
- end
178
-
179
- it "should build a new HTTP DELETE request" do
180
- request = Net::HTTP::Delete.new(@url.path)
181
- Net::HTTP::Delete.should_receive(:new).with("/?foo=bar", @base_headers).and_return(request)
182
- @rest.run_request(:DELETE, @url)
183
- end
184
-
185
- it "should raise an error if the method is not GET/PUT/POST/DELETE" do
186
- lambda { @rest.api_request(:MONKEY, @url) }.should raise_error(ArgumentError)
187
- end
173
+ describe "streaming downloads to a tempfile" do
174
+ before do
175
+ @tempfile = Tempfile.open("chef-rspec-rest_spec-line-#{__LINE__}--")
176
+ Tempfile.stub!(:new).with("chef-rest").and_return(@tempfile)
177
+ Tempfile.stub!(:open).and_return(@tempfile)
188
178
 
189
- it "returns the response body when the response is successful but content-type is not JSON" do
190
- @rest.run_request(:GET, @url).should == "ninja"
191
- end
179
+ @request_mock = {}
180
+ Net::HTTP::Get.stub!(:new).and_return(@request_mock)
192
181
 
193
- it "should call read_body without a block if the request is not raw" do
194
- @http_response.should_receive(:body)
195
- @rest.run_request(:GET, @url, {}, nil, false)
182
+ @http_response_mock = mock("Net::HTTP Response mock")
196
183
  end
197
184
 
198
- it "should inflate the body as to an object if JSON is returned" do
199
- @http_response.add_field("content-type", "application/json")
200
- Chef::JSONCompat.should_receive(:from_json).with("ninja").and_return("ohai2u_success")
201
- @rest.run_request(:GET, @url, {}).should == "ohai2u_success"
185
+ after do
186
+ @tempfile.rspec_reset
187
+ @tempfile.close!
202
188
  end
203
189
 
204
- it "should return false on a Not Modified response" do
205
- http_response = Net::HTTPNotModified.new("1.1", "304", "It's old Bob")
206
- @http_client.stub!(:request).and_yield(http_response).and_return(http_response)
207
- http_response.stub!(:read_body)
208
- @rest.run_request(:GET, @url).should be_false
190
+ it "should build a new HTTP GET request without the application/json accept header" do
191
+ expected_headers = {'X-Chef-Version' => Chef::VERSION, 'Accept-Encoding' => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE}
192
+ Net::HTTP::Get.should_receive(:new).with("/?foo=bar", expected_headers).and_return(@request_mock)
193
+ @rest.streaming_request(@url, {})
209
194
  end
210
195
 
211
- %w[ HTTPFound HTTPMovedPermanently HTTPSeeOther HTTPUseProxy HTTPTemporaryRedirect HTTPMultipleChoice ].each do |resp_name|
212
- it "should call run_request again on a #{resp_name} response" do
213
- resp_cls = Net.const_get(resp_name)
214
- resp_code = Net::HTTPResponse::CODE_TO_OBJ.keys.detect { |k| Net::HTTPResponse::CODE_TO_OBJ[k] == resp_cls }
215
- http_response = resp_cls.new("1.1", resp_code, "bob somewhere else")
216
- http_response.add_field("location", @url.path)
217
- http_response.stub!(:read_body)
218
-
219
- @http_client.stub!(:request).and_yield(http_response).and_return(http_response)
220
- lambda { @rest.run_request(:GET, @url) }.should raise_error(Chef::Exceptions::RedirectLimitExceeded)
221
- end
196
+ it "should create a tempfile for the output of a raw request" do
197
+ @rest.streaming_request(@url, {}).should equal(@tempfile)
222
198
  end
223
199
 
224
- # CHEF-3140
225
- context "when configured to disable compression" do
226
- before do
227
- @rest = Chef::REST.new(@base_url, nil, nil, :disable_gzip => true)
228
- end
229
-
230
- it "does not accept encoding gzip" do
231
- @rest.send(:build_headers, :GET, @url, {}).should_not have_key("Accept-Encoding")
232
- end
233
-
234
- it "does not decompress a response encoded as gzip" do
235
- @http_response.add_field("content-encoding", "gzip")
236
- request = Net::HTTP::Get.new(@url.path)
237
- Net::HTTP::Get.should_receive(:new).and_return(request)
238
- # will raise a Zlib error if incorrect
239
- @rest.api_request(:GET, @url, {}).should == "ninja"
240
- end
200
+ it "should read the body of the response in chunks on a raw request" do
201
+ @http_response.should_receive(:read_body).and_return(true)
202
+ @rest.streaming_request(@url, {})
241
203
  end
242
204
 
243
- it "should show the JSON error message on an unsuccessful request" do
244
- http_response = Net::HTTPServerError.new("1.1", "500", "drooling from inside of mouth")
245
- http_response.add_field("content-type", "application/json")
246
- http_response.stub!(:body).and_return('{ "error":[ "Ears get sore!", "Not even four" ] }')
247
- http_response.stub!(:read_body)
248
- @http_client.stub!(:request).and_yield(http_response).and_return(http_response)
249
- @rest.stub!(:sleep)
250
- lambda {@rest.run_request(:GET, @url)}.should raise_error(Net::HTTPFatalError)
251
- @log_stringio.string.should match(Regexp.escape('WARN: HTTP Request Returned 500 drooling from inside of mouth: Ears get sore!, Not even four'))
205
+ it "should populate the tempfile with the value of the raw request" do
206
+ @http_response_mock.stub!(:read_body).and_yield("ninja")
207
+ @tempfile.should_receive(:write).with("ninja").once.and_return(true)
208
+ @rest.streaming_request(@url, {})
252
209
  end
253
210
 
254
- it "should raise an exception on an unsuccessful request" do
255
- @http_response = Net::HTTPServerError.new("1.1", "500", "drooling from inside of mouth")
256
- http_response = Net::HTTPServerError.new("1.1", "500", "drooling from inside of mouth")
257
- http_response.stub!(:read_body)
258
- @rest.stub!(:sleep)
259
- @http_client.stub!(:request).and_yield(http_response).and_return(http_response)
260
- lambda {@rest.run_request(:GET, @url)}.should raise_error(Net::HTTPFatalError)
211
+ it "should close the tempfile if we're doing a raw request" do
212
+ @tempfile.should_receive(:close).once.and_return(true)
213
+ @rest.streaming_request(@url, {})
261
214
  end
262
215
 
263
- it "adds the rest_request object to any http exception raised" do
264
- @http_response = Net::HTTPServerError.new("1.1", "500", "drooling from inside of mouth")
265
- http_response = Net::HTTPServerError.new("1.1", "500", "drooling from inside of mouth")
266
- http_response.stub!(:read_body)
267
- @rest.stub!(:sleep)
268
- @http_client.stub!(:request).and_yield(http_response).and_return(http_response)
269
- exception = begin
270
- @rest.api_request(:GET, @url, {})
271
- rescue => e
272
- e
273
- end
274
-
275
- e.chef_rest_request.url.should == @url
276
- e.chef_rest_request.method.should == :GET
216
+ it "should not raise a divide by zero exception if the size is 0" do
217
+ @http_response_mock.stub!(:header).and_return({ 'Content-Length' => "5" })
218
+ @http_response_mock.stub!(:read_body).and_yield('')
219
+ lambda { @rest.streaming_request(@url, {}) }.should_not raise_error(ZeroDivisionError)
277
220
  end
278
221
 
279
- describe "streaming downloads to a tempfile" do
280
- before do
281
- @tempfile = Tempfile.open("chef-rspec-rest_spec-line-#{__LINE__}--")
282
- Tempfile.stub!(:new).with("chef-rest").and_return(@tempfile)
283
- Tempfile.stub!(:open).and_return(@tempfile)
284
-
285
- @request_mock = {}
286
- Net::HTTP::Get.stub!(:new).and_return(@request_mock)
287
-
288
- @http_response_mock = mock("Net::HTTP Response mock")
289
- end
290
-
291
- after do
292
- @tempfile.rspec_reset
293
- @tempfile.close!
294
- end
295
-
296
- it "should build a new HTTP GET request without the application/json accept header" do
297
- expected_headers = {'X-Chef-Version' => Chef::VERSION, 'Accept-Encoding' => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE}
298
- Net::HTTP::Get.should_receive(:new).with("/?foo=bar", expected_headers).and_return(@request_mock)
299
- @rest.run_request(:GET, @url, {}, false, nil, true)
300
- end
301
-
302
- it "should create a tempfile for the output of a raw request" do
303
- @rest.run_request(:GET, @url, {}, false, nil, true).should equal(@tempfile)
304
- end
305
-
306
- it "should read the body of the response in chunks on a raw request" do
307
- @http_response.should_receive(:read_body).and_return(true)
308
- @rest.run_request(:GET, @url, {}, false, nil, true)
309
- end
310
-
311
- it "should populate the tempfile with the value of the raw request" do
312
- @http_response_mock.stub!(:read_body).and_yield("ninja")
313
- @tempfile.should_receive(:write).with("ninja").once.and_return(true)
314
- @rest.run_request(:GET, @url, {}, false, nil, true)
315
- end
316
-
317
- it "should close the tempfile if we're doing a raw request" do
318
- @tempfile.should_receive(:close).once.and_return(true)
319
- @rest.run_request(:GET, @url, {}, false, nil, true)
320
- end
321
-
322
- it "should not raise a divide by zero exception if the size is 0" do
323
- @http_response_mock.stub!(:header).and_return({ 'Content-Length' => "5" })
324
- @http_response_mock.stub!(:read_body).and_yield('')
325
- lambda { @rest.run_request(:GET, @url, {}, false, nil, true) }.should_not raise_error(ZeroDivisionError)
326
- end
327
-
328
- it "should not raise a divide by zero exception if the Content-Length is 0" do
329
- @http_response_mock.stub!(:header).and_return({ 'Content-Length' => "0" })
330
- @http_response_mock.stub!(:read_body).and_yield("ninja")
331
- lambda { @rest.run_request(:GET, @url, {}, false, nil, true) }.should_not raise_error(ZeroDivisionError)
332
- end
333
-
222
+ it "should not raise a divide by zero exception if the Content-Length is 0" do
223
+ @http_response_mock.stub!(:header).and_return({ 'Content-Length' => "0" })
224
+ @http_response_mock.stub!(:read_body).and_yield("ninja")
225
+ lambda { @rest.streaming_request(@url, {}) }.should_not raise_error(ZeroDivisionError)
334
226
  end
335
227
 
336
228
  end
@@ -358,6 +250,24 @@ describe Chef::REST do
358
250
  @request_mock['User-Agent'].should match /^Chef Client\/#{Chef::VERSION}/
359
251
  end
360
252
 
253
+ # CHEF-3140
254
+ context "when configured to disable compression" do
255
+ before do
256
+ @rest = Chef::REST.new(@base_url, nil, nil, :disable_gzip => true)
257
+ end
258
+
259
+ it "does not accept encoding gzip" do
260
+ @rest.send(:build_headers, :GET, @url, {}).should_not have_key("Accept-Encoding")
261
+ end
262
+
263
+ it "does not decompress a response encoded as gzip" do
264
+ @http_response.add_field("content-encoding", "gzip")
265
+ request = Net::HTTP::Get.new(@url.path)
266
+ Net::HTTP::Get.should_receive(:new).and_return(request)
267
+ # will raise a Zlib error if incorrect
268
+ @rest.api_request(:GET, @url, {}).should == "ninja"
269
+ end
270
+ end
361
271
  context "when configured with custom http headers" do
362
272
  before(:each) do
363
273
  @custom_headers = {
@@ -440,41 +350,66 @@ describe Chef::REST do
440
350
  end
441
351
  end
442
352
 
443
- it "should show the JSON error message on an unsuccessful request" do
444
- http_response = Net::HTTPServerError.new("1.1", "500", "drooling from inside of mouth")
445
- http_response.add_field("content-type", "application/json")
446
- http_response.stub!(:body).and_return('{ "error":[ "Ears get sore!", "Not even four" ] }')
353
+ it "should return `false` when response is 304 NotModified" do
354
+ http_response = Net::HTTPNotModified.new("1.1", "304", "it's the same as when you asked 5 minutes ago")
447
355
  http_response.stub!(:read_body)
448
- @rest.stub!(:sleep)
356
+
449
357
  @http_client.stub!(:request).and_yield(http_response).and_return(http_response)
450
358
 
451
- lambda {@rest.run_request(:GET, @url)}.should raise_error(Net::HTTPFatalError)
452
- @log_stringio.string.should match(Regexp.escape('WARN: HTTP Request Returned 500 drooling from inside of mouth: Ears get sore!, Not even four'))
359
+ @rest.api_request(:GET, @url).should be_false
453
360
  end
454
361
 
455
- it "decompresses the JSON error message on an unsuccessful request" do
456
- http_response = Net::HTTPServerError.new("1.1", "500", "drooling from inside of mouth")
457
- http_response.add_field("content-type", "application/json")
458
- http_response.add_field("content-encoding", "deflate")
459
- unzipped_body = '{ "error":[ "Ears get sore!", "Not even four" ] }'
460
- gzipped_body = Zlib::Deflate.deflate(unzipped_body, 1)
461
- http_response.stub!(:body).and_return gzipped_body
462
- http_response.stub!(:read_body)
463
- @rest.stub!(:sleep)
464
- @http_client.stub!(:request).and_yield(http_response).and_return(http_response)
362
+ describe "when the request fails" do
363
+ before do
364
+ @original_log_level = Chef::Log.level
365
+ Chef::Log.level = :info
366
+ end
465
367
 
466
- lambda {@rest.run_request(:GET, @url)}.should raise_error(Net::HTTPFatalError)
467
- @log_stringio.string.should match(Regexp.escape('WARN: HTTP Request Returned 500 drooling from inside of mouth: Ears get sore!, Not even four'))
468
- end
368
+ after do
369
+ Chef::Log.level = @original_log_level
370
+ end
469
371
 
470
- it "should raise an exception on an unsuccessful request" do
471
- http_response = Net::HTTPServerError.new("1.1", "500", "drooling from inside of mouth")
472
- http_response.stub!(:body)
473
- http_response.stub!(:read_body)
474
- @rest.stub!(:sleep)
475
- @http_client.stub!(:request).and_yield(http_response).and_return(http_response)
476
- lambda {@rest.api_request(:GET, @url)}.should raise_error(Net::HTTPFatalError)
372
+ it "should show the JSON error message on an unsuccessful request" do
373
+ http_response = Net::HTTPServerError.new("1.1", "500", "drooling from inside of mouth")
374
+ http_response.add_field("content-type", "application/json")
375
+ http_response.stub!(:body).and_return('{ "error":[ "Ears get sore!", "Not even four" ] }')
376
+ http_response.stub!(:read_body)
377
+ @rest.stub!(:sleep)
378
+ @http_client.stub!(:request).and_yield(http_response).and_return(http_response)
379
+
380
+ lambda {@rest.api_request(:GET, @url)}.should raise_error(Net::HTTPFatalError)
381
+ @log_stringio.string.should match(Regexp.escape('INFO: HTTP Request Returned 500 drooling from inside of mouth: Ears get sore!, Not even four'))
382
+ end
383
+
384
+ it "decompresses the JSON error message on an unsuccessful request" do
385
+ http_response = Net::HTTPServerError.new("1.1", "500", "drooling from inside of mouth")
386
+ http_response.add_field("content-type", "application/json")
387
+ http_response.add_field("content-encoding", "deflate")
388
+ unzipped_body = '{ "error":[ "Ears get sore!", "Not even four" ] }'
389
+ gzipped_body = Zlib::Deflate.deflate(unzipped_body)
390
+ gzipped_body.force_encoding(Encoding::BINARY) if "strings".respond_to?(:force_encoding)
391
+
392
+ http_response.stub!(:body).and_return gzipped_body
393
+ http_response.stub!(:read_body)
394
+ @rest.stub!(:sleep)
395
+ @rest.stub!(:http_retry_count).and_return(0)
396
+ @http_client.stub!(:request).and_yield(http_response).and_return(http_response)
397
+
398
+ lambda {@rest.api_request(:GET, @url)}.should raise_error(Net::HTTPFatalError)
399
+ @log_stringio.string.should match(Regexp.escape('INFO: HTTP Request Returned 500 drooling from inside of mouth: Ears get sore!, Not even four'))
400
+ end
401
+
402
+ it "should raise an exception on an unsuccessful request" do
403
+ http_response = Net::HTTPServerError.new("1.1", "500", "drooling from inside of mouth")
404
+ http_response.stub!(:body)
405
+ http_response.stub!(:read_body)
406
+ @rest.stub!(:sleep)
407
+ @http_client.stub!(:request).and_yield(http_response).and_return(http_response)
408
+ lambda {@rest.api_request(:GET, @url)}.should raise_error(Net::HTTPFatalError)
409
+ end
477
410
  end
411
+
412
+
478
413
  end
479
414
 
480
415
  context "when streaming downloads to a tempfile" do