chef 13.6.4 → 13.7.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (257) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/acceptance/Gemfile +2 -2
  4. data/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/libraries/top_cookbooks.rb +1 -6
  5. data/distro/powershell/chef/chef.psm1 +1 -5
  6. data/lib/chef/api_client.rb +5 -5
  7. data/lib/chef/api_client_v1.rb +6 -6
  8. data/lib/chef/application.rb +3 -2
  9. data/lib/chef/application/knife.rb +4 -0
  10. data/lib/chef/chef_class.rb +2 -2
  11. data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
  12. data/lib/chef/chef_fs/data_handler/data_handler_base.rb +2 -4
  13. data/lib/chef/client.rb +3 -3
  14. data/lib/chef/cookbook/chefignore.rb +4 -0
  15. data/lib/chef/cookbook/cookbook_collection.rb +2 -2
  16. data/lib/chef/cookbook/metadata.rb +2 -2
  17. data/lib/chef/data_bag.rb +1 -1
  18. data/lib/chef/deprecated.rb +10 -0
  19. data/lib/chef/event_dispatch/base.rb +2 -2
  20. data/lib/chef/http.rb +10 -10
  21. data/lib/chef/knife.rb +16 -15
  22. data/lib/chef/knife/configure.rb +12 -36
  23. data/lib/chef/knife/cookbook_upload.rb +4 -4
  24. data/lib/chef/knife/core/bootstrap_context.rb +1 -1
  25. data/lib/chef/knife/core/status_presenter.rb +6 -2
  26. data/lib/chef/knife/core/ui.rb +1 -1
  27. data/lib/chef/knife/data_bag_secret_options.rb +1 -1
  28. data/lib/chef/knife/data_bag_show.rb +1 -1
  29. data/lib/chef/knife/edit.rb +1 -1
  30. data/lib/chef/knife/ssh.rb +47 -35
  31. data/lib/chef/knife/user_create.rb +2 -0
  32. data/lib/chef/knife/user_delete.rb +2 -0
  33. data/lib/chef/knife/user_edit.rb +2 -0
  34. data/lib/chef/knife/user_reregister.rb +2 -0
  35. data/lib/chef/knife/user_show.rb +2 -0
  36. data/lib/chef/mixin/powershell_out.rb +1 -1
  37. data/lib/chef/node/attribute.rb +46 -70
  38. data/lib/chef/node/attribute_collections.rb +5 -5
  39. data/lib/chef/node/common_api.rb +1 -1
  40. data/lib/chef/node/immutable_collections.rb +180 -23
  41. data/lib/chef/node/mixin/state_tracking.rb +6 -6
  42. data/lib/chef/node_map.rb +63 -45
  43. data/lib/chef/property.rb +8 -8
  44. data/lib/chef/provider.rb +9 -3
  45. data/lib/chef/provider/apt_preference.rb +1 -1
  46. data/lib/chef/provider/apt_repository.rb +1 -1
  47. data/lib/chef/provider/apt_update.rb +1 -1
  48. data/lib/chef/provider/file.rb +1 -1
  49. data/lib/chef/provider/group/dscl.rb +6 -2
  50. data/lib/chef/provider/ifconfig.rb +96 -34
  51. data/lib/chef/provider/launchd.rb +0 -1
  52. data/lib/chef/provider/log.rb +3 -13
  53. data/lib/chef/provider/package/dnf.rb +1 -1
  54. data/lib/chef/provider/package/smartos.rb +2 -2
  55. data/lib/chef/provider/reboot.rb +12 -0
  56. data/lib/chef/provider/remote_directory.rb +1 -1
  57. data/lib/chef/provider/remote_file/http.rb +3 -2
  58. data/lib/chef/provider/service/solaris.rb +6 -2
  59. data/lib/chef/provider/systemd_unit.rb +34 -33
  60. data/lib/chef/provider/user/dscl.rb +1 -1
  61. data/lib/chef/provider/windows_path.rb +6 -7
  62. data/lib/chef/provider/windows_task.rb +89 -33
  63. data/lib/chef/provider/yum_repository.rb +24 -9
  64. data/lib/chef/resource/apt_package.rb +1 -0
  65. data/lib/chef/resource/apt_preference.rb +4 -0
  66. data/lib/chef/resource/apt_repository.rb +4 -0
  67. data/lib/chef/resource/apt_update.rb +3 -0
  68. data/lib/chef/resource/bash.rb +4 -0
  69. data/lib/chef/resource/batch.rb +5 -0
  70. data/lib/chef/resource/bff_package.rb +4 -0
  71. data/lib/chef/resource/breakpoint.rb +6 -0
  72. data/lib/chef/resource/cab_package.rb +6 -6
  73. data/lib/chef/resource/chef_gem.rb +13 -0
  74. data/lib/chef/resource/chocolatey_package.rb +4 -6
  75. data/lib/chef/resource/cookbook_file.rb +13 -15
  76. data/lib/chef/resource/cron.rb +2 -0
  77. data/lib/chef/resource/csh.rb +4 -0
  78. data/lib/chef/resource/directory.rb +8 -26
  79. data/lib/chef/resource/dnf_package.rb +5 -0
  80. data/lib/chef/resource/dpkg_package.rb +2 -0
  81. data/lib/chef/resource/dsc_resource.rb +5 -0
  82. data/lib/chef/resource/dsc_script.rb +6 -0
  83. data/lib/chef/resource/env.rb +3 -0
  84. data/lib/chef/resource/erl_call.rb +5 -0
  85. data/lib/chef/resource/execute.rb +5 -1
  86. data/lib/chef/resource/file.rb +2 -1
  87. data/lib/chef/resource/file/verification.rb +10 -0
  88. data/lib/chef/resource/freebsd_package.rb +10 -2
  89. data/lib/chef/resource/gem_package.rb +2 -0
  90. data/lib/chef/resource/git.rb +2 -0
  91. data/lib/chef/resource/group.rb +1 -0
  92. data/lib/chef/resource/homebrew_package.rb +3 -0
  93. data/lib/chef/resource/http_request.rb +2 -0
  94. data/lib/chef/resource/ifconfig.rb +23 -150
  95. data/lib/chef/resource/ips_package.rb +1 -0
  96. data/lib/chef/resource/ksh.rb +6 -0
  97. data/lib/chef/resource/launchd.rb +5 -4
  98. data/lib/chef/resource/link.rb +10 -0
  99. data/lib/chef/resource/log.rb +19 -46
  100. data/lib/chef/resource/macports_package.rb +1 -0
  101. data/lib/chef/resource/mdadm.rb +4 -0
  102. data/lib/chef/resource/mount.rb +1 -0
  103. data/lib/chef/resource/msu_package.rb +7 -8
  104. data/lib/chef/resource/ohai.rb +2 -0
  105. data/lib/chef/resource/openbsd_package.rb +3 -0
  106. data/lib/chef/resource/osx_profile.rb +10 -40
  107. data/lib/chef/resource/package.rb +6 -0
  108. data/lib/chef/resource/pacman_package.rb +1 -0
  109. data/lib/chef/resource/paludis_package.rb +3 -0
  110. data/lib/chef/resource/perl.rb +4 -0
  111. data/lib/chef/resource/portage_package.rb +1 -0
  112. data/lib/chef/resource/powershell_package.rb +5 -0
  113. data/lib/chef/resource/powershell_script.rb +8 -0
  114. data/lib/chef/resource/python.rb +4 -0
  115. data/lib/chef/resource/reboot.rb +14 -20
  116. data/lib/chef/resource/registry_key.rb +1 -0
  117. data/lib/chef/resource/remote_directory.rb +3 -0
  118. data/lib/chef/resource/remote_file.rb +2 -0
  119. data/lib/chef/resource/resource_notification.rb +17 -0
  120. data/lib/chef/resource/route.rb +1 -0
  121. data/lib/chef/resource/rpm_package.rb +1 -0
  122. data/lib/chef/resource/ruby.rb +4 -0
  123. data/lib/chef/resource/ruby_block.rb +3 -0
  124. data/lib/chef/resource/script.rb +4 -0
  125. data/lib/chef/resource/service.rb +1 -0
  126. data/lib/chef/resource/smartos_package.rb +1 -0
  127. data/lib/chef/resource/solaris_package.rb +1 -0
  128. data/lib/chef/resource/subversion.rb +1 -0
  129. data/lib/chef/resource/systemd_unit.rb +6 -0
  130. data/lib/chef/resource/template.rb +9 -0
  131. data/lib/chef/resource/user.rb +1 -0
  132. data/lib/chef/resource/windows_package.rb +2 -0
  133. data/lib/chef/resource/windows_path.rb +5 -10
  134. data/lib/chef/resource/windows_service.rb +3 -0
  135. data/lib/chef/resource/windows_task.rb +66 -87
  136. data/lib/chef/resource/yum_repository.rb +26 -22
  137. data/lib/chef/resource/zypper_package.rb +2 -0
  138. data/lib/chef/resource/zypper_repository.rb +6 -1
  139. data/lib/chef/run_context.rb +8 -2
  140. data/lib/chef/server_api.rb +1 -0
  141. data/lib/chef/util/selinux.rb +5 -4
  142. data/lib/chef/version.rb +1 -1
  143. data/lib/chef/version/platform.rb +18 -0
  144. data/lib/chef/version_constraint/platform.rb +2 -0
  145. data/spec/data/client.d_00/02-strings.rb +2 -0
  146. data/spec/functional/assets/chefinittest +6 -4
  147. data/spec/functional/knife/ssh_spec.rb +54 -7
  148. data/spec/functional/resource/bff_spec.rb +3 -3
  149. data/spec/functional/resource/ifconfig_spec.rb +1 -1
  150. data/spec/functional/resource/mount_spec.rb +7 -3
  151. data/spec/functional/resource/user/useradd_spec.rb +4 -4
  152. data/spec/functional/resource/windows_task_spec.rb +6 -6
  153. data/spec/functional/win32/security_spec.rb +7 -33
  154. data/spec/integration/knife/data_bag_show_spec.rb +1 -1
  155. data/spec/integration/recipes/noop_resource_spec.rb +1 -1
  156. data/spec/integration/recipes/recipe_dsl_spec.rb +30 -30
  157. data/spec/integration/recipes/resource_action_spec.rb +2 -2
  158. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +71 -15
  159. data/spec/spec_helper.rb +19 -0
  160. data/spec/support/shared/functional/execute_resource.rb +1 -1
  161. data/spec/support/shared/unit/application_dot_d.rb +2 -0
  162. data/spec/support/shared/unit/execute_resource.rb +8 -1
  163. data/spec/support/shared/unit/provider/file.rb +9 -1
  164. data/spec/unit/chef_fs/data_handler/data_bag_item_data_handler.rb +10 -7
  165. data/spec/unit/chef_fs/file_system/repository/directory_spec.rb +2 -2
  166. data/spec/unit/client_spec.rb +1 -1
  167. data/spec/unit/deprecated_spec.rb +4 -4
  168. data/spec/unit/http_spec.rb +9 -0
  169. data/spec/unit/knife/bootstrap_spec.rb +5 -0
  170. data/spec/unit/knife/configure_spec.rb +10 -60
  171. data/spec/unit/knife/data_bag_create_spec.rb +40 -2
  172. data/spec/unit/knife/data_bag_show_spec.rb +16 -2
  173. data/spec/unit/knife/ssh_spec.rb +85 -39
  174. data/spec/unit/knife_spec.rb +2 -0
  175. data/spec/unit/lwrp_spec.rb +5 -3
  176. data/spec/unit/mixin/powershell_type_coercions_spec.rb +7 -6
  177. data/spec/unit/node/attribute_spec.rb +55 -24
  178. data/spec/unit/node/immutable_collections_spec.rb +28 -14
  179. data/spec/unit/node/vivid_mash_spec.rb +27 -10
  180. data/spec/unit/node_map_spec.rb +34 -0
  181. data/spec/unit/property_spec.rb +13 -13
  182. data/spec/unit/provider/group/dscl_spec.rb +14 -5
  183. data/spec/unit/provider/ifconfig_spec.rb +10 -3
  184. data/spec/unit/provider/remote_file/http_spec.rb +23 -19
  185. data/spec/unit/provider/service/solaris_smf_service_spec.rb +6 -5
  186. data/spec/unit/provider/user/dscl_spec.rb +26 -0
  187. data/spec/unit/provider/windows_task_spec.rb +148 -4
  188. data/spec/unit/provider_spec.rb +1 -1
  189. data/spec/unit/resource/apt_package_spec.rb +1 -1
  190. data/spec/unit/resource/bash_spec.rb +8 -10
  191. data/spec/unit/resource/batch_spec.rb +1 -1
  192. data/spec/unit/resource/cab_package_spec.rb +19 -1
  193. data/spec/unit/resource/chef_gem_spec.rb +3 -3
  194. data/spec/unit/resource/chocolatey_package_spec.rb +10 -10
  195. data/spec/unit/resource/conditional_spec.rb +2 -2
  196. data/spec/unit/resource/cookbook_file_spec.rb +24 -30
  197. data/spec/unit/resource/cron_spec.rb +79 -82
  198. data/spec/unit/resource/csh_spec.rb +8 -10
  199. data/spec/unit/resource/deploy_spec.rb +1 -1
  200. data/spec/unit/resource/directory_spec.rb +28 -31
  201. data/spec/unit/resource/dnf_package_spec.rb +9 -9
  202. data/spec/unit/resource/env_spec.rb +7 -7
  203. data/spec/unit/resource/erl_call_spec.rb +9 -9
  204. data/spec/unit/resource/execute_spec.rb +6 -6
  205. data/spec/unit/resource/file/verification_spec.rb +18 -4
  206. data/spec/unit/resource/file_spec.rb +53 -56
  207. data/spec/unit/resource/freebsd_package_spec.rb +7 -7
  208. data/spec/unit/resource/gem_package_spec.rb +1 -1
  209. data/spec/unit/resource/git_spec.rb +7 -9
  210. data/spec/unit/resource/group_spec.rb +60 -70
  211. data/spec/unit/resource/http_request_spec.rb +16 -19
  212. data/spec/unit/resource/ifconfig_spec.rb +3 -3
  213. data/spec/unit/resource/ips_package_spec.rb +3 -5
  214. data/spec/unit/resource/ksh_spec.rb +8 -10
  215. data/spec/unit/resource/launchd_spec.rb +17 -10
  216. data/spec/unit/resource/link_spec.rb +53 -53
  217. data/spec/unit/resource/log_spec.rb +24 -28
  218. data/spec/unit/resource/mdadm_spec.rb +42 -44
  219. data/spec/unit/resource/mount_spec.rb +97 -99
  220. data/spec/unit/resource/msu_package_spec.rb +14 -8
  221. data/spec/unit/resource/ohai_spec.rb +15 -17
  222. data/spec/unit/resource/openbsd_package_spec.rb +3 -3
  223. data/spec/unit/resource/osx_profile_spec.rb +7 -7
  224. data/spec/unit/resource/package_spec.rb +36 -40
  225. data/spec/unit/resource/perl_spec.rb +8 -11
  226. data/spec/unit/resource/portage_package_spec.rb +8 -10
  227. data/spec/unit/resource/powershell_package_spec.rb +9 -9
  228. data/spec/unit/resource/python_spec.rb +8 -11
  229. data/spec/unit/resource/reboot_spec.rb +50 -0
  230. data/spec/unit/resource/registry_key_spec.rb +84 -98
  231. data/spec/unit/resource/remote_directory_spec.rb +40 -42
  232. data/spec/unit/resource/remote_file_spec.rb +78 -80
  233. data/spec/unit/resource/route_spec.rb +42 -44
  234. data/spec/unit/resource/rpm_package_spec.rb +5 -7
  235. data/spec/unit/resource/ruby_block_spec.rb +14 -16
  236. data/spec/unit/resource/ruby_spec.rb +8 -12
  237. data/spec/unit/resource/scm_spec.rb +66 -69
  238. data/spec/unit/resource/script_spec.rb +1 -1
  239. data/spec/unit/resource/service_spec.rb +80 -83
  240. data/spec/unit/resource/smartos_package_spec.rb +5 -0
  241. data/spec/unit/resource/solaris_package_spec.rb +3 -5
  242. data/spec/unit/resource/subversion_spec.rb +18 -16
  243. data/spec/unit/resource/systemd_unit_spec.rb +50 -54
  244. data/spec/unit/resource/template_spec.rb +56 -61
  245. data/spec/unit/resource/user_spec.rb +47 -53
  246. data/spec/unit/resource/windows_package_spec.rb +1 -1
  247. data/spec/unit/resource/windows_path_spec.rb +11 -8
  248. data/spec/unit/resource/windows_task_spec.rb +129 -33
  249. data/spec/unit/resource/yum_package_spec.rb +1 -1
  250. data/spec/unit/resource/yum_repository_spec.rb +61 -8
  251. data/spec/unit/resource/zypper_repository_spec.rb +17 -18
  252. data/spec/unit/util/selinux_spec.rb +3 -6
  253. data/tasks/dependencies.rb +0 -5
  254. data/tasks/rspec.rb +1 -1
  255. metadata +6 -6
  256. data/acceptance/top-cookbooks/.kitchen.docker.yml +0 -13
  257. data/acceptance/top-cookbooks/.kitchen.git.yml +0 -11
