chef 13.0.118-universal-mingw32 → 13.1.31-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -27
  3. data/VERSION +1 -1
  4. data/acceptance/.bundle/config +2 -0
  5. data/acceptance/basics/test/integration/chef-current-install/serverspec/chef_client_spec.rb +1 -1
  6. data/acceptance/bin/aws.rb +17 -0
  7. data/acceptance/bin/berks +17 -0
  8. data/acceptance/bin/bundler +17 -0
  9. data/acceptance/bin/chef-acceptance +17 -0
  10. data/acceptance/bin/coderay +17 -0
  11. data/acceptance/bin/erubis +17 -0
  12. data/acceptance/bin/htmldiff +17 -0
  13. data/acceptance/bin/httpclient +17 -0
  14. data/acceptance/bin/inspec +17 -0
  15. data/acceptance/bin/kitchen +17 -0
  16. data/acceptance/bin/ldiff +17 -0
  17. data/acceptance/bin/nokogiri +17 -0
  18. data/acceptance/bin/pry +17 -0
  19. data/acceptance/bin/rake +17 -0
  20. data/acceptance/bin/rspec +17 -0
  21. data/acceptance/bin/rwinrm +17 -0
  22. data/acceptance/bin/rwinrmcp +17 -0
  23. data/acceptance/bin/safe_yaml +17 -0
  24. data/acceptance/bin/thor +17 -0
  25. data/acceptance/fips/.kitchen/fips-unit-functional-centos-6.yml +7 -0
  26. data/acceptance/fips/.kitchen/kitchen-vagrant/kitchen-fips-fips-unit-functional-centos-6/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  27. data/acceptance/fips/.kitchen/kitchen-vagrant/kitchen-fips-fips-unit-functional-centos-6/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  28. data/acceptance/fips/.kitchen/kitchen-vagrant/kitchen-fips-fips-unit-functional-centos-6/.vagrant/machines/default/virtualbox/id +1 -0
  29. data/acceptance/fips/.kitchen/kitchen-vagrant/kitchen-fips-fips-unit-functional-centos-6/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  30. data/acceptance/fips/.kitchen/kitchen-vagrant/kitchen-fips-fips-unit-functional-centos-6/.vagrant/machines/default/virtualbox/private_key +27 -0
  31. data/acceptance/fips/.kitchen/kitchen-vagrant/kitchen-fips-fips-unit-functional-centos-6/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  32. data/acceptance/fips/.kitchen/kitchen-vagrant/kitchen-fips-fips-unit-functional-centos-6/Vagrantfile +11 -0
  33. data/acceptance/fips/.kitchen/logs/fips-integration-centos-6.log +0 -0
  34. data/acceptance/fips/.kitchen/logs/fips-integration-windows-2012r2.log +0 -0
  35. data/acceptance/fips/.kitchen/logs/fips-unit-functional-centos-6.log +80 -0
  36. data/acceptance/fips/.kitchen/logs/kitchen.log +4 -0
  37. data/chef.gemspec +1 -1
  38. data/lib/chef/application/client.rb +1 -1
  39. data/lib/chef/application/knife.rb +1 -1
  40. data/lib/chef/application/solo.rb +1 -0
  41. data/lib/chef/cookbook/remote_file_vendor.rb +1 -1
  42. data/lib/chef/cookbook/synchronizer.rb +20 -7
  43. data/lib/chef/cookbook_manifest.rb +8 -0
  44. data/lib/chef/deprecated.rb +10 -0
  45. data/lib/chef/knife/client_key_create.rb +3 -0
  46. data/lib/chef/knife/client_key_delete.rb +1 -0
  47. data/lib/chef/knife/client_key_edit.rb +1 -0
  48. data/lib/chef/knife/client_key_list.rb +1 -0
  49. data/lib/chef/knife/client_key_show.rb +1 -0
  50. data/lib/chef/knife/user_key_create.rb +1 -0
  51. data/lib/chef/knife/user_key_delete.rb +1 -0
  52. data/lib/chef/knife/user_key_edit.rb +1 -0
  53. data/lib/chef/knife/user_key_list.rb +1 -0
  54. data/lib/chef/knife/user_key_show.rb +1 -0
  55. data/lib/chef/local_mode.rb +1 -0
  56. data/lib/chef/mixin/which.rb +1 -1
  57. data/lib/chef/platform/service_helpers.rb +1 -1
  58. data/lib/chef/provider/apt_repository.rb +7 -4
  59. data/lib/chef/provider/execute.rb +1 -1
  60. data/lib/chef/provider/package/cab.rb +18 -13
  61. data/lib/chef/provider/package/msu.rb +2 -2
  62. data/lib/chef/provider/package/rubygems.rb +3 -5
  63. data/lib/chef/provider/user/aix.rb +1 -1
  64. data/lib/chef/provider/user/windows.rb +1 -1
  65. data/lib/chef/providers.rb +0 -1
  66. data/lib/chef/resource/breakpoint.rb +12 -0
  67. data/lib/chef/resource/env.rb +3 -35
  68. data/lib/chef/resource/route.rb +13 -107
  69. data/lib/chef/resource/service.rb +5 -5
  70. data/lib/chef/resource/user.rb +6 -4
  71. data/lib/chef/resource/windows_task.rb +3 -3
  72. data/lib/chef/run_context.rb +7 -0
  73. data/lib/chef/runner.rb +2 -1
  74. data/lib/chef/version.rb +1 -1
  75. data/spec/functional/resource/chocolatey_package_spec.rb +1 -8
  76. data/spec/functional/resource/registry_spec.rb +1 -1
  77. data/spec/functional/resource/user/useradd_spec.rb +1 -1
  78. data/spec/functional/resource/windows_task_spec.rb +459 -0
  79. data/spec/integration/client/client_spec.rb +32 -0
  80. data/spec/spec_helper.rb +2 -0
  81. data/spec/support/platform_helpers.rb +7 -0
  82. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +3 -3
  83. data/spec/unit/cookbook/synchronizer_spec.rb +5 -4
  84. data/spec/unit/cookbook_manifest_spec.rb +17 -2
  85. data/spec/unit/provider/env_spec.rb +2 -2
  86. data/spec/unit/provider/group/dscl_spec.rb +2 -2
  87. data/spec/unit/provider/group/pw_spec.rb +3 -3
  88. data/spec/unit/provider/group/usermod_spec.rb +6 -6
  89. data/spec/unit/provider/group/windows_spec.rb +3 -3
  90. data/spec/unit/provider/group_spec.rb +4 -4
  91. data/spec/unit/provider/http_request_spec.rb +1 -1
  92. data/spec/unit/provider/package/aix_spec.rb +2 -2
  93. data/spec/unit/provider/package/apt_spec.rb +2 -2
  94. data/spec/unit/provider/package/ips_spec.rb +2 -2
  95. data/spec/unit/provider/package/macports_spec.rb +4 -4
  96. data/spec/unit/provider/package/pacman_spec.rb +2 -2
  97. data/spec/unit/provider/package/rubygems_spec.rb +14 -11
  98. data/spec/unit/provider/package/yum_spec.rb +10 -10
  99. data/spec/unit/provider/route_spec.rb +7 -7
  100. data/spec/unit/provider/service/arch_service_spec.rb +6 -6
  101. data/spec/unit/provider/service/init_service_spec.rb +2 -2
  102. data/spec/unit/provider/service/invokercd_service_spec.rb +1 -1
  103. data/spec/unit/provider/service/simple_service_spec.rb +1 -1
  104. data/spec/unit/provider/service/upstart_service_spec.rb +5 -5
  105. data/spec/unit/provider/service_spec.rb +1 -1
  106. data/spec/unit/provider/user/aix_spec.rb +97 -0
  107. data/spec/unit/provider/user/pw_spec.rb +5 -5
  108. data/spec/unit/provider/user_spec.rb +1 -1
  109. data/spec/unit/provider_resolver_spec.rb +11 -11
  110. data/spec/unit/resource/breakpoint_spec.rb +28 -11
  111. data/spec/unit/resource/windows_task_spec.rb +2 -2
  112. data/spec/unit/runner_spec.rb +4 -0
  113. data/tasks/bin/run_external_test +20 -42
  114. data/tasks/bundle.rb +0 -8
  115. data/tasks/changelog.rb +5 -1
  116. data/tasks/dependencies.rb +4 -2
  117. metadata +80 -19
  118. data/acceptance/fips/.acceptance/acceptance-cookbook/.gitignore +0 -2
  119. data/acceptance/fips/.acceptance/acceptance-cookbook/metadata.rb +0 -2
  120. data/acceptance/fips/.acceptance/acceptance-cookbook/recipes/destroy.rb +0 -1
  121. data/acceptance/fips/.acceptance/acceptance-cookbook/recipes/provision.rb +0 -1
  122. data/acceptance/fips/.acceptance/acceptance-cookbook/recipes/verify.rb +0 -1
  123. data/acceptance/fips/.kitchen.yml +0 -8
  124. data/acceptance/fips/test/integration/fips-integration/serverspec/Gemfile +0 -9
  125. data/acceptance/fips/test/integration/fips-integration/serverspec/fips-integration_spec.rb +0 -52
  126. data/acceptance/fips/test/integration/fips-unit-functional/serverspec/Gemfile +0 -7
  127. data/acceptance/fips/test/integration/fips-unit-functional/serverspec/fips-unit-functional_spec.rb +0 -56
  128. data/lib/chef/provider/breakpoint.rb +0 -38
  129. data/spec/unit/provider/breakpoint_spec.rb +0 -53
  130. data/tasks/bin/create-override-gemfile +0 -110
  131. data/tasks/gemfile_util.rb +0 -390
