chef 11.18.12 → 12.0.0.alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (307) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +10 -0
  3. data/README.md +1 -1
  4. data/distro/common/html/_sources/index.txt +5 -2
  5. data/distro/common/html/_sources/knife_serve.txt +19 -0
  6. data/distro/common/html/_sources/knife_ssl_check.txt +2 -2
  7. data/distro/common/html/_sources/knife_ssl_fetch.txt +2 -2
  8. data/distro/common/html/_static/basic.css +1 -1
  9. data/distro/common/html/_static/doctools.js +1 -1
  10. data/distro/common/html/_static/searchtools.js +1 -1
  11. data/distro/common/html/_static/websupport.js +1 -1
  12. data/distro/common/html/ctl_chef_client.html +19 -9
  13. data/distro/common/html/ctl_chef_server.html +7 -1
  14. data/distro/common/html/ctl_chef_shell.html +3 -4
  15. data/distro/common/html/ctl_chef_solo.html +12 -7
  16. data/distro/common/html/index.html +19 -12
  17. data/distro/common/html/knife.html +1 -2
  18. data/distro/common/html/knife_bootstrap.html +16 -5
  19. data/distro/common/html/knife_client.html +8 -5
  20. data/distro/common/html/knife_common_options.html +11 -12
  21. data/distro/common/html/knife_configure.html +2 -3
  22. data/distro/common/html/knife_cookbook.html +16 -17
  23. data/distro/common/html/knife_cookbook_site.html +19 -18
  24. data/distro/common/html/knife_data_bag.html +6 -7
  25. data/distro/common/html/knife_delete.html +2 -3
  26. data/distro/common/html/knife_deps.html +2 -3
  27. data/distro/common/html/knife_diff.html +3 -4
  28. data/distro/common/html/knife_download.html +6 -7
  29. data/distro/common/html/knife_edit.html +0 -1
  30. data/distro/common/html/knife_environment.html +3 -4
  31. data/distro/common/html/knife_exec.html +0 -1
  32. data/distro/common/html/knife_index_rebuild.html +0 -1
  33. data/distro/common/html/knife_list.html +5 -6
  34. data/distro/common/html/knife_node.html +13 -6
  35. data/distro/common/html/knife_raw.html +0 -1
  36. data/distro/common/html/knife_recipe_list.html +0 -1
  37. data/distro/common/html/knife_role.html +1 -2
  38. data/distro/common/html/knife_search.html +2 -3
  39. data/distro/common/html/knife_serve.html +79 -0
  40. data/distro/common/html/knife_show.html +1 -2
  41. data/distro/common/html/knife_ssh.html +2 -3
  42. data/distro/common/html/knife_ssl_check.html +12 -9
  43. data/distro/common/html/knife_ssl_fetch.html +9 -10
  44. data/distro/common/html/knife_status.html +2 -3
  45. data/distro/common/html/knife_tag.html +0 -1
  46. data/distro/common/html/knife_upload.html +3 -4
  47. data/distro/common/html/knife_user.html +2 -3
  48. data/distro/common/html/knife_using.html +0 -1
  49. data/distro/common/html/knife_xargs.html +3 -4
  50. data/distro/common/html/search.html +0 -1
  51. data/distro/common/html/searchindex.js +1 -1
  52. data/lib/chef/api_client.rb +1 -1
  53. data/lib/chef/application.rb +24 -67
  54. data/lib/chef/application/client.rb +1 -1
  55. data/lib/chef/application/knife.rb +1 -1
  56. data/lib/chef/chef_fs/chef_fs_data_store.rb +2 -3
  57. data/lib/chef/chef_fs/command_line.rb +2 -3
  58. data/lib/chef/chef_fs/data_handler/group_data_handler.rb +1 -5
  59. data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -2
  60. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -2
  61. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +2 -2
  62. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +2 -3
  63. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +4 -5
  64. data/lib/chef/config.rb +26 -2
  65. data/lib/chef/config_fetcher.rb +1 -1
  66. data/lib/chef/cookbook/cookbook_version_loader.rb +4 -4
  67. data/lib/chef/cookbook/metadata.rb +1 -1
  68. data/lib/chef/cookbook/synchronizer.rb +50 -8
  69. data/lib/chef/cookbook_uploader.rb +9 -23
  70. data/lib/chef/cookbook_version.rb +3 -2
  71. data/lib/chef/data_bag.rb +1 -1
  72. data/lib/chef/data_bag_item.rb +1 -1
  73. data/lib/chef/dsl/recipe.rb +1 -14
  74. data/lib/chef/encrypted_data_bag_item/decryptor.rb +3 -3
  75. data/lib/chef/environment.rb +1 -1
  76. data/lib/chef/exceptions.rb +2 -24
  77. data/lib/chef/file_content_management/tempfile.rb +8 -1
  78. data/lib/chef/formatters/base.rb +0 -7
  79. data/lib/chef/http.rb +12 -19
  80. data/lib/chef/http/json_input.rb +12 -1
  81. data/lib/chef/json_compat.rb +45 -64
  82. data/lib/chef/knife.rb +2 -5
  83. data/lib/chef/knife/bootstrap.rb +2 -2
  84. data/lib/chef/knife/bootstrap/archlinux-gems.erb +2 -2
  85. data/lib/chef/knife/bootstrap/centos5-gems.erb +2 -2
  86. data/lib/chef/knife/bootstrap/chef-aix.erb +2 -2
  87. data/lib/chef/knife/bootstrap/chef-full.erb +2 -2
  88. data/lib/chef/knife/bootstrap/fedora13-gems.erb +2 -2
  89. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +2 -2
  90. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +2 -2
  91. data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +2 -2
  92. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  93. data/lib/chef/knife/cookbook_site_install.rb +10 -34
  94. data/lib/chef/knife/cookbook_site_list.rb +1 -1
  95. data/lib/chef/knife/cookbook_site_search.rb +1 -1
  96. data/lib/chef/knife/cookbook_site_share.rb +3 -3
  97. data/lib/chef/knife/cookbook_site_show.rb +3 -3
  98. data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
  99. data/lib/chef/knife/cookbook_upload.rb +1 -1
  100. data/lib/chef/knife/core/subcommand_loader.rb +0 -24
  101. data/lib/chef/knife/core/ui.rb +8 -7
  102. data/lib/chef/knife/deps.rb +2 -3
  103. data/lib/chef/knife/serve.rb +2 -1
  104. data/lib/chef/local_mode.rb +105 -0
  105. data/lib/chef/mixin/file_class.rb +1 -4
  106. data/lib/chef/mixin/shell_out.rb +15 -0
  107. data/lib/chef/mixin/windows_architecture_helper.rb +0 -16
  108. data/lib/chef/node.rb +1 -1
  109. data/lib/chef/platform/query_helpers.rb +1 -5
  110. data/lib/chef/policy_builder/expand_node_object.rb +3 -0
  111. data/lib/chef/provider.rb +2 -0
  112. data/lib/chef/provider/cookbook_file.rb +0 -1
  113. data/lib/chef/provider/deploy.rb +0 -1
  114. data/lib/chef/provider/deploy/revision.rb +1 -1
  115. data/lib/chef/provider/env.rb +10 -25
  116. data/lib/chef/provider/env/windows.rb +23 -10
  117. data/lib/chef/provider/execute.rb +0 -3
  118. data/lib/chef/provider/file.rb +0 -3
  119. data/lib/chef/provider/git.rb +0 -6
  120. data/lib/chef/provider/group/dscl.rb +9 -27
  121. data/lib/chef/provider/group/gpasswd.rb +0 -3
  122. data/lib/chef/provider/group/groupmod.rb +0 -4
  123. data/lib/chef/provider/group/suse.rb +0 -3
  124. data/lib/chef/provider/group/usermod.rb +0 -3
  125. data/lib/chef/provider/link.rb +22 -5
  126. data/lib/chef/provider/log.rb +15 -4
  127. data/lib/chef/provider/mdadm.rb +0 -3
  128. data/lib/chef/provider/mount/mount.rb +0 -2
  129. data/lib/chef/provider/mount/solaris.rb +0 -2
  130. data/lib/chef/provider/package.rb +0 -1
  131. data/lib/chef/provider/package/apt.rb +0 -3
  132. data/lib/chef/provider/package/dpkg.rb +0 -1
  133. data/lib/chef/provider/package/easy_install.rb +0 -4
  134. data/lib/chef/provider/package/freebsd/base.rb +0 -3
  135. data/lib/chef/provider/package/freebsd/pkgng.rb +0 -2
  136. data/lib/chef/provider/package/freebsd/port.rb +0 -2
  137. data/lib/chef/provider/package/ips.rb +0 -3
  138. data/lib/chef/provider/package/paludis.rb +0 -5
  139. data/lib/chef/provider/package/portage.rb +0 -2
  140. data/lib/chef/provider/package/rpm.rb +2 -4
  141. data/lib/chef/provider/package/rubygems.rb +0 -4
  142. data/lib/chef/provider/package/smartos.rb +0 -3
  143. data/lib/chef/provider/package/windows/msi.rb +0 -2
  144. data/lib/chef/provider/package/yum.rb +0 -4
  145. data/lib/chef/provider/package/zypper.rb +0 -3
  146. data/lib/chef/provider/registry_key.rb +0 -2
  147. data/lib/chef/provider/remote_directory.rb +0 -1
  148. data/lib/chef/provider/remote_file.rb +0 -1
  149. data/lib/chef/provider/remote_file/cache_control_data.rb +1 -3
  150. data/lib/chef/provider/remote_file/content.rb +0 -1
  151. data/lib/chef/provider/remote_file/fetcher.rb +0 -2
  152. data/lib/chef/provider/remote_file/ftp.rb +0 -1
  153. data/lib/chef/provider/resource_update.rb +0 -3
  154. data/lib/chef/provider/service/freebsd.rb +0 -3
  155. data/lib/chef/provider/service/init.rb +0 -3
  156. data/lib/chef/provider/service/macosx.rb +0 -1
  157. data/lib/chef/provider/service/redhat.rb +0 -2
  158. data/lib/chef/provider/service/simple.rb +0 -3
  159. data/lib/chef/provider/service/solaris.rb +0 -3
  160. data/lib/chef/provider/service/systemd.rb +15 -14
  161. data/lib/chef/provider/service/windows.rb +0 -3
  162. data/lib/chef/provider/subversion.rb +0 -2
  163. data/lib/chef/provider/template.rb +0 -2
  164. data/lib/chef/provider/template/content.rb +0 -1
  165. data/lib/chef/provider/user/dscl.rb +156 -549
  166. data/lib/chef/provider/user/solaris.rb +0 -1
  167. data/lib/chef/provider/user/useradd.rb +0 -3
  168. data/lib/chef/provider/whyrun_safe_ruby_block.rb +1 -1
  169. data/lib/chef/providers.rb +0 -1
  170. data/lib/chef/resource.rb +1 -4
  171. data/lib/chef/resource/freebsd_package.rb +2 -10
  172. data/lib/chef/resource/lwrp_base.rb +1 -12
  173. data/lib/chef/resource/user.rb +0 -18
  174. data/lib/chef/resource_collection.rb +1 -1
  175. data/lib/chef/resource_reporter.rb +10 -10
  176. data/lib/chef/resources.rb +0 -1
  177. data/lib/chef/role.rb +3 -3
  178. data/lib/chef/run_list.rb +1 -1
  179. data/lib/chef/tasks/chef_repo.rake +131 -264
  180. data/lib/chef/user.rb +1 -1
  181. data/lib/chef/util/path_helper.rb +2 -2
  182. data/lib/chef/version.rb +9 -1
  183. data/lib/chef/win32/api/system.rb +0 -9
  184. data/spec/data/bootstrap/test-hints.erb +1 -1
  185. data/spec/data/bootstrap/test.erb +1 -1
  186. data/spec/functional/dsl/reboot_pending_spec.rb +53 -58
  187. data/spec/functional/knife/cookbook_delete_spec.rb +3 -3
  188. data/spec/functional/knife/exec_spec.rb +1 -1
  189. data/spec/functional/mixin/shell_out_spec.rb +48 -0
  190. data/spec/functional/resource/base.rb +0 -10
  191. data/spec/functional/resource/group_spec.rb +1 -5
  192. data/spec/functional/resource/link_spec.rb +8 -0
  193. data/spec/functional/resource/{user/useradd_spec.rb → user_spec.rb} +1 -1
  194. data/spec/integration/knife/chef_fs_data_store_spec.rb +3 -3
  195. data/spec/integration/knife/chef_repo_path_spec.rb +1 -6
  196. data/spec/integration/knife/chef_repository_file_system_spec.rb +1 -1
  197. data/spec/integration/knife/chefignore_spec.rb +1 -1
  198. data/spec/integration/knife/common_options_spec.rb +50 -3
  199. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +1 -1
  200. data/spec/integration/knife/delete_spec.rb +1 -1
  201. data/spec/integration/knife/deps_spec.rb +1 -1
  202. data/spec/integration/knife/diff_spec.rb +3 -3
  203. data/spec/integration/knife/download_spec.rb +3 -3
  204. data/spec/integration/knife/list_spec.rb +1 -1
  205. data/spec/integration/knife/raw_spec.rb +1 -11
  206. data/spec/integration/knife/redirection_spec.rb +1 -1
  207. data/spec/integration/knife/serve_spec.rb +2 -2
  208. data/spec/integration/knife/show_spec.rb +1 -1
  209. data/spec/integration/knife/upload_spec.rb +9 -9
  210. data/spec/spec_helper.rb +0 -9
  211. data/spec/support/pedant/pedant_config.rb +2 -1
  212. data/spec/support/pedant/run_pedant.rb +2 -1
  213. data/spec/support/platform_helpers.rb +5 -24
  214. data/spec/support/shared/integration/integration_helper.rb +2 -1
  215. data/spec/support/shared/matchers.rb +17 -0
  216. data/spec/tiny_server.rb +1 -2
  217. data/spec/unit/api_client_spec.rb +3 -3
  218. data/spec/unit/application_spec.rb +9 -32
  219. data/spec/unit/config_fetcher_spec.rb +1 -1
  220. data/spec/unit/cookbook/metadata_spec.rb +3 -7
  221. data/spec/unit/cookbook/synchronizer_spec.rb +441 -226
  222. data/spec/unit/cookbook_loader_spec.rb +1 -1
  223. data/spec/unit/cookbook_uploader_spec.rb +160 -0
  224. data/spec/unit/cookbook_version_spec.rb +0 -4
  225. data/spec/unit/data_bag_item_spec.rb +1 -5
  226. data/spec/unit/data_bag_spec.rb +1 -5
  227. data/spec/unit/deprecation_spec.rb +1 -1
  228. data/spec/unit/dsl/recipe_spec.rb +12 -0
  229. data/spec/unit/encrypted_data_bag_item_spec.rb +7 -14
  230. data/spec/unit/environment_spec.rb +3 -7
  231. data/spec/unit/exceptions_spec.rb +0 -6
  232. data/spec/unit/http/json_input_spec.rb +128 -0
  233. data/spec/unit/json_compat_spec.rb +17 -58
  234. data/spec/unit/knife/client_create_spec.rb +3 -3
  235. data/spec/unit/knife/configure_client_spec.rb +6 -5
  236. data/spec/unit/knife/cookbook_delete_spec.rb +1 -1
  237. data/spec/unit/knife/cookbook_download_spec.rb +5 -5
  238. data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +1 -0
  239. data/spec/unit/knife/cookbook_metadata_spec.rb +1 -1
  240. data/spec/unit/knife/cookbook_site_download_spec.rb +10 -11
  241. data/spec/unit/knife/cookbook_site_install_spec.rb +116 -161
  242. data/spec/unit/knife/cookbook_site_share_spec.rb +8 -8
  243. data/spec/unit/knife/cookbook_upload_spec.rb +3 -2
  244. data/spec/unit/knife/core/bootstrap_context_spec.rb +3 -3
  245. data/spec/unit/knife/core/subcommand_loader_spec.rb +1 -66
  246. data/spec/unit/knife/data_bag_from_file_spec.rb +2 -1
  247. data/spec/unit/knife/tag_create_spec.rb +3 -3
  248. data/spec/unit/knife/tag_delete_spec.rb +3 -3
  249. data/spec/unit/knife/user_create_spec.rb +1 -1
  250. data/spec/unit/knife_spec.rb +14 -14
  251. data/spec/unit/lwrp_spec.rb +1 -21
  252. data/spec/unit/mixin/shell_out_spec.rb +92 -0
  253. data/spec/unit/node_spec.rb +0 -4
  254. data/spec/unit/platform/query_helpers_spec.rb +0 -23
  255. data/spec/unit/provider/env/windows_spec.rb +34 -70
  256. data/spec/unit/provider/env_spec.rb +11 -76
  257. data/spec/unit/provider/group/dscl_spec.rb +1 -38
  258. data/spec/unit/provider/log_spec.rb +18 -0
  259. data/spec/unit/provider/package/rpm_spec.rb +0 -12
  260. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +1 -1
  261. data/spec/unit/provider/service/systemd_service_spec.rb +44 -27
  262. data/spec/unit/provider/user/dscl_spec.rb +264 -660
  263. data/spec/unit/provider/user/useradd_spec.rb +0 -1
  264. data/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +2 -2
  265. data/spec/unit/provider_spec.rb +12 -0
  266. data/spec/unit/recipe_spec.rb +0 -41
  267. data/spec/unit/resource_collection_spec.rb +1 -5
  268. data/spec/unit/resource_reporter_spec.rb +3 -51
  269. data/spec/unit/resource_spec.rb +3 -14
  270. data/spec/unit/rest_spec.rb +1 -4
  271. data/spec/unit/role_spec.rb +0 -10
  272. data/spec/unit/run_list_spec.rb +1 -5
  273. data/spec/unit/user_spec.rb +1 -5
  274. metadata +20 -100
  275. data/lib/chef/mixin/windows_env_helper.rb +0 -56
  276. data/lib/chef/provider/dsc_script.rb +0 -175
  277. data/lib/chef/resource/dsc_script.rb +0 -126
  278. data/lib/chef/streaming_cookbook_uploader.rb +0 -205
  279. data/lib/chef/util/dsc/configuration_generator.rb +0 -115
  280. data/lib/chef/util/dsc/lcm_output_parser.rb +0 -133
  281. data/lib/chef/util/dsc/local_configuration_manager.rb +0 -141
  282. data/lib/chef/util/dsc/resource_info.rb +0 -26
  283. data/lib/chef/util/powershell/cmdlet.rb +0 -136
  284. data/lib/chef/util/powershell/cmdlet_result.rb +0 -46
  285. data/spec/data/mac_users/10.7-8.plist.xml +0 -559
  286. data/spec/data/mac_users/10.7-8.shadow.xml +0 -11
  287. data/spec/data/mac_users/10.7.plist.xml +0 -559
  288. data/spec/data/mac_users/10.7.shadow.xml +0 -11
  289. data/spec/data/mac_users/10.8.plist.xml +0 -559
  290. data/spec/data/mac_users/10.8.shadow.xml +0 -21
  291. data/spec/data/mac_users/10.9.plist.xml +0 -560
  292. data/spec/data/mac_users/10.9.shadow.xml +0 -21
  293. data/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +0 -51
  294. data/spec/functional/resource/dsc_script_spec.rb +0 -382
  295. data/spec/functional/resource/env_spec.rb +0 -182
  296. data/spec/functional/resource/user/dscl_spec.rb +0 -199
  297. data/spec/functional/util/powershell/cmdlet_spec.rb +0 -113
  298. data/spec/support/lib/chef/resource/zen_follower.rb +0 -46
  299. data/spec/support/shared/shared_examples.rb +0 -10
  300. data/spec/unit/chef_fs/data_handler/group_handler_spec.rb +0 -63
  301. data/spec/unit/formatters/base_spec.rb +0 -48
  302. data/spec/unit/provider/dsc_script_spec.rb +0 -174
  303. data/spec/unit/resource/dsc_script_spec.rb +0 -98
  304. data/spec/unit/util/dsc/configuration_generator_spec.rb +0 -171
  305. data/spec/unit/util/dsc/lcm_output_parser_spec.rb +0 -169
  306. data/spec/unit/util/dsc/local_configuration_manager_spec.rb +0 -139
  307. data/spec/unit/util/powershell/cmdlet_spec.rb +0 -106
