chef 10.34.6 → 11.0.0.beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (506) hide show
  1. data/CONTRIBUTING.md +155 -0
  2. data/README.md +89 -0
  3. data/Rakefile +4 -12
  4. data/bin/chef-apply +25 -0
  5. data/bin/chef-shell +34 -0
  6. data/bin/shef +6 -5
  7. data/distro/common/html/chef-client.8.html +4 -4
  8. data/distro/common/html/chef-expander.8.html +4 -4
  9. data/distro/common/html/chef-expanderctl.8.html +4 -4
  10. data/distro/common/html/chef-server-webui.8.html +4 -4
  11. data/distro/common/html/chef-server.8.html +4 -4
  12. data/distro/common/html/{shef.1.html → chef-shell.1.html} +49 -46
  13. data/distro/common/html/chef-solo.8.html +18 -12
  14. data/distro/common/html/chef-solr.8.html +4 -4
  15. data/distro/common/html/knife-bootstrap.1.html +4 -4
  16. data/distro/common/html/knife-client.1.html +4 -4
  17. data/distro/common/html/knife-configure.1.html +4 -4
  18. data/distro/common/html/knife-cookbook-site.1.html +4 -4
  19. data/distro/common/html/knife-cookbook.1.html +10 -7
  20. data/distro/common/html/knife-data-bag.1.html +10 -7
  21. data/distro/common/html/knife-environment.1.html +8 -6
  22. data/distro/common/html/knife-exec.1.html +9 -9
  23. data/distro/common/html/knife-index.1.html +4 -4
  24. data/distro/common/html/knife-node.1.html +4 -4
  25. data/distro/common/html/knife-role.1.html +4 -4
  26. data/distro/common/html/knife-search.1.html +4 -4
  27. data/distro/common/html/knife-ssh.1.html +4 -4
  28. data/distro/common/html/knife-status.1.html +4 -4
  29. data/distro/common/html/knife-tag.1.html +4 -4
  30. data/distro/common/html/knife.1.html +8 -13
  31. data/distro/common/man/man1/{shef.1 → chef-shell.1} +21 -57
  32. data/distro/common/man/man1/knife-bootstrap.1 +1 -1
  33. data/distro/common/man/man1/knife-client.1 +1 -1
  34. data/distro/common/man/man1/knife-configure.1 +1 -1
  35. data/distro/common/man/man1/knife-cookbook-site.1 +1 -1
  36. data/distro/common/man/man1/knife-cookbook.1 +15 -2
  37. data/distro/common/man/man1/knife-data-bag.1 +15 -2
  38. data/distro/common/man/man1/knife-environment.1 +12 -2
  39. data/distro/common/man/man1/knife-exec.1 +4 -7
  40. data/distro/common/man/man1/knife-index.1 +1 -1
  41. data/distro/common/man/man1/knife-node.1 +1 -1
  42. data/distro/common/man/man1/knife-role.1 +1 -1
  43. data/distro/common/man/man1/knife-search.1 +1 -1
  44. data/distro/common/man/man1/knife-ssh.1 +1 -1
  45. data/distro/common/man/man1/knife-status.1 +1 -1
  46. data/distro/common/man/man1/knife-tag.1 +1 -1
  47. data/distro/common/man/man1/knife.1 +3 -6
  48. data/distro/common/man/man8/chef-client.8 +1 -1
  49. data/distro/common/man/man8/chef-expander.8 +1 -1
  50. data/distro/common/man/man8/chef-expanderctl.8 +1 -1
  51. data/distro/common/man/man8/chef-server-webui.8 +1 -1
  52. data/distro/common/man/man8/chef-server.8 +1 -1
  53. data/distro/common/man/man8/chef-solo.8 +36 -4
  54. data/distro/common/man/man8/chef-solr.8 +1 -1
  55. data/distro/common/markdown/man1/{shef.mkd → chef-shell.mkd} +49 -43
  56. data/distro/common/markdown/man1/knife-exec.mkd +11 -6
  57. data/distro/common/markdown/man1/knife.mkd +4 -9
  58. data/distro/debian/etc/default/chef-client +0 -1
  59. data/distro/debian/etc/init.d/chef-client +2 -2
  60. data/lib/chef.rb +2 -5
  61. data/lib/chef/api_client.rb +20 -130
  62. data/lib/chef/api_client/registration.rb +126 -0
  63. data/lib/chef/application.rb +71 -14
  64. data/lib/chef/application/apply.rb +160 -0
  65. data/lib/chef/application/client.rb +25 -18
  66. data/lib/chef/application/knife.rb +0 -2
  67. data/lib/chef/application/solo.rb +23 -8
  68. data/lib/chef/application/windows_service.rb +5 -2
  69. data/lib/chef/applications.rb +1 -0
  70. data/lib/chef/chef_fs.rb +11 -0
  71. data/lib/chef/chef_fs/command_line.rb +232 -0
  72. data/lib/chef/chef_fs/file_pattern.rb +312 -0
  73. data/lib/chef/chef_fs/file_system.rb +358 -0
  74. data/lib/chef/chef_fs/file_system/base_fs_dir.rb +47 -0
  75. data/lib/chef/chef_fs/file_system/base_fs_object.rb +121 -0
  76. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +109 -0
  77. data/{spec/unit/monkey_patches/uri_spec.rb → lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb} +12 -15
  78. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +84 -0
  79. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +188 -0
  80. data/lib/chef/chef_fs/file_system/cookbook_file.rb +78 -0
  81. data/lib/chef/chef_fs/file_system/cookbook_subdir.rb +54 -0
  82. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +68 -0
  83. data/lib/chef/chef_fs/file_system/data_bag_dir.rb +78 -0
  84. data/lib/chef/chef_fs/file_system/data_bag_item.rb +59 -0
  85. data/lib/chef/chef_fs/file_system/data_bags_dir.rb +66 -0
  86. data/lib/chef/chef_fs/file_system/file_system_entry.rb +90 -0
  87. data/lib/chef/{index_queue.rb → chef_fs/file_system/file_system_error.rb} +14 -12
  88. data/lib/chef/{resource/whyrun_safe_ruby_block.rb → chef_fs/file_system/file_system_root_dir.rb} +10 -10
  89. data/lib/chef/chef_fs/file_system/must_delete_recursively_error.rb +31 -0
  90. data/lib/chef/chef_fs/file_system/nodes_dir.rb +47 -0
  91. data/lib/chef/{provider/whyrun_safe_ruby_block.rb → chef_fs/file_system/nonexistent_fs_object.rb} +19 -9
  92. data/lib/chef/chef_fs/file_system/not_found_error.rb +31 -0
  93. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +84 -0
  94. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +123 -0
  95. data/lib/chef/chef_fs/knife.rb +77 -0
  96. data/lib/chef/chef_fs/path_utils.rb +64 -0
  97. data/lib/chef/client.rb +44 -21
  98. data/lib/chef/config.rb +52 -43
  99. data/lib/chef/cookbook/synchronizer.rb +6 -8
  100. data/lib/chef/cookbook/syntax_check.rb +61 -14
  101. data/lib/chef/cookbook_loader.rb +39 -26
  102. data/lib/chef/cookbook_uploader.rb +17 -19
  103. data/lib/chef/cookbook_version.rb +3 -302
  104. data/lib/chef/daemon.rb +3 -18
  105. data/lib/chef/data_bag.rb +4 -97
  106. data/lib/chef/data_bag_item.rb +2 -65
  107. data/lib/chef/digester.rb +73 -0
  108. data/lib/chef/dsl.rb +6 -0
  109. data/lib/chef/dsl/data_query.rb +66 -0
  110. data/lib/chef/dsl/include_attribute.rb +60 -0
  111. data/lib/chef/dsl/include_recipe.rb +42 -0
  112. data/lib/chef/dsl/platform_introspection.rb +213 -0
  113. data/lib/chef/dsl/recipe.rb +84 -0
  114. data/lib/chef/dsl/registry_helper.rb +59 -0
  115. data/lib/chef/encrypted_data_bag_item.rb +74 -19
  116. data/lib/chef/environment.rb +9 -180
  117. data/lib/chef/exceptions.rb +87 -14
  118. data/lib/chef/formatters/base.rb +4 -1
  119. data/lib/chef/formatters/error_inspectors/registration_error_inspector.rb +0 -4
  120. data/lib/chef/json_compat.rb +1 -97
  121. data/lib/chef/knife.rb +90 -41
  122. data/lib/chef/knife/bootstrap/archlinux-gems.erb +2 -2
  123. data/lib/chef/knife/bootstrap/centos5-gems.erb +2 -2
  124. data/lib/chef/knife/bootstrap/chef-full.erb +3 -3
  125. data/lib/chef/knife/bootstrap/fedora13-gems.erb +2 -2
  126. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +2 -2
  127. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +2 -2
  128. data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +2 -2
  129. data/lib/chef/knife/configure.rb +1 -2
  130. data/lib/chef/knife/cookbook_metadata.rb +1 -0
  131. data/lib/chef/knife/cookbook_test.rb +3 -2
  132. data/lib/chef/knife/cookbook_upload.rb +12 -7
  133. data/lib/chef/knife/core/bootstrap_context.rb +1 -1
  134. data/lib/chef/knife/core/generic_presenter.rb +26 -13
  135. data/lib/chef/knife/core/node_editor.rb +36 -16
  136. data/lib/chef/knife/core/node_presenter.rb +1 -1
  137. data/lib/chef/knife/core/text_formatter.rb +23 -37
  138. data/lib/chef/knife/core/ui.rb +15 -9
  139. data/lib/chef/knife/delete.rb +39 -0
  140. data/lib/chef/knife/diff.rb +46 -0
  141. data/lib/chef/knife/download.rb +50 -0
  142. data/lib/chef/knife/environment_show.rb +7 -0
  143. data/lib/chef/knife/exec.rb +5 -5
  144. data/lib/chef/knife/help_topics.rb +1 -1
  145. data/lib/chef/knife/index_rebuild.rb +91 -7
  146. data/lib/chef/knife/list.rb +109 -0
  147. data/lib/chef/knife/raw.rb +108 -0
  148. data/lib/chef/knife/search.rb +40 -22
  149. data/lib/chef/knife/show.rb +32 -0
  150. data/lib/chef/knife/ssh.rb +6 -2
  151. data/lib/chef/knife/upload.rb +50 -0
  152. data/lib/chef/mixin/checksum.rb +3 -3
  153. data/lib/chef/mixin/deep_merge.rb +55 -197
  154. data/lib/chef/mixin/language.rb +9 -222
  155. data/lib/chef/mixin/language_include_attribute.rb +6 -38
  156. data/lib/chef/mixin/language_include_recipe.rb +3 -35
  157. data/lib/chef/mixin/params_validate.rb +6 -19
  158. data/lib/chef/mixin/recipe_definition_dsl_core.rb +8 -61
  159. data/lib/chef/mixin/securable.rb +32 -7
  160. data/lib/chef/mixin/template.rb +40 -0
  161. data/lib/chef/mixins.rb +0 -4
  162. data/lib/chef/monkey_patches/net_http.rb +0 -34
  163. data/lib/chef/node.rb +133 -309
  164. data/lib/chef/node/attribute.rb +333 -473
  165. data/lib/chef/node/attribute_collections.rb +199 -0
  166. data/lib/chef/node/immutable_collections.rb +186 -0
  167. data/lib/chef/platform.rb +7 -22
  168. data/lib/chef/provider.rb +2 -49
  169. data/lib/chef/provider/breakpoint.rb +6 -6
  170. data/lib/chef/provider/cookbook_file.rb +5 -33
  171. data/lib/chef/provider/deploy.rb +2 -1
  172. data/lib/chef/provider/directory.rb +14 -17
  173. data/lib/chef/provider/file.rb +19 -52
  174. data/lib/chef/provider/group.rb +31 -51
  175. data/lib/chef/provider/group/dscl.rb +13 -53
  176. data/lib/chef/provider/group/gpasswd.rb +19 -14
  177. data/lib/chef/provider/group/groupadd.rb +1 -41
  178. data/lib/chef/provider/group/groupmod.rb +36 -46
  179. data/lib/chef/provider/group/pw.rb +16 -59
  180. data/lib/chef/provider/group/suse.rb +13 -16
  181. data/lib/chef/provider/group/usermod.rb +18 -40
  182. data/lib/chef/provider/group/windows.rb +6 -13
  183. data/lib/chef/provider/http_request.rb +25 -42
  184. data/lib/chef/provider/link.rb +2 -0
  185. data/lib/chef/provider/lwrp_base.rb +150 -0
  186. data/lib/chef/provider/package/portage.rb +4 -9
  187. data/lib/chef/provider/package/rpm.rb +2 -2
  188. data/lib/chef/provider/package/rubygems.rb +9 -41
  189. data/lib/chef/provider/package/yum.rb +12 -19
  190. data/lib/chef/provider/registry_key.rb +156 -0
  191. data/lib/chef/provider/remote_directory.rb +2 -0
  192. data/lib/chef/provider/remote_file.rb +21 -12
  193. data/lib/chef/provider/ruby_block.rb +5 -2
  194. data/lib/chef/provider/service.rb +15 -0
  195. data/lib/chef/provider/service/init.rb +9 -7
  196. data/lib/chef/provider/service/macosx.rb +15 -73
  197. data/lib/chef/provider/service/simple.rb +1 -1
  198. data/lib/chef/provider/service/solaris.rb +3 -3
  199. data/lib/chef/provider/template.rb +22 -25
  200. data/lib/chef/provider/template_finder.rb +61 -0
  201. data/lib/chef/provider/user.rb +0 -1
  202. data/lib/chef/provider/user/dscl.rb +175 -568
  203. data/lib/chef/provider/user/useradd.rb +30 -47
  204. data/lib/chef/providers.rb +3 -2
  205. data/lib/chef/recipe.rb +14 -8
  206. data/lib/chef/resource.rb +13 -154
  207. data/lib/chef/resource/group.rb +1 -11
  208. data/lib/chef/resource/http_request.rb +2 -1
  209. data/lib/chef/resource/lwrp_base.rb +127 -0
  210. data/lib/chef/resource/mount.rb +10 -11
  211. data/lib/chef/resource/registry_key.rb +86 -0
  212. data/lib/chef/resource/remote_directory.rb +6 -5
  213. data/lib/chef/resource/remote_file.rb +22 -31
  214. data/lib/chef/resource/ruby_block.rb +2 -2
  215. data/lib/chef/resource/service.rb +14 -0
  216. data/lib/chef/resource/user.rb +0 -18
  217. data/lib/chef/resource_collection.rb +25 -21
  218. data/lib/chef/resources.rb +2 -1
  219. data/lib/chef/rest.rb +50 -131
  220. data/lib/chef/rest/auth_credentials.rb +4 -20
  221. data/lib/chef/rest/rest_request.rb +2 -7
  222. data/lib/chef/role.rb +1 -97
  223. data/lib/chef/run_context.rb +108 -130
  224. data/lib/chef/run_context/cookbook_compiler.rb +280 -0
  225. data/lib/chef/run_list.rb +0 -2
  226. data/lib/chef/run_list/run_list_expansion.rb +0 -15
  227. data/lib/chef/run_lock.rb +90 -0
  228. data/lib/chef/runner.rb +28 -5
  229. data/lib/chef/sandbox.rb +15 -148
  230. data/lib/chef/scan_access_control.rb +2 -4
  231. data/lib/chef/shef/ext.rb +3 -575
  232. data/lib/chef/{shef.rb → shell.rb} +35 -40
  233. data/lib/chef/shell/ext.rb +593 -0
  234. data/lib/chef/{shef → shell}/model_wrapper.rb +3 -3
  235. data/lib/chef/{shef/shef_rest.rb → shell/shell_rest.rb} +4 -4
  236. data/lib/chef/{shef/shef_session.rb → shell/shell_session.rb} +17 -15
  237. data/lib/chef/shell_out.rb +7 -0
  238. data/lib/chef/util/windows/net_group.rb +1 -5
  239. data/lib/chef/version.rb +3 -3
  240. data/lib/chef/win32/api/process.rb +0 -1
  241. data/lib/chef/win32/handle.rb +1 -8
  242. data/lib/chef/win32/registry.rb +371 -0
  243. data/spec/data/big_json.json +1 -2
  244. data/spec/data/big_json_plus_one.json +1 -2
  245. data/spec/data/cookbooks/openldap/attributes/default.rb +10 -9
  246. data/spec/data/cookbooks/openldap/attributes/smokey.rb +1 -1
  247. data/spec/data/lwrp/providers/inline_compiler.rb +26 -0
  248. data/spec/data/nodes/default.rb +3 -3
  249. data/spec/data/nodes/test.example.com.rb +3 -3
  250. data/spec/data/nodes/test.rb +3 -3
  251. data/spec/data/partial_one.erb +1 -0
  252. data/spec/data/run_context/cookbooks/circular-dep1/attributes/default.rb +4 -0
  253. data/spec/data/run_context/cookbooks/circular-dep1/definitions/circular_dep1_res.rb +1 -0
  254. data/spec/data/run_context/cookbooks/circular-dep1/libraries/lib.rb +2 -0
  255. data/spec/data/run_context/cookbooks/circular-dep1/metadata.rb +2 -0
  256. data/spec/data/run_context/cookbooks/circular-dep1/providers/provider.rb +1 -0
  257. data/spec/data/{knife-home/.chef/plugins/knife/example_home_subcommand.rb → run_context/cookbooks/circular-dep1/recipes/default.rb} +0 -0
  258. data/spec/data/run_context/cookbooks/circular-dep1/resources/resource.rb +1 -0
  259. data/spec/data/run_context/cookbooks/circular-dep2/attributes/default.rb +3 -0
  260. data/spec/data/run_context/cookbooks/circular-dep2/definitions/circular_dep2_res.rb +1 -0
  261. data/spec/data/run_context/cookbooks/circular-dep2/libraries/lib.rb +2 -0
  262. data/spec/data/run_context/cookbooks/circular-dep2/metadata.rb +2 -0
  263. data/spec/data/run_context/cookbooks/circular-dep2/providers/provider.rb +1 -0
  264. data/spec/data/{lwrp_const_scoping/resources/conflict.rb → run_context/cookbooks/circular-dep2/recipes/default.rb} +0 -0
  265. data/spec/data/run_context/cookbooks/circular-dep2/resources/resource.rb +1 -0
  266. data/spec/data/run_context/cookbooks/dependency1/attributes/aa_first.rb +2 -0
  267. data/spec/data/run_context/cookbooks/dependency1/attributes/default.rb +2 -0
  268. data/spec/data/run_context/cookbooks/dependency1/attributes/zz_last.rb +3 -0
  269. data/spec/data/run_context/cookbooks/dependency1/definitions/dependency1_res.rb +1 -0
  270. data/spec/data/run_context/cookbooks/dependency1/libraries/lib.rb +2 -0
  271. data/spec/data/run_context/cookbooks/dependency1/providers/provider.rb +1 -0
  272. data/spec/data/run_context/cookbooks/dependency1/recipes/default.rb +0 -0
  273. data/spec/data/run_context/cookbooks/dependency1/resources/resource.rb +1 -0
  274. data/spec/data/run_context/cookbooks/dependency2/attributes/default.rb +3 -0
  275. data/spec/data/run_context/cookbooks/dependency2/definitions/dependency2_res.rb +1 -0
  276. data/spec/data/run_context/cookbooks/dependency2/libraries/lib.rb +2 -0
  277. data/spec/data/run_context/cookbooks/dependency2/providers/provider.rb +1 -0
  278. data/spec/data/run_context/cookbooks/dependency2/recipes/default.rb +0 -0
  279. data/spec/data/run_context/cookbooks/dependency2/resources/resource.rb +1 -0
  280. data/spec/data/run_context/cookbooks/no-default-attr/attributes/server.rb +3 -0
  281. data/spec/data/run_context/cookbooks/no-default-attr/definitions/no_default-attr_res.rb +1 -0
  282. data/spec/data/run_context/cookbooks/no-default-attr/providers/provider.rb +1 -0
  283. data/spec/data/run_context/cookbooks/no-default-attr/recipes/default.rb +0 -0
  284. data/spec/data/run_context/cookbooks/no-default-attr/resources/resource.rb +1 -0
  285. data/spec/data/run_context/cookbooks/test-with-circular-deps/attributes/default.rb +3 -0
  286. data/spec/data/run_context/cookbooks/test-with-circular-deps/definitions/test_with-circular-deps_res.rb +1 -0
  287. data/spec/data/run_context/cookbooks/test-with-circular-deps/libraries/lib.rb +2 -0
  288. data/spec/data/run_context/cookbooks/test-with-circular-deps/metadata.rb +2 -0
  289. data/spec/data/run_context/cookbooks/test-with-circular-deps/providers/provider.rb +1 -0
  290. data/spec/data/run_context/cookbooks/test-with-circular-deps/recipes/default.rb +0 -0
  291. data/spec/data/run_context/cookbooks/test-with-circular-deps/resources/resource.rb +1 -0
  292. data/spec/data/run_context/cookbooks/test-with-deps/attributes/default.rb +3 -0
  293. data/spec/data/run_context/cookbooks/test-with-deps/definitions/test_with-deps_res.rb +1 -0
  294. data/spec/data/run_context/cookbooks/test-with-deps/libraries/lib.rb +1 -0
  295. data/spec/data/run_context/cookbooks/test-with-deps/metadata.rb +3 -0
  296. data/spec/data/run_context/cookbooks/test-with-deps/providers/provider.rb +1 -0
  297. data/spec/data/run_context/cookbooks/test-with-deps/recipes/default.rb +0 -0
  298. data/spec/data/run_context/cookbooks/test-with-deps/recipes/server.rb +0 -0
  299. data/spec/data/run_context/cookbooks/test-with-deps/resources/resource.rb +1 -0
  300. data/spec/data/run_context/cookbooks/test/attributes/default.rb +0 -0
  301. data/spec/data/run_context/cookbooks/test/attributes/george.rb +1 -1
  302. data/spec/data/run_context/cookbooks/test/definitions/test_res.rb +1 -0
  303. data/spec/data/run_context/cookbooks/test/providers/provider.rb +1 -0
  304. data/spec/data/run_context/cookbooks/test/resources/resource.rb +1 -0
  305. data/spec/data/shef-config.rb +7 -0
  306. data/spec/functional/dsl/registry_helper_spec.rb +63 -0
  307. data/spec/functional/knife/cookbook_delete_spec.rb +1 -1
  308. data/spec/functional/knife/exec_spec.rb +2 -2
  309. data/spec/functional/knife/ssh_spec.rb +5 -1
  310. data/spec/functional/resource/cookbook_file_spec.rb +7 -19
  311. data/spec/functional/resource/directory_spec.rb +4 -0
  312. data/spec/functional/resource/file_spec.rb +56 -22
  313. data/spec/functional/resource/link_spec.rb +2 -0
  314. data/spec/functional/resource/registry_spec.rb +576 -0
  315. data/spec/functional/resource/remote_directory_spec.rb +142 -36
  316. data/spec/functional/resource/remote_file_spec.rb +18 -0
  317. data/spec/functional/resource/template_spec.rb +23 -2
  318. data/spec/functional/run_lock_spec.rb +106 -0
  319. data/spec/functional/shell_spec.rb +100 -0
  320. data/spec/functional/win32/registry_helper_spec.rb +632 -0
  321. data/spec/spec_helper.rb +5 -29
  322. data/spec/stress/win32/security_spec.rb +1 -1
  323. data/spec/support/chef_helpers.rb +0 -2
  324. data/spec/support/platform_helpers.rb +8 -15
  325. data/spec/support/shared/functional/directory_resource.rb +84 -22
  326. data/spec/support/shared/functional/file_resource.rb +169 -71
  327. data/spec/support/shared/functional/securable_resource.rb +143 -119
  328. data/spec/support/shared/functional/securable_resource_with_reporting.rb +375 -0
  329. data/spec/support/shared/unit/file_system_support.rb +110 -0
  330. data/spec/support/shared/unit/platform_introspector.rb +162 -0
  331. data/spec/unit/api_client/registration_spec.rb +175 -0
  332. data/spec/unit/api_client_spec.rb +78 -156
  333. data/spec/unit/application/apply.rb +84 -0
  334. data/spec/unit/application/client_spec.rb +1 -37
  335. data/spec/unit/application/knife_spec.rb +5 -0
  336. data/spec/unit/application_spec.rb +57 -2
  337. data/spec/unit/checksum/storage/filesystem_spec.rb +1 -1
  338. data/spec/unit/chef_fs/diff_spec.rb +328 -0
  339. data/spec/unit/chef_fs/file_pattern_spec.rb +526 -0
  340. data/spec/unit/chef_fs/file_system/chef_server_root_dir_spec.rb +237 -0
  341. data/spec/unit/chef_fs/file_system/cookbooks_dir_spec.rb +568 -0
  342. data/spec/unit/chef_fs/file_system/data_bags_dir_spec.rb +220 -0
  343. data/spec/unit/chef_fs/file_system_spec.rb +136 -0
  344. data/spec/unit/client_spec.rb +124 -33
  345. data/spec/unit/config_spec.rb +46 -13
  346. data/spec/unit/cookbook/synchronizer_spec.rb +1 -49
  347. data/spec/unit/cookbook/syntax_check_spec.rb +48 -109
  348. data/spec/unit/cookbook_loader_spec.rb +153 -91
  349. data/spec/unit/cookbook_manifest_spec.rb +81 -81
  350. data/spec/unit/cookbook_spec.rb +3 -20
  351. data/spec/unit/cookbook_version_spec.rb +23 -122
  352. data/spec/unit/daemon_spec.rb +3 -24
  353. data/spec/unit/data_bag_spec.rb +6 -4
  354. data/spec/unit/digester_spec.rb +50 -0
  355. data/spec/unit/dsl/data_query_spec.rb +66 -0
  356. data/spec/unit/dsl/platform_introspection_spec.rb +130 -0
  357. data/spec/unit/dsl/regsitry_helper_spec.rb +55 -0
  358. data/spec/unit/encrypted_data_bag_item_spec.rb +50 -105
  359. data/spec/unit/environment_spec.rb +0 -130
  360. data/spec/unit/exceptions_spec.rb +2 -3
  361. data/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +3 -3
  362. data/spec/unit/json_compat_spec.rb +15 -7
  363. data/spec/unit/knife/bootstrap_spec.rb +2 -0
  364. data/spec/unit/knife/configure_spec.rb +20 -14
  365. data/spec/unit/knife/cookbook_metadata_spec.rb +11 -4
  366. data/spec/unit/knife/cookbook_test_spec.rb +1 -0
  367. data/spec/unit/knife/cookbook_upload_spec.rb +43 -8
  368. data/spec/unit/knife/core/bootstrap_context_spec.rb +1 -1
  369. data/spec/unit/knife/core/ui_spec.rb +156 -125
  370. data/spec/unit/knife/data_bag_create_spec.rb +9 -0
  371. data/spec/unit/knife/data_bag_edit_spec.rb +1 -4
  372. data/spec/unit/knife/data_bag_from_file_spec.rb +4 -6
  373. data/spec/unit/knife/data_bag_show_spec.rb +11 -4
  374. data/spec/unit/knife/index_rebuild_spec.rb +96 -33
  375. data/spec/unit/knife/knife_help.rb +7 -7
  376. data/spec/unit/knife/node_edit_spec.rb +6 -33
  377. data/spec/unit/knife/node_run_list_remove_spec.rb +2 -1
  378. data/spec/unit/knife/ssh_spec.rb +12 -15
  379. data/spec/unit/knife/status_spec.rb +2 -2
  380. data/spec/unit/knife_spec.rb +53 -0
  381. data/spec/unit/lwrp_spec.rb +59 -42
  382. data/spec/unit/mixin/checksum_spec.rb +2 -2
  383. data/spec/unit/mixin/deep_merge_spec.rb +101 -799
  384. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +6 -1
  385. data/spec/unit/mixin/params_validate_spec.rb +4 -37
  386. data/spec/unit/mixin/securable_spec.rb +5 -3
  387. data/spec/unit/mixin/template_spec.rb +119 -0
  388. data/spec/unit/node/attribute_spec.rb +195 -173
  389. data/spec/unit/node/immutable_collections_spec.rb +139 -0
  390. data/spec/unit/node_spec.rb +366 -370
  391. data/spec/unit/platform_spec.rb +9 -10
  392. data/spec/unit/provider/breakpoint_spec.rb +8 -8
  393. data/spec/unit/provider/cookbook_file_spec.rb +4 -8
  394. data/spec/unit/provider/directory_spec.rb +96 -64
  395. data/spec/unit/provider/env_spec.rb +2 -2
  396. data/spec/unit/provider/file_spec.rb +48 -39
  397. data/spec/unit/provider/group/dscl_spec.rb +0 -36
  398. data/spec/unit/provider/group/gpasswd_spec.rb +9 -16
  399. data/spec/unit/provider/group/groupadd_spec.rb +4 -3
  400. data/spec/unit/provider/group/groupmod_spec.rb +1 -0
  401. data/spec/unit/provider/group/pw_spec.rb +15 -12
  402. data/spec/unit/provider/group/usermod_spec.rb +6 -21
  403. data/spec/unit/provider/group/windows_spec.rb +8 -0
  404. data/spec/unit/provider/group_spec.rb +6 -28
  405. data/spec/unit/provider/http_request_spec.rb +28 -69
  406. data/spec/unit/provider/ifconfig_spec.rb +2 -2
  407. data/spec/unit/provider/ohai_spec.rb +4 -4
  408. data/spec/unit/provider/package/apt_spec.rb +0 -1
  409. data/spec/unit/provider/package/ips_spec.rb +0 -1
  410. data/spec/unit/provider/package/portage_spec.rb +0 -44
  411. data/spec/unit/provider/package/rpm_spec.rb +0 -12
  412. data/spec/unit/provider/package/rubygems_spec.rb +1 -44
  413. data/spec/unit/provider/package/yum_spec.rb +39 -36
  414. data/spec/unit/provider/package_spec.rb +7 -5
  415. data/spec/unit/provider/registry_key_spec.rb +269 -0
  416. data/spec/unit/provider/remote_directory_spec.rb +7 -3
  417. data/spec/unit/provider/remote_file_spec.rb +36 -0
  418. data/spec/unit/provider/route_spec.rb +4 -3
  419. data/spec/unit/provider/ruby_block_spec.rb +8 -0
  420. data/spec/unit/provider/service/arch_service_spec.rb +5 -5
  421. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  422. data/spec/unit/provider/service/freebsd_service_spec.rb +5 -5
  423. data/spec/unit/provider/service/init_service_spec.rb +27 -4
  424. data/spec/unit/provider/service/insserv_service_spec.rb +1 -1
  425. data/spec/unit/provider/service/invokercd_service_spec.rb +4 -4
  426. data/spec/unit/provider/service/macosx_spec.rb +11 -66
  427. data/spec/unit/provider/service/redhat_spec.rb +1 -1
  428. data/spec/unit/provider/service/simple_service_spec.rb +3 -3
  429. data/spec/unit/provider/service/upstart_service_spec.rb +9 -9
  430. data/spec/unit/provider/subversion_spec.rb +1 -1
  431. data/spec/unit/provider/template_spec.rb +35 -11
  432. data/spec/unit/provider/user/dscl_spec.rb +285 -681
  433. data/spec/unit/provider/user/useradd_spec.rb +1 -22
  434. data/spec/unit/provider/user_spec.rb +1 -1
  435. data/spec/unit/recipe_spec.rb +10 -8
  436. data/spec/unit/registry_helper_spec.rb +374 -0
  437. data/spec/unit/resource/mount_spec.rb +0 -11
  438. data/spec/unit/resource/registry_key_spec.rb +171 -0
  439. data/spec/unit/resource/remote_file_spec.rb +21 -23
  440. data/spec/unit/resource/ruby_block_spec.rb +7 -3
  441. data/spec/unit/resource/service_spec.rb +11 -0
  442. data/spec/unit/resource_spec.rb +4 -19
  443. data/spec/unit/rest/auth_credentials_spec.rb +2 -19
  444. data/spec/unit/rest_spec.rb +130 -284
  445. data/spec/unit/run_context/cookbook_compiler_spec.rb +181 -0
  446. data/spec/unit/run_context_spec.rb +18 -4
  447. data/spec/unit/run_list_spec.rb +0 -209
  448. data/spec/unit/run_lock_spec.rb +37 -0
  449. data/spec/unit/runner_spec.rb +101 -2
  450. data/spec/unit/scan_access_control_spec.rb +4 -4
  451. data/spec/unit/{shef → shell}/model_wrapper_spec.rb +5 -5
  452. data/spec/unit/{shef/shef_ext_spec.rb → shell/shell_ext_spec.rb} +21 -21
  453. data/spec/unit/{shef/shef_session_spec.rb → shell/shell_session_spec.rb} +14 -69
  454. data/spec/unit/shell_out_spec.rb +18 -0
  455. data/spec/unit/{shef_spec.rb → shell_spec.rb} +20 -20
  456. metadata +275 -234
  457. checksums.yaml +0 -15
  458. data/README.rdoc +0 -177
  459. data/distro/common/html/knife-recipe.1.html +0 -92
  460. data/lib/chef/certificate.rb +0 -161
  461. data/lib/chef/checksum.rb +0 -167
  462. data/lib/chef/checksum_cache.rb +0 -190
  463. data/lib/chef/cookbook_version_selector.rb +0 -168
  464. data/lib/chef/couchdb.rb +0 -246
  465. data/lib/chef/index_queue/amqp_client.rb +0 -116
  466. data/lib/chef/index_queue/consumer.rb +0 -76
  467. data/lib/chef/index_queue/indexable.rb +0 -109
  468. data/lib/chef/knife/bootstrap/ubuntu12.10-gems.erb +0 -60
  469. data/lib/chef/monkey_patches/moneta.rb +0 -50
  470. data/lib/chef/monkey_patches/uri.rb +0 -70
  471. data/lib/chef/openid_registration.rb +0 -187
  472. data/lib/chef/provider/user/solaris.rb +0 -90
  473. data/lib/chef/solr_query.rb +0 -187
  474. data/lib/chef/solr_query/lucene.treetop +0 -150
  475. data/lib/chef/solr_query/lucene_nodes.rb +0 -285
  476. data/lib/chef/solr_query/query_transform.rb +0 -65
  477. data/lib/chef/solr_query/solr_http_request.rb +0 -132
  478. data/lib/chef/webui_user.rb +0 -231
  479. data/spec/data/cookbooks/openldap/files/default/.dotfile +0 -1
  480. data/spec/data/cookbooks/openldap/files/default/.ssh/id_rsa +0 -1
  481. data/spec/data/cookbooks/openldap/files/default/remotedir/.a_dotdir/.a_dotfile_in_a_dotdir +0 -1
  482. data/spec/data/cookbooks/openldap/files/default/remotedir/remotesubdir/.a_dotfile +0 -1
  483. data/spec/data/mac_users/10.7-8.plist.xml +0 -559
  484. data/spec/data/mac_users/10.7-8.shadow.xml +0 -11
  485. data/spec/data/mac_users/10.7.plist.xml +0 -559
  486. data/spec/data/mac_users/10.7.shadow.xml +0 -11
  487. data/spec/data/mac_users/10.8.plist.xml +0 -559
  488. data/spec/data/mac_users/10.8.shadow.xml +0 -21
  489. data/spec/data/mac_users/10.9.plist.xml +0 -560
  490. data/spec/data/mac_users/10.9.shadow.xml +0 -21
  491. data/spec/functional/resource/base.rb +0 -40
  492. data/spec/functional/resource/group_spec.rb +0 -343
  493. data/spec/functional/resource/user/dscl_spec.rb +0 -199
  494. data/spec/unit/certificate_spec.rb +0 -76
  495. data/spec/unit/checksum_cache_spec.rb +0 -209
  496. data/spec/unit/checksum_spec.rb +0 -94
  497. data/spec/unit/couchdb_spec.rb +0 -274
  498. data/spec/unit/index_queue_spec.rb +0 -391
  499. data/spec/unit/mixin/language_spec.rb +0 -305
  500. data/spec/unit/openid_registration_spec.rb +0 -153
  501. data/spec/unit/provider/user/solaris_spec.rb +0 -414
  502. data/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +0 -47
  503. data/spec/unit/solr_query/query_transform_spec.rb +0 -454
  504. data/spec/unit/solr_query/solr_http_request_spec.rb +0 -244
  505. data/spec/unit/solr_query_spec.rb +0 -203
  506. data/spec/unit/webui_user_spec.rb +0 -238