@@ -2,7 +2,7 @@
2
2
  # Author:: Adam Jacob (<adam@chef.io>)
3
3
  # Author:: Christopher Walters (<cw@chef.io>)
4
4
  # Author:: Tim Hinderliter (<tim@chef.io>)
5
- # Copyright:: Copyright 2008-2016, Chef Software Inc.
5
+ # Copyright:: Copyright 2008-2017, Chef Software Inc.
6
6
  # License:: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,6 +34,7 @@ class Chef
34
34
 
35
35
  def initialize(run_context)
36
36
  @run_context = run_context
37
+ run_context.runner = self
37
38
  end
38
39
 
39
40
  def delayed_actions
@@ -21,7 +21,7 @@
21
21
 
22
22
  class Chef
23
23
  CHEF_ROOT = File.expand_path("../..", __FILE__)
24
- VERSION = "13.0.118"
24
+ VERSION = "13.1.31"
25
25
  end
26
26
 
27
27
  #
@@ -18,16 +18,9 @@
18
18
  require "spec_helper"
19
19
  require "chef/mixin/powershell_out"
20
20
 
21
- describe Chef::Resource::ChocolateyPackage, :windows_only do
21
+ describe Chef::Resource::ChocolateyPackage, :windows_only, :choco_installed do
22
22
  include Chef::Mixin::PowershellOut