@@ -21,6 +21,7 @@ require 'tmpdir'
21
21
  require 'fileutils'
22
22
  require 'chef/config'
23
23
  require 'chef_zero/rspec'
24
+ require 'json'
24
25
  require 'support/shared/integration/knife_support'
25
26
  require 'support/shared/integration/app_server_support'
26
27
  require 'spec_helper'
@@ -68,7 +69,7 @@ module IntegrationSupport
68
69
  File.open(filename, 'w') do |file|
69
70
  raw = case contents
70
71
  when Hash
71
- Chef::JSONCompat.to_json_pretty(contents)
72
+ JSON.pretty_generate(contents)
72
73
  when Array
73
74
  contents.join("\n")
74
75
  else
@@ -0,0 +1,17 @@
1
+
2
+ require 'rspec/expectations'
3
+ require 'spec/support/platform_helpers'
4
+
5
+ RSpec::Matchers.define :match_environment_variable do |varname|
6
+ match do |actual|
7
+ expected = if windows? && ENV[varname].nil?
8
+ # On Windows, if an environment variable is not set, the command
9
+ # `echo %VARNAME%` outputs %VARNAME%
10
+ "%#{varname}%"
11
+ else
12
+ ENV[varname].to_s
13
+ end
14
+
15
+ actual == expected
16
+ end
17
+ end
data/spec/tiny_server.rb CHANGED
@@ -25,7 +25,6 @@ require 'singleton'
25
25
  require 'chef/json_compat'