@@ -50,7 +50,7 @@ describe Chef::Config do
50
50
  before do
51
51
  Chef::Config.chef_server_url = "https://junglist.gen.nz"
52
52
  end
53
-
53
+
54
54
  it_behaves_like "server URL"
55
55
  end
56
56
 
@@ -58,10 +58,54 @@ describe Chef::Config do
58
58
  before do
59
59
  Chef::Config.chef_server_url = " https://junglist.gen.nz"
60
60
  end
61
-
61
+
62
62
  it_behaves_like "server URL"
63
63
  end
64
64
 
65
+ describe "when configuring formatters" do
66
+ # if TTY and not(force-logger)
67
+ # formatter = configured formatter or default formatter
68
+ # formatter goes to STDOUT/ERR
69
+ # if log file is writeable
70
+ # log level is configured level or info
71
+ # log location is file
72
+ # else
73
+ # log level is warn
74
+ # log location is STDERR
75
+ # end
76
+ # elsif not(TTY) and force formatter
77
+ # formatter = configured formatter or default formatter
78
+ # if log_location specified
79
+ # formatter goes to log_location
80
+ # else
81
+ # formatter goes to STDOUT/ERR
82
+ # end
83
+ # else
84
+ # formatter = "null"
85
+ # log_location = configured-value or defualt
86
+ # log_level = info or defualt
87
+ # end
88
+ #
89
+ before do
90
+ @config_class = Class.new(Chef::Config)
91
+ end
92
+
93
+ it "has an empty list of formatters by default" do
94
+ @config_class.formatters.should == []
95
+ end
96
+
97
+ it "configures a formatter with a short name" do
98
+ @config_class.add_formatter(:doc)
99
+ @config_class.formatters.should == [[:doc, nil]]
100
+ end
101
+
102
+ it "configures a formatter with a file output" do
103
+ @config_class.add_formatter(:doc, "/var/log/formatter.log")
104
+ @config_class.formatters.should == [[:doc, "/var/log/formatter.log"]]
105
+ end
106
+
107
+ end
108
+
65
109
  context "when the url is a frozen string" do