@@ -118,6 +118,7 @@ describe Chef::Provider::Service::Solaris do
118
118
  it "should create a current resource with the name of the new resource" do
119
119
  expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status)
120
120
  expect(Chef::Resource::Service).to receive(:new).and_return(@current_resource)
121
+ expect(@provider.maintenance).to be_falsey
121
122
  @provider.load_current_resource
122
123
  end
123
124
 
@@ -162,7 +163,7 @@ describe Chef::Provider::Service::Solaris do
162
163
  end
163
164
 
164
165
  it "should call svcadm enable -s chef" do
165
- expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status)
166
+ expect(@provider).to receive(:shell_out!).twice.with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status)
166
167
  expect(@provider).not_to receive(:shell_out!).with("/usr/sbin/svcadm", "clear", @current_resource.service_name)
167
168
  expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "enable", "-s", @current_resource.service_name).and_return(@success)
168
169
  @provider.load_current_resource
@@ -172,7 +173,7 @@ describe Chef::Provider::Service::Solaris do
172
173
  end
173
174
 
174
175
  it "should call svcadm enable -s chef for start_service" do
175
- expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status)
176
+ expect(@provider).to receive(:shell_out!).twice.with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status)
176
177
  expect(@provider).not_to receive(:shell_out!).with("/usr/sbin/svcadm", "clear", @current_resource.service_name)