26
26
  require 'open-uri'
27
27
  require 'chef/config'
28
- require 'chef/json_compat'
29
28
 
30
29
  module TinyServer
31
30
 
@@ -153,7 +152,7 @@ module TinyServer
153
152
  :available_routes => @routes, :request => env}
154
153
  # Uncomment me for glorious debugging
155
154
  # pp :not_found => debug_info
156
- [404, {'Content-Type' => 'application/json'}, [ Chef::JSONCompat.to_json(debug_info) ]]
155
+ [404, {'Content-Type' => 'application/json'}, [ debug_info.to_json ]]
157
156
  end
158
157
  end
159
158
 
@@ -92,7 +92,7 @@ describe Chef::ApiClient do
92
92
  before(:each) do
93
93
  @client.name("black")
94
94
  @client.public_key("crowes")
95
- @json = Chef::JSONCompat.to_json(@client)
95
+ @json = @client.to_json
96
96
  end
97
97
 
98
98
  it "serializes as a JSON object" do
@@ -117,7 +117,7 @@ describe Chef::ApiClient do
117
117
 
118
118
  it "includes the private key when present" do
119
119
  @client.private_key("monkeypants")
120
- Chef::JSONCompat.to_json(@client).should include(%q{"private_key":"monkeypants"})
120
+ @client.to_json.should include(%q{"private_key":"monkeypants"})
121
121
  end
122
122
 
123
123
  it "does not include the private key if not present" do
@@ -135,7 +135,7 @@ describe Chef::ApiClient do
135
135
  "validator" => true,
136
136
  "json_class" => "Chef::ApiClient"
137
137
  }
138
- @client = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(client))
138
+ @client = Chef::JSONCompat.from_json(client.to_json)
139
139
  end
140
140
 
141
141
  it "should deserialize to a Chef::ApiClient object" do
@@ -255,12 +255,7 @@ describe Chef::Application do
255
255
 
256
256
  it "should set ENV['http_proxy']" do
257
257
  @app.configure_proxy_environment_variables
258
- @env['http_proxy'].should == "#{scheme}://#{address}:#{port}"
259
- end
260
-
261
- it "should set ENV['HTTP_PROXY']" do
262
- @app.configure_proxy_environment_variables
263
- @env['HTTP_PROXY'].should == "#{scheme}://#{address}:#{port}"
258
+ @env['http_proxy'].should == "http://#{address}:#{port}"
264
259
  end
265
260
 
