chef 12.4.3-universal-mingw32 → 12.5.1-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (320) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +21 -25
  3. data/Gemfile +46 -0
  4. data/README.md +4 -4
  5. data/Rakefile +4 -110
  6. data/bin/chef-service-manager +3 -1
  7. data/distro/common/html/knife_cookbook_site.html +18 -18
  8. data/distro/common/man/man1/knife-cookbook-site.1 +11 -11
  9. data/lib/chef.rb +1 -1
  10. data/lib/chef/application.rb +1 -1
  11. data/lib/chef/application/apply.rb +19 -1
  12. data/lib/chef/application/client.rb +11 -5
  13. data/lib/chef/application/knife.rb +2 -2
  14. data/lib/chef/application/solo.rb +1 -1
  15. data/lib/chef/application/windows_service_manager.rb +19 -12
  16. data/lib/chef/chef_class.rb +46 -0
  17. data/lib/chef/chef_fs/config.rb +22 -24
  18. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +3 -1
  19. data/lib/chef/chef_fs/file_pattern.rb +4 -15
  20. data/lib/chef/chef_fs/file_system/acl_dir.rb +3 -4
  21. data/lib/chef/chef_fs/file_system/acls_dir.rb +5 -1
  22. data/lib/chef/chef_fs/file_system/base_fs_dir.rb +0 -5
  23. data/lib/chef/chef_fs/file_system/base_fs_object.rb +5 -2
  24. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +2 -9
  25. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +2 -9
  26. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +10 -17
  27. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -12
  28. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +15 -11
  29. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +8 -2
  30. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +4 -4
  31. data/lib/chef/chef_fs/file_system/cookbooks_acl_dir.rb +1 -1
  32. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -11
  33. data/lib/chef/chef_fs/file_system/data_bags_dir.rb +3 -5
  34. data/lib/chef/chef_fs/file_system/environments_dir.rb +1 -1
  35. data/lib/chef/chef_fs/file_system/file_system_entry.rb +7 -4
  36. data/lib/chef/chef_fs/file_system/memory_dir.rb +2 -3
  37. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +15 -0
  38. data/lib/chef/chef_fs/file_system/nodes_dir.rb +1 -1
  39. data/lib/chef/chef_fs/file_system/organization_members_entry.rb +2 -2
  40. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +4 -9
  41. data/lib/chef/chef_fs/knife.rb +35 -7
  42. data/lib/chef/chef_fs/path_utils.rb +65 -34
  43. data/lib/chef/client.rb +2 -3
  44. data/lib/chef/config.rb +34 -2
  45. data/lib/chef/{mixin/wstring.rb → constants.rb} +9 -13
  46. data/lib/chef/cookbook/metadata.rb +25 -3
  47. data/lib/chef/cookbook/synchronizer.rb +1 -1
  48. data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
  49. data/lib/chef/cookbook_version.rb +3 -3
  50. data/lib/chef/delayed_evaluator.rb +21 -0
  51. data/lib/chef/deprecation/mixin/template.rb +1 -2
  52. data/lib/chef/deprecation/provider/cookbook_file.rb +1 -1
  53. data/lib/chef/deprecation/provider/file.rb +1 -1
  54. data/lib/chef/deprecation/provider/remote_directory.rb +52 -0
  55. data/lib/chef/deprecation/provider/remote_file.rb +1 -2
  56. data/lib/chef/deprecation/provider/template.rb +1 -1
  57. data/lib/chef/deprecation/warnings.rb +3 -4
  58. data/lib/chef/dsl/reboot_pending.rb +3 -2
  59. data/lib/chef/dsl/recipe.rb +26 -7
  60. data/lib/chef/dsl/resources.rb +2 -2
  61. data/lib/chef/event_dispatch/base.rb +51 -22
  62. data/lib/chef/event_dispatch/dispatcher.rb +21 -6
  63. data/lib/chef/event_dispatch/dsl.rb +64 -0
  64. data/lib/chef/exceptions.rb +28 -1
  65. data/lib/chef/file_content_management/tempfile.rb +1 -1
  66. data/lib/chef/formatters/base.rb +3 -0
  67. data/lib/chef/formatters/doc.rb +56 -6
  68. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +36 -0
  69. data/lib/chef/formatters/minimal.rb +2 -2
  70. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +3 -1
  71. data/lib/chef/http/http_request.rb +1 -1
  72. data/lib/chef/knife.rb +35 -55
  73. data/lib/chef/knife/bootstrap.rb +41 -0
  74. data/lib/chef/knife/bootstrap/chef_vault_handler.rb +1 -0
  75. data/lib/chef/knife/bootstrap/client_builder.rb +16 -0
  76. data/lib/chef/knife/bootstrap/templates/README.md +3 -4
  77. data/lib/chef/knife/bootstrap/templates/chef-full.erb +1 -1
  78. data/lib/chef/knife/cookbook_create.rb +1 -1
  79. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  80. data/lib/chef/knife/cookbook_site_install.rb +1 -1
  81. data/lib/chef/knife/cookbook_site_share.rb +6 -6
  82. data/lib/chef/knife/cookbook_site_unshare.rb +2 -2
  83. data/lib/chef/knife/core/bootstrap_context.rb +12 -4
  84. data/lib/chef/knife/core/custom_manifest_loader.rb +69 -0
  85. data/lib/chef/knife/core/gem_glob_loader.rb +138 -0
  86. data/lib/chef/knife/core/hashed_command_loader.rb +80 -0
  87. data/lib/chef/knife/core/node_presenter.rb +24 -1
  88. data/lib/chef/knife/core/object_loader.rb +1 -0
  89. data/lib/chef/knife/core/subcommand_loader.rb +131 -146
  90. data/lib/chef/knife/node_run_list_remove.rb +12 -1
  91. data/lib/chef/knife/null.rb +10 -0
  92. data/lib/chef/knife/rehash.rb +62 -0
  93. data/lib/chef/knife/search.rb +3 -3
  94. data/lib/chef/knife/ssh.rb +52 -30
  95. data/lib/chef/knife/ssl_check.rb +3 -2
  96. data/lib/chef/knife/user_edit.rb +1 -2
  97. data/lib/chef/local_mode.rb +5 -0
  98. data/lib/chef/log.rb +5 -1
  99. data/lib/chef/mixin/deprecation.rb +8 -8
  100. data/lib/chef/mixin/params_validate.rb +362 -135
  101. data/lib/chef/mixin/template.rb +48 -0
  102. data/lib/chef/mixin/which.rb +1 -1
  103. data/lib/chef/mixin/wide_string.rb +72 -0
  104. data/lib/chef/mixin/windows_architecture_helper.rb +15 -39
  105. data/lib/chef/mixin/windows_env_helper.rb +4 -1
  106. data/lib/chef/monkey_patches/webrick-utils.rb +51 -0
  107. data/lib/chef/monkey_patches/win32/registry.rb +72 -0
  108. data/lib/chef/node.rb +116 -3
  109. data/lib/chef/node_map.rb +2 -2
  110. data/lib/chef/platform/handler_map.rb +0 -5
  111. data/lib/chef/platform/provider_mapping.rb +5 -6
  112. data/lib/chef/platform/query_helpers.rb +46 -4
  113. data/lib/chef/platform/rebooter.rb +1 -1
  114. data/lib/chef/platform/service_helpers.rb +30 -32
  115. data/lib/chef/policy_builder.rb +1 -8
  116. data/lib/chef/policy_builder/dynamic.rb +186 -0
  117. data/lib/chef/policy_builder/expand_node_object.rb +30 -15
  118. data/lib/chef/policy_builder/policyfile.rb +155 -18
  119. data/lib/chef/property.rb +568 -0
  120. data/lib/chef/provider.rb +222 -13
  121. data/lib/chef/provider/batch.rb +8 -0
  122. data/lib/chef/provider/deploy.rb +5 -7
  123. data/lib/chef/provider/directory.rb +14 -2
  124. data/lib/chef/provider/dsc_resource.rb +5 -9
  125. data/lib/chef/provider/group/pw.rb +1 -1
  126. data/lib/chef/provider/ifconfig.rb +2 -2
  127. data/lib/chef/provider/lwrp_base.rb +1 -75
  128. data/lib/chef/provider/mount.rb +7 -3
  129. data/lib/chef/provider/package.rb +1 -1
  130. data/lib/chef/provider/package/dpkg.rb +5 -11
  131. data/lib/chef/provider/package/rpm.rb +2 -2
  132. data/lib/chef/provider/package/rubygems.rb +1 -1
  133. data/lib/chef/provider/package/windows/msi.rb +2 -2
  134. data/lib/chef/provider/package/yum.rb +17 -5
  135. data/lib/chef/provider/powershell_script.rb +59 -23
  136. data/lib/chef/provider/registry_key.rb +5 -5
  137. data/lib/chef/provider/remote_directory.rb +190 -102
  138. data/lib/chef/provider/service.rb +12 -2
  139. data/lib/chef/provider/service/aix.rb +1 -1
  140. data/lib/chef/provider/service/debian.rb +3 -5
  141. data/lib/chef/provider/service/freebsd.rb +1 -1
  142. data/lib/chef/provider/service/gentoo.rb +3 -3
  143. data/lib/chef/provider/service/init.rb +3 -3
  144. data/lib/chef/provider/service/insserv.rb +2 -4
  145. data/lib/chef/provider/service/invokercd.rb +2 -4
  146. data/lib/chef/provider/service/macosx.rb +5 -1
  147. data/lib/chef/provider/service/openbsd.rb +2 -1
  148. data/lib/chef/provider/service/redhat.rb +52 -16
  149. data/lib/chef/provider/service/simple.rb +2 -2
  150. data/lib/chef/provider/service/systemd.rb +3 -5
  151. data/lib/chef/provider/service/upstart.rb +4 -6
  152. data/lib/chef/provider/subversion.rb +13 -7
  153. data/lib/chef/provider/template/content.rb +16 -6
  154. data/lib/chef/provider/user/solaris.rb +32 -4
  155. data/lib/chef/provider/windows_script.rb +3 -5
  156. data/lib/chef/provider_resolver.rb +2 -2
  157. data/lib/chef/recipe.rb +1 -8
  158. data/lib/chef/resource.rb +563 -90
  159. data/lib/chef/resource/action_class.rb +83 -0
  160. data/lib/chef/resource/chef_gem.rb +3 -3
  161. data/lib/chef/resource/deploy.rb +8 -2
  162. data/lib/chef/resource/dsc_script.rb +2 -0
  163. data/lib/chef/resource/file/verification.rb +7 -1
  164. data/lib/chef/resource/lwrp_base.rb +1 -7
  165. data/lib/chef/resource/registry_key.rb +1 -1
  166. data/lib/chef/resource/service.rb +10 -2
  167. data/lib/chef/resource/subversion.rb +5 -0
  168. data/lib/chef/resource/windows_script.rb +6 -2
  169. data/lib/chef/resource/yum_package.rb +10 -1
  170. data/lib/chef/resource_resolver.rb +3 -3
  171. data/lib/chef/run_context.rb +402 -83
  172. data/lib/chef/run_list/versioned_recipe_list.rb +15 -0
  173. data/lib/chef/run_lock.rb +30 -21
  174. data/lib/chef/util/powershell/ps_credential.rb +4 -0
  175. data/lib/chef/util/windows.rb +0 -32
  176. data/lib/chef/util/windows/net_group.rb +85 -106
  177. data/lib/chef/util/windows/net_use.rb +35 -71
  178. data/lib/chef/util/windows/net_user.rb +0 -1
  179. data/lib/chef/util/windows/volume.rb +19 -19
  180. data/lib/chef/version.rb +3 -3
  181. data/lib/chef/win32/api.rb +1 -0
  182. data/lib/chef/win32/api/file.rb +20 -0
  183. data/lib/chef/win32/api/net.rb +163 -43
  184. data/lib/chef/win32/api/registry.rb +51 -0
  185. data/lib/chef/win32/api/system.rb +23 -0
  186. data/lib/chef/win32/api/unicode.rb +0 -43
  187. data/lib/chef/win32/crypto.rb +2 -1
  188. data/lib/chef/win32/file.rb +28 -3
  189. data/lib/chef/win32/mutex.rb +1 -2
  190. data/lib/chef/win32/net.rb +162 -8
  191. data/lib/chef/win32/process.rb +13 -0
  192. data/lib/chef/win32/registry.rb +35 -30
  193. data/lib/chef/win32/security.rb +1 -1
  194. data/lib/chef/win32/security/token.rb +1 -1
  195. data/lib/chef/win32/system.rb +62 -0
  196. data/lib/chef/win32/unicode.rb +7 -2
  197. data/lib/chef/win32/version.rb +0 -4
  198. data/lib/chef/workstation_config_loader.rb +3 -158
  199. data/spec/data/cookbooks/openldap/templates/default/helpers.erb +14 -0
  200. data/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb +1 -0
  201. data/spec/data/cookbooks/openldap/templates/default/nested_partial.erb +1 -0
  202. data/spec/data/dsc_lcm.pfx +0 -0
  203. data/spec/data/run_context/cookbooks/include/recipes/default.rb +24 -0
  204. data/spec/data/run_context/cookbooks/include/recipes/includee.rb +3 -0
  205. data/spec/functional/dsl/reboot_pending_spec.rb +33 -43
  206. data/spec/functional/knife/cookbook_delete_spec.rb +17 -7
  207. data/spec/functional/knife/ssh_spec.rb +16 -0
  208. data/spec/functional/rebooter_spec.rb +1 -1
  209. data/spec/functional/resource/deploy_revision_spec.rb +1 -1
  210. data/spec/functional/resource/dsc_resource_spec.rb +2 -0
  211. data/spec/functional/resource/dsc_script_spec.rb +91 -2
  212. data/spec/functional/resource/group_spec.rb +67 -44
  213. data/spec/functional/resource/{powershell_spec.rb → powershell_script_spec.rb} +107 -18
  214. data/spec/functional/resource/windows_service_spec.rb +1 -1
  215. data/spec/functional/run_lock_spec.rb +368 -189
  216. data/spec/functional/win32/{registry_helper_spec.rb → registry_spec.rb} +16 -23
  217. data/spec/functional/win32/service_manager_spec.rb +2 -2
  218. data/spec/integration/client/client_spec.rb +51 -0
  219. data/spec/integration/knife/chef_repo_path_spec.rb +13 -11
  220. data/spec/integration/knife/download_spec.rb +4 -0
  221. data/spec/integration/knife/list_spec.rb +8 -0
  222. data/spec/integration/knife/upload_spec.rb +1 -1
  223. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -16
  224. data/spec/integration/recipes/remote_directory.rb +74 -0
  225. data/spec/integration/recipes/resource_action_spec.rb +363 -0
  226. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +423 -0
  227. data/spec/integration/recipes/resource_load_spec.rb +206 -0
  228. data/spec/spec_helper.rb +9 -0
  229. data/spec/support/platform_helpers.rb +13 -0
  230. data/spec/support/shared/context/win32.rb +34 -0
  231. data/spec/support/shared/functional/win32_service.rb +2 -1
  232. data/spec/support/shared/functional/windows_script.rb +63 -26
  233. data/spec/support/shared/unit/mock_shellout.rb +46 -0
  234. data/spec/support/shared/unit/provider/file.rb +10 -4
  235. data/spec/unit/application/client_spec.rb +16 -3
  236. data/spec/unit/application/knife_spec.rb +2 -2
  237. data/spec/unit/application/solo_spec.rb +4 -3
  238. data/spec/unit/chef_class_spec.rb +23 -4
  239. data/spec/unit/chef_fs/path_util_spec.rb +108 -0
  240. data/spec/unit/client_spec.rb +6 -1
  241. data/spec/unit/config_spec.rb +31 -0
  242. data/spec/unit/cookbook/metadata_spec.rb +23 -3
  243. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  244. data/spec/unit/deprecation_spec.rb +3 -6
  245. data/spec/unit/dsl/reboot_pending_spec.rb +12 -6
  246. data/spec/unit/event_dispatch/dispatcher_spec.rb +65 -3
  247. data/spec/unit/event_dispatch/dsl_spec.rb +83 -0
  248. data/spec/unit/formatters/doc_spec.rb +32 -0
  249. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +26 -0
  250. data/spec/unit/json_compat_spec.rb +4 -3
  251. data/spec/unit/knife/bootstrap/client_builder_spec.rb +27 -0
  252. data/spec/unit/knife/bootstrap_spec.rb +55 -3
  253. data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
  254. data/spec/unit/knife/core/bootstrap_context_spec.rb +21 -4
  255. data/spec/unit/knife/core/custom_manifest_loader_spec.rb +41 -0
  256. data/spec/unit/knife/core/gem_glob_loader_spec.rb +210 -0
  257. data/spec/unit/knife/core/hashed_command_loader_spec.rb +93 -0
  258. data/spec/unit/knife/core/subcommand_loader_spec.rb +16 -192
  259. data/spec/unit/knife/node_run_list_remove_spec.rb +17 -0
  260. data/spec/unit/knife/ssl_check_spec.rb +4 -0
  261. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +10 -10
  262. data/spec/unit/mixin/params_validate_spec.rb +4 -2
  263. data/spec/unit/mixin/template_spec.rb +5 -1
  264. data/spec/unit/mixin/windows_architecture_helper_spec.rb +13 -8
  265. data/spec/unit/node_spec.rb +220 -0
  266. data/spec/unit/platform/query_helpers_spec.rb +146 -3
  267. data/spec/unit/policy_builder/dynamic_spec.rb +275 -0
  268. data/spec/unit/policy_builder/expand_node_object_spec.rb +37 -38
  269. data/spec/unit/policy_builder/policyfile_spec.rb +260 -46
  270. data/spec/unit/property/state_spec.rb +506 -0
  271. data/spec/unit/property/validation_spec.rb +663 -0
  272. data/spec/unit/property_spec.rb +1094 -0
  273. data/spec/unit/provider/deploy_spec.rb +5 -5
  274. data/spec/unit/provider/directory_spec.rb +35 -0
  275. data/spec/unit/provider/dsc_resource_spec.rb +3 -10
  276. data/spec/unit/provider/ifconfig_spec.rb +22 -2
  277. data/spec/unit/provider/mount/aix_spec.rb +2 -1
  278. data/spec/unit/provider/mount/mount_spec.rb +6 -0
  279. data/spec/unit/provider/mount/windows_spec.rb +14 -0
  280. data/spec/unit/provider/mount_spec.rb +12 -1
  281. data/spec/unit/provider/package/dpkg_spec.rb +8 -1
  282. data/spec/unit/provider/package/rpm_spec.rb +18 -1
  283. data/spec/unit/provider/package/rubygems_spec.rb +18 -0
  284. data/spec/unit/provider/package/yum_spec.rb +97 -24
  285. data/spec/unit/provider/powershell_script_spec.rb +106 -0
  286. data/spec/unit/provider/registry_key_spec.rb +12 -0
  287. data/spec/unit/provider/remote_directory_spec.rb +1 -2
  288. data/spec/unit/provider/service/aix_service_spec.rb +3 -3
  289. data/spec/unit/provider/service/gentoo_service_spec.rb +4 -4
  290. data/spec/unit/provider/service/macosx_spec.rb +4 -4
  291. data/spec/unit/provider/service/openbsd_service_spec.rb +10 -8
  292. data/spec/unit/provider/service/redhat_spec.rb +88 -8
  293. data/spec/unit/provider/service/upstart_service_spec.rb +11 -7
  294. data/spec/unit/provider/service/windows_spec.rb +211 -200
  295. data/spec/unit/provider/subversion_spec.rb +50 -31
  296. data/spec/unit/provider/template/content_spec.rb +93 -2
  297. data/spec/unit/provider/user/solaris_spec.rb +66 -9
  298. data/spec/unit/provider_resolver_spec.rb +707 -650
  299. data/spec/unit/provider_spec.rb +1 -3
  300. data/spec/unit/recipe_spec.rb +0 -4
  301. data/spec/unit/resource/deploy_spec.rb +7 -1
  302. data/spec/unit/resource/dsc_script_spec.rb +4 -0
  303. data/spec/unit/resource/file/verification_spec.rb +33 -5
  304. data/spec/unit/resource/{powershell_spec.rb → powershell_script_spec.rb} +17 -13
  305. data/spec/unit/resource/service_spec.rb +4 -4
  306. data/spec/unit/resource/subversion_spec.rb +4 -0
  307. data/spec/unit/resource/yum_package_spec.rb +10 -1
  308. data/spec/unit/resource_spec.rb +2 -2
  309. data/spec/unit/run_context/child_run_context_spec.rb +133 -0
  310. data/spec/unit/run_context_spec.rb +7 -0
  311. data/spec/unit/run_list/versioned_recipe_list_spec.rb +5 -0
  312. data/spec/unit/win32/registry_spec.rb +394 -0
  313. data/tasks/external_tests.rb +47 -23
  314. data/tasks/maintainers.rb +155 -14
  315. metadata +64 -53
  316. data/lib/chef/knife/bootstrap/templates/archlinux-gems.erb +0 -76
  317. data/lib/chef/knife/bootstrap/templates/chef-aix.erb +0 -72
  318. data/spec/unit/provider/powershell_spec.rb +0 -80
  319. data/spec/unit/registry_helper_spec.rb +0 -376
  320. data/spec/unit/workstation_config_loader_spec.rb +0 -283