177
178
  expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "enable", "-s", @current_resource.service_name).and_return(@success)
178
179
  @provider.load_current_resource
@@ -182,7 +183,7 @@ describe Chef::Provider::Service::Solaris do
182
183
 
183
184
  it "should call svcadm clear chef for start_service when state maintenance" do
184
185
  # we are in maint mode
185
- expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@maintenance_svc_status)
186
+ expect(@provider).to receive(:shell_out!).twice.with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@maintenance_svc_status)
186
187
  expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "clear", @current_resource.service_name).and_return(@success)
187
188
  expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "enable", "-s", @current_resource.service_name).and_return(@success)
188
189
 
@@ -205,7 +206,7 @@ describe Chef::Provider::Service::Solaris do
205
206
 
206
207
  it "should call svcadm enable -s -r chef" do
207
208
  @new_resource.options("-r")
208
- expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status)
209
+ expect(@provider).to receive(:shell_out!).twice.with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status)
209
210
  expect(@provider).not_to receive(:shell_out!).with("/usr/sbin/svcadm", "clear", @current_resource.service_name)
210
211
  expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "enable", "-s", "-r", @current_resource.service_name).and_return(@success)
211
212
  @provider.load_current_resource
@@ -215,7 +216,7 @@ describe Chef::Provider::Service::Solaris do
215
216
 