266
261
  describe "when Chef::Config[:http_proxy_user] is set" do
@@ -270,8 +265,7 @@ describe Chef::Application do
270
265
 
271
266
  it "should set ENV['http_proxy'] with the username" do
272
267
  @app.configure_proxy_environment_variables
273
- @env['http_proxy'].should == "#{scheme}://username@#{address}:#{port}"
274
- @env['HTTP_PROXY'].should == "#{scheme}://username@#{address}:#{port}"
268
+ @env['http_proxy'].should == "http://username@#{address}:#{port}"
275
269
  end
276
270
 
277
271
  context "when :http_proxy_user contains '@' and/or ':'" do
@@ -281,8 +275,7 @@ describe Chef::Application do
281
275
 
282
276
  it "should set ENV['http_proxy'] with the escaped username" do
283
277
  @app.configure_proxy_environment_variables
284
- @env['http_proxy'].should == "#{scheme}://my%3Ausern%40me@#{address}:#{port}"
285
- @env['HTTP_PROXY'].should == "#{scheme}://my%3Ausern%40me@#{address}:#{port}"
278
+ @env['http_proxy'].should == "http://my%3Ausern%40me@#{address}:#{port}"
286
279
  end
287
280
  end
288
281
 
@@ -293,8 +286,7 @@ describe Chef::Application do
293
286
 
294
287
  it "should set ENV['http_proxy'] with the password" do
295
288
  @app.configure_proxy_environment_variables
296
- @env['http_proxy'].should == "#{scheme}://username:password@#{address}:#{port}"
297
- @env['HTTP_PROXY'].should == "#{scheme}://username:password@#{address}:#{port}"
289
+ @env['http_proxy'].should == "http://username:password@#{address}:#{port}"
298
290
  end
299
291
 
300
292
  context "when :http_proxy_pass contains '@' and/or ':'" do
@@ -304,8 +296,7 @@ describe Chef::Application do
304
296
 
305
297
  it "should set ENV['http_proxy'] with the escaped password" do
306
298
  @app.configure_proxy_environment_variables
307
- @env['http_proxy'].should == "#{scheme}://username:%3AP%40ssword101@#{address}:#{port}"
308
- @env['HTTP_PROXY'].should == "#{scheme}://username:%3AP%40ssword101@#{address}:#{port}"
299
+ @env['http_proxy'].should == "http://username:%3AP%40ssword101@#{address}:#{port}"
309
300
  end
310
301
  end
311
302
  end
@@ -319,8 +310,7 @@ describe Chef::Application do
319
310
 
320
311
  it "should set ENV['http_proxy']" do
321
312
  @app.configure_proxy_environment_variables
322
- @env['http_proxy'].should == "#{scheme}://#{address}:#{port}"
323
- @env['HTTP_PROXY'].should == "#{scheme}://#{address}:#{port}"
313
+ @env['http_proxy'].should == "http://#{address}:#{port}"
324
314
  end
325
315
  end
326
316
  end
@@ -348,43 +338,30 @@ describe Chef::Application do
348
338
 
349
339
  describe "when Chef::Config[:http_proxy] is set" do
350
340
  context "when given an FQDN" do
351
- let(:scheme) { "http" }
352
- let(:address) { "proxy.example.org" }
353
- let(:port) { 8080 }
354
- let(:http_proxy) { "#{scheme}://#{address}:#{port}" }
355
-
356
- it_should_behave_like "setting ENV['http_proxy']"
357
- end
358
-
359
- context "when given an HTTPS URL" do
360
- let(:scheme) { "https" }
361
341
  let(:address) { "proxy.example.org" }
362
342
  let(:port) { 8080 }
363
- let(:http_proxy) { "#{scheme}://#{address}:#{port}" }
343
+ let(:http_proxy) { "http://#{address}:#{port}" }
364
344
 
365
345
  it_should_behave_like "setting ENV['http_proxy']"
366
346
  end
367
347
 
368
348
  context "when given an IP" do
369
- let(:scheme) { "http" }
370
349
  let(:address) { "127.0.0.1" }
371
350
  let(:port) { 22 }
372
- let(:http_proxy) { "#{scheme}://#{address}:#{port}" }
351
+ let(:http_proxy) { "http://#{address}:#{port}" }
373
352
 
374
353
  it_should_behave_like "setting ENV['http_proxy']"
375
354
  end
376
355
 
377
356
  context "when given an IPv6" do
378
- let(:scheme) { "http" }
379
357
  let(:address) { "[2001:db8::1]" }
380
358
  let(:port) { 80 }
381
- let(:http_proxy) { "#{scheme}://#{address}:#{port}" }
359
+ let(:http_proxy) { "http://#{address}:#{port}" }
382
360
 
383
361
  it_should_behave_like "setting ENV['http_proxy']"
384
362
  end
385
363
 
386
364
  context "when given without including http://" do
387
- let(:scheme) { "http" }
388
365
  let(:address) { "proxy.example.org" }
389
366
  let(:port) { 8181 }
390
367
  let(:http_proxy) { "#{address}:#{port}" }
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'chef/config_fetcher'
3
3
  describe Chef::ConfigFetcher do
4
- let(:valid_json) { Chef::JSONCompat.to_json({:a=>"b"}) }
4
+ let(:valid_json) { {:a=>"b"}.to_json }
5
5
  let(:invalid_json) { %q[{"syntax-error": "missing quote}] }
6
6
  let(:http) { double("Chef::HTTP::Simple") }
7
7
 
@@ -582,7 +582,7 @@ describe Chef::Cookbook::Metadata do
582
582
  @meta.version "1.2.3"
583
583
  end
584
584
 
585
- describe "#to_json" do
585
+ describe "serialize" do
586
586
  before(:each) do
587
587
  @serial = Chef::JSONCompat.from_json(@meta.to_json)
588
588
  end
@@ -613,15 +613,11 @@ describe Chef::Cookbook::Metadata do
613
613
  @serial[t].should == @meta.send(t.to_sym)
614
614
  end
615
615
  end
616
-
617
- it "should produce the same output from to_json and Chef::JSONCompat" do
618
- expect(@meta.to_json).to eq(Chef::JSONCompat.to_json(@meta))
619
- end
620
616
  end
621
617
 
622
- describe "::from_json" do
618
+ describe "deserialize" do
623
619
  before(:each) do
624
- @deserial = Chef::Cookbook::Metadata.from_json(Chef::JSONCompat.to_json(@meta))
620
+ @deserial = Chef::Cookbook::Metadata.from_json(@meta.to_json)
625
621
  end
626
622
 
627
623
  it "should deserialize to a Chef::Cookbook::Metadata object" do
@@ -5,302 +5,517 @@ require 'chef/cookbook_version'
5
5
  describe Chef::CookbookCacheCleaner do
6
6
  describe "when cleaning up unused cookbook components" do
7
7
 
8
- before do
9
- @cleaner = Chef::CookbookCacheCleaner.instance
10
- @cleaner.reset!
8
+ let(:cleaner) do
9
+ cleaner = Chef::CookbookCacheCleaner.instance
10
+ cleaner.reset!
11
+ cleaner
11
12
  end
12
13
 
13
- it "removes all files that belong to unused cookbooks" do
14
- end
14
+ let(:file_cache) { double("Chef::FileCache with files from unused cookbooks") }
15
15
 
16
- it "removes all files not validated during the chef run" do
17
- file_cache = double("Chef::FileCache with files from unused cookbooks")
18
- unused_template_files = %w{cookbooks/unused/templates/default/foo.conf.erb cookbooks/unused/tempaltes/default/bar.conf.erb}
19
- valid_cached_cb_files = %w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb}
20
- @cleaner.mark_file_as_valid('cookbooks/valid1/recipes/default.rb')
21
- @cleaner.mark_file_as_valid('cookbooks/valid2/recipes/default.rb')
22
- file_cache.should_receive(:find).with(File.join(%w{cookbooks ** *})).and_return(valid_cached_cb_files + unused_template_files)
23
- file_cache.should_receive(:delete).with('cookbooks/unused/templates/default/foo.conf.erb')
24
- file_cache.should_receive(:delete).with('cookbooks/unused/tempaltes/default/bar.conf.erb')
25
- cookbook_hash = {"valid1"=> {}, "valid2" => {}}
26
- @cleaner.stub(:cache).and_return(file_cache)
27
- @cleaner.cleanup_file_cache
16
+ let(:unused_template_files) do
17
+ %w{
18
+ cookbooks/unused/templates/default/foo.conf.erb
19
+ cookbooks/unused/tempaltes/default/bar.conf.erb
20
+ }
28
21
  end
29
22
 
30
- describe "on chef-solo" do
31
- before do
32
- Chef::Config[:solo] = true
33
- end
23
+ let(:valid_cached_cb_files) do
24
+ %w{
25
+ cookbooks/valid1/recipes/default.rb
26
+ cookbooks/valid2/recipes/default.rb
27
+ }
28
+ end
34
29
 
35
- after do
36
- Chef::Config[:solo] = false
30
+ before do
31
+ valid_cached_cb_files.each do |cbf|
32
+ cleaner.mark_file_as_valid(cbf)
37
33
  end
34
+ end
38
35
 
39
- it "does not remove anything" do
40
- @cleaner.cache.stub(:find).and_return(%w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb})
41
- @cleaner.cache.should_not_receive(:delete)
42
- @cleaner.cleanup_file_cache
36
+ it "removes all files not validated during the chef run" do
37
+ expect(file_cache).to receive(:find).with(File.join(%w{cookbooks ** {*,.*}})).and_return(valid_cached_cb_files + unused_template_files)
38
+ unused_template_files.each do |cbf|
39
+ expect(file_cache).to receive(:delete).with(cbf)
43
40
  end
41
+ cookbook_hash = {"valid1"=> {}, "valid2" => {}}
42
+ allow(cleaner).to receive(:cache).and_return(file_cache)
43
+ cleaner.cleanup_file_cache
44
+ end
44
45
 
46
+ it "does not remove anything when skip_removal is true" do
47
+ cleaner.skip_removal = true
48
+ allow(cleaner.cache).to receive(:find).and_return(%w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb})
49
+ expect(cleaner.cache).not_to receive(:delete)
50
+ cleaner.cleanup_file_cache
45
51
  end