66
110
  before do
67
111
  Chef::Config.chef_server_url = " https://junglist.gen.nz".freeze
@@ -217,17 +261,6 @@ describe Chef::Config do
217
261
  end
218
262
  end
219
263
 
220
- describe "Chef::Config[:event_handlers]" do
221
- it "sets a event_handlers to an empty array by default" do
222
- Chef::Config[:event_handlers].should eq([])
223
- end
224
- it "should be able to add custom handlers" do
225
- o = Object.new
226
- Chef::Config[:event_handlers] << o
227
- Chef::Config[:event_handlers].should be_include(o)
228
- end
229
- end
230
-
231
264
  after(:each) do
232
265
  Chef::Config.configuration = @original_config
233
266
  end
@@ -63,7 +63,6 @@ describe Chef::CookbookSynchronizer do
63
63
  "checksum" => "abc456" }
64
64
  @cookbook_a_manifest["attributes"] = [ @cookbook_a_default_attrs ]
65
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
66
  @cookbook_a.manifest = @cookbook_a_manifest
68
67
  @cookbook_manifest["cookbook_a"] = @cookbook_a
69
68
 
@@ -103,7 +102,7 @@ describe Chef::CookbookSynchronizer do
103
102
  before do
104
103
  # Would rather not stub out methods on the test subject, but setting up