216
217
  it "should call svcadm enable -s -r -t chef when passed an array of options" do
217
218
  @new_resource.options(["-r", "-t"])
218
- expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status)
219
+ expect(@provider).to receive(:shell_out!).twice.with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status)
219
220
  expect(@provider).not_to receive(:shell_out!).with("/usr/sbin/svcadm", "clear", @current_resource.service_name)
220
221
  expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "enable", "-s", "-r", "-t", @current_resource.service_name).and_return(@success)
221
222
  @provider.load_current_resource
@@ -213,6 +213,32 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30"
213
213
  end
214
214
  end
215
215
 
216
+ describe "current_home_exists?" do
217
+ let(:current_resource) do
218
+ new_resource.dup
219
+ end
220
+
221
+ before do
222
+ provider.current_resource = current_resource
223
+ end
224
+
225
+ it "returns false for nil home dir" do
226
+ current_resource.home nil
227
+ expect(provider.current_home_exists?).to be_falsey
228
+ end
229
+
230
+ it "is false for empty string" do
231
+ current_resource.home ""
232
+ expect(provider.current_home_exists?).to be_falsey
233
+ end
234
+
235
+ it "is true for existing directory" do
236
+ current_resource.home "/Users/blah"
237
+ allow(::File).to receive(:exist?).with("/Users/blah").and_return(true)
238
+ expect(provider.current_home_exists?).to be_truthy
239
+ end
240
+ end
241
+
216
242
  describe "when modifying the home directory" do