46
52
 
53
+ it "does not remove anything on chef-solo" do
54
+ Chef::Config[:solo] = true
55
+ allow(cleaner.cache).to receive(:find).and_return(%w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb})
56
+ expect(cleaner.cache).not_to receive(:delete)
57
+ cleaner.cleanup_file_cache
58
+ end
47
59
  end
48
60
  end
49
61
 
50
62
  describe Chef::CookbookSynchronizer do
51
- before do
63
+ let(:cookbook_a_default_recipe) do
64
+ {
65
+ "path" => "recipes/default.rb",
66
+ "url" => "http://chef.example.com/abc123",
67
+ "checksum" => "abc123",
68
+ }
69
+ end
70
+
71
+ let(:cookbook_a_default_attrs) do
72
+ {
73
+ "path" => "attributes/default.rb",
74
+ "url" => "http://chef.example.com/abc456",
75
+ "checksum" => "abc456",
76
+ }
77
+ end
78
+
79
+ let(:cookbook_a_template) do
80
+ {
81
+ "path" => "templates/default/apache2.conf.erb",
82
+ "url" => "http://chef.example.com/ffffff",
83
+ "checksum" => "abc125",
84
+ }
85
+ end
86
+
87
+ let(:cookbook_a_file) do
88
+ {
89
+ "path" => "files/default/megaman.conf",
90
+ "url" => "http://chef.example.com/megaman.conf",
91
+ "checksum" => "abc124",
92
+ }
93
+ end
94
+
95
+ let(:cookbook_a_manifest) do
52
96
  segments = [ :resources, :providers, :recipes, :definitions, :libraries, :attributes, :files, :templates, :root_files ]
53
- @cookbook_manifest = {}
54
- @cookbook_a = Chef::CookbookVersion.new("cookbook_a")
55
- @cookbook_a_manifest = segments.inject({}) {|h, segment| h[segment.to_s] = []; h}
56
- @cookbook_a_default_recipe = { "path" => "recipes/default.rb",
57
- "url" => "http://chef.example.com/abc123",
58
- "checksum" => "abc123" }
59
- @cookbook_a_manifest["recipes"] = [ @cookbook_a_default_recipe ]
60
-
61
- @cookbook_a_default_attrs = { "path" => "attributes/default.rb",
62
- "url" => "http://chef.example.com/abc456",
63
- "checksum" => "abc456" }
64
- @cookbook_a_manifest["attributes"] = [ @cookbook_a_default_attrs ]
65
- @cookbook_a_manifest["templates"] = [{"path" => "templates/default/apache2.conf.erb", "url" => "http://chef.example.com/ffffff"}]
66
- @cookbook_a_manifest["files"] = [{"path" => "files/default/megaman.conf", "url" => "http://chef.example.com/megaman.conf"}]
67
- @cookbook_a.manifest = @cookbook_a_manifest
68
- @cookbook_manifest["cookbook_a"] = @cookbook_a
69
-
70
- @events = Chef::EventDispatch::Dispatcher.new
71
- @synchronizer = Chef::CookbookSynchronizer.new(@cookbook_manifest, @events)
97
+ cookbook_a_manifest = segments.inject({}) {|h, segment| h[segment.to_s] = []; h}
98
+ cookbook_a_manifest["recipes"] = [ cookbook_a_default_recipe ]
99
+ cookbook_a_manifest["attributes"] = [ cookbook_a_default_attrs ]
100
+ cookbook_a_manifest["templates"] = [ cookbook_a_template ]
101
+ cookbook_a_manifest["files"] = [ cookbook_a_file ]
102
+ cookbook_a_manifest
103
+ end
104
+
105
+ let(:cookbook_a) do
106
+ cookbook_a = Chef::CookbookVersion.new("cookbook_a")
107
+ cookbook_a.manifest = cookbook_a_manifest
108
+ cookbook_a
109
+ end
110
+
111
+ let(:cookbook_manifest) do
112
+ {
113
+ "cookbook_a" => cookbook_a
114
+ }
115
+ end
116
+
117
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
118
+
119
+ let(:no_lazy_load) { true }
120
+
121
+ let(:synchronizer) do
122
+ Chef::Config[:no_lazy_load] = no_lazy_load
123
+ Chef::CookbookSynchronizer.new(cookbook_manifest, events)
72
124
  end
73
125
 
74
126
  it "lists the cookbook names" do
75
- @synchronizer.cookbook_names.should == %w[cookbook_a]
127
+ expect(synchronizer.cookbook_names).to eq(%w[cookbook_a])
76
128
  end
77
129
 
78
130
  it "lists the cookbook manifests" do
79
- @synchronizer.cookbooks.should == [@cookbook_a]
131
+ expect(synchronizer.cookbooks).to eq([cookbook_a])
80
132
  end
81
133
 
82
- context "when the cache contains unneeded cookbooks" do
83
- before do
84
- @file_cache = double("Chef::FileCache with files from unused cookbooks")
85
- @valid_cached_cb_files = %w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb}
86
- @obsolete_cb_files = %w{cookbooks/old1/recipes/default.rb cookbooks/old2/recipes/default.rb}
134
+ context "#clear_obsoleted_cookbooks" do
135
+ after do
136
+ # Singletons == Global State == Bad
137
+ Chef::CookbookCacheCleaner.instance.skip_removal = nil
138
+ end
87
139
 
88
- @cookbook_hash = {"valid1"=> {}, "valid2" => {}}
140
+ it "behaves correctly when remove_obsoleted_files is false" do
141
+ synchronizer.remove_obsoleted_files = false
142
+ expect(synchronizer).not_to receive(:remove_old_cookbooks)
143
+ expect(synchronizer).to receive(:remove_deleted_files)
144
+ synchronizer.clear_obsoleted_cookbooks
145
+ expect(Chef::CookbookCacheCleaner.instance.skip_removal).to be true
146
+ end
147
+
148
+ it "behaves correctly when remove_obsoleted_files is true" do
149
+ synchronizer.remove_obsoleted_files = true
150
+ expect(synchronizer).to receive(:remove_old_cookbooks)
151
+ expect(synchronizer).to receive(:remove_deleted_files)
152
+ synchronizer.clear_obsoleted_cookbooks
153
+ expect(Chef::CookbookCacheCleaner.instance.skip_removal).to be nil
154
+ end
155
+ end
156
+
157
+ context "#remove_old_cookbooks" do
158
+ let(:file_cache) { double("Chef::FileCache with files from unused cookbooks") }
89
159
 