23
23
 
24
- before(:all) do
25
- powershell_out!("iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))")
26
- unless ENV["PATH"] =~ /chocolatey\\bin/
27
- ENV["PATH"] = "C:\\ProgramData\\chocolatey\\bin;#{ENV["PATH"]}"
28
- end
29
- end
30
-
31
24
  let(:package_name) { "test-A" }
32
25
  let(:package_list) { proc { powershell_out!("choco list -lo -r #{Array(package_name).join(' ')}").stdout.chomp } }
33
26
  let(:package_source) { File.join(CHEF_SPEC_ASSETS, "chocolatey_feed") }
@@ -124,7 +124,7 @@ describe Chef::Resource::RegistryKey, :windows_only, :broken => true do
124
124
 
125
125
  @new_resource.cookbook_name = "monkey"
126
126
  @cookbook_version = double("Cookbook::Version", :version => "1.2.3")
127
- allow(@new_resource).to receive(:cookbook_version).and_return(@cookbook_version)
127
+ @new_resource.cookbook_version(@cookbook_version)
128
128
  end
129
129
 
130
130
  after (:all) do
@@ -639,7 +639,7 @@ describe Chef::Provider::User::Useradd, metadata do
639
639
  # TODO: platform_family should be setup in spec_helper w/ tags
640
640
  if %w{opensuse}.include?(OHAI_SYSTEM["platform_family"]) ||
641
641
  (%w{suse}.include?(OHAI_SYSTEM["platform_family"]) &&
642
- OHAI_SYSTEM["platform_version"].to_f < 12.1)
642
+ OHAI_SYSTEM["platform_version"].to_f < 12.0)
643
643
  # suse 11.x gets this right:
644
644
  it "errors out trying to unlock the user" do
645
645
  expect(@error).to be_a(Mixlib::ShellOut::ShellCommandFailed)