217
243
  let(:current_resource) do
218
244
  new_resource.dup
@@ -40,7 +40,7 @@ describe Chef::Provider::WindowsTask do
40
40
  :LastRunTime => "3/30/2017 2:27:00 PM",
41
41
  :LastResult => "1",
42
42
  :Author => "Administrator",
43
- :TaskToRun => "chef-client",
43
+ :TaskToRun => "chef-client -L C:\\tmp\\",
44
44
  :StartIn => "N/A",
45
45
  :Comment => "N/A",
46
46
  :ScheduledTaskState => "Enabled",
@@ -91,7 +91,7 @@ describe Chef::Provider::WindowsTask do
91
91
  allow(provider).to receive(:load_task_hash).and_return(task_hash)
92
92
  current_resource = provider.load_current_resource
93
93
  expect(current_resource.exists).to be(true)
94
- expect(current_resource.command).to eq("chef-client")
94
+ expect(current_resource.command).to eq("chef-client -L C:\\tmp\\")
95
95
  expect(current_resource.user).to eq("SYSTEM")
96
96
  expect(current_resource.run_level).to eq(:highest)
97
97
  expect(current_resource.frequency).to eq(:minute)
@@ -110,6 +110,49 @@ describe Chef::Provider::WindowsTask do
110
110
  expect(new_resource).not_to be_updated_by_last_action
111
111
  end
112
112
 
113
+ it "sets the start_time in 24hr format while updating an existing task" do
114
+ # task_hash has start_time = "1:12:00 PM"
115
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
116
+ provider.load_current_resource
117
+ allow(provider).to receive(:task_need_update?).and_return(true)
118
+ allow(provider).to receive(:convert_system_date_to_mm_dd_yyyy).and_return("03/30/2017")
119
+ allow(provider).to receive(:run_schtasks)
120
+ provider.run_action(:create)
121
+ # start_time gets set in 24hr format for new_resource
122
+ expect(new_resource.start_time).to eq("13:12")
123
+ expect(new_resource).to be_updated_by_last_action
124
+ end
125
+
126
+ it "sets the start_day in mm/dd/yyyy format while updating an existing task" do
127
+ # start_day in yyyy-MM-dd format
128
+ task_hash[:StartDate] = "2017-03-30"
129
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
130
+ current_resource = provider.load_current_resource
131
+ allow(provider).to receive(:task_need_update?).and_return(true)
132
+ allow(provider).to receive(:convert_system_date_format_to_ruby_date_format).and_return("%Y-%m-%d")
133
+ allow(provider).to receive(:run_schtasks)
134
+ provider.run_action(:create)
135
+ # start_day gets set in mm/dd/yyyy format for new_resource
136
+ expect(new_resource.start_day).to eq("03/30/2017")
137
+ expect(new_resource).to be_updated_by_last_action
138
+ end
139
+
140
+ context "when start_day and start_time are N/A for frequency :on_logon" do
141
+ it "doesn't update the start_day and start_time of new_resource" do
142
+ task_hash[:on_logon] = true
143
+ task_hash[:StartDate] = "N/A"
144
+ task_hash[:StartTime] = "N/A"
145
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
146
+ current_resource = provider.load_current_resource
147
+ allow(provider).to receive(:task_need_update?).and_return(true)
148
+ allow(provider).to receive(:run_schtasks)
149
+ expect(provider).not_to receive(:convert_system_date_to_mm_dd_yyyy)
150
+ expect(DateTime).not_to receive(:parse)
151
+ expect(new_resource.start_day).to eq(nil)
152
+ expect(new_resource.start_time).to eq(nil)
153
+ end
154
+ end
155
+
113
156
  context "when task is not existing" do