105
104
  # the state is a PITA and tests for this behavior are above.
106
- @synchronizer.stub!(:clear_obsoleted_cookbooks)
105
+ @synchronizer.should_receive(:clear_obsoleted_cookbooks)
107
106
 
108
107
  @server_api = mock("Chef::REST (mock)")
109
108
  @file_cache = mock("Chef::FileCache (mock)")
@@ -163,53 +162,6 @@ describe Chef::CookbookSynchronizer do
163
162
  @synchronizer.sync_cookbooks
164
163
  end
165
164
 
166
- 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 = mock("Tempfile for cookbook_a megaman.conf file",
175
- :path => "/tmp/cookbook_a_file_default_tempfile")
176
- @cookbook_a_template_default_tempfile = mock("Tempfile for cookbook_a apache.conf.erb template",
177
- :path => "/tmp/cookbook_a_template_default_tempfile")
178
- end
179
-
180
- after do
181
- Chef::Config[:no_lazy_load] = false
182
- end
183
-
184
- 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
211
- end
212
- end
213
165
  end
214
166
 
215
167
  context "when the cache contains outdated files" do
@@ -16,175 +16,114 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- ###################################################
20
- # OLD:
21
- ###################################################
22
- # def test_ruby(cookbook_dir)
23
- # cache = Chef::ChecksumCache.instance
24
- # Dir[File.join(cookbook_dir, '**', '*.rb')].each do |ruby_file|
25
- # key = cache.generate_key(ruby_file, "chef-test")
26
- # fstat = File.stat(ruby_file)
27
- #
28
- # if cache.lookup_checksum(key, fstat)
29
- # Chef::Log.info("No change in checksum of #{ruby_file}")
30
- # else
31
- # Chef::Log.info("Testing #{ruby_file} for syntax errors...")
32
- # Chef::Mixin::Command.run_command(:command => "ruby -c #{ruby_file}", :output_on_failure => true)
33
- # cache.generate_checksum(key, ruby_file, fstat)
34
- # end
35
- # end
36
- # end
37
- #
38
- #def test_templates(cookbook_dir)
39
- # cache = Chef::ChecksumCache.instance
40
- # Dir[File.join(cookbook_dir, '**', '*.erb')].each do |erb_file|
41
- # key = cache.generate_key(erb_file, "chef-test")
42
- # fstat = File.stat(erb_file)
43
- #
44
- # if cache.lookup_checksum(key, fstat)
45
- # Chef::Log.info("No change in checksum of #{erb_file}")
46
- # else
47
- # Chef::Log.info("Testing template #{erb_file} for syntax errors...")
48
- # Chef::Mixin::Command.run_command(:command => "sh -c 'erubis -x #{erb_file} | ruby -c'", :output_on_failure => true)
49
- # cache.generate_checksum(key, erb_file, fstat)
50
- # end
51
- # end
52
- #end
53
- #
54
-
55
- ###################################################
56
- # NEW:
57
- ###################################################
58
- # def test_template_file(cookbook_dir, erb_file)
59
- # Chef::Log.debug("Testing template #{erb_file} for syntax errors...")
60
- # result = shell_out("sh -c 'erubis -x #{erb_file} | ruby -c'")
61
- # result.error!
62
- # rescue Mixlib::ShellOut::ShellCommandFailed
63
- # file_relative_path = erb_file[/^#{Regexp.escape(cookbook_dir+File::Separator)}(.*)/, 1]
64
- # Chef::Log.fatal("Erb template #{file_relative_path} has a syntax error:")
65
- # result.stderr.each_line { |l| Chef::Log.fatal(l.chomp) }
66
- # exit(1)
67
- # end
68
- #
69
- # def test_ruby_file(cookbook_dir, ruby_file)
70
- # Chef::Log.debug("Testing #{ruby_file} for syntax errors...")
71
- # result = shell_out("ruby -c #{ruby_file}")
72
- # result.error!
73
- # rescue Mixlib::ShellOut::ShellCommandFailed
74
- # file_relative_path = ruby_file[/^#{Regexp.escape(cookbook_dir+File::Separator)}(.*)/, 1]
75
- # Chef::Log.fatal("Cookbook file #{file_relative_path} has a syntax error:")
76
- # result.stderr.each_line { |l| Chef::Log.fatal(l.chomp) }
77
- # exit(1)
78
- # end
79
- #
80
-
81
19
  require 'spec_helper'