@@ -0,0 +1,663 @@
1
+ require 'support/shared/integration/integration_helper'
2
+
3
+ describe "Chef::Resource.property validation" do
4
+ include IntegrationSupport
5
+
6
+ module Namer
7
+ @i = 0
8
+ def self.next_resource_name
9
+ "chef_resource_property_spec_#{@i += 1}"
10
+ end
11
+ def self.reset_index
12
+ @current_index = 0
13
+ end
14
+ def self.current_index
15
+ @current_index
16
+ end
17
+ def self.next_index
18
+ @current_index += 1
19
+ end
20
+ end
21
+
22
+ def lazy(&block)
23
+ Chef::DelayedEvaluator.new(&block)
24
+ end
25
+
26
+ before do
27
+ Namer.reset_index
28
+ end
29
+
30
+ def self.new_resource_name
31
+ Namer.next_resource_name
32
+ end
33
+
34
+ let(:resource_class) do
35
+ new_resource_name = self.class.new_resource_name
36
+ Class.new(Chef::Resource) do
37
+ resource_name new_resource_name
38
+ def blah
39
+ Namer.next_index
40
+ end
41
+ def self.blah
42
+ "class#{Namer.next_index}"
43
+ end
44
+ end
45
+ end
46
+
47
+ let(:resource) do
48
+ resource_class.new("blah")
49
+ end
50
+
51
+ def self.english_join(values)
52
+ return '<nothing>' if values.size == 0
53
+ return values[0].inspect if values.size == 1
54
+ "#{values[0..-2].map { |v| v.inspect }.join(", ")} and #{values[-1].inspect}"
55
+ end
56
+
57
+ def self.with_property(*properties, &block)
58
+ tags_index = properties.find_index { |p| !p.is_a?(String)}
59
+ if tags_index
60
+ properties, tags = properties[0..tags_index-1], properties[tags_index..-1]
61
+ else
62
+ tags = []
63
+ end
64
+ properties = properties.map { |property| "property #{property}" }
65
+ context "With properties #{english_join(properties)}", *tags do
66
+ before do
67
+ properties.each do |property_str|
68
+ resource_class.class_eval(property_str, __FILE__, __LINE__)
69
+ end
70
+ end
71
+ instance_eval(&block)
72
+ end
73
+ end
74
+
75
+ def self.validation_test(validation, success_values, failure_values, getter_values=[], *tags)
76
+ with_property ":x, #{validation}", *tags do
77
+ it "gets nil when retrieving the initial (non-set) value" do
78
+ expect(resource.x).to be_nil
79
+ end
80
+ success_values.each do |v|
81
+ it "value #{v.inspect} is valid" do
82
+ resource.instance_eval { @x = 'default' }
83
+ expect(resource.x v).to eq v
84
+ expect(resource.x).to eq v
85
+ end
86
+ end
87
+ failure_values.each do |v|
88
+ it "value #{v.inspect} is invalid" do
89
+ expect { resource.x v }.to raise_error Chef::Exceptions::ValidationFailed
90
+ resource.instance_eval { @x = 'default' }
91
+ expect { resource.x v }.to raise_error Chef::Exceptions::ValidationFailed
92
+ end
93
+ end
94
+ getter_values.each do |v|
95
+ it "setting value to #{v.inspect} does not change the value" do
96
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
97
+ resource.instance_eval { @x = 'default' }
98
+ expect(resource.x v).to eq 'default'
99
+ expect(resource.x).to eq 'default'
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ context "basic get, set, and nil set" do
106
+ with_property ":x, kind_of: String" do
107
+ context "when the variable already has a value" do
108
+ before do
109
+ resource.instance_eval { @x = 'default' }
110
+ end
111
+ it "get succeeds" do
112
+ expect(resource.x).to eq 'default'
113
+ end
114
+ it "set to valid value succeeds" do
115
+ expect(resource.x 'str').to eq 'str'
116
+ expect(resource.x).to eq 'str'
117
+ end
118
+ it "set to invalid value raises ValidationFailed" do
119
+ expect { resource.x 10 }.to raise_error Chef::Exceptions::ValidationFailed
120
+ end
121
+ it "set to nil emits a deprecation warning and does a get" do
122
+ expect { resource.x nil }.to raise_error Chef::Exceptions::DeprecatedFeatureError
123
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
124
+ resource.x 'str'
125
+ expect(resource.x nil).to eq 'str'
126
+ expect(resource.x).to eq 'str'
127
+ end
128
+ end
129
+ context "when the variable does not have an initial value" do
130
+ it "get succeeds" do
131
+ expect(resource.x).to be_nil
132
+ end
133
+ it "set to valid value succeeds" do
134
+ expect(resource.x 'str').to eq 'str'
135
+ expect(resource.x).to eq 'str'
136
+ end
137
+ it "set to invalid value raises ValidationFailed" do
138
+ expect { resource.x 10 }.to raise_error Chef::Exceptions::ValidationFailed
139
+ end
140
+ it "set to nil emits a deprecation warning and does a get" do
141
+ expect { resource.x nil }.to raise_error Chef::Exceptions::DeprecatedFeatureError
142
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
143
+ resource.x 'str'
144
+ expect(resource.x nil).to eq 'str'
145
+ expect(resource.x).to eq 'str'
146
+ end
147
+ end
148
+ end
149
+ with_property ":x, [ String, nil ]" do
150
+ context "when the variable already has a value" do
151
+ before do
152
+ resource.instance_eval { @x = 'default' }
153
+ end
154
+ it "get succeeds" do
155
+ expect(resource.x).to eq 'default'
156
+ end
157
+ it "set(nil) sets the value" do
158
+ expect(resource.x nil).to be_nil
159
+ expect(resource.x).to be_nil
160
+ end
161
+ it "set to valid value succeeds" do
162
+ expect(resource.x 'str').to eq 'str'
163
+ expect(resource.x).to eq 'str'
164
+ end
165
+ it "set to invalid value raises ValidationFailed" do
166
+ expect { resource.x 10 }.to raise_error Chef::Exceptions::ValidationFailed
167
+ end
168
+ end
169
+ context "when the variable does not have an initial value" do
170
+ it "get succeeds" do
171
+ expect(resource.x).to be_nil
172
+ end
173
+ it "set(nil) sets the value" do
174
+ expect(resource.x nil).to be_nil
175
+ expect(resource.x).to be_nil
176
+ end
177
+ it "set to valid value succeeds" do
178
+ expect(resource.x 'str').to eq 'str'
179
+ expect(resource.x).to eq 'str'
180
+ end
181
+ it "set to invalid value raises ValidationFailed" do
182
+ expect { resource.x 10 }.to raise_error Chef::Exceptions::ValidationFailed
183
+ end
184
+ end
185
+ end
186
+ end
187
+
188
+ # Bare types
189
+ context "bare types" do
190
+ validation_test 'String',
191
+ [ 'hi' ],
192
+ [ 10 ],
193
+ [ nil ]
194
+
195
+ validation_test ':a',
196
+ [ :a ],
197
+ [ :b ],
198
+ [ nil ]
199
+
200
+ validation_test ':a, is: :b',
201
+ [ :a, :b ],
202
+ [ :c ],
203
+ [ nil ]
204
+
205
+ validation_test ':a, is: [ :b, :c ]',
206
+ [ :a, :b, :c ],
207
+ [ :d ],
208
+ [ nil ]
209
+
210
+ validation_test '[ :a, :b ], is: :c',
211
+ [ :a, :b, :c ],
212
+ [ :d ],
213
+ [ nil ]
214
+
215
+ validation_test '[ :a, :b ], is: [ :c, :d ]',
216
+ [ :a, :b, :c, :d ],
217
+ [ :e ],
218
+ [ nil ]
219
+
220
+ validation_test 'nil',
221
+ [ nil ],
222
+ [ :a ]
223
+
224
+ validation_test '[ nil ]',
225
+ [ nil ],
226
+ [ :a ]
227
+
228
+ validation_test '[]',
229
+ [],
230
+ [ :a ],
231
+ [ nil ]
232
+ end
233
+
234
+ # is
235
+ context "is" do
236
+ # Class
237
+ validation_test 'is: String',
238
+ [ 'a', '' ],
239
+ [ :a, 1 ],
240
+ [ nil ]
241
+
242
+ # Value
243
+ validation_test 'is: :a',
244
+ [ :a ],
245
+ [ :b ],
246
+ [ nil ]
247
+
248
+ validation_test 'is: [ :a, :b ]',
249
+ [ :a, :b ],
250
+ [ [ :a, :b ] ],
251
+ [ nil ]
252
+
253
+ validation_test 'is: [ [ :a, :b ] ]',
254
+ [ [ :a, :b ] ],
255
+ [ :a, :b ],
256
+ [ nil ]
257
+
258
+ # Regex
259
+ validation_test 'is: /abc/',
260
+ [ 'abc', 'wowabcwow' ],
261
+ [ '', 'abac' ],
262
+ [ nil ]
263
+
264
+ # Property
265
+ validation_test 'is: Chef::Property.new(is: :a)',
266
+ [ :a ],
267
+ [ :b, nil ]
268
+
269
+ # RSpec Matcher
270
+ class Globalses
271
+ extend RSpec::Matchers
272
+ end
273
+
274
+ validation_test "is: Globalses.eq(10)",
275
+ [ 10 ],
276
+ [ 1 ],
277
+ [ nil ]
278
+
279
+ # Proc
280
+ validation_test 'is: proc { |x| x }',
281
+ [ true, 1 ],
282
+ [ false ],
283
+ [ nil ]
284
+
285
+ validation_test 'is: proc { |x| x > blah }',
286
+ [ 10 ],
287
+ [ -1 ]
288
+
289
+ validation_test 'is: nil',
290
+ [ nil ],
291
+ [ 'a' ]
292
+
293
+ validation_test 'is: [ String, nil ]',
294
+ [ 'a', nil ],
295
+ [ :b ]
296
+
297
+ validation_test 'is: []',
298
+ [],
299
+ [ :a ],
300
+ [ nil ]
301
+ end
302
+
303
+ # Combination
304
+ context "combination" do
305
+ validation_test 'kind_of: String, equal_to: "a"',
306
+ [ 'a' ],
307
+ [ 'b' ],
308
+ [ nil ]
309
+ end
310
+
311
+ # equal_to
312
+ context "equal_to" do
313
+ # Value
314
+ validation_test 'equal_to: :a',
315
+ [ :a ],
316
+ [ :b ],
317
+ [ nil ]
318
+
319
+ validation_test 'equal_to: [ :a, :b ]',
320
+ [ :a, :b ],
321
+ [ [ :a, :b ] ],
322
+ [ nil ]
323
+
324
+ validation_test 'equal_to: [ [ :a, :b ] ]',
325
+ [ [ :a, :b ] ],
326
+ [ :a, :b ],
327
+ [ nil ]
328
+
329
+ validation_test 'equal_to: nil',
330
+ [ ],
331
+ [ 'a' ],
332
+ [ nil ]
333
+
334
+ validation_test 'equal_to: [ "a", nil ]',
335
+ [ 'a' ],
336
+ [ 'b' ],
337
+ [ nil ]
338
+
339
+ validation_test 'equal_to: [ nil, "a" ]',
340
+ [ 'a' ],
341
+ [ 'b' ],
342
+ [ nil ]
343
+
344
+ validation_test 'equal_to: []',
345
+ [],
346
+ [ :a ],
347
+ [ nil ]
348
+ end
349
+
350
+ # kind_of
351
+ context "kind_of" do
352
+ validation_test 'kind_of: String',
353
+ [ 'a' ],
354
+ [ :b ],
355
+ [ nil ]
356
+
357
+ validation_test 'kind_of: [ String, Symbol ]',
358
+ [ 'a', :b ],
359
+ [ 1 ],
360
+ [ nil ]
361
+
362
+ validation_test 'kind_of: [ Symbol, String ]',
363
+ [ 'a', :b ],
364
+ [ 1 ],
365
+ [ nil ]
366
+
367
+ validation_test 'kind_of: NilClass',
368
+ [ ],
369
+ [ 'a' ],
370
+ [ nil ]
371
+
372
+ validation_test 'kind_of: [ NilClass, String ]',
373
+ [ 'a' ],
374
+ [ :a ],
375
+ [ nil ]
376
+
377
+ validation_test 'kind_of: []',
378
+ [],
379
+ [ :a ],
380
+ [ nil ]
381
+
382
+ validation_test 'kind_of: nil',
383
+ [],
384
+ [ :a ],
385
+ [ nil ]
386
+ end
387
+
388
+ # regex
389
+ context "regex" do
390
+ validation_test 'regex: /abc/',
391
+ [ 'xabcy' ],
392
+ [ 'gbh', 123 ],
393
+ [ nil ]
394
+
395
+ validation_test 'regex: [ /abc/, /z/ ]',
396
+ [ 'xabcy', 'aza' ],
397
+ [ 'gbh', 123 ],
398
+ [ nil ]
399
+
400
+ validation_test 'regex: [ /z/, /abc/ ]',
401
+ [ 'xabcy', 'aza' ],
402
+ [ 'gbh', 123 ],
403
+ [ nil ]
404
+
405
+ validation_test 'regex: [ [ /z/, /abc/ ], [ /n/ ] ]',
406
+ [ 'xabcy', 'aza', 'ana' ],
407
+ [ 'gbh', 123 ],
408
+ [ nil ]
409
+
410
+ validation_test 'regex: []',
411
+ [],
412
+ [ :a ],
413
+ [ nil ]
414
+
415
+ validation_test 'regex: nil',
416
+ [],
417
+ [ :a ],
418
+ [ nil ]
419
+ end
420
+
421
+ # callbacks
422
+ context "callbacks" do
423
+ validation_test 'callbacks: { "a" => proc { |x| x > 10 }, "b" => proc { |x| x%2 == 0 } }',
424
+ [ 12 ],
425
+ [ 11, 4 ]
426
+
427
+ validation_test 'callbacks: { "a" => proc { |x| x%2 == 0 }, "b" => proc { |x| x > 10 } }',
428
+ [ 12 ],
429
+ [ 11, 4 ]
430
+
431
+ validation_test 'callbacks: { "a" => proc { |x| x.nil? } }',
432
+ [ ],
433
+ [ 'a' ],
434
+ [ nil ]
435
+
436
+ validation_test 'callbacks: {}',
437
+ [ :a ],
438
+ [],
439
+ [ nil ]
440
+ end
441
+
442
+ # respond_to
443
+ context "respond_to" do
444
+ validation_test 'respond_to: :split',
445
+ [ 'hi' ],
446
+ [ 1 ],
447
+ [ nil ]
448
+
449
+ validation_test 'respond_to: "split"',
450
+ [ 'hi' ],
451
+ [ 1 ],
452
+ [ nil ]
453
+
454
+ validation_test 'respond_to: :to_s',
455
+ [ :a ],
456
+ [],
457
+ [ nil ]
458
+
459
+ validation_test 'respond_to: [ :split, :to_s ]',
460
+ [ 'hi' ],
461
+ [ 1 ],
462
+ [ nil ]
463
+
464
+ validation_test 'respond_to: %w(split to_s)',
465
+ [ 'hi' ],
466
+ [ 1 ],
467
+ [ nil ]
468
+
469
+ validation_test 'respond_to: [ :to_s, :split ]',
470
+ [ 'hi' ],
471
+ [ 1, ],
472
+ [ nil ]
473
+
474
+ validation_test 'respond_to: []',
475
+ [ :a ],
476
+ [],
477
+ [ nil ]
478
+
479
+ validation_test 'respond_to: nil',
480
+ [ :a ],
481
+ [],
482
+ [ nil ]
483
+ end
484
+
485
+ context "cannot_be" do
486
+ validation_test 'cannot_be: :empty',
487
+ [ 1, [1,2], { a: 10 } ],
488
+ [ [] ],
489
+ [ nil ]
490
+
491
+ validation_test 'cannot_be: "empty"',
492
+ [ 1, [1,2], { a: 10 } ],
493
+ [ [] ],
494
+ [ nil ]
495
+
496
+ validation_test 'cannot_be: [ :empty, :nil ]',
497
+ [ 1, [1,2], { a: 10 } ],
498
+ [ [] ],
499
+ [ nil ]
500
+
501
+ validation_test 'cannot_be: [ "empty", "nil" ]',
502
+ [ 1, [1,2], { a: 10 } ],
503
+ [ [] ],
504
+ [ nil ]
505
+
506
+ validation_test 'cannot_be: [ :nil, :empty ]',
507
+ [ 1, [1,2], { a: 10 } ],
508
+ [ [] ],
509
+ [ nil ]
510
+
511
+ validation_test 'cannot_be: [ :empty, :nil, :blahblah ]',
512
+ [ 1, [1,2], { a: 10 } ],
513
+ [ [] ],
514
+ [ nil ]
515
+
516
+ validation_test 'cannot_be: []',
517
+ [ :a ],
518
+ [],
519
+ [ nil ]
520
+
521
+ validation_test 'cannot_be: nil',
522
+ [ :a ],
523
+ [],
524
+ [ nil ]
525
+
526
+ end
527
+
528
+ context "required" do
529
+ with_property ':x, required: true' do
530
+ it "if x is not specified, retrieval fails" do
531
+ expect { resource.x }.to raise_error Chef::Exceptions::ValidationFailed
532
+ end
533
+ it "value 1 is valid" do
534
+ expect(resource.x 1).to eq 1
535
+ expect(resource.x).to eq 1
536
+ end
537
+ it "value nil emits a deprecation warning and does a get" do
538
+ expect { resource.x nil }.to raise_error Chef::Exceptions::DeprecatedFeatureError
539
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
540
+ resource.x 1
541
+ expect(resource.x nil).to eq 1
542
+ expect(resource.x).to eq 1
543
+ end
544
+ end
545
+
546
+ with_property ':x, [String, nil], required: true' do
547
+ it "if x is not specified, retrieval fails" do
548
+ expect { resource.x }.to raise_error Chef::Exceptions::ValidationFailed
549
+ end
550
+ it "value nil is valid" do
551
+ expect(resource.x nil).to be_nil
552
+ expect(resource.x).to be_nil
553
+ end
554
+ it "value '1' is valid" do
555
+ expect(resource.x '1').to eq '1'
556
+ expect(resource.x).to eq '1'
557
+ end
558
+ it "value 1 is invalid" do
559
+ expect { resource.x 1 }.to raise_error Chef::Exceptions::ValidationFailed
560
+ end
561
+ end
562
+
563
+ with_property ':x, name_property: true, required: true' do
564
+ it "if x is not specified, the name property is returned" do
565
+ expect(resource.x).to eq 'blah'
566
+ end
567
+ it "value 1 is valid" do
568
+ expect(resource.x 1).to eq 1
569
+ expect(resource.x).to eq 1
570
+ end
571
+ it "value nil emits a deprecation warning and does a get" do
572
+ expect { resource.x nil }.to raise_error Chef::Exceptions::DeprecatedFeatureError
573
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
574
+ resource.x 1
575
+ expect(resource.x nil).to eq 1
576
+ expect(resource.x).to eq 1
577
+ end
578
+ end
579
+
580
+ with_property ':x, default: 10, required: true' do
581
+ it "if x is not specified, the default is returned" do
582
+ expect(resource.x).to eq 10
583
+ end
584
+ it "value 1 is valid" do
585
+ expect(resource.x 1).to eq 1
586
+ expect(resource.x).to eq 1
587
+ end
588
+ it "value nil is invalid" do
589
+ expect { resource.x nil }.to raise_error Chef::Exceptions::DeprecatedFeatureError
590
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
591
+ resource.x 1
592
+ expect(resource.x nil).to eq 1
593
+ expect(resource.x).to eq 1
594
+ end
595
+ end
596
+ end
597
+
598
+ context "custom validators (def _pv_blarghle)" do
599
+ before do
600
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
601
+ end
602
+
603
+ with_property ':x, blarghle: 1' do
604
+ context "and a class that implements _pv_blarghle" do
605
+ before do
606
+ resource_class.class_eval do
607
+ def _pv_blarghle(opts, key, value)
608
+ if _pv_opts_lookup(opts, key) != value
609
+ raise Chef::Exceptions::ValidationFailed, "ouch"
610
+ end
611
+ end
612
+ end
613
+ end
614
+
615
+ it "value 1 is valid" do
616
+ expect(resource.x 1).to eq 1
617
+ expect(resource.x).to eq 1
618
+ end
619
+
620
+ it "value '1' is invalid" do
621
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
622
+ expect { resource.x '1' }.to raise_error Chef::Exceptions::ValidationFailed
623
+ end
624
+
625
+ it "value nil does a get" do
626
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
627
+ resource.x 1
628
+ resource.x nil
629
+ expect(resource.x).to eq 1
630
+ end
631
+ end
632
+ end
633
+
634
+ with_property ':x, blarghle: 1' do
635
+ context "and a class that implements _pv_blarghle" do
636
+ before do
637
+ resource_class.class_eval do
638
+ def _pv_blarghle(opts, key, value)
639
+ if _pv_opts_lookup(opts, key) != value
640
+ raise Chef::Exceptions::ValidationFailed, "ouch"
641
+ end
642
+ end
643
+ end
644
+ end
645
+
646
+ it "value 1 is valid" do
647
+ expect(resource.x 1).to eq 1
648
+ expect(resource.x).to eq 1
649
+ end
650
+
651
+ it "value '1' is invalid" do
652
+ expect { resource.x '1' }.to raise_error Chef::Exceptions::ValidationFailed
653
+ end
654
+
655
+ it "value nil does a get" do
656
+ resource.x 1
657
+ resource.x nil
658
+ expect(resource.x).to eq 1
659
+ end
660
+ end
661
+ end
662
+ end
663
+ end