114
157
  before do
115
158
  allow(provider).to receive(:load_task_hash)
@@ -285,7 +328,7 @@ describe Chef::Provider::WindowsTask do
285
328
  before do
286
329
  @task_action = "CREATE"
287
330
  @options = { "F" => "", "SC" => :minute, "MO" => 15, "TR" => "chef-client", "RU" => "SYSTEM", "RL" => "HIGHEST" }
288
- @cmd = "schtasks /CREATE /TN \"sample_task\" /F /SC \"minute\" /MO \"15\" /TR \"chef-client\" /RU \"SYSTEM\" /RL \"HIGHEST\" "
331
+ @cmd = "schtasks /CREATE /TN \"sample_task\" /F /SC \"minute\" /MO \"15\" /RU \"SYSTEM\" /RL \"HIGHEST\" /TR \"chef-client \" "
289
332
  end
290
333
 
291
334
  it "forms the command properly from the given options" do
@@ -336,7 +379,7 @@ describe Chef::Provider::WindowsTask do
336
379
  allow(provider).to receive(:get_system_short_date_format).and_return("MM/dd/yyyy")
337
380
  provider.load_current_resource
338
381
 
339
- new_resource.command "chef-client"
382
+ new_resource.command "chef-client -L C:\\tmp\\"
340
383
  new_resource.run_level :highest
341
384
  new_resource.frequency :minute
342
385
  new_resource.frequency_modifier 15
@@ -379,6 +422,13 @@ describe Chef::Provider::WindowsTask do
379
422
  expect(provider.send(:task_need_update?)).to be(true)
380
423
  end
381
424
  end
425
+
426
+ context "when command updated" do
427
+ it "return true" do
428
+ new_resource.command "chef-client"
429
+ expect(provider.send(:task_need_update?)).to be(true)
430
+ end
431
+ end
382
432
  end
383
433
  end
384
434
 
@@ -570,4 +620,98 @@ describe Chef::Provider::WindowsTask do
570
620
  expect(provider.send(:frequency_modifier_allowed)).to be(false)
571
621
  end
572
622
  end
