win32-taskscheduler 2.0.1 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/win32-taskscheduler.rb +1 -1
- data/lib/win32/taskscheduler.rb +266 -292
- data/lib/win32/taskscheduler/constants.rb +6 -6
- data/lib/win32/taskscheduler/helper.rb +10 -10
- data/lib/win32/taskscheduler/sid.rb +12 -12
- data/lib/win32/taskscheduler/time_calc_helper.rb +71 -40
- data/lib/win32/taskscheduler/version.rb +1 -1
- metadata +5 -53
- data/CHANGELOG.md +0 -184
- data/Gemfile +0 -3
- data/README.md +0 -78
- data/RELEASE_NOTES.md +0 -14
- data/Rakefile +0 -38
- data/VERSION +0 -1
- data/appveyor.yml +0 -40
- data/examples/taskscheduler_example.rb +0 -54
- data/spec/functional/win32/taskscheduler/time_calc_helper_spec.rb +0 -392
- data/spec/functional/win32/taskscheduler_spec.rb +0 -883
- data/spec/spec_helper.rb +0 -224
- data/spec/unit/win32/taskscheduler/constants_spec.rb +0 -20
- data/spec/unit/win32/taskscheduler/time_calc_helper_spec.rb +0 -217
- data/spec/unit/win32/taskscheduler_spec.rb +0 -169
- data/test/test_taskscheduler.rb +0 -690
- data/win32-taskscheduler.gemspec +0 -34
@@ -1,883 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'win32ole'
|
3
|
-
require 'win32/taskscheduler'
|
4
|
-
|
5
|
-
RSpec.describe Win32::TaskScheduler, :windows_only do
|
6
|
-
before { create_test_folder }
|
7
|
-
after { clear_them }
|
8
|
-
before { load_task_variables }
|
9
|
-
|
10
|
-
describe '#constructor' do
|
11
|
-
let(:ts) { Win32::TaskScheduler }
|
12
|
-
context 'Task' do
|
13
|
-
it 'Does not creates task when default(nil)' do
|
14
|
-
task = nil
|
15
|
-
expect(ts.new(task)).to be_a(ts)
|
16
|
-
expect(no_of_tasks).to eq(0)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'Does not creates task without trigger' do
|
20
|
-
expect(ts.new(@task)).to be_a(ts)
|
21
|
-
expect(no_of_tasks).to eq(0)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'Creates a task with trigger' do
|
25
|
-
expect(ts.new(@task, @trigger)).to be_a(ts)
|
26
|
-
expect(no_of_tasks).to eq(1)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'Trigger' do
|
31
|
-
it 'Does not creates task when default(nil)' do
|
32
|
-
trigger = nil
|
33
|
-
expect(ts.new(@task, trigger)).to be_a(ts)
|
34
|
-
expect(no_of_tasks).to eq(0)
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'Raises error without trigger type' do
|
38
|
-
@trigger[:trigger_type] = nil
|
39
|
-
expect { ts.new(@task, @trigger) }.to raise_error(ArgumentError)
|
40
|
-
expect(no_of_tasks).to eq(0)
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'Creates a task with trigger type' do
|
44
|
-
expect(ts.new(@task, @trigger)).to be_a(ts)
|
45
|
-
expect(no_of_tasks).to eq(1)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'Folder' do
|
50
|
-
let(:folder) { '\\Foo' }
|
51
|
-
it 'Raises error when nil' do
|
52
|
-
expect { ts.new(@task, @trigger, nil) }.to raise_error(NoMethodError)
|
53
|
-
expect(no_of_tasks).to eq(0)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "Raises error when path separators(\\\) are absent" do
|
57
|
-
invalid_path = 'Foo'
|
58
|
-
expect { ts.new(@task, @trigger, invalid_path) }.to raise_error(ArgumentError)
|
59
|
-
expect(no_of_tasks).to eq(0)
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'Creates a task when default(root)' do
|
63
|
-
expect(ts.new(@task, @trigger, @folder)).to be_a(ts)
|
64
|
-
expect(no_of_tasks).to eq(1)
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'When force is true' do
|
68
|
-
let(:force) { true }
|
69
|
-
it 'Creates a task at specified folder' do
|
70
|
-
expect(ts.new(@task, @trigger, folder, force)).to be_a(ts)
|
71
|
-
expect(no_of_tasks(folder)).to eq(1)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'When force is false' do
|
76
|
-
let(:force) { false }
|
77
|
-
it 'Raises an error when folder does not exists' do
|
78
|
-
expect { ts.new(@task, @trigger, folder, force) }.to raise_error(ArgumentError)
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'Creates a task at specified folder if it exists' do
|
82
|
-
new_folder = @test_folder.CreateFolder(folder)
|
83
|
-
expect(ts.new(@task, @trigger, new_folder.Path, force)).to be_a(ts)
|
84
|
-
expect(no_of_tasks(folder)).to eq(1)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe '#tasks' do
|
91
|
-
before { create_task }
|
92
|
-
it 'Returns Task Names' do
|
93
|
-
expect(@ts.tasks).to include(@task)
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'is an alias with enum' do
|
97
|
-
expect(@ts.enum).to include(@task)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe '#exists?' do
|
102
|
-
let(:folder) { '\\Foo' }
|
103
|
-
let(:force) { true }
|
104
|
-
before { create_task }
|
105
|
-
|
106
|
-
context 'valid task path returns true' do
|
107
|
-
it 'at root' do
|
108
|
-
expect(@ts.exists?(@task)).to be_truthy
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'at nested folder' do
|
112
|
-
@ts = Win32::TaskScheduler.new(@task, @trigger, folder, force)
|
113
|
-
task = @test_path + folder + '\\' + @task
|
114
|
-
expect(@ts.exists?(task)).to be_truthy
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
context 'invalid task path returns false' do
|
119
|
-
it 'at root' do
|
120
|
-
expect(@ts.exists?('invalid')).to be_falsy
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'at nested folder' do
|
124
|
-
@ts = Win32::TaskScheduler.new(@task, @trigger, folder, force)
|
125
|
-
task = folder + '\\' + 'invalid'
|
126
|
-
expect(@ts.exists?(task)).to be_falsy
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe '#get_task' do
|
132
|
-
let(:folder) { '\\Foo' }
|
133
|
-
let(:force) { true }
|
134
|
-
before { create_task }
|
135
|
-
|
136
|
-
context 'from root' do
|
137
|
-
it 'Returns the Task if exists' do
|
138
|
-
expect(@ts.get_task(@task)).to be_a(@current_task.class)
|
139
|
-
end
|
140
|
-
|
141
|
-
it 'Raises an error if task does not exists' do
|
142
|
-
expect { @ts.get_task('invalid') }.to raise_error(tasksch_err)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context 'from nested folder' do
|
147
|
-
it 'Returns the Task if exists' do
|
148
|
-
skip 'Implementation Pending'
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'Raises an error if task does not exists' do
|
152
|
-
skip 'Implementation Pending'
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
describe '#activate' do
|
158
|
-
let(:folder) { '\\Foo' }
|
159
|
-
let(:force) { true }
|
160
|
-
before { create_task }
|
161
|
-
|
162
|
-
context 'from root' do
|
163
|
-
it 'Activates the Task if exists' do
|
164
|
-
expect(@ts.activate(@task)).to be_a(@current_task.class)
|
165
|
-
expect(@current_task.Enabled).to be_truthy
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'Raises an error if task does not exists' do
|
169
|
-
expect { @ts.activate('invalid') }.to raise_error(tasksch_err)
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
context 'from nested folder' do
|
174
|
-
it 'Activates the Task if exists' do
|
175
|
-
skip 'Implementation Pending'
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'Raises an error if task does not exists' do
|
179
|
-
skip 'Implementation Pending'
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
describe '#delete' do
|
185
|
-
let(:folder) { '\\Foo' }
|
186
|
-
let(:force) { true }
|
187
|
-
before { create_task }
|
188
|
-
|
189
|
-
context 'from root' do
|
190
|
-
it 'Deletes the Task if exists' do
|
191
|
-
expect(no_of_tasks).to eq(1)
|
192
|
-
@ts.delete(@task)
|
193
|
-
expect(no_of_tasks).to eq(0)
|
194
|
-
end
|
195
|
-
|
196
|
-
it 'Raises an error if task does not exists' do
|
197
|
-
expect { @ts.delete('invalid') }.to raise_error(tasksch_err)
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
context 'from nested folder' do
|
202
|
-
it 'Activates the Task if exists' do
|
203
|
-
skip 'Implementation Pending'
|
204
|
-
end
|
205
|
-
|
206
|
-
it 'Raises an error if task does not exists' do
|
207
|
-
skip 'Implementation Pending'
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
describe '#run' do
|
213
|
-
before { create_task }
|
214
|
-
after { stop_the_app }
|
215
|
-
|
216
|
-
it 'Execute(Start) the Task' do
|
217
|
-
@ts.run
|
218
|
-
expect(@ts.status).to eq('running')
|
219
|
-
.or eq('queued')
|
220
|
-
.or eq('ready') # It takes time to load sometimes
|
221
|
-
end
|
222
|
-
|
223
|
-
it 'Raises an error if task does not exists' do
|
224
|
-
@ts.instance_variable_set(:@task, nil)
|
225
|
-
expect { @ts.run }.to raise_error(tasksch_err)
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
describe '#terminate' do
|
230
|
-
before { create_task }
|
231
|
-
after { stop_the_app }
|
232
|
-
|
233
|
-
it 'terminates the Task if exists' do
|
234
|
-
@ts.terminate
|
235
|
-
expect(@ts.status).to eq('ready')
|
236
|
-
end
|
237
|
-
|
238
|
-
it 'has an alias stop' do
|
239
|
-
@ts.stop
|
240
|
-
expect(@ts.status).to eq('ready')
|
241
|
-
end
|
242
|
-
|
243
|
-
it 'Raises an error if task does not exists' do
|
244
|
-
@ts.instance_variable_set(:@task, nil)
|
245
|
-
expect { @ts.terminate }.to raise_error(tasksch_err)
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
describe '#application_name' do
|
250
|
-
before { create_task }
|
251
|
-
it 'Returns the application name of task' do
|
252
|
-
check = @app
|
253
|
-
expect(@ts.application_name).to eq(check)
|
254
|
-
end
|
255
|
-
|
256
|
-
it 'Sets the application name of task' do
|
257
|
-
stub_user
|
258
|
-
check = 'cmd.exe'
|
259
|
-
expect(@ts.application_name = check).to eq(check)
|
260
|
-
expect(@ts.application_name).to eq(check)
|
261
|
-
end
|
262
|
-
|
263
|
-
it 'Raises an error if task does not exists' do
|
264
|
-
@ts.instance_variable_set(:@task, nil)
|
265
|
-
expect { @ts.application_name }.to raise_error(tasksch_err)
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
describe '#parameters' do
|
270
|
-
before { create_task }
|
271
|
-
it 'Returns the parameters of task' do
|
272
|
-
check = ''
|
273
|
-
expect(@ts.parameters).to eq(check)
|
274
|
-
end
|
275
|
-
|
276
|
-
it 'Sets the parameters of task' do
|
277
|
-
stub_user
|
278
|
-
check = 'cmd.exe'
|
279
|
-
expect(@ts.parameters = check).to eq(check)
|
280
|
-
expect(@ts.parameters).to eq(check)
|
281
|
-
end
|
282
|
-
|
283
|
-
it 'Raises an error if task does not exists' do
|
284
|
-
@ts.instance_variable_set(:@task, nil)
|
285
|
-
expect { @ts.parameters }.to raise_error(tasksch_err)
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
describe '#working_directory' do
|
290
|
-
before { create_task }
|
291
|
-
it 'Returns the working directory of task' do
|
292
|
-
check = ''
|
293
|
-
expect(@ts.working_directory).to eq(check)
|
294
|
-
end
|
295
|
-
|
296
|
-
it 'Sets the working directory of task' do
|
297
|
-
stub_user
|
298
|
-
check = Dir.pwd
|
299
|
-
expect(@ts.working_directory = check).to eq(check)
|
300
|
-
expect(@ts.working_directory).to eq(check)
|
301
|
-
end
|
302
|
-
|
303
|
-
it 'Raises an error if task does not exists' do
|
304
|
-
@ts.instance_variable_set(:@task, nil)
|
305
|
-
expect { @ts.working_directory }.to raise_error(tasksch_err)
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
309
|
-
describe '#priority' do
|
310
|
-
before { create_task }
|
311
|
-
it 'Returns default priority of task' do
|
312
|
-
check = 'below_normal_7'
|
313
|
-
expect(@ts.priority).to eq(check)
|
314
|
-
end
|
315
|
-
|
316
|
-
it '0 Sets the priority of task to critical' do
|
317
|
-
stub_user
|
318
|
-
check = 0
|
319
|
-
expect(@ts.priority = check).to eq(check)
|
320
|
-
expect(@ts.priority).to eq('critical')
|
321
|
-
end
|
322
|
-
|
323
|
-
it '1 Sets the priority of task to highest' do
|
324
|
-
stub_user
|
325
|
-
check = 1
|
326
|
-
expect(@ts.priority = check).to eq(check)
|
327
|
-
expect(@ts.priority).to eq('highest')
|
328
|
-
end
|
329
|
-
|
330
|
-
it '2 Sets the priority of task to above_normal_2' do
|
331
|
-
stub_user
|
332
|
-
check = 2
|
333
|
-
expect(@ts.priority = check).to eq(check)
|
334
|
-
expect(@ts.priority).to eq('above_normal_2')
|
335
|
-
end
|
336
|
-
|
337
|
-
it '3 Sets the priority of task to above_normal_3' do
|
338
|
-
stub_user
|
339
|
-
check = 3
|
340
|
-
expect(@ts.priority = check).to eq(check)
|
341
|
-
expect(@ts.priority).to eq('above_normal_3')
|
342
|
-
end
|
343
|
-
|
344
|
-
it '4 Sets the priority of task to normal_4' do
|
345
|
-
stub_user
|
346
|
-
check = 4
|
347
|
-
expect(@ts.priority = check).to eq(check)
|
348
|
-
expect(@ts.priority).to eq('normal_4')
|
349
|
-
end
|
350
|
-
|
351
|
-
it '5 Sets the priority of task to normal_5' do
|
352
|
-
stub_user
|
353
|
-
check = 5
|
354
|
-
expect(@ts.priority = check).to eq(check)
|
355
|
-
expect(@ts.priority).to eq('normal_5')
|
356
|
-
end
|
357
|
-
|
358
|
-
it '6 Sets the priority of task to normal_6' do
|
359
|
-
stub_user
|
360
|
-
check = 6
|
361
|
-
expect(@ts.priority = check).to eq(check)
|
362
|
-
expect(@ts.priority).to eq('normal_6')
|
363
|
-
end
|
364
|
-
|
365
|
-
it '7 Sets the priority of task to below_normal_7' do
|
366
|
-
stub_user
|
367
|
-
check = 7
|
368
|
-
expect(@ts.priority = check).to eq(check)
|
369
|
-
expect(@ts.priority).to eq('below_normal_7')
|
370
|
-
end
|
371
|
-
|
372
|
-
it '8 Sets the priority of task to below_normal_8' do
|
373
|
-
stub_user
|
374
|
-
check = 8
|
375
|
-
expect(@ts.priority = check).to eq(check)
|
376
|
-
expect(@ts.priority).to eq('below_normal_8')
|
377
|
-
end
|
378
|
-
|
379
|
-
it '9 Sets the priority of task to lowest' do
|
380
|
-
stub_user
|
381
|
-
check = 9
|
382
|
-
expect(@ts.priority = check).to eq(check)
|
383
|
-
expect(@ts.priority).to eq('lowest')
|
384
|
-
end
|
385
|
-
|
386
|
-
it '10 Sets the priority of task to idle' do
|
387
|
-
stub_user
|
388
|
-
check = 10
|
389
|
-
expect(@ts.priority = check).to eq(check)
|
390
|
-
expect(@ts.priority).to eq('idle')
|
391
|
-
end
|
392
|
-
|
393
|
-
it 'Raises an error if task does not exists' do
|
394
|
-
@ts.instance_variable_set(:@task, nil)
|
395
|
-
expect { @ts.priority }.to raise_error(tasksch_err)
|
396
|
-
end
|
397
|
-
end
|
398
|
-
|
399
|
-
describe '#comment' do
|
400
|
-
before { create_task }
|
401
|
-
it 'Returns the comment of task' do
|
402
|
-
check = 'Sample task for testing purpose'
|
403
|
-
expect(@ts.comment).to eq(check)
|
404
|
-
end
|
405
|
-
|
406
|
-
it 'Sets the Comment(Description) of task' do
|
407
|
-
stub_user
|
408
|
-
check = 'Description To Test'
|
409
|
-
expect(@ts.comment = check).to eq(check)
|
410
|
-
expect(@ts.comment).to eq(check)
|
411
|
-
end
|
412
|
-
|
413
|
-
it 'alias with Description' do
|
414
|
-
stub_user
|
415
|
-
check = 'Description To Test'
|
416
|
-
expect(@ts.description = check).to eq(check)
|
417
|
-
expect(@ts.comment).to eq(check)
|
418
|
-
end
|
419
|
-
|
420
|
-
it 'Raises an error if task does not exists' do
|
421
|
-
@ts.instance_variable_set(:@task, nil)
|
422
|
-
expect { @ts.comment }.to raise_error(tasksch_err)
|
423
|
-
end
|
424
|
-
end
|
425
|
-
|
426
|
-
describe '#author' do
|
427
|
-
before { create_task }
|
428
|
-
it 'Returns the author of task' do
|
429
|
-
check = 'Rspec'
|
430
|
-
expect(@ts.author).to eq(check)
|
431
|
-
end
|
432
|
-
|
433
|
-
it 'Sets the Author of task' do
|
434
|
-
stub_user
|
435
|
-
check = 'Author'
|
436
|
-
expect(@ts.author = check).to eq(check)
|
437
|
-
expect(@ts.author).to eq(check)
|
438
|
-
end
|
439
|
-
|
440
|
-
it 'alias with Creator' do
|
441
|
-
stub_user
|
442
|
-
check = 'Description To Test'
|
443
|
-
expect(@ts.creator = check).to eq(check)
|
444
|
-
expect(@ts.author).to eq(check)
|
445
|
-
end
|
446
|
-
|
447
|
-
it 'Raises an error if task does not exists' do
|
448
|
-
@ts.instance_variable_set(:@task, nil)
|
449
|
-
expect { @ts.author }.to raise_error(tasksch_err)
|
450
|
-
end
|
451
|
-
end
|
452
|
-
|
453
|
-
describe '#max_run_time' do
|
454
|
-
before { create_task }
|
455
|
-
it 'Returns the Execution Time Limit of task' do
|
456
|
-
skip 'Due to logical error in implementation'
|
457
|
-
check = (72 * 60 * 60) # Task: PT72H
|
458
|
-
expect(@ts.max_run_time).to eq(check)
|
459
|
-
end
|
460
|
-
|
461
|
-
it 'Sets the max_run_time of task' do
|
462
|
-
skip 'Due to logical error in implementation'
|
463
|
-
check = 1_244_145_000_000
|
464
|
-
expect(@ts.max_run_time = check).to eq(check)
|
465
|
-
expect(@ts.max_run_time).to eq(check)
|
466
|
-
end
|
467
|
-
|
468
|
-
it 'Raises an error if task does not exists' do
|
469
|
-
@ts.instance_variable_set(:@task, nil)
|
470
|
-
expect { @ts.max_run_time }.to raise_error(tasksch_err)
|
471
|
-
end
|
472
|
-
end
|
473
|
-
|
474
|
-
describe '#enabled?' do
|
475
|
-
before { create_task }
|
476
|
-
it 'Returns true when Task is enabled' do
|
477
|
-
expect(@ts.enabled?).to be_truthy
|
478
|
-
end
|
479
|
-
|
480
|
-
it 'Raises an error if task does not exists' do
|
481
|
-
@ts.instance_variable_set(:@task, nil)
|
482
|
-
expect { @ts.enabled? }.to raise_error(tasksch_err)
|
483
|
-
end
|
484
|
-
end
|
485
|
-
|
486
|
-
describe '#next_run_time' do
|
487
|
-
before { create_task }
|
488
|
-
it 'Returns a Time object that indicates the next time the task will run' do
|
489
|
-
expect(@ts.next_run_time).to be_a(Time)
|
490
|
-
end
|
491
|
-
|
492
|
-
it 'Raises an error if task does not exists' do
|
493
|
-
@ts.instance_variable_set(:@task, nil)
|
494
|
-
expect { @ts.next_run_time }.to raise_error(tasksch_err)
|
495
|
-
end
|
496
|
-
end
|
497
|
-
|
498
|
-
describe '#most_recent_run_time' do
|
499
|
-
before { create_task }
|
500
|
-
|
501
|
-
it 'Returns nil if the task has never run' do
|
502
|
-
skip 'Error in implementation; Time.parse requires String'
|
503
|
-
expect(@ts.most_recent_run_time).to be_nil
|
504
|
-
end
|
505
|
-
|
506
|
-
it 'Returns Time object indicating the most recent time the task ran' do
|
507
|
-
skip 'Error in implementation; Time.parse requires String'
|
508
|
-
@ts.run
|
509
|
-
expect(@ts.most_recent_run_time).to be_a(Time)
|
510
|
-
@ts.stop
|
511
|
-
end
|
512
|
-
|
513
|
-
it 'Raises an error if task does not exists' do
|
514
|
-
@ts.instance_variable_set(:@task, nil)
|
515
|
-
expect { @ts.most_recent_run_time }.to raise_error(tasksch_err)
|
516
|
-
end
|
517
|
-
end
|
518
|
-
|
519
|
-
describe '#account_information' do
|
520
|
-
before { create_task }
|
521
|
-
context 'Service Account Users' do
|
522
|
-
let(:service_user) { 'LOCAL SERVICE' }
|
523
|
-
let(:password) { nil }
|
524
|
-
it 'Does not require any password' do
|
525
|
-
expect(@ts.set_account_information(service_user, password)). to be_truthy
|
526
|
-
expect(@ts.account_information.upcase).to eq(service_user)
|
527
|
-
end
|
528
|
-
it 'passing account_name will display account_simple_name' do
|
529
|
-
user = 'NT AUTHORITY\LOCAL SERVICE'
|
530
|
-
expect(@ts.set_account_information(user, password)). to be_truthy
|
531
|
-
expect(@ts.account_information.upcase).to eq(service_user)
|
532
|
-
end
|
533
|
-
it 'Raises an error if password is given' do
|
534
|
-
password = 'XYZ'
|
535
|
-
expect { @ts.set_account_information(service_user, password) }. to raise_error(tasksch_err)
|
536
|
-
end
|
537
|
-
end
|
538
|
-
context 'Built in Groups' do
|
539
|
-
let(:group_user) { 'USERS' }
|
540
|
-
let(:password) { nil }
|
541
|
-
it 'Does not require any password' do
|
542
|
-
expect(@ts.set_account_information(group_user, password)). to be_truthy
|
543
|
-
expect(@ts.account_information.upcase).to eq(group_user)
|
544
|
-
end
|
545
|
-
it 'passing account_name will display account_simple_name' do
|
546
|
-
user = 'BUILTIN\USERS'
|
547
|
-
expect(@ts.set_account_information(user, password)). to be_truthy
|
548
|
-
expect(@ts.account_information.upcase).to eq(group_user)
|
549
|
-
end
|
550
|
-
it 'Raises an error if password is given' do
|
551
|
-
password = 'XYZ'
|
552
|
-
expect { @ts.set_account_information(group_user, password) }. to raise_error(tasksch_err)
|
553
|
-
end
|
554
|
-
end
|
555
|
-
context 'Non-system users' do
|
556
|
-
it 'Require a password' do
|
557
|
-
user = ENV['user']
|
558
|
-
password = nil
|
559
|
-
expect { @ts.set_account_information(user, password) }. to raise_error(tasksch_err)
|
560
|
-
expect(@ts.account_information).to include(user)
|
561
|
-
end
|
562
|
-
end
|
563
|
-
it 'Raises an error if task does not exists' do
|
564
|
-
@ts.instance_variable_set(:@task, nil)
|
565
|
-
user = 'User'
|
566
|
-
password = 'XXXX'
|
567
|
-
expect { @ts.set_account_information(user, password) }. to raise_error(tasksch_err)
|
568
|
-
expect(@ts.account_information).to be_nil
|
569
|
-
end
|
570
|
-
end
|
571
|
-
|
572
|
-
describe '#status' do
|
573
|
-
before { create_task }
|
574
|
-
it 'Returns tasks status' do
|
575
|
-
expect(@ts.status).to be_a(String)
|
576
|
-
end
|
577
|
-
|
578
|
-
it 'Raises an error if task does not exists' do
|
579
|
-
@ts.instance_variable_set(:@task, nil)
|
580
|
-
expect { @ts.status }.to raise_error(tasksch_err)
|
581
|
-
end
|
582
|
-
end
|
583
|
-
|
584
|
-
describe '#exit_code' do
|
585
|
-
before { create_task }
|
586
|
-
it 'Returns the exit code from the last scheduled run' do
|
587
|
-
expect(@ts.exit_code).to be_a(Integer)
|
588
|
-
end
|
589
|
-
|
590
|
-
it 'Raises an error if task does not exists' do
|
591
|
-
@ts.instance_variable_set(:@task, nil)
|
592
|
-
expect { @ts.exit_code }.to raise_error(tasksch_err)
|
593
|
-
end
|
594
|
-
end
|
595
|
-
|
596
|
-
describe '#trigger_count' do
|
597
|
-
before { create_task }
|
598
|
-
it 'Returns No of triggers associated with the task' do
|
599
|
-
expect(@ts.trigger_count).to eq(1)
|
600
|
-
end
|
601
|
-
|
602
|
-
it 'Raises an error if task does not exists' do
|
603
|
-
@ts.instance_variable_set(:@task, nil)
|
604
|
-
expect { @ts.trigger_count }.to raise_error(tasksch_err)
|
605
|
-
end
|
606
|
-
end
|
607
|
-
|
608
|
-
describe '#trigger_string' do
|
609
|
-
before { create_task }
|
610
|
-
it 'Returns a string that describes the current trigger at '\
|
611
|
-
'the specified index for the active task' do
|
612
|
-
expect(@ts.trigger_string(0)).to be_a(String)
|
613
|
-
end
|
614
|
-
|
615
|
-
it 'Raises an error if trigger is not found at the given index' do
|
616
|
-
expect { @ts.trigger_string(1) }.to raise_error(tasksch_err)
|
617
|
-
end
|
618
|
-
|
619
|
-
it 'Raises an error if task does not exists' do
|
620
|
-
@ts.instance_variable_set(:@task, nil)
|
621
|
-
expect { @ts.trigger_string(0) }.to raise_error(tasksch_err)
|
622
|
-
end
|
623
|
-
end
|
624
|
-
|
625
|
-
describe '#idle_settings' do
|
626
|
-
before { create_task }
|
627
|
-
it 'Returns a hash containing idle settings of the current task' do
|
628
|
-
settings = @ts.idle_settings
|
629
|
-
expect(settings).to be_a(Hash)
|
630
|
-
expect(settings).to include(stop_on_idle_end: true)
|
631
|
-
end
|
632
|
-
|
633
|
-
it 'Raises an error if task does not exists' do
|
634
|
-
@ts.instance_variable_set(:@task, nil)
|
635
|
-
expect { @ts.idle_settings }. to raise_error(tasksch_err)
|
636
|
-
end
|
637
|
-
end
|
638
|
-
|
639
|
-
describe '#network_settings' do
|
640
|
-
before { create_task }
|
641
|
-
it 'Returns a hash containing network settings of the current task' do
|
642
|
-
settings = @ts.network_settings
|
643
|
-
expect(settings).to be_a(Hash)
|
644
|
-
expect(settings).to include(name: '')
|
645
|
-
end
|
646
|
-
|
647
|
-
it 'Raises an error if task does not exists' do
|
648
|
-
@ts.instance_variable_set(:@task, nil)
|
649
|
-
expect { @ts.network_settings }. to raise_error(tasksch_err)
|
650
|
-
end
|
651
|
-
end
|
652
|
-
|
653
|
-
describe '#settings' do
|
654
|
-
before { create_task }
|
655
|
-
it 'Returns a hash containing all the settings of the current task' do
|
656
|
-
settings = @ts.settings
|
657
|
-
expect(settings).to be_a(Hash)
|
658
|
-
expect(settings).to include(enabled: true)
|
659
|
-
end
|
660
|
-
|
661
|
-
it 'Raises an error if task does not exists' do
|
662
|
-
@ts.instance_variable_set(:@task, nil)
|
663
|
-
expect { @ts.settings }. to raise_error(tasksch_err)
|
664
|
-
end
|
665
|
-
end
|
666
|
-
|
667
|
-
describe '#configure_settings' do
|
668
|
-
before { create_task }
|
669
|
-
before { stub_user }
|
670
|
-
|
671
|
-
it 'Require a hash' do
|
672
|
-
expect { @ts.configure_settings('XYZ') }. to raise_error(TypeError)
|
673
|
-
expect(@ts.configure_settings({})).to eq({})
|
674
|
-
end
|
675
|
-
|
676
|
-
it 'Raises an error if invalid setting is passed' do
|
677
|
-
expect { @ts.configure_settings(invalid: true) }. to raise_error(TypeError)
|
678
|
-
end
|
679
|
-
|
680
|
-
it 'Sets settings of the task and returns a hash' do
|
681
|
-
settings = { allow_demand_start: false,
|
682
|
-
disallow_start_if_on_batteries: false,
|
683
|
-
enabled: false,
|
684
|
-
stop_if_going_on_batteries: false }
|
685
|
-
|
686
|
-
expect(@ts.configure_settings(settings)).to eq(settings)
|
687
|
-
expect(@ts.settings).to include(settings)
|
688
|
-
end
|
689
|
-
|
690
|
-
it 'Sets idle settings of the task' do
|
691
|
-
# It accepts time in minutes
|
692
|
-
# and returns the result in ISO8601 format
|
693
|
-
settings = { idle_duration: 11,
|
694
|
-
wait_timeout: 10,
|
695
|
-
stop_on_idle_end: true,
|
696
|
-
restart_on_idle: false }
|
697
|
-
|
698
|
-
result_settings = { idle_duration: 'PT11M',
|
699
|
-
wait_timeout: 'PT10M',
|
700
|
-
stop_on_idle_end: true,
|
701
|
-
restart_on_idle: false }
|
702
|
-
|
703
|
-
@ts.configure_settings(settings)
|
704
|
-
expect(@ts.idle_settings).to eq(result_settings)
|
705
|
-
end
|
706
|
-
|
707
|
-
it 'Set settings and idle settings of the task' do
|
708
|
-
settings = {
|
709
|
-
allow_demand_start: false,
|
710
|
-
disallow_start_if_on_batteries: false,
|
711
|
-
stop_if_going_on_batteries: false
|
712
|
-
}
|
713
|
-
|
714
|
-
idle_settings = {
|
715
|
-
stop_on_idle_end: true,
|
716
|
-
restart_on_idle: false
|
717
|
-
}
|
718
|
-
|
719
|
-
@ts.configure_settings(settings.merge(idle_settings))
|
720
|
-
expect(@ts.settings).to include(settings)
|
721
|
-
expect(@ts.idle_settings).to include(idle_settings)
|
722
|
-
end
|
723
|
-
|
724
|
-
it 'Raises an error if task does not exists' do
|
725
|
-
@ts.instance_variable_set(:@task, nil)
|
726
|
-
expect { @ts.settings }. to raise_error(tasksch_err)
|
727
|
-
end
|
728
|
-
end
|
729
|
-
|
730
|
-
describe '#principals' do
|
731
|
-
before { create_task }
|
732
|
-
it 'Returns a hash containing all the principal information of the current task' do
|
733
|
-
principals = @ts.principals
|
734
|
-
expect(principals).to be_a(Hash)
|
735
|
-
expect(principals).to include(id: 'Author')
|
736
|
-
end
|
737
|
-
|
738
|
-
it 'Raises an error if task does not exists' do
|
739
|
-
@ts.instance_variable_set(:@task, nil)
|
740
|
-
expect { @ts.principals }. to raise_error(tasksch_err)
|
741
|
-
end
|
742
|
-
end
|
743
|
-
|
744
|
-
describe '#principals' do
|
745
|
-
before { create_task }
|
746
|
-
it 'Returns a hash containing all the principal information of the current task' do
|
747
|
-
principals = @ts.principals
|
748
|
-
expect(principals).to be_a(Hash)
|
749
|
-
expect(principals).to include(id: 'Author')
|
750
|
-
end
|
751
|
-
|
752
|
-
it 'Raises an error if task does not exists' do
|
753
|
-
@ts.instance_variable_set(:@task, nil)
|
754
|
-
expect { @ts.principals }. to raise_error(tasksch_err)
|
755
|
-
end
|
756
|
-
end
|
757
|
-
|
758
|
-
describe '#configure_principals' do
|
759
|
-
before { create_task }
|
760
|
-
before { stub_user }
|
761
|
-
|
762
|
-
it 'Sets the principals for current active task' do
|
763
|
-
principals = @ts.principals
|
764
|
-
principals[:user_id] = 'SYSTEM'
|
765
|
-
principals[:display_name] = 'Rspec'
|
766
|
-
principals[:run_level] = Win32::TaskScheduler::TASK_RUNLEVEL_HIGHEST
|
767
|
-
principals[:logon_type] = Win32::TaskScheduler::TASK_LOGON_SERVICE_ACCOUNT
|
768
|
-
|
769
|
-
@ts.configure_principals(principals)
|
770
|
-
expect(@ts.principals).to eq(principals)
|
771
|
-
end
|
772
|
-
|
773
|
-
it 'Raises an error if task does not exists' do
|
774
|
-
@ts.instance_variable_set(:@task, nil)
|
775
|
-
expect { @ts.principals }. to raise_error(tasksch_err)
|
776
|
-
end
|
777
|
-
end
|
778
|
-
|
779
|
-
describe '#trigger' do
|
780
|
-
before { create_task }
|
781
|
-
|
782
|
-
it 'Returns a hash that describes the trigger '\
|
783
|
-
'at the given index for the current task' do
|
784
|
-
trigger = @ts.trigger(0)
|
785
|
-
expect(trigger).to be_a(Hash)
|
786
|
-
expect(trigger).not_to be_empty
|
787
|
-
end
|
788
|
-
|
789
|
-
it 'Raises an error if trigger is not found at the given index' do
|
790
|
-
expect { @ts.trigger(1) }.to raise_error(tasksch_err)
|
791
|
-
end
|
792
|
-
|
793
|
-
it 'Raises an error if task does not exists' do
|
794
|
-
@ts.instance_variable_set(:@task, nil)
|
795
|
-
expect { @ts.trigger(0) }.to raise_error(tasksch_err)
|
796
|
-
end
|
797
|
-
end
|
798
|
-
|
799
|
-
describe '#trigger=' do
|
800
|
-
before { create_task }
|
801
|
-
before { stub_user }
|
802
|
-
all_triggers.each do |type, trigger_hash|
|
803
|
-
it "Updates the first trigger for type: #{type}" do
|
804
|
-
@ts.trigger = trigger_hash
|
805
|
-
returned_trigger = @ts.trigger(0)
|
806
|
-
expect(returned_trigger).to eq(trigger_hash)
|
807
|
-
expect(@ts.trigger_count).to eq(1)
|
808
|
-
end
|
809
|
-
|
810
|
-
it "Updates the trigger at given index for type: #{type}" do
|
811
|
-
skip 'Implementation Pending'
|
812
|
-
@ts.trigger = trigger_hash
|
813
|
-
returned_trigger = @ts.trigger(0)
|
814
|
-
expect(returned_trigger).to eq(trigger_hash)
|
815
|
-
expect(@ts.trigger_count).to eq(1)
|
816
|
-
end
|
817
|
-
|
818
|
-
it 'Raises an error if task does not exists' do
|
819
|
-
@ts.instance_variable_set(:@task, nil)
|
820
|
-
expect { @ts.trigger = trigger_hash }.to raise_error(tasksch_err)
|
821
|
-
end
|
822
|
-
end
|
823
|
-
end
|
824
|
-
|
825
|
-
describe '#new_work_item' do
|
826
|
-
before { create_task }
|
827
|
-
context 'Creates a new task' do
|
828
|
-
all_triggers.each do |type, trigger_hash|
|
829
|
-
it "for the triger: #{type}" do
|
830
|
-
task_count = 1 # One task already exists
|
831
|
-
expect(@ts.new_work_item("Task_#{type}", trigger_hash)).to be_a(@current_task.class)
|
832
|
-
task_count += 1
|
833
|
-
expect(no_of_tasks).to eq(task_count)
|
834
|
-
end
|
835
|
-
end
|
836
|
-
end
|
837
|
-
|
838
|
-
context 'Updates the existing task' do
|
839
|
-
all_triggers.each do |type, trigger_hash|
|
840
|
-
it "for the triger: #{type}" do
|
841
|
-
expect(@ts.new_work_item(@task, trigger_hash)).to be_a(@current_task.class)
|
842
|
-
expect(no_of_tasks).to eq(1)
|
843
|
-
end
|
844
|
-
|
845
|
-
it 'Raises an error if task does not exists' do
|
846
|
-
@ts.instance_variable_set(:@task, nil)
|
847
|
-
expect { @ts.trigger = trigger_hash }.to raise_error(tasksch_err)
|
848
|
-
end
|
849
|
-
end
|
850
|
-
end
|
851
|
-
end
|
852
|
-
|
853
|
-
private
|
854
|
-
|
855
|
-
def load_task_variables
|
856
|
-
time = Time.now
|
857
|
-
# Ensuring root path will be test path
|
858
|
-
allow_any_instance_of(Win32::TaskScheduler).to receive(:root_path).and_return(@test_path)
|
859
|
-
@app = 'iexplore.exe'
|
860
|
-
@task = 'test_task'
|
861
|
-
@folder = @test_path
|
862
|
-
@force = false
|
863
|
-
@trigger = { start_year: time.year, start_month: time.month,
|
864
|
-
start_day: time.day, start_hour: time.hour,
|
865
|
-
start_minute: time.min,
|
866
|
-
# Will update this in test cases when required
|
867
|
-
trigger_type: Win32::TaskScheduler::ONCE }
|
868
|
-
@ts = Win32::TaskScheduler.new
|
869
|
-
end
|
870
|
-
|
871
|
-
# Sets the user Id as nil, hence SYSTEM will be considered
|
872
|
-
# Alternatively, we may to provide the login users password
|
873
|
-
def stub_user
|
874
|
-
# @ts.instance_variable_set(:@password, 'user_login_password')
|
875
|
-
allow(@ts).to receive(:task_user_id).and_return(nil)
|
876
|
-
end
|
877
|
-
|
878
|
-
# Will stop the appliaction only if it is running
|
879
|
-
def stop_the_app
|
880
|
-
`tasklist /FI "IMAGENAME eq #{@app}" 2>NUL | find /I /N "#{@app}">NUL
|
881
|
-
if "%ERRORLEVEL%"=="0" taskkill /f /im #{@app}`
|
882
|
-
end
|
883
|
-
end
|