90
- @synchronizer = Chef::CookbookSynchronizer.new(@cookbook_hash, @events)
160
+ let(:cookbook_manifest) do
161
+ {"valid1"=> {}, "valid2" => {}}
91
162
  end
92
163
 
93
164
  it "removes unneeded cookbooks" do
94
- @file_cache.should_receive(:find).with(File.join(%w{cookbooks ** *})).and_return(@valid_cached_cb_files + @obsolete_cb_files)
95
- @file_cache.should_receive(:delete).with('cookbooks/old1/recipes/default.rb')
96
- @file_cache.should_receive(:delete).with('cookbooks/old2/recipes/default.rb')
97
- @synchronizer.stub(:cache).and_return(@file_cache)
98
- @synchronizer.clear_obsoleted_cookbooks
165
+ valid_cached_cb_files = %w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb}
166
+ obsolete_cb_files = %w{cookbooks/old1/recipes/default.rb cookbooks/old2/recipes/default.rb}
167
+ expect(file_cache).to receive(:find).with(File.join(%w{cookbooks ** {*,.*}})).and_return(valid_cached_cb_files + obsolete_cb_files)
168
+ expect(file_cache).to receive(:delete).with('cookbooks/old1/recipes/default.rb')
169
+ expect(file_cache).to receive(:delete).with('cookbooks/old2/recipes/default.rb')
170
+ allow(synchronizer).to receive(:cache).and_return(file_cache)
171
+ synchronizer.remove_old_cookbooks
99
172
  end
100
173
  end
101
174
 
102
- describe "when syncing cookbooks with the server" do
103
- before do
104
- # Would rather not stub out methods on the test subject, but setting up
105
- # the state is a PITA and tests for this behavior are above.
106
- @synchronizer.stub(:clear_obsoleted_cookbooks)
175
+ context "#remove_deleted_files" do
176
+ let(:file_cache) { double("Chef::FileCache with files from unused cookbooks") }
177
+
178
+ let(:cookbook_manifest) do
179
+ {"valid1"=> {}, "valid2" => {}}
180
+ end
181
+
182
+ it "removes only deleted files" do
183
+ valid_cached_cb_files = %w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb}
184
+ obsolete_cb_files = %w{cookbooks/valid1/recipes/deleted.rb cookbooks/valid2/recipes/deleted.rb}
185
+ expect(file_cache).to receive(:find).with(File.join(%w{cookbooks ** {*,.*}})).and_return(valid_cached_cb_files + obsolete_cb_files)
186
+ # valid1 is a cookbook in our run_list
187
+ expect(synchronizer).to receive(:have_cookbook?).with("valid1").at_least(:once).and_return(true)
188
+ # valid2 is a cookbook not in our run_list (we're simulating an override run_list where valid2 needs to be preserved)
189
+ expect(synchronizer).to receive(:have_cookbook?).with("valid2").at_least(:once).and_return(false)
190
+ expect(file_cache).to receive(:delete).with('cookbooks/valid1/recipes/deleted.rb')
191
+ expect(synchronizer).to receive(:cookbook_segment).with("valid1", "recipes").at_least(:once).and_return([ { "path" => "recipes/default.rb" }])
192
+ allow(synchronizer).to receive(:cache).and_return(file_cache)
193
+ synchronizer.remove_deleted_files
194
+ end
195
+ end
196
+
197
+ let(:cookbook_a_default_recipe_tempfile) do
198
+ double("Tempfile for cookbook_a default.rb recipe",
199
+ :path => "/tmp/cookbook_a_recipes_default_rb")
200
+ end
107
201
 
108
- @server_api = double("Chef::REST (mock)")
109
- @file_cache = double("Chef::FileCache (mock)")
110
- @synchronizer.stub(:server_api).and_return(@server_api)
111
- @synchronizer.stub(:cache).and_return(@file_cache)
202
+ let(:cookbook_a_default_attribute_tempfile) do
203
+ double("Tempfile for cookbook_a default.rb attr file",
204
+ :path => "/tmp/cookbook_a_attributes_default_rb")
205
+ end
112
206
 
207
+ let(:cookbook_a_file_default_tempfile) do
208
+ double("Tempfile for cookbook_a megaman.conf file",
209
+ :path => "/tmp/cookbook_a_file_default_tempfile")
210
+ end
113
211
 
114
- @cookbook_a_default_recipe_tempfile = double("Tempfile for cookbook_a default.rb recipe",
115
- :path => "/tmp/cookbook_a_recipes_default_rb")
212
+ let(:cookbook_a_template_default_tempfile) do
213
+ double("Tempfile for cookbook_a apache.conf.erb template",
214
+ :path => "/tmp/cookbook_a_template_default_tempfile")
215
+ end
116
216
 
117
- @cookbook_a_default_attribute_tempfile = double("Tempfile for cookbook_a default.rb attr file",
118
- :path => "/tmp/cookbook_a_attributes_default_rb")
217
+ def setup_common_files_missing_expectations
218
+ # Files are not in the cache:
219
+ expect(file_cache).to receive(:has_key?).
220
+ with("cookbooks/cookbook_a/recipes/default.rb").
221
+ and_return(false)
222
+ expect(file_cache).to receive(:has_key?).
223
+ with("cookbooks/cookbook_a/attributes/default.rb").
224
+ and_return(false)
225
+
226
+ # Fetch and copy default.rb recipe
227
+ expect(server_api).to receive(:get_rest).
228
+ with('http://chef.example.com/abc123', true).
229
+ and_return(cookbook_a_default_recipe_tempfile)
230
+ expect(file_cache).to receive(:move_to).
231
+ with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb")
232
+ expect(file_cache).to receive(:load).
233
+ with("cookbooks/cookbook_a/recipes/default.rb", false).
234
+ and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
235
+
236
+ # Fetch and copy default.rb attribute file
237
+ expect(server_api).to receive(:get_rest).
238
+ with('http://chef.example.com/abc456', true).
239
+ and_return(cookbook_a_default_attribute_tempfile)
240
+ expect(file_cache).to receive(:move_to).
241
+ with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb")
242
+ expect(file_cache).to receive(:load).
243
+ with("cookbooks/cookbook_a/attributes/default.rb", false).
244
+ and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb")
245
+ end
119
246
 