623
+
624
+ # In windows_task resource sec_to_dur method converts seconds to duration in format 60 == 'PT60S'
625
+ # random_delay_updated? method use the value return by sec_to_dur as input for comparison for new_resource.random_delay mocking the same here
626
+ describe "#random_delay_updated?" do
627
+ before do
628
+ new_resource.command "chef-client"
629
+ new_resource.run_level :highest
630
+ new_resource.frequency :minute
631
+ new_resource.frequency_modifier 15
632
+ new_resource.user "SYSTEM"
633
+ end
634
+
635
+ it "returns false if current_resource.random_delay = nil & random_delay is set to '0' seconds" do
636
+ task_hash[:random_delay] = nil
637
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
638
+ provider.load_current_resource
639
+ new_resource.random_delay = "PT0S"
640
+ expect(provider.send(:random_delay_updated?)).to be(false)
641
+ end
642
+
643
+ it "returns false if current_resource.random_delay = 'P7D' & random_delay is set to '604800' seconds " do
644
+ task_hash[:random_delay] = "P7D"
645
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
646
+ provider.load_current_resource
647
+ new_resource.random_delay = "PT604800S"
648
+ expect(provider.send(:random_delay_updated?)).to be(false)
649
+ end
650
+
651
+ it "returns false if current_resource.random_delay = 'P7DT1S' & random_delay is set to '604801' seconds" do
652
+ task_hash[:random_delay] = "P7DT1S"
653
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
654
+ provider.load_current_resource
655
+ new_resource.random_delay = "PT604801S"
656
+ expect(provider.send(:random_delay_updated?)).to be(false)
657
+ end
658
+
659
+ it "returns true if current_resource.random_delay = 'PT1S' & random_delay is set to '3600' seconds" do
660
+ task_hash[:random_delay] = "PT1S"
661
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
662
+ provider.load_current_resource
663
+ new_resource.random_delay = "PT3600S"
664
+ expect(provider.send(:random_delay_updated?)).to be(true)
665
+ end
666
+
667
+ it "returns false if current_resource.random_delay = 'P2Y1MT2H' & random_delay is set to '65707200' seconds" do
668
+ task_hash[:random_delay] = "P2Y1MT2H"
669
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
670
+ provider.load_current_resource
671
+ new_resource.random_delay = "PT65707200S"
672
+ expect(provider.send(:random_delay_updated?)).to be(false)
673
+ end
674
+ end
675
+
676
+ describe "#execution_time_limit_updated?" do
677
+ before do
678
+ new_resource.command "chef-client"
679
+ new_resource.run_level :highest
680
+ new_resource.frequency :minute
681
+ new_resource.frequency_modifier 15
682
+ new_resource.user "SYSTEM"
683
+ end
684
+
685
+ it "returns false if current_resource.execution_time_limit = 'P7D' & execution_time_limit is set to 604800 seconds " do
686
+ task_hash[:execution_time_limit] = "P7D"
687
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
688
+ provider.load_current_resource
689
+ new_resource.execution_time_limit = "PT604800S"
690
+ expect(provider.send(:execution_time_limit_updated?)).to be(false)
691
+ end
692
+
693
+ it "returns false if current_resource.execution_time_limit = 'P7DT1S' & execution_time_limit is set to 604801 seconds" do
694
+ task_hash[:execution_time_limit] = "P7DT1S"
695
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
696
+ provider.load_current_resource
697
+ new_resource.execution_time_limit = "PT604801S"
698
+ expect(provider.send(:execution_time_limit_updated?)).to be(false)
699
+ end
700
+
701
+ it "returns true if current_resource.execution_time_limit = 'PT1S' & execution_time_limit is set to '3600' seconds" do
702
+ task_hash[:execution_time_limit] = "PT1S"
703
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
704
+ provider.load_current_resource
705
+ new_resource.execution_time_limit = "PT3600S"
706
+ expect(provider.send(:execution_time_limit_updated?)).to be(true)
707
+ end
708
+
709
+ it "returns false if current_resource.execution_time_limit = 'P2Y1MT2H' & execution_time_limit is set to '65707200' seconds" do
710
+ task_hash[:execution_time_limit] = "P2Y1MT2H"
711
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
712
+ provider.load_current_resource
713
+ new_resource.execution_time_limit = "PT65707200S"
714
+ expect(provider.send(:execution_time_limit_updated?)).to be(false)
715
+ end
716
+ end
573
717
  end
@@ -197,7 +197,7 @@ describe Chef::Provider do
197
197
 
198
198
  context "when using use_inline_resources" do
199
199
  it "should log a deprecation warning" do
200
- pending Chef::VERSION.start_with?("13.6")
200
+ pending Chef::VERSION.start_with?("14.1")
201
201
  expect(Chef).to receive(:deprecated).with(:use_inline_resources, kind_of(String))
202
202
  Class.new(described_class) { use_inline_resources }
203
203
  end
@@ -31,7 +31,7 @@ describe Chef::Resource::AptPackage, "initialize" do
31
31
 
32
32
  let(:resource) { Chef::Resource::AptPackage.new("foo") }
33
33
 
34
- it "should support default_release" do
34
+ it "supports default_release" do
35
35
  resource.default_release("lenny-backports")
36
36
  expect(resource.default_release).to eql("lenny-backports")
37
37
  end
@@ -20,21 +20,19 @@ require "spec_helper"
20
20
 
21
21
  describe Chef::Resource::Bash do
22
22
 
23
- before(:each) do
24
- @resource = Chef::Resource::Bash.new("fakey_fakerton")
25
- end
23
+ let(:resource) { Chef::Resource::Bash.new("fakey_fakerton") }
26
24
 
27
- it "should create a new Chef::Resource::Bash" do
28
- expect(@resource).to be_a_kind_of(Chef::Resource)
29
- expect(@resource).to be_a_kind_of(Chef::Resource::Bash)
25
+ it "creates a new Chef::Resource::Bash" do
26
+ expect(resource).to be_a_kind_of(Chef::Resource)
27
+ expect(resource).to be_a_kind_of(Chef::Resource::Bash)
30
28
  end
31
29
 
32
- it "should have a resource name of :bash" do
33
- expect(@resource.resource_name).to eql(:bash)
30
+ it "has a resource name of :bash" do
31
+ expect(resource.resource_name).to eql(:bash)
34
32
  end
35
33
 
36
- it "should have an interpreter of bash" do
37
- expect(@resource.interpreter).to eql("bash")
34
+ it "has an interpreter of bash" do
35
+ expect(resource.interpreter).to eql("bash")
38
36
  end
39
37
 
40
38
  end
@@ -33,7 +33,7 @@ describe Chef::Resource::Batch do
33
33
 