82
20
  require "chef/cookbook/syntax_check"
83
21
 
84
22
  describe Chef::Cookbook::SyntaxCheck do
23
+
24
+ let(:cookbook_path) { File.join(CHEF_SPEC_DATA, 'cookbooks', 'openldap') }
25
+ let(:syntax_check) { Chef::Cookbook::SyntaxCheck.new(cookbook_path) }
26
+
85
27
  before do
86
28
  Chef::Log.logger = Logger.new(StringIO.new)
29
+ Chef::Log.level = :warn # suppress "Syntax OK" messages
87
30
 
88
- @cookbook_path = File.join(CHEF_SPEC_DATA, 'cookbooks', 'openldap')
89
31
 
90
- @attr_files = %w{default.rb smokey.rb}.map { |f| File.join(@cookbook_path, 'attributes', f) }
91
- @defn_files = %w{client.rb server.rb}.map { |f| File.join(@cookbook_path, 'definitions', f)}
92
- @recipes = %w{default.rb gigantor.rb one.rb}.map { |f| File.join(@cookbook_path, 'recipes', f) }
32
+ @attr_files = %w{default.rb smokey.rb}.map { |f| File.join(cookbook_path, 'attributes', f) }
33
+ @defn_files = %w{client.rb server.rb}.map { |f| File.join(cookbook_path, 'definitions', f)}
34
+ @recipes = %w{default.rb gigantor.rb one.rb}.map { |f| File.join(cookbook_path, 'recipes', f) }
93
35
  @ruby_files = @attr_files + @defn_files + @recipes