247
+ def setup_no_lazy_files_and_templates_missing_expectations
248
+ expect(file_cache).to receive(:has_key?).
249
+ with("cookbooks/cookbook_a/files/default/megaman.conf").
250
+ and_return(false)
251
+ expect(file_cache).to receive(:has_key?).
252
+ with("cookbooks/cookbook_a/templates/default/apache2.conf.erb").
253
+ and_return(false)
254
+
255
+ expect(server_api).to receive(:get_rest).
256
+ with('http://chef.example.com/megaman.conf', true).
257
+ and_return(cookbook_a_file_default_tempfile)
258
+ expect(file_cache).to receive(:move_to).
259
+ with("/tmp/cookbook_a_file_default_tempfile", "cookbooks/cookbook_a/files/default/megaman.conf")
260
+ expect(file_cache).to receive(:load).
261
+ with("cookbooks/cookbook_a/files/default/megaman.conf", false).
262
+ and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf")
263
+
264
+ expect(server_api).to receive(:get_rest).
265
+ with('http://chef.example.com/ffffff', true).
266
+ and_return(cookbook_a_template_default_tempfile)
267
+ expect(file_cache).to receive(:move_to).
268
+ with("/tmp/cookbook_a_template_default_tempfile", "cookbooks/cookbook_a/templates/default/apache2.conf.erb")
269
+ expect(file_cache).to receive(:load).
270
+ with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false).
271
+ and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb")
272
+ end
273
+
274
+ def setup_common_files_chksum_mismatch_expectations
275
+ # Files are in the cache:
276
+ expect(file_cache).to receive(:has_key?).
277
+ with("cookbooks/cookbook_a/recipes/default.rb").
278
+ and_return(true)
279
+ expect(file_cache).to receive(:has_key?).
280
+ with("cookbooks/cookbook_a/attributes/default.rb").
281
+ and_return(true)
282
+
283
+ # Fetch and copy default.rb recipe
284
+ expect(server_api).to receive(:get_rest).
285
+ with('http://chef.example.com/abc123', true).
286
+ and_return(cookbook_a_default_recipe_tempfile)
287
+ expect(file_cache).to receive(:move_to).
288
+ with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb")
289
+ expect(file_cache).to receive(:load).
290
+ with("cookbooks/cookbook_a/recipes/default.rb", false).
291
+ twice.
292
+ and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
293
+
294
+ # Current file has fff000, want abc123
295
+ expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
296
+ with("/file-cache/cookbooks/cookbook_a/recipes/default.rb").
297
+ and_return("fff000")
298
+
299
+ # Fetch and copy default.rb attribute file
300
+ expect(server_api).to receive(:get_rest).
301
+ with('http://chef.example.com/abc456', true).
302
+ and_return(cookbook_a_default_attribute_tempfile)
303
+ expect(file_cache).to receive(:move_to).
304
+ with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb")
305
+ expect(file_cache).to receive(:load).
306
+ with("cookbooks/cookbook_a/attributes/default.rb", false).
307
+ twice.
308
+ and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb")
309
+
310
+ # Current file has fff000, want abc456
311
+ expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
312
+ with("/file-cache/cookbooks/cookbook_a/attributes/default.rb").
313
+ and_return("fff000")
314
+ end
315
+
316
+ def setup_no_lazy_files_and_templates_chksum_mismatch_expectations
317
+ # Files are in the cache:
318
+ expect(file_cache).to receive(:has_key?).
319
+ with("cookbooks/cookbook_a/files/default/megaman.conf").
320
+ and_return(true)
321
+ expect(file_cache).to receive(:has_key?).
322
+ with("cookbooks/cookbook_a/templates/default/apache2.conf.erb").
323
+ and_return(true)
324
+
325
+ # Fetch and copy megaman.conf
326
+ expect(server_api).to receive(:get_rest).
327
+ with('http://chef.example.com/megaman.conf', true).
328
+ and_return(cookbook_a_file_default_tempfile)
329
+ expect(file_cache).to receive(:move_to).
330
+ with("/tmp/cookbook_a_file_default_tempfile", "cookbooks/cookbook_a/files/default/megaman.conf")
331
+ expect(file_cache).to receive(:load).
332
+ with("cookbooks/cookbook_a/files/default/megaman.conf", false).
333
+ twice.
334
+ and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf")
335
+
336
+ # Fetch and copy apache2.conf template
337
+ expect(server_api).to receive(:get_rest).
338
+ with('http://chef.example.com/ffffff', true).
339
+ and_return(cookbook_a_template_default_tempfile)
340
+ expect(file_cache).to receive(:move_to).
341
+ with("/tmp/cookbook_a_template_default_tempfile", "cookbooks/cookbook_a/templates/default/apache2.conf.erb")
342
+ expect(file_cache).to receive(:load).
343
+ with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false).
344
+ twice.
345
+ and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb")
346
+
347
+ # Current file has fff000
348
+ expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
349
+ with("/file-cache/cookbooks/cookbook_a/default/megaman.conf").
350
+ and_return("fff000")
351
+
352
+ # Current file has fff000
353
+ expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
354
+ with("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb").
355
+ and_return("fff000")
356
+ end
357
+
358
+ def setup_common_files_present_expectations
359
+ # Files are in the cache:
360
+ expect(file_cache).to receive(:has_key?).
361
+ with("cookbooks/cookbook_a/recipes/default.rb").
362
+ and_return(true)
363
+ expect(file_cache).to receive(:has_key?).
364
+ with("cookbooks/cookbook_a/attributes/default.rb").
365
+ and_return(true)
366
+
367
+ # Current file has abc123, want abc123
368
+ expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
369
+ with("/file-cache/cookbooks/cookbook_a/recipes/default.rb").
370
+ and_return("abc123")
371
+
372
+ # Current file has abc456, want abc456
373
+ expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
374
+ with("/file-cache/cookbooks/cookbook_a/attributes/default.rb").
375
+ and_return("abc456")
376
+
377
+ # :load called twice
378
+ expect(file_cache).to receive(:load).
379
+ with("cookbooks/cookbook_a/recipes/default.rb", false).
380
+ twice.
381
+ and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
382
+ expect(file_cache).to receive(:load).
383
+ with("cookbooks/cookbook_a/attributes/default.rb", false).
384
+ twice.
385
+ and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb")
386
+ end
387
+
388
+ def setup_no_lazy_files_and_templates_present_expectations
389
+ # Files are in the cache:
390
+ expect(file_cache).to receive(:has_key?).
391
+ with("cookbooks/cookbook_a/files/default/megaman.conf").
392
+ and_return(true)
393
+ expect(file_cache).to receive(:has_key?).
394
+ with("cookbooks/cookbook_a/templates/default/apache2.conf.erb").
395
+ and_return(true)
396
+
397
+ # Current file has abc124, want abc124
398
+ expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
399
+ with("/file-cache/cookbooks/cookbook_a/default/megaman.conf").
400
+ and_return("abc124")
401
+
402
+ # Current file has abc125, want abc125
403
+ expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
404
+ with("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb").
405
+ and_return("abc125")
406
+
407
+ # :load called twice
408
+ expect(file_cache).to receive(:load).
409
+ with("cookbooks/cookbook_a/files/default/megaman.conf", false).
410
+ twice.
411
+ and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf")
412
+ expect(file_cache).to receive(:load).
413
+ with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false).
414
+ twice.
415
+ and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb")
416
+ end
417
+
418
+ describe "when syncing cookbooks with the server" do
419
+ let(:server_api) { double("Chef::REST (mock)") }
420
+
421
+ let(:file_cache) { double("Chef::FileCache (mock)") }
422
+
423
+ before do
424
+ # Would rather not stub out methods on the test subject, but setting up
425
+ # the state is a PITA and tests for this behavior are above.
426
+ allow(synchronizer).to receive(:clear_obsoleted_cookbooks)
427
+ allow(synchronizer).to receive(:server_api).and_return(server_api)
428
+ allow(synchronizer).to receive(:cache).and_return(file_cache)
120
429
  end
121
430
 
122
431
  context "when the cache does not contain the desired files" do
123
432
  before do
124
-
125
- # Files are not in the cache:
126
- @file_cache.should_receive(:has_key?).
127
- with("cookbooks/cookbook_a/recipes/default.rb").
128
- and_return(false)
129
- @file_cache.should_receive(:has_key?).
130
- with("cookbooks/cookbook_a/attributes/default.rb").
131
- and_return(false)
132
-
133
- # Fetch and copy default.rb recipe
134
- @server_api.should_receive(:get_rest).
135
- with('http://chef.example.com/abc123', true).
136
- and_return(@cookbook_a_default_recipe_tempfile)
137
- @file_cache.should_receive(:move_to).
138
- with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb")
139
- @file_cache.should_receive(:load).
140
- with("cookbooks/cookbook_a/recipes/default.rb", false).
141
- and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
142
-
143
- # Fetch and copy default.rb attribute file
144
- @server_api.should_receive(:get_rest).
145
- with('http://chef.example.com/abc456', true).
146
- and_return(@cookbook_a_default_attribute_tempfile)
147
- @file_cache.should_receive(:move_to).
148
- with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb")
149
- @file_cache.should_receive(:load).
150
- with("cookbooks/cookbook_a/attributes/default.rb", false).
151
- and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb")
433
+ setup_common_files_missing_expectations
152
434
  end
153
435
 
154
- it "fetches eagerly loaded files" do
155
- @synchronizer.sync_cookbooks
156
- end
436
+ context "Chef::Config[:no_lazy_load] is false" do
437
+ let(:no_lazy_load) { false }
157
438
 