34
34
  end
35
35
 
36
- it "should create a new Chef::Resource::Batch" do
36
+ it "creates a new Chef::Resource::Batch" do
37
37
  expect(@resource).to be_a_kind_of(Chef::Resource::Batch)
38
38
  end
39
39
 
@@ -32,7 +32,25 @@ describe Chef::Resource::CabPackage do
32
32
  expect(resource.resource_name).to eql(:cab_package)
33
33
  end
34
34
 
35
- it "coerce its name to a package_name" do
35
+ it "sets the default action as :install" do
36
+ expect(resource.action).to eql([:install])
37
+ end
38
+
39
+ it "coerces name property to package_name property" do
36
40
  expect(resource.package_name).to eql("test_pkg")
37
41
  end
42
+
43
+ it "coerces name property to a source property if source not provided" do
44
+ expect(resource.source).to end_with("test_pkg")
45
+ end
46
+
47
+ it "coerces name property to a source property if source not provided and package_name is" do
48
+ resource.package_name("package.cab")
49
+ expect(resource.source).to end_with("package.cab")
50
+ end
51
+
52
+ it "coerces source property if it does not looks like a path" do
53
+ resource.source("package.cab")
54
+ expect(resource.source).not_to eq("package.cab")
55
+ end
38
56
  end
@@ -34,15 +34,15 @@ end
34
34
  describe Chef::Resource::ChefGem, "gem_binary" do
35
35
  let(:resource) { Chef::Resource::ChefGem.new("foo") }
36
36
 
37
- it "should raise an exception when gem_binary is set" do
37
+ it "raises an exception when gem_binary is set" do
38
38
  expect { resource.gem_binary("/lol/cats/gem") }.to raise_error(ArgumentError)
39
39
  end
40
40
 
41
- it "should set the gem_binary based on computing it from RbConfig" do
41
+ it "sets the gem_binary based on computing it from RbConfig" do
42
42
  expect(resource.gem_binary).to eql("#{RbConfig::CONFIG['bindir']}/gem")
43
43
  end
44
44
 
45
- it "should set compile_time to false by default" do
45
+ it "sets compile_time to false by default" do
46
46
  expect(resource.compile_time).to be false
47
47
  end
48
48
 
@@ -22,50 +22,50 @@ describe Chef::Resource::ChocolateyPackage do
22
22
 
23
23
  let(:resource) { Chef::Resource::ChocolateyPackage.new("fakey_fakerton") }
24
24
 
25
- it "should create a new Chef::Resource::ChocolateyPackage" do
25
+ it "creates a new Chef::Resource::ChocolateyPackage" do
26
26
  expect(resource).to be_a_kind_of(Chef::Resource)
27
27
  expect(resource).to be_a_kind_of(Chef::Resource::Package)
28
28
  expect(resource).to be_a_instance_of(Chef::Resource::ChocolateyPackage)
29
29
  end
30
30
 
31
- it "should have a resource name of :python" do
31
+ it "has a resource name of :python" do
32
32
  expect(resource.resource_name).to eql(:chocolatey_package)
33
33
  end
34
34
 
35
- it "should coerce its name to a package_name array" do
35
+ it "coerces its name to a package_name array" do
36
36
  expect(resource.package_name).to eql(["fakey_fakerton"])
37
37
  end
38
38
 
39
- it "the package_name setter should coerce to arrays" do
39
+ it "the package_name setter coerces to arrays" do
40
40
  resource.package_name("git")
41
41
  expect(resource.package_name).to eql(["git"])
42
42
  end
43
43
 
44
- it "the package_name setter should accept arrays" do
44
+ it "the package_name setter accepts arrays" do
45
45
  resource.package_name(%w{git unzip})
46
46
  expect(resource.package_name).to eql(%w{git unzip})
47
47
  end
48
48
 
49
- it "the name should accept arrays" do
49
+ it "the name accepts arrays" do
50
50
  resource = Chef::Resource::ChocolateyPackage.new(%w{git unzip})
51
51
  expect(resource.package_name).to eql(%w{git unzip})
52
52
  end
53
53
 
54
- it "the default version should be nil" do
54
+ it "the default version is nil" do
55
55
  expect(resource.version).to eql(nil)
56
56
  end
57
57
 
58
- it "the version setter should coerce to arrays" do
58
+ it "the version setter coerces to arrays" do
59
59
  resource.version("1.2.3")
60
60
  expect(resource.version).to eql(["1.2.3"])
61
61
  end
62
62
 
63
- it "the version setter should accept arrays" do
63
+ it "the version setter accepts arrays" do
64
64
  resource.version(["1.2.3", "4.5.6"])
65
65
  expect(resource.version).to eql(["1.2.3", "4.5.6"])
66
66
  end
67
67
 
68
- it "the default returns should be 0" do
68
+ it "the default returns is 0" do
69
69
  expect(resource.returns).to eql([0])
70
70
  end
71
71