94
36
 
95
- @template_files = %w{openldap_stuff.conf.erb openldap_variable_stuff.conf.erb test.erb}.map { |f| File.join(@cookbook_path, 'templates', 'default', f)}
37
+ @template_files = %w{openldap_stuff.conf.erb openldap_variable_stuff.conf.erb test.erb}.map { |f| File.join(cookbook_path, 'templates', 'default', f)}
96
38
 
97
- @syntax_check = Chef::Cookbook::SyntaxCheck.new(@cookbook_path)
98
39
  end
99
40
 
100
41
  it "creates a syntax checker given the cookbook name when Chef::Config.cookbook_path is set" do
101
- Chef::Config[:cookbook_path] = File.dirname(@cookbook_path)
42
+ Chef::Config[:cookbook_path] = File.dirname(cookbook_path)
102
43
  syntax_check = Chef::Cookbook::SyntaxCheck.for_cookbook(:openldap)
103
- syntax_check.cookbook_path.should == @cookbook_path
44
+ syntax_check.cookbook_path.should == cookbook_path
104
45
  end
105
46
 
106
47
  describe "when first created" do
107
48
  it "has the path to the cookbook to syntax check" do
108
- @syntax_check.cookbook_path.should == @cookbook_path
109
- end
110
-
111
- it "has access to the checksum cache" do
112
- @syntax_check.cache.should equal(Chef::ChecksumCache.instance)
49
+ syntax_check.cookbook_path.should == cookbook_path
113
50
  end
114
51
 
115
52
  it "lists the ruby files in the cookbook" do
116
- @syntax_check.ruby_files.sort.should == @ruby_files.sort
53
+ syntax_check.ruby_files.sort.should == @ruby_files.sort
117
54
  end
118
55
 
119
56
  it "lists the erb templates in the cookbook" do
120
- @syntax_check.template_files.sort.should == @template_files.sort
57
+ syntax_check.template_files.sort.should == @template_files.sort
121
58
  end
122
59
 
123
60
  end
124
61
 
125
62
  describe "when validating cookbooks" do
63
+ let(:cache_path) { Dir.mktmpdir }
64
+
126
65
  before do
127
- Chef::Config[:cache_type] = 'Memory'
128
- @checksum_cache_klass = Class.new(Chef::ChecksumCache)
129
- @checksum_cache = @checksum_cache_klass.instance
130
- @checksum_cache.reset!('Memory')
131
- @syntax_check.stub!(:cache).and_return(@checksum_cache)
132
- $stdout.stub!(:write)
66
+ Chef::Config[:syntax_check_cache_path] = cache_path
67
+ end
68
+
69
+ after do
70
+ FileUtils.rm_rf(cache_path) if File.exist?(cache_path)
71
+ Chef::Config[:syntax_check_cache_path] = nil
133
72
  end
134
73
 
135
74
  describe "and the files have not been syntax checked previously" do
136
75
  it "shows that all ruby files require a syntax check" do
137
- @syntax_check.untested_ruby_files.sort.should == @ruby_files.sort
76
+ syntax_check.untested_ruby_files.sort.should == @ruby_files.sort
138
77
  end
139
78
 
140
79
  it "shows that all template files require a syntax check" do
141
- @syntax_check.untested_template_files.sort.should == @template_files.sort
80
+ syntax_check.untested_template_files.sort.should == @template_files.sort
142
81
  end
143
82
 
144
83
  it "removes a ruby file from the list of untested files after it is marked as validated" do
145
- recipe = File.join(@cookbook_path, 'recipes', 'default.rb')
146
- @syntax_check.validated(recipe)
147
- @syntax_check.untested_ruby_files.should_not include(recipe)
84
+ recipe = File.join(cookbook_path, 'recipes', 'default.rb')
85
+ syntax_check.validated(recipe)
86
+ syntax_check.untested_ruby_files.should_not include(recipe)
148
87
  end
149
88
 
150
89
  it "removes a template file from the list of untested files after it is marked as validated" do
151
- template = File.join(@cookbook_path, 'templates', 'default', 'test.erb')
152
- @syntax_check.validated(template)
153
- @syntax_check.untested_template_files.should_not include(template)
90
+ template = File.join(cookbook_path, 'templates', 'default', 'test.erb')
91
+ syntax_check.validated(template)
92
+ syntax_check.untested_template_files.should_not include(template)
154
93
  end