158
- it "does not fetch templates or cookbook files" do
159
- # Implicitly tested in previous test; this test is just for behavior specification.
160
- @server_api.should_not_receive(:get_rest).
161
- with('http://chef.example.com/ffffff', true)
439
+ it "fetches eagerly loaded files" do
440
+ synchronizer.sync_cookbooks
441
+ end
442
+
443
+ it "does not fetch templates or cookbook files" do
444
+ # Implicitly tested in previous test; this test is just for behavior specification.
445
+ expect(server_api).not_to receive(:get_rest).
446
+ with('http://chef.example.com/ffffff', true)
162
447
 
163
- @synchronizer.sync_cookbooks
448
+ synchronizer.sync_cookbooks
449
+ end
164
450
  end
165
451
 
166
452
  context "Chef::Config[:no_lazy_load] is true" do
167
- before do
168
- Chef::Config[:no_lazy_load] = true
169
- @synchronizer = Chef::CookbookSynchronizer.new(@cookbook_manifest, @events)
170
- @synchronizer.stub(:server_api).and_return(@server_api)
171
- @synchronizer.stub(:cache).and_return(@file_cache)
172
- @synchronizer.stub(:clear_obsoleted_cookbooks)
173
-
174
- @cookbook_a_file_default_tempfile = double("Tempfile for cookbook_a megaman.conf file",
175
- :path => "/tmp/cookbook_a_file_default_tempfile")
176
- @cookbook_a_template_default_tempfile = double("Tempfile for cookbook_a apache.conf.erb template",
177
- :path => "/tmp/cookbook_a_template_default_tempfile")
178
- end
453
+ let(:no_lazy_load) { true }
179
454
 
180
- after do
181
- Chef::Config[:no_lazy_load] = false
455
+ before do
456
+ setup_no_lazy_files_and_templates_missing_expectations
182
457
  end
183
458
 
184
459
  it "fetches templates and cookbook files" do
185
- @file_cache.should_receive(:has_key?).
186
- with("cookbooks/cookbook_a/files/default/megaman.conf").
187
- and_return(false)
188
- @file_cache.should_receive(:has_key?).
189
- with("cookbooks/cookbook_a/templates/default/apache2.conf.erb").
190
- and_return(false)
191
-
192
- @server_api.should_receive(:get_rest).
193
- with('http://chef.example.com/megaman.conf', true).
194
- and_return(@cookbook_a_file_default_tempfile)
195
- @file_cache.should_receive(:move_to).
196
- with("/tmp/cookbook_a_file_default_tempfile", "cookbooks/cookbook_a/files/default/megaman.conf")
197
- @file_cache.should_receive(:load).
198
- with("cookbooks/cookbook_a/files/default/megaman.conf", false).
199
- and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf")
200
-
201
- @server_api.should_receive(:get_rest).
202
- with('http://chef.example.com/ffffff', true).
203
- and_return(@cookbook_a_template_default_tempfile)
204
- @file_cache.should_receive(:move_to).
205
- with("/tmp/cookbook_a_template_default_tempfile", "cookbooks/cookbook_a/templates/default/apache2.conf.erb")
206
- @file_cache.should_receive(:load).
207
- with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false).
208
- and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb")
209
-
210
- @synchronizer.sync_cookbooks
460
+ synchronizer.sync_cookbooks
211
461
  end
212
462
  end
213
463
  end
214
464
 
215
465
  context "when the cache contains outdated files" do
216
466
  before do
217
- # Files are in the cache:
218
- @file_cache.should_receive(:has_key?).
219
- with("cookbooks/cookbook_a/recipes/default.rb").
220
- and_return(true)
221
- @file_cache.should_receive(:has_key?).
222
- with("cookbooks/cookbook_a/attributes/default.rb").
223
- and_return(true)
224
-
225
-
226
- # Fetch and copy default.rb recipe
227
- @server_api.should_receive(:get_rest).
228
- with('http://chef.example.com/abc123', true).
229
- and_return(@cookbook_a_default_recipe_tempfile)
230
- @file_cache.should_receive(:move_to).
231
- with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb")
232
- @file_cache.should_receive(:load).
233
- with("cookbooks/cookbook_a/recipes/default.rb", false).
234
- twice.
235
- and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
236
-
237
- # Current file has fff000, want abc123
238
- Chef::CookbookVersion.should_receive(:checksum_cookbook_file).
239
- with("/file-cache/cookbooks/cookbook_a/recipes/default.rb").
240
- and_return("fff000")
241
-
242
- # Fetch and copy default.rb attribute file
243
- @server_api.should_receive(:get_rest).
244
- with('http://chef.example.com/abc456', true).
245
- and_return(@cookbook_a_default_attribute_tempfile)
246
- @file_cache.should_receive(:move_to).
247
- with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb")
248
- @file_cache.should_receive(:load).
249
- with("cookbooks/cookbook_a/attributes/default.rb", false).
250
- twice.
251
- and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb")
252
-
253
- # Current file has fff000, want abc456
254
- Chef::CookbookVersion.should_receive(:checksum_cookbook_file).
255
- with("/file-cache/cookbooks/cookbook_a/attributes/default.rb").
256
- and_return("fff000")
467
+ setup_common_files_chksum_mismatch_expectations
257
468
  end
258
469
 
259
- it "updates the outdated files" do
260
- @synchronizer.sync_cookbooks
470
+ context "Chef::Config[:no_lazy_load] is true" do
471
+ let(:no_lazy_load) { true }
472
+
473
+ before do
474
+ setup_no_lazy_files_and_templates_chksum_mismatch_expectations
475
+ end
476
+
477
+ it "updates the outdated files" do
478
+ synchronizer.sync_cookbooks
479
+ end
480
+ end
481
+
482
+ context "Chef::Config[:no_lazy_load] is false" do
483
+ let(:no_lazy_load) { false }
484
+
485
+ it "updates the outdated files" do
486
+ synchronizer.sync_cookbooks
487
+ end
261
488
  end
262
489
  end
263
490
 
264
491
  context "when the cache is up to date" do
265
492
  before do
266
- # Files are in the cache:
267
- @file_cache.should_receive(:has_key?).
268
- with("cookbooks/cookbook_a/recipes/default.rb").
269
- and_return(true)
270
- @file_cache.should_receive(:has_key?).
271
- with("cookbooks/cookbook_a/attributes/default.rb").
272
- and_return(true)
273
-
274
- # Current file has abc123, want abc123
275
- Chef::CookbookVersion.should_receive(:checksum_cookbook_file).
276
- with("/file-cache/cookbooks/cookbook_a/recipes/default.rb").
277
- and_return("abc123")
278
-
279
- # Current file has abc456, want abc456
280
- Chef::CookbookVersion.should_receive(:checksum_cookbook_file).
281
- with("/file-cache/cookbooks/cookbook_a/attributes/default.rb").
282
- and_return("abc456")
283
-
284
- @file_cache.should_receive(:load).
285
- with("cookbooks/cookbook_a/recipes/default.rb", false).
286
- twice.
287
- and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
288
-
289
- @file_cache.should_receive(:load).
290
- with("cookbooks/cookbook_a/attributes/default.rb", false).
291
- twice.
292
- and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb")
493
+ setup_common_files_present_expectations
293
494
  end
294
495
 
295
- it "does not update files" do
296
- @file_cache.should_not_receive(:move_to)
297
- @server_api.should_not_receive(:get_rest)
298
- @synchronizer.sync_cookbooks
496
+ context "Chef::Config[:no_lazy_load] is true" do
497
+ let(:no_lazy_load) { true }
498
+
499
+ before do
500
+ setup_no_lazy_files_and_templates_present_expectations
501
+ end
502
+
503
+ it "does not update files" do
504
+ expect(file_cache).not_to receive(:move_to)
505
+ expect(server_api).not_to receive(:get_rest)
506
+ synchronizer.sync_cookbooks
507
+ end
299
508
  end
300
509
 
301
- end
510
+ context "Chef::Config[:no_lazy_load] is false" do
511
+ let(:no_lazy_load) { false }
302
512
 
513
+ it "does not update files" do
514
+ expect(file_cache).not_to receive(:move_to)
515
+ expect(server_api).not_to receive(:get_rest)
516
+ synchronizer.sync_cookbooks
517
+ end
518
+ end
519
+ end
303
520
  end
304
-
305
521
  end
306
-