@@ -0,0 +1,459 @@
1
+ #
2
+ # Author:: Nimisha Sharad (<nimisha.sharad@msystechnologies.com>)
3
+ # Copyright:: Copyright (c) 2016 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require "spec_helper"
20
+ require "chef/provider/windows_task"
21
+
22
+ describe Chef::Resource::WindowsTask, :windows_only do
23
+ let(:task_name) { "chef-client" }
24
+ let(:new_resource) { Chef::Resource::WindowsTask.new(task_name) }
25
+ let(:windows_task_provider) do
26
+ node = Chef::Node.new
27
+ events = Chef::EventDispatch::Dispatcher.new
28
+ run_context = Chef::RunContext.new(node, {}, events)
29
+ Chef::Provider::WindowsTask.new(new_resource, run_context)
30
+ end
31
+
32
+ describe "action :create" do
33
+ after { delete_task }
34
+
35
+ context "when frequency and frequency_modifier are not passed" do
36
+ subject do
37
+ new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
38
+ new_resource.command task_name
39
+ new_resource
40
+ end
41
+
42
+ it "creates a scheduled task to run every 1 hr" do
43
+ subject.run_action(:create)
44
+ task_details = windows_task_provider.send(:load_task_hash, task_name)
45
+ expect(task_details[:TaskName]).to eq("\\chef-client")
46
+ expect(task_details[:TaskToRun]).to eq("chef-client")
47
+ expect(task_details[:"Repeat:Every"]).to eq("1 Hour(s), 0 Minute(s)")
48
+ end
49
+ end
50
+
51
+ context "frequency :minute" do
52
+ subject do
53
+ new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
54
+ new_resource.command task_name
55
+ new_resource.run_level :highest
56
+ new_resource.frequency :minute
57
+ new_resource.frequency_modifier 15
58
+ new_resource
59
+ end
60
+
61
+ it "creates a scheduled task that runs after every 15 minutes" do
62
+ subject.run_action(:create)
63
+ task_details = windows_task_provider.send(:load_task_hash, task_name)
64
+ expect(task_details[:TaskName]).to eq("\\chef-client")
65
+ expect(task_details[:Status]).to eq("Ready")
66
+ expect(task_details[:TaskToRun]).to eq("chef-client")
67
+ expect(task_details[:"Repeat:Every"]).to eq("0 Hour(s), 15 Minute(s)")
68
+ expect(task_details[:run_level]).to eq("HighestAvailable")
69
+ end
70
+ end
71
+
72
+ context "frequency :hourly" do
73
+ subject do
74
+ new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
75
+ new_resource.command task_name
76
+ new_resource.run_level :highest
77
+ new_resource.frequency :hourly
78
+ new_resource.frequency_modifier 3
79
+ new_resource
80
+ end
81
+
82
+ it "creates a scheduled task that runs after every 3 hrs" do
83
+ subject.run_action(:create)
84
+ task_details = windows_task_provider.send(:load_task_hash, task_name)
85
+ expect(task_details[:TaskName]).to eq("\\chef-client")
86
+ expect(task_details[:Status]).to eq("Ready")
87
+ expect(task_details[:TaskToRun]).to eq("chef-client")
88
+ expect(task_details[:"Repeat:Every"]).to eq("3 Hour(s), 0 Minute(s)")
89
+ expect(task_details[:run_level]).to eq("HighestAvailable")
90
+ end
91
+ end
92
+
93
+ context "frequency :daily" do
94
+ subject do
95
+ new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
96
+ new_resource.command task_name
97
+ new_resource.run_level :highest
98
+ new_resource.frequency :daily
99
+ new_resource
100
+ end
101
+
102
+ it "creates a scheduled task to run daily" do
103
+ subject.run_action(:create)
104
+ task_details = windows_task_provider.send(:load_task_hash, task_name)
105
+ expect(task_details[:TaskName]).to eq("\\chef-client")
106
+ expect(task_details[:Status]).to eq("Ready")
107
+ expect(task_details[:TaskToRun]).to eq("chef-client")
108
+ expect(task_details[:ScheduleType]).to eq("Daily")
109
+ expect(task_details[:Days]).to eq("Every 1 day(s)")
110
+ expect(task_details[:run_level]).to eq("HighestAvailable")
111
+ end
112
+ end
113
+
114
+ context "frequency :monthly" do
115
+ subject do
116
+ new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
117
+ new_resource.command task_name
118
+ new_resource.run_level :highest
119
+ new_resource.frequency :monthly
120
+ new_resource.frequency_modifier 2
121
+ new_resource
122
+ end
123
+
124
+ it "creates a scheduled task to every 2 months" do
125
+ subject.run_action(:create)
126
+ task_details = windows_task_provider.send(:load_task_hash, task_name)
127
+ expect(task_details[:TaskName]).to eq("\\chef-client")
128
+ expect(task_details[:Status]).to eq("Ready")
129
+ expect(task_details[:TaskToRun]).to eq("chef-client")
130
+ expect(task_details[:ScheduleType]).to eq("Monthly")
131
+ expect(task_details[:Months]).to eq("FEB, APR, JUN, AUG, OCT, DEC")
132
+ expect(task_details[:run_level]).to eq("HighestAvailable")
133
+ end
134
+ end
135
+
136
+ context "frequency :once" do
137
+ subject do
138
+ new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
139
+ new_resource.command task_name
140
+ new_resource.run_level :highest
141
+ new_resource.frequency :once
142
+ new_resource
143
+ end
144
+
145
+ context "when start_time is not provided" do
146
+ it "raises argument error" do
147
+ expect { subject.run_action(:create) }.to raise_error(Mixlib::ShellOut::ShellCommandFailed)
148
+ end
149
+ end
150
+
151
+ context "when start_time is provided" do
152
+ it "creates the scheduled task to run once at 5pm" do
153
+ subject.start_time "17:00"
154
+ subject.run_action(:create)
155
+ task_details = windows_task_provider.send(:load_task_hash, task_name)
156
+ expect(task_details[:TaskName]).to eq("\\chef-client")
157
+ expect(task_details[:Status]).to eq("Ready")
158
+ expect(task_details[:TaskToRun]).to eq("chef-client")
159
+ expect(task_details[:ScheduleType]).to eq("One Time Only")
160
+ expect(task_details[:StartTime]).to eq("5:00:00 PM")
161
+ expect(task_details[:run_level]).to eq("HighestAvailable")
162
+ end
163
+ end
164
+ end
165
+
166
+ context "frequency :weekly" do
167
+ subject do
168
+ new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
169
+ new_resource.command task_name
170
+ new_resource.run_level :highest
171
+ new_resource.frequency :weekly
172
+ new_resource
173
+ end
174
+
175
+ it "creates the scheduled task to run weekly" do
176
+ subject.run_action(:create)
177
+ task_details = windows_task_provider.send(:load_task_hash, task_name)
178
+ expect(task_details[:TaskName]).to eq("\\chef-client")
179
+ expect(task_details[:Status]).to eq("Ready")
180
+ expect(task_details[:TaskToRun]).to eq("chef-client")
181
+ expect(task_details[:ScheduleType]).to eq("Weekly")
182
+ expect(task_details[:Months]).to eq("Every 1 week(s)")
183
+ expect(task_details[:run_level]).to eq("HighestAvailable")
184
+ end
185
+
186
+ context "when days are provided" do
187
+ it "creates the scheduled task to run on particular days" do
188
+ subject.day "Mon, Fri"
189
+ subject.frequency_modifier 2
190
+ subject.run_action(:create)
191
+ task_details = windows_task_provider.send(:load_task_hash, task_name)
192
+ expect(task_details[:TaskName]).to eq("\\chef-client")
193
+ expect(task_details[:Status]).to eq("Ready")
194
+ expect(task_details[:TaskToRun]).to eq("chef-client")
195
+ expect(task_details[:Days]).to eq("MON, FRI")
196
+ expect(task_details[:ScheduleType]).to eq("Weekly")
197
+ expect(task_details[:Months]).to eq("Every 2 week(s)")
198
+ expect(task_details[:run_level]).to eq("HighestAvailable")
199
+ end
200
+ end
201
+
202
+ context "when invalid day is passed" do
203
+ it "raises error" do
204
+ subject.day "abc"
205
+ expect { subject.run_action(:create) }.to raise_error(Mixlib::ShellOut::ShellCommandFailed)
206
+ end
207
+ end
208
+
209
+ context "when months are passed" do
210
+ it "raises error that months are supported only when frequency=:monthly" do
211
+ subject.months "Jan"
212
+ expect { subject.run_action(:create) }.to raise_error(Mixlib::ShellOut::ShellCommandFailed)
213
+ end
214
+ end
215
+ end
216
+
217
+ context "frequency :on_logon" do
218
+ subject do
219
+ new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
220
+ new_resource.command task_name
221
+ new_resource.run_level :highest
222
+ new_resource.frequency :on_logon
223
+ new_resource
224
+ end
225
+
226
+ it "creates the scheduled task to on logon" do
227
+ subject.run_action(:create)
228
+ task_details = windows_task_provider.send(:load_task_hash, task_name)
229
+ expect(task_details[:TaskName]).to eq("\\chef-client")
230
+ expect(task_details[:Status]).to eq("Ready")
231
+ expect(task_details[:TaskToRun]).to eq("chef-client")
232
+ expect(task_details[:ScheduleType]).to eq("At logon time")
233
+ expect(task_details[:run_level]).to eq("HighestAvailable")
234
+ end
235
+ end
236
+
237
+ context "frequency :on_idle" do
238
+ subject do
239
+ new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
240
+ new_resource.command task_name
241
+ new_resource.run_level :highest
242
+ new_resource.frequency :on_idle
243
+ new_resource
244
+ end
245
+
246
+ context "when idle_time is not passed" do
247
+ it "raises error" do
248
+ expect { subject.run_action(:create) }.to raise_error(Mixlib::ShellOut::ShellCommandFailed)
249
+ end
250
+ end
251
+
252
+ context "when idle_time is passed" do
253
+ it "creates the scheduled task to run when system is idle" do
254
+ subject.idle_time 20
255
+ subject.run_action(:create)
256
+ task_details = windows_task_provider.send(:load_task_hash, task_name)
257
+ expect(task_details[:TaskName]).to eq("\\chef-client")
258
+ expect(task_details[:TaskToRun]).to eq("chef-client")
259
+ expect(task_details[:ScheduleType]).to eq("At idle time")
260
+ expect(task_details[:run_level]).to eq("HighestAvailable")
261
+ expect(task_details[:idle_time]).to eq("PT20M")
262
+ end
263
+ end
264
+ end
265
+
266
+ context "when random_delay is passed" do
267
+ subject do
268
+ new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
269
+ new_resource.command task_name
270
+ new_resource.run_level :highest
271
+ new_resource
272
+ end
273
+
274
+ it "sets the random_delay for frequency :minute" do
275
+ subject.frequency :minute
276
+ subject.random_delay "PT20M"
277
+ subject.run_action(:create)
278
+ task_details = windows_task_provider.send(:load_task_hash, task_name)
279
+ expect(task_details[:TaskName]).to eq("\\chef-client")
280
+ expect(task_details[:ScheduleType]).to eq("One Time Only, Minute")
281
+ expect(task_details[:TaskToRun]).to eq("chef-client")
282
+ expect(task_details[:run_level]).to eq("HighestAvailable")
283
+ expect(task_details[:random_delay]).to eq("PT20M")
284
+ end
285
+
286
+ it "raises error if invalid random_delay is passed" do
287
+ subject.frequency :minute
288
+ subject.random_delay "abc"
289
+ expect { subject.after_created }.to raise_error("Invalid value passed for `random_delay`. Please pass seconds as a String e.g. '60'.")
290
+ end
291
+
292
+ it "raises error if random_delay is passed with frequency on_idle" do
293
+ subject.frequency :on_idle
294
+ subject.random_delay "PT20M"
295
+ expect { subject.after_created }.to raise_error("`random_delay` property is supported only for frequency :minute, :hourly, :daily, :weekly and :monthly")
296
+ end
297
+ end
298
+ end
299
+
300
+ describe "#after_created" do
301
+ subject do
302
+ new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
303
+ new_resource.command task_name
304
+ new_resource.run_level :highest
305
+ new_resource
306
+ end
307
+
308
+ context "when start_day is passed with frequency :onstart" do
309
+ it "raises error" do
310
+ subject.frequency :onstart
311
+ subject.start_day "mon"
312
+ expect { subject.after_created }.to raise_error("`start_day` property is not supported with frequency: onstart")
313
+ end
314
+ end
315
+
316
+ context "when a non-system user is passed without password" do
317
+ it "raises error" do
318
+ subject.user "Administrator"
319
+ subject.frequency :onstart
320
+ expect { subject.after_created }.to raise_error("Can't specify a non-system user without a password!")
321
+ end
322
+ end
323
+
324
+ context "when interactive_enabled is passed for a System user without password" do
325
+ it "raises error" do
326
+ subject.interactive_enabled true
327
+ subject.frequency :onstart
328
+ expect { subject.after_created }.to raise_error("Please provide the password when attempting to set interactive/non-interactive.")
329
+ end
330
+ end
331
+
332
+ context "when frequency_modifier > 1439 is passed for frequency=:minute" do
333
+ it "raises error" do
334
+ subject.frequency_modifier 1450
335
+ subject.frequency :minute
336
+ expect { subject.after_created }.to raise_error("frequency_modifier value 1450 is invalid. Valid values for :minute frequency are 1 - 1439.")
337
+ end
338
+ end
339
+
340
+ context "when invalid months are passed" do
341
+ it "raises error" do
342
+ subject.months "xyz"
343
+ subject.frequency :monthly
344
+ expect { subject.after_created }.to raise_error("months attribute invalid. Only valid values are: JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC and *. Multiple values must be separated by a comma.")
345
+ end
346
+ end
347
+
348
+ context "when idle_time > 999 is passed" do
349
+ it "raises error" do
350
+ subject.idle_time 1000
351
+ subject.frequency :on_idle
352
+ expect { subject.after_created }.to raise_error("idle_time value 1000 is invalid. Valid values for :on_idle frequency are 1 - 999.")
353
+ end
354
+ end
355
+
356
+ context "when idle_time is passed for frequency=:monthly" do
357
+ it "raises error" do
358
+ subject.idle_time 300
359
+ subject.frequency :monthly
360
+ expect { subject.after_created }.to raise_error("idle_time attribute is only valid for tasks that run on_idle")
361
+ end
362
+ end
363
+ end
364
+
365
+ describe "action :delete" do
366
+ subject do
367
+ new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
368
+ new_resource.command task_name
369
+ new_resource
370
+ end
371
+
372
+ it "deletes the task if it exists" do
373
+ subject.run_action(:create)
374
+ delete_task
375
+ task_details = windows_task_provider.send(:load_task_hash, task_name)
376
+ expect(task_details).to eq(false)
377
+ end
378
+ end
379
+
380
+ describe "action :run" do
381
+ after { delete_task }
382
+
383
+ subject do
384
+ new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
385
+ new_resource.command "dir"
386
+ new_resource.run_level :highest
387
+ new_resource
388
+ end
389
+
390
+ it "runs the existing task" do
391
+ skip "Task status is returned as Ready instead of Running randomly"
392
+ subject.run_action(:create)
393
+ subject.run_action(:run)
394
+ task_details = windows_task_provider.send(:load_task_hash, task_name)
395
+ expect(task_details[:Status]).to eq("Running")
396
+ end
397
+ end
398
+
399
+ describe "action :end", :volatile do
400
+ after { delete_task }
401
+
402
+ subject do
403
+ new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
404
+ new_resource.command task_name
405
+ new_resource
406
+ end
407
+
408
+ it "ends the running task" do
409
+ subject.run_action(:create)
410
+ subject.run_action(:run)
411
+ task_details = windows_task_provider.send(:load_task_hash, task_name)
412
+ subject.run_action(:end)
413
+ task_details = windows_task_provider.send(:load_task_hash, task_name)
414
+ expect(task_details[:Status]).to eq("Ready")
415
+ end
416
+ end
417
+
418
+ describe "action :enable" do
419
+ after { delete_task }
420
+
421
+ subject do
422
+ new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
423
+ new_resource.command task_name
424
+ new_resource
425
+ end
426
+
427
+ it "enables the disabled task" do
428
+ subject.run_action(:create)
429
+ subject.run_action(:disable)
430
+ task_details = windows_task_provider.send(:load_task_hash, task_name)
431
+ expect(task_details[:ScheduledTaskState]).to eq("Disabled")
432
+ subject.run_action(:enable)
433
+ task_details = windows_task_provider.send(:load_task_hash, task_name)
434
+ expect(task_details[:ScheduledTaskState]).to eq("Enabled")
435
+ end
436
+ end
437
+
438
+ describe "action :disable" do
439
+ after { delete_task }
440
+
441
+ subject do
442
+ new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
443
+ new_resource.command task_name
444
+ new_resource
445
+ end
446
+
447
+ it "disables the task" do
448
+ subject.run_action(:create)
449
+ subject.run_action(:disable)
450
+ task_details = windows_task_provider.send(:load_task_hash, task_name)
451
+ expect(task_details[:ScheduledTaskState]).to eq("Disabled")
452
+ end
453
+ end
454
+
455
+ def delete_task
456
+ task_to_delete = Chef::Resource::WindowsTask.new(task_name, run_context)
457
+ task_to_delete.run_action(:delete)
458
+ end
459
+ end