155
94
 
156
95
  it "validates all ruby files" do
157
- @syntax_check.validate_ruby_files.should be_true
158
- @syntax_check.untested_ruby_files.should be_empty
96
+ syntax_check.validate_ruby_files.should be_true
97
+ syntax_check.untested_ruby_files.should be_empty
159
98
  end
160
99
 
161
100
  it "validates all templates" do
162
- @syntax_check.validate_templates.should be_true
163
- @syntax_check.untested_template_files.should be_empty
101
+ syntax_check.validate_templates.should be_true
102
+ syntax_check.untested_template_files.should be_empty
164
103
  end
165
104
 
166
105
  describe "and a file has a syntax error" do
167
106
  before do
168
- @cookbook_path = File.join(CHEF_SPEC_DATA, 'cookbooks', 'borken')
169
- @syntax_check.cookbook_path.replace(@cookbook_path)
107
+ cookbook_path = File.join(CHEF_SPEC_DATA, 'cookbooks', 'borken')
108
+ syntax_check.cookbook_path.replace(cookbook_path)
170
109
  end
171
110
 
172
111
  it "it indicates that a ruby file has a syntax error" do
173
- @syntax_check.validate_ruby_files.should be_false
112
+ syntax_check.validate_ruby_files.should be_false
174
113
  end
175
114
 
176
115
  it "does not remove the invalid file from the list of untested files" do
177
- @syntax_check.untested_ruby_files.should include(File.join(@cookbook_path, 'recipes', 'default.rb'))
178
- lambda { @syntax_check.validate_ruby_files }.should_not change(@syntax_check, :untested_ruby_files)
116
+ syntax_check.untested_ruby_files.should include(File.join(cookbook_path, 'recipes', 'default.rb'))
117
+ lambda { syntax_check.validate_ruby_files }.should_not change(syntax_check, :untested_ruby_files)
179
118
  end
180
119
 
181
120
  it "indicates that a template file has a syntax error" do
182
- @syntax_check.validate_templates.should be_false
121
+ syntax_check.validate_templates.should be_false
183
122
  end
184
123
 
185
124
  it "does not remove the invalid template from the list of untested templates" do
186
- @syntax_check.untested_template_files.should include(File.join(@cookbook_path, 'templates', 'default', 'borken.erb'))
187
- lambda {@syntax_check.validate_templates}.should_not change(@syntax_check, :untested_template_files)
125
+ syntax_check.untested_template_files.should include(File.join(cookbook_path, 'templates', 'default', 'borken.erb'))
126
+ lambda {syntax_check.validate_templates}.should_not change(syntax_check, :untested_template_files)
188
127
  end
189
128
 
190
129
  end
@@ -193,18 +132,18 @@ describe Chef::Cookbook::SyntaxCheck do
193
132
 
194
133
  describe "and the files have been syntax checked previously" do
195
134
  before do
196
- @syntax_check.untested_ruby_files.each { |f| @syntax_check.validated(f) }
197
- @syntax_check.untested_template_files.each { |f| @syntax_check.validated(f) }
135
+ syntax_check.untested_ruby_files.each { |f| syntax_check.validated(f) }
136
+ syntax_check.untested_template_files.each { |f| syntax_check.validated(f) }
198
137
  end
199
138
 
200
139
  it "does not syntax check ruby files" do
201
- @syntax_check.should_not_receive(:shell_out)
202
- @syntax_check.validate_ruby_files.should be_true
140
+ syntax_check.should_not_receive(:shell_out)
141
+ syntax_check.validate_ruby_files.should be_true
203
142
  end
204
143
 
205
144
  it "does not syntax check templates" do
206
- @syntax_check.should_not_receive(:shell_out)
207
- @syntax_check.validate_templates.should be_true
145
+ syntax_check.should_not_receive(:shell_out)
146
+ syntax_check.validate_templates.should be_true
208
147
  end
209
148
  end
210
149
  end
@@ -25,121 +25,183 @@ describe Chef::CookbookLoader do
25
25
  @cookbook_loader = Chef::CookbookLoader.new(@repo_paths)
26
26
  end
27
27
 
28
- describe "[]" do
29
- it "should return cookbook objects with []" do
30
- @cookbook_loader[:openldap].should be_a_kind_of(Chef::CookbookVersion)
28
+ describe "loading all cookbooks" do
29
+ before(:each) do
30
+ @cookbook_loader.load_cookbooks
31
31
  end
32
32
 
33
+ describe "[]" do
34
+ it "should return cookbook objects with []" do
35
+ @cookbook_loader[:openldap].should be_a_kind_of(Chef::CookbookVersion)
36
+ end
33
37
 
34
- it "should raise an exception if it cannot find a cookbook with []" do
35
- lambda { @cookbook_loader[:monkeypoop] }.should raise_error(Chef::Exceptions::CookbookNotFoundInRepo)
36
- end
37
-
38
- it "should allow you to look up available cookbooks with [] and a symbol" do
39
- @cookbook_loader[:openldap].name.should eql(:openldap)
40
- end
38
+ it "should raise an exception if it cannot find a cookbook with []" do
39
+ lambda { @cookbook_loader[:monkeypoop] }.should raise_error(Chef::Exceptions::CookbookNotFoundInRepo)
40
+ end
41
41
 
42
- it "should allow you to look up available cookbooks with [] and a string" do
43
- @cookbook_loader["openldap"].name.should eql(:openldap)
44
- end
45
- end
42
+ it "should allow you to look up available cookbooks with [] and a symbol" do
43
+ @cookbook_loader[:openldap].name.should eql(:openldap)
44
+ end
46
45
 
47
- describe "each" do
48
- it "should allow you to iterate over cookbooks with each" do
49
- seen = Hash.new
50
- @cookbook_loader.each do |cookbook_name, cookbook|
51
- seen[cookbook_name] = true
46
+ it "should allow you to look up available cookbooks with [] and a string" do
47
+ @cookbook_loader["openldap"].name.should eql(:openldap)
52
48
  end
53
- seen.should have_key("openldap")
54
- seen.should have_key("apache2")
55
49
  end
56
50
 
57
- it "should iterate in alphabetical order" do
58
- seen = Array.new
59
- @cookbook_loader.each do |cookbook_name, cookbook|
60
- seen << cookbook_name
51
+ describe "each" do
52
+ it "should allow you to iterate over cookbooks with each" do
53
+ seen = Hash.new
54
+ @cookbook_loader.each do |cookbook_name, cookbook|
55
+ seen[cookbook_name] = true
56
+ end
57
+ seen.should have_key("openldap")
58
+ seen.should have_key("apache2")
61
59
  end
62
- seen[0].should == "angrybash"
63
- seen[1].should == "apache2"
64
- seen[2].should == "borken"
65
- seen[3].should == "java"
66
- seen[4].should == "openldap"
67
- end
68
- end
69
60
 
70
- describe "load_cookbooks" do
71
- it "should find all the cookbooks in the cookbook path" do
72
- Chef::Config.cookbook_path << File.expand_path(File.join(CHEF_SPEC_DATA, "hidden-cookbooks"))
73
- @cookbook_loader.load_cookbooks
74
- @cookbook_loader.should have_key(:openldap)
75
- @cookbook_loader.should have_key(:apache2)
61
+ it "should iterate in alphabetical order" do
62
+ seen = Array.new
63
+ @cookbook_loader.each do |cookbook_name, cookbook|
64
+ seen << cookbook_name
65
+ end
66
+ seen[0].should == "angrybash"
67
+ seen[1].should == "apache2"
68
+ seen[2].should == "borken"
69
+ seen[3].should == "java"
70
+ seen[4].should == "openldap"
71
+ end
76
72
  end
73
+
74
+ describe "load_cookbooks" do
75
+ it "should find all the cookbooks in the cookbook path" do
76
+ Chef::Config.cookbook_path << File.expand_path(File.join(CHEF_SPEC_DATA, "hidden-cookbooks"))
77
+ @cookbook_loader.load_cookbooks
78
+ @cookbook_loader.should have_key(:openldap)
79
+ @cookbook_loader.should have_key(:apache2)
80
+ end
81
+
82
+ it "should allow you to override an attribute file via cookbook_path" do
83
+ @cookbook_loader[:openldap].attribute_filenames.detect { |f|
84
+ f =~ /cookbooks\/openldap\/attributes\/default.rb/
85
+ }.should_not eql(nil)
86
+ @cookbook_loader[:openldap].attribute_filenames.detect { |f|
87
+ f =~ /kitchen\/openldap\/attributes\/default.rb/
88
+ }.should eql(nil)
89
+ end
90
+
91
+ it "should load different attribute files from deeper paths" do
92
+ @cookbook_loader[:openldap].attribute_filenames.detect { |f|
93
+ f =~ /kitchen\/openldap\/attributes\/robinson.rb/
94
+ }.should_not eql(nil)
95
+ end
96
+
97
+ it "should allow you to override a definition file via cookbook_path" do
98
+ @cookbook_loader[:openldap].definition_filenames.detect { |f|
99
+ f =~ /cookbooks\/openldap\/definitions\/client.rb/
100
+ }.should_not eql(nil)
101
+ @cookbook_loader[:openldap].definition_filenames.detect { |f|
102
+ f =~ /kitchen\/openldap\/definitions\/client.rb/
103
+ }.should eql(nil)
104
+ end
105
+
106
+ it "should load definition files from deeper paths" do
107
+ @cookbook_loader[:openldap].definition_filenames.detect { |f|
108
+ f =~ /kitchen\/openldap\/definitions\/drewbarrymore.rb/
109
+ }.should_not eql(nil)
110
+ end
111
+
112
+ it "should allow you to override a recipe file via cookbook_path" do
113
+ @cookbook_loader[:openldap].recipe_filenames.detect { |f|
114
+ f =~ /cookbooks\/openldap\/recipes\/gigantor.rb/
115
+ }.should_not eql(nil)
116
+ @cookbook_loader[:openldap].recipe_filenames.detect { |f|
117
+ f =~ /kitchen\/openldap\/recipes\/gigantor.rb/
118
+ }.should eql(nil)
119
+ end
120
+
121
+ it "should load recipe files from deeper paths" do
122
+ @cookbook_loader[:openldap].recipe_filenames.detect { |f|
123
+ f =~ /kitchen\/openldap\/recipes\/woot.rb/
124
+ }.should_not eql(nil)
125
+ end
126
+
127
+ it "should allow you to have an 'ignore' file, which skips loading files in later cookbooks" do
128
+ @cookbook_loader[:openldap].recipe_filenames.detect { |f|
129
+ f =~ /kitchen\/openldap\/recipes\/ignoreme.rb/
130
+ }.should eql(nil)
131
+ end
132
+
133
+ it "should find files that start with a ." do
134
+ @cookbook_loader[:openldap].file_filenames.detect { |f|
135
+ f =~ /\.dotfile$/
136
+ }.should =~ /\.dotfile$/
137
+ @cookbook_loader[:openldap].file_filenames.detect { |f|
138
+ f =~ /\.ssh\/id_rsa$/
139
+ }.should =~ /\.ssh\/id_rsa$/
140
+ end
141
+
142
+ it "should load the metadata for the cookbook" do
143
+ @cookbook_loader.metadata[:openldap].name.should == :openldap
144
+ @cookbook_loader.metadata[:openldap].should be_a_kind_of(Chef::Cookbook::Metadata)
145
+ end
77
146
 
78
- it "should allow you to override an attribute file via cookbook_path" do
79
- @cookbook_loader[:openldap].attribute_filenames.detect { |f|
80
- f =~ /cookbooks\/openldap\/attributes\/default.rb/
81
- }.should_not eql(nil)
82
- @cookbook_loader[:openldap].attribute_filenames.detect { |f|
83
- f =~ /kitchen\/openldap\/attributes\/default.rb/
84
- }.should eql(nil)
85
- end
147
+ it "should check each cookbook directory only once (CHEF-3487)" do
148
+ cookbooks = []
149
+ @repo_paths.each do |repo_path|
150
+ cookbooks |= Dir[File.join(repo_path, "*")]
151
+ end
152
+ cookbooks.each do |cookbook|
153
+ File.should_receive(:directory?).with(cookbook).once;
154
+ end
155
+ @cookbook_loader.load_cookbooks
156
+ end
157
+ end # load_cookbooks
86
158
 
87
- it "should load different attribute files from deeper paths" do
88
- @cookbook_loader[:openldap].attribute_filenames.detect { |f|
89
- f =~ /kitchen\/openldap\/attributes\/robinson.rb/
90
- }.should_not eql(nil)
91
- end
159
+ end # loading all cookbooks
92
160
 
93
- it "should allow you to override a definition file via cookbook_path" do
94
- @cookbook_loader[:openldap].definition_filenames.detect { |f|
95
- f =~ /cookbooks\/openldap\/definitions\/client.rb/
96
- }.should_not eql(nil)
97
- @cookbook_loader[:openldap].definition_filenames.detect { |f|
98
- f =~ /kitchen\/openldap\/definitions\/client.rb/
99
- }.should eql(nil)
161
+ describe "loading only one cookbook" do
162
+ before(:each) do
163
+ @cookbook_loader = Chef::CookbookLoader.new(@repo_paths)
164
+ @cookbook_loader.load_cookbook("openldap")
100
165
  end
101
166
 
102
- it "should load definition files from deeper paths" do
103
- @cookbook_loader[:openldap].definition_filenames.detect { |f|
104
- f =~ /kitchen\/openldap\/definitions\/drewbarrymore.rb/
105
- }.should_not eql(nil)
167
+ it "should have loaded the correct cookbook" do
168
+ seen = Hash.new
169
+ @cookbook_loader.each do |cookbook_name, cookbook|
170
+ seen[cookbook_name] = true
171
+ end
172
+ seen.should have_key("openldap")
106
173
  end
107
174
 
108
- it "should allow you to override a recipe file via cookbook_path" do
109
- @cookbook_loader[:openldap].recipe_filenames.detect { |f|
110
- f =~ /cookbooks\/openldap\/recipes\/gigantor.rb/
111
- }.should_not eql(nil)
112
- @cookbook_loader[:openldap].recipe_filenames.detect { |f|
113
- f =~ /kitchen\/openldap\/recipes\/gigantor.rb/
114
- }.should eql(nil)
175
+ it "should not load the cookbook again when accessed" do
176
+ @cookbook_loader.should_not_receive('load_cookbook')
177
+ @cookbook_loader["openldap"]
115
178
  end
116
179
 
117
- it "should load recipe files from deeper paths" do
118
- @cookbook_loader[:openldap].recipe_filenames.detect { |f|
119
- f =~ /kitchen\/openldap\/recipes\/woot.rb/
120
- }.should_not eql(nil)
180
+ it "should not load the other cookbooks" do
181
+ seen = Hash.new
182
+ @cookbook_loader.each do |cookbook_name, cookbook|
183
+ seen[cookbook_name] = true
184
+ end
185
+ seen.should_not have_key("apache2")
121
186
  end
122
187
 
123
- it "should allow you to have an 'ignore' file, which skips loading files in later cookbooks" do
124
- @cookbook_loader[:openldap].recipe_filenames.detect { |f|
125
- f =~ /kitchen\/openldap\/recipes\/ignoreme.rb/
126
- }.should eql(nil)
188
+ it "should load another cookbook lazily with []" do
189
+ @cookbook_loader["apache2"].should be_a_kind_of(Chef::CookbookVersion)
127
190
  end
128
191
 
129
- it "should find files that start with a ." do
130
- @cookbook_loader[:openldap].file_filenames.detect { |f|
131
- f =~ /\.dotfile$/
132
- }.should =~ /\.dotfile$/
133
- @cookbook_loader[:openldap].file_filenames.detect { |f|
134
- f =~ /\.ssh\/id_rsa$/
135
- }.should =~ /\.ssh\/id_rsa$/
136
- end
192
+ describe "loading all cookbooks after loading only one cookbook" do
193
+ before(:each) do
194
+ @cookbook_loader.load_cookbooks
195
+ end
137
196
 
138
- it "should load the metadata for the cookbook" do
139
- @cookbook_loader.metadata[:openldap].name.should == :openldap
140
- @cookbook_loader.metadata[:openldap].should be_a_kind_of(Chef::Cookbook::Metadata)
197
+ it "should load all cookbooks" do
198
+ seen = Hash.new
199
+ @cookbook_loader.each do |cookbook_name, cookbook|
200
+ seen[cookbook_name] = true
201
+ end
202
+ seen.should have_key("openldap")
203
+ seen.should have_key("apache2")
204
+ end
141
205
  end
142
-
143
- end
144
-
206
+ end # loading only one cookbook
145
207
  end