razorrisk-razor-control 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/RakeFile +46 -0
  3. data/lib/razor_risk/razor/control/cucumber_helpers/consolidate_reports.rb +80 -0
  4. data/lib/razor_risk/razor/control/cucumber_helpers/executor.rb +108 -0
  5. data/lib/razor_risk/razor/control/cucumber_helpers.rb +3 -0
  6. data/lib/razor_risk/razor/control/diagnostics/util_functions.rb +203 -0
  7. data/lib/razor_risk/razor/control/diagnostics/zeroth_include.rb +27 -0
  8. data/lib/razor_risk/razor/control/exceptions.rb +121 -0
  9. data/lib/razor_risk/razor/control/gem/gem_helpers.rb +397 -0
  10. data/lib/razor_risk/razor/control/rake_helpers/aborter.rb +90 -0
  11. data/lib/razor_risk/razor/control/rake_helpers/diagnostic_tasks.rb +74 -0
  12. data/lib/razor_risk/razor/control/rake_helpers/gem_tasks.rb +128 -0
  13. data/lib/razor_risk/razor/control/rake_helpers/razor_tasks.rb +195 -0
  14. data/lib/razor_risk/razor/control/rake_helpers/task_helpers.rb +86 -0
  15. data/lib/razor_risk/razor/control/rake_helpers.rb +3 -0
  16. data/lib/razor_risk/razor/control/razor/executor.rb +131 -0
  17. data/lib/razor_risk/razor/control/razor/razor_instance.rb +227 -0
  18. data/lib/razor_risk/razor/control/razor.rb +2 -0
  19. data/lib/razor_risk/razor/control/version.rb +41 -0
  20. data/test/unit/control/cucumber_helpers/reports/expected/groups.html +213 -0
  21. data/test/unit/control/cucumber_helpers/reports/expected/no_groups.html +170 -0
  22. data/test/unit/control/cucumber_helpers/reports/groups/LbbwConfig/LbbwConfig.json +69 -0
  23. data/test/unit/control/cucumber_helpers/reports/groups/StandardConfig/StandardConfig.json +69 -0
  24. data/test/unit/control/cucumber_helpers/reports/no_groups/LbbwConfig.json +69 -0
  25. data/test/unit/control/cucumber_helpers/reports/no_groups/StandardConfig/StandardConfig.json +69 -0
  26. data/test/unit/control/cucumber_helpers/tc_consolidate_reports.rb +73 -0
  27. data/test/unit/control/cucumber_helpers/tc_executor.rb +406 -0
  28. data/test/unit/control/gem/tc_gem_helpers.rb +405 -0
  29. data/test/unit/control/rake_helpers/tc_aborter.rb +131 -0
  30. data/test/unit/control/rake_helpers/tc_task_helpers.rb +228 -0
  31. data/test/unit/control/razor/tc_executor.rb +129 -0
  32. data/test/unit/control/razor/tc_razor_instance.rb +517 -0
  33. data/test/unit/control/razor/test_scripts/exit_failure.cmd +3 -0
  34. data/test/unit/control/razor/test_scripts/exit_strange.cmd +3 -0
  35. data/test/unit/control/razor/test_scripts/exit_success.cmd +3 -0
  36. data/test/unit/control/razor/test_scripts/pause.cmd +5 -0
  37. data/test/unit/control/razor/test_scripts/print.cmd +6 -0
  38. data/test/unit/control/tc_exceptions.rb +120 -0
  39. metadata +192 -0
@@ -0,0 +1,517 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ # ######################################################################## #
4
+ #
5
+ # Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
6
+ #
7
+ # ######################################################################## #
8
+
9
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
10
+
11
+ unless $DEBUG
12
+
13
+ require 'pantheios/globals'
14
+ require 'pantheios/services/null_log_service'
15
+
16
+ ::Pantheios::Globals.INITIAL_SERVICE_CLASSES = [ ::Pantheios::Services::NullLogService ]
17
+ end
18
+
19
+ require 'razor_risk/razor/control/exceptions'
20
+
21
+ require 'razor_risk/razor/control/razor/razor_instance'
22
+ require 'razor_risk/razor/control/razor/executor'
23
+
24
+ require 'xqsr3/extensions/test/unit'
25
+
26
+ require 'test/unit'
27
+
28
+ require 'fileutils'
29
+ require 'tmpdir'
30
+
31
+ class Test_Config < Test::Unit::TestCase
32
+
33
+ include ::RazorRisk::Razor::Control::Razor
34
+
35
+ def test_Config_is_a_class
36
+
37
+ assert_kind_of ::Class, Config
38
+ end
39
+
40
+ def test_can_be_initialised
41
+
42
+ assert_nothing_raised do
43
+ Config.new('Name', 'path', 'path', '1_start.cmd', '4_rebuild.cmd')
44
+ end
45
+ end
46
+
47
+ def test_sets_attributes
48
+
49
+ name = 'name'
50
+ path = 'path'
51
+ script_dir = 'script_dir'
52
+ tod_script = 'tod_script'
53
+ rebuild_script = 'rebuild_script'
54
+
55
+ config = Config.new(
56
+ name,
57
+ path,
58
+ script_dir,
59
+ tod_script,
60
+ rebuild_script,
61
+ )
62
+
63
+ assert_equal name, config.name
64
+ assert_equal path, config.path
65
+ assert_equal script_dir, config.script_dir
66
+ assert_equal tod_script, config.tod_script
67
+ assert_equal rebuild_script, config.rebuild_script
68
+ end
69
+ end
70
+
71
+ class Test_RazorInstance < Test::Unit::TestCase
72
+
73
+ include ::RazorRisk::Razor::Control::Exceptions
74
+ include ::RazorRisk::Razor::Control::Razor
75
+
76
+ def test_RazorInstance_is_a_class
77
+
78
+ assert_kind_of ::Class, RazorInstance
79
+ end
80
+
81
+ def test_initialize_fails_if_directory_does_not_exist
82
+
83
+ config = Config.new(
84
+ 'StandardConfig',
85
+ 'config/StandardConfig',
86
+ 'config',
87
+ '1_start.cmd',
88
+ '4_rebuild.cmd',
89
+ )
90
+
91
+ assert_raise_with_message(
92
+ RazorControlException,
93
+ /Razor directory.*does not exist/
94
+ ) do
95
+ RazorInstance.new(
96
+ 'some_dir',
97
+ 'some_env',
98
+ [config],
99
+ )
100
+ end
101
+ end
102
+
103
+ def test_initialize_fails_if_directory_is_a_file
104
+
105
+ config = Config.new(
106
+ 'StandardConfig',
107
+ 'config/StandardConfig',
108
+ 'config',
109
+ '1_start.cmd',
110
+ '4_rebuild.cmd',
111
+ )
112
+
113
+ Dir.mktmpdir do |dir|
114
+ file = File.join(dir, 'file')
115
+ FileUtils.touch(file)
116
+ assert_raise_with_message(
117
+ RazorControlException,
118
+ /Razor directory.*is not a directory/
119
+ ) do
120
+ RazorInstance.new(
121
+ file,
122
+ 'some_env',
123
+ [config],
124
+ )
125
+ end
126
+ end
127
+ end
128
+
129
+ def test_initialize_fails_if_no_configs_supplied
130
+
131
+ Dir.mktmpdir do |dir|
132
+ assert_raise_with_message(
133
+ RazorControlException,
134
+ /must have at least one config defined/
135
+ ) do
136
+ RazorInstance.new(
137
+ dir,
138
+ 'some_env',
139
+ [],
140
+ )
141
+ end
142
+ end
143
+ end
144
+
145
+ def test_initialize_fails_if_config_path_is_not_a_directory
146
+
147
+ Dir.mktmpdir do |dir|
148
+
149
+ file = File.join(dir, 'file')
150
+ FileUtils.touch(file)
151
+
152
+ config = Config.new(
153
+ 'StandardConfig',
154
+ 'file',
155
+ 'config',
156
+ '1_start.cmd',
157
+ '4_rebuild.cmd',
158
+ )
159
+
160
+ assert_raise_with_message(
161
+ RazorControlException,
162
+ /did not have an existing directory path/
163
+ ) do
164
+ RazorInstance.new(
165
+ dir,
166
+ 'some_env',
167
+ [config],
168
+ )
169
+ end
170
+ end
171
+ end
172
+
173
+ def test_can_be_initialize
174
+
175
+ Dir.mktmpdir do |dir|
176
+
177
+ path = File.join(dir, 'path')
178
+ FileUtils.mkdir(path)
179
+
180
+ config = Config.new(
181
+ 'StandardConfig',
182
+ 'path',
183
+ 'config',
184
+ '1_start.cmd',
185
+ '4_rebuild.cmd',
186
+ )
187
+
188
+ assert_nothing_raised do
189
+ RazorInstance.new(
190
+ dir,
191
+ 'some_env',
192
+ [config],
193
+ )
194
+ end
195
+ end
196
+ end
197
+
198
+ def test_kill_fails_if_file_does_not_exist
199
+
200
+ Dir.mktmpdir do |dir|
201
+
202
+ executor = MockExecutor.new([])
203
+
204
+ path = File.join(dir, 'path')
205
+ FileUtils.mkdir(path)
206
+
207
+ config = Config.new(
208
+ 'StandardConfig',
209
+ 'path',
210
+ 'config',
211
+ '1_start.cmd',
212
+ '4_rebuild.cmd',
213
+ )
214
+
215
+ r = RazorInstance.new(
216
+ dir,
217
+ 'some_env',
218
+ [ config ],
219
+ executor: executor,
220
+ )
221
+
222
+ assert_raise_with_message(
223
+ RazorControlException,
224
+ /file.*does not exist/
225
+ ) do
226
+ r.kill
227
+ end
228
+ end
229
+ end
230
+
231
+ def test_kill_uses_correct_command
232
+
233
+ Dir.mktmpdir do |dir|
234
+
235
+ env = 'env'
236
+ name = 'name'
237
+ path = 'path'
238
+ script_dir = 'script_dir'
239
+ tod_script = 'tod_script'
240
+ rebuild_script = 'rebuild_script'
241
+ codes = [ 0, 1, 2 ]
242
+
243
+ config = Config.new(
244
+ name,
245
+ path,
246
+ script_dir,
247
+ tod_script,
248
+ rebuild_script,
249
+ )
250
+
251
+ config_dir = File.join(dir, path)
252
+ Dir.mkdir(config_dir)
253
+
254
+ config_script_dir = File.join(config_dir, script_dir)
255
+ Dir.mkdir(config_script_dir)
256
+
257
+ FileUtils.touch(File.join(dir, 'razor_kill.cmd'))
258
+
259
+ executor = MockExecutor.new(*codes)
260
+
261
+ exp_opts = {
262
+ chdir: dir
263
+ }
264
+
265
+ r = RazorInstance.new(
266
+ dir,
267
+ env,
268
+ [ config ],
269
+ executor: executor,
270
+ )
271
+
272
+ assert_raise_with_message(::ArgumentError, /wrong number of arguments/i) do
273
+ r.kill 'abc'
274
+ end
275
+
276
+ assert_equal codes.shift, r.kill
277
+ assert_equal codes.shift, r.kill
278
+ assert_equal codes.shift, r.kill
279
+ assert_equal 'razor_kill.cmd', executor.commands.shift
280
+ assert_equal exp_opts, executor.opts.shift
281
+ end
282
+ end
283
+
284
+ def test_rebuild_fails_if_file_does_not_exist
285
+
286
+ Dir.mktmpdir do |dir|
287
+
288
+ executor = MockExecutor.new([])
289
+
290
+ path = File.join(dir, 'path')
291
+ FileUtils.mkdir(path)
292
+
293
+ script_dir = File.join(path, 'config')
294
+ FileUtils.mkdir(script_dir)
295
+
296
+ config = Config.new(
297
+ 'StandardConfig',
298
+ 'path',
299
+ 'config',
300
+ '1_start.cmd',
301
+ '4_rebuild.cmd',
302
+ )
303
+
304
+ r = RazorInstance.new(
305
+ dir,
306
+ 'some_env',
307
+ [ config ],
308
+ executor: executor,
309
+ )
310
+
311
+ assert_raise_with_message(
312
+ RazorControlException,
313
+ /file.*does not exist/
314
+ ) do
315
+ r.rebuild('StandardConfig')
316
+ end
317
+ end
318
+ end
319
+
320
+ def test_rebuild_uses_correct_command
321
+
322
+ Dir.mktmpdir do |dir|
323
+
324
+ codes = [ 0, 1, 2 ]
325
+ executor = MockExecutor.new(*codes)
326
+
327
+ config = Config.new(
328
+ 'StandardConfig',
329
+ 'path',
330
+ 'config',
331
+ '1_start.cmd',
332
+ '4_rebuild.cmd',
333
+ )
334
+
335
+ path = File.join(dir, config.path)
336
+ FileUtils.mkdir(path)
337
+
338
+ script_dir = File.join(path, config.script_dir)
339
+ FileUtils.mkdir(script_dir)
340
+
341
+ script = File.join(script_dir, config.rebuild_script)
342
+ FileUtils.touch(script)
343
+
344
+ exp_opts = {
345
+ chdir: script_dir
346
+ }
347
+
348
+ r = RazorInstance.new(
349
+ dir,
350
+ 'some_env',
351
+ [ config ],
352
+ executor: executor,
353
+ )
354
+
355
+ assert_raise_with_message(
356
+ ::ArgumentError,
357
+ /wrong number of arguments/i
358
+ ) do
359
+ r.rebuild
360
+ end
361
+
362
+ assert_equal codes.shift, r.rebuild(config.name)
363
+ assert_equal codes.shift, r.rebuild(config.name)
364
+ assert_equal codes.shift, r.rebuild(config.name)
365
+ assert_equal config.rebuild_script, executor.commands.shift
366
+ assert_equal exp_opts, executor.opts.shift
367
+ end
368
+ end
369
+
370
+ def test_turn_of_day_fails_if_file_does_not_exist
371
+
372
+ Dir.mktmpdir do |dir|
373
+
374
+ executor = MockExecutor.new([])
375
+
376
+ config = Config.new(
377
+ 'StandardConfig',
378
+ 'path',
379
+ 'config',
380
+ '1_start.cmd',
381
+ '4_rebuild.cmd',
382
+ )
383
+
384
+ path = File.join(dir, config.path)
385
+ FileUtils.mkdir(path)
386
+
387
+ script_dir = File.join(path, config.script_dir)
388
+ FileUtils.mkdir(script_dir)
389
+
390
+ config = Config.new(
391
+ 'StandardConfig',
392
+ 'path',
393
+ 'config',
394
+ '1_start.cmd',
395
+ '4_rebuild.cmd',
396
+ )
397
+
398
+ r = RazorInstance.new(
399
+ dir,
400
+ 'some_env',
401
+ [ config ],
402
+ executor: executor,
403
+ )
404
+
405
+ assert_raise_with_message(
406
+ RazorControlException,
407
+ /file.*does not exist/
408
+ ) do
409
+ r.turn_of_day('StandardConfig')
410
+ end
411
+ end
412
+ end
413
+
414
+ def test_turn_of_day_uses_correct_command
415
+
416
+ Dir.mktmpdir do |dir|
417
+
418
+ codes = [ 0, 1, 2 ]
419
+ executor = MockExecutor.new(*codes)
420
+
421
+ config = Config.new(
422
+ 'StandardConfig',
423
+ 'path',
424
+ 'config',
425
+ '1_start.cmd',
426
+ '4_rebuild.cmd',
427
+ )
428
+
429
+ path = File.join(dir, config.path)
430
+ FileUtils.mkdir(path)
431
+
432
+ script_dir = File.join(path, config.script_dir)
433
+ FileUtils.mkdir(script_dir)
434
+
435
+ script = File.join(script_dir, config.tod_script)
436
+ FileUtils.touch(script)
437
+
438
+ exp_opts = {
439
+ chdir: script_dir
440
+ }
441
+
442
+ r = RazorInstance.new(
443
+ dir,
444
+ 'some_env',
445
+ [ config ],
446
+ executor: executor,
447
+ )
448
+
449
+ assert_raise_with_message(
450
+ ::ArgumentError,
451
+ /wrong number of arguments/i
452
+ ) do
453
+ r.rebuild
454
+ end
455
+
456
+ assert_equal codes.shift, r.turn_of_day(config.name)
457
+ assert_equal codes.shift, r.turn_of_day(config.name)
458
+ assert_equal codes.shift, r.turn_of_day(config.name)
459
+ assert_equal config.tod_script, executor.commands.shift
460
+ assert_equal exp_opts, executor.opts.shift
461
+ end
462
+ end
463
+
464
+ def test_works_with_no_script_directory
465
+
466
+ Dir.mktmpdir do |dir|
467
+
468
+ codes = [ 0, 0, 0 ]
469
+ executor = MockExecutor.new(*codes)
470
+
471
+ config = Config.new(
472
+ 'StandardConfig',
473
+ 'path',
474
+ '',
475
+ '1_start.cmd',
476
+ '4_rebuild.cmd',
477
+ )
478
+
479
+ path = File.join(dir, config.path)
480
+ FileUtils.mkdir(path)
481
+
482
+ FileUtils.touch(File.join(dir, 'razor_kill.cmd'))
483
+ FileUtils.touch(File.join(path, config.rebuild_script))
484
+ FileUtils.touch(File.join(path, config.tod_script))
485
+
486
+ r = RazorInstance.new(
487
+ dir,
488
+ 'some_env',
489
+ [ config ],
490
+ executor: executor,
491
+ )
492
+
493
+ assert_raise_with_message(
494
+ ::ArgumentError,
495
+ /wrong number of arguments/i
496
+ ) do
497
+ r.rebuild
498
+ end
499
+
500
+ assert_equal codes.shift, r.kill
501
+ assert_equal 'razor_kill.cmd', executor.commands.shift
502
+ assert_equal({ chdir: dir }, executor.opts.shift)
503
+
504
+ assert_equal codes.shift, r.turn_of_day(config.name)
505
+ assert_equal config.tod_script, executor.commands.shift
506
+ assert_equal({ chdir: "#{path}/" }, executor.opts.shift)
507
+
508
+ assert_equal codes.shift, r.rebuild(config.name)
509
+ assert_equal config.rebuild_script, executor.commands.shift
510
+ assert_equal({ chdir: "#{path}/" }, executor.opts.shift)
511
+ end
512
+ end
513
+ end
514
+
515
+ # ############################## end of file ############################# #
516
+
517
+
@@ -0,0 +1,3 @@
1
+ @echo off
2
+
3
+ exit 1
@@ -0,0 +1,3 @@
1
+ @echo off
2
+
3
+ exit 128
@@ -0,0 +1,3 @@
1
+ @echo off
2
+
3
+ exit 0
@@ -0,0 +1,5 @@
1
+ @echo off
2
+
3
+ pause
4
+
5
+ exit 0
@@ -0,0 +1,6 @@
1
+ @echo off
2
+
3
+ echo stdout
4
+ echo stderr 1>&2
5
+
6
+ exit 0
@@ -0,0 +1,120 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ # ######################################################################## #
4
+ #
5
+ # Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
6
+ #
7
+ # ######################################################################## #
8
+
9
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 3), 'lib')
10
+
11
+ unless $DEBUG
12
+
13
+ require 'pantheios/globals'
14
+ require 'pantheios/services/null_log_service'
15
+
16
+ ::Pantheios::Globals.INITIAL_SERVICE_CLASSES = [ ::Pantheios::Services::NullLogService ]
17
+ end
18
+
19
+ require 'razor_risk/razor/control/exceptions'
20
+
21
+ require 'xqsr3/extensions/test/unit'
22
+
23
+ require 'test/unit'
24
+
25
+ class Test_Control_Exceptions < Test::Unit::TestCase
26
+
27
+ class Test_ControlException < Test::Unit::TestCase
28
+
29
+ include ::RazorRisk::Razor::Control::Exceptions
30
+
31
+ class ArbitraryChildException < ControlException; end
32
+
33
+ def test_EntityConnectorException_is_a_class
34
+
35
+ assert_kind_of ::Class, ControlException
36
+ end
37
+
38
+ def test_EntityConnectorException_is_abstract
39
+
40
+ assert_raise_with_message(
41
+ ::NoMethodError,
42
+ /private method.*new.*called for.*RazorRisk::Razor::Control::Exceptions::ControlException/
43
+ ) do
44
+ ControlException.new
45
+ end
46
+ end
47
+
48
+ def test_ArbitraryChildException_is_not_abstract
49
+
50
+ assert_not_nil ArbitraryChildException.new('some message', an_option: true, another_option: false)
51
+ end
52
+ end
53
+
54
+ class Test_GemDeploymentException < Test::Unit::TestCase
55
+
56
+ include ::RazorRisk::Razor::Control::Exceptions
57
+
58
+ def test_GemDeploymentException_is_a_class
59
+
60
+ assert_kind_of ::Class, GemDeploymentException
61
+ end
62
+
63
+ def test_GemDeploymentException_can_be_constructed
64
+
65
+ assert_nothing_raised do
66
+ GemDeploymentException.new 'some message'
67
+ end
68
+ end
69
+
70
+ def test_GemDeploymentException_can_thrown
71
+
72
+ msg = 'some message'
73
+ assert_raise_with_message(GemDeploymentException, msg) do
74
+
75
+ raise GemDeploymentException.new msg
76
+ end
77
+ end
78
+ end
79
+
80
+ class Test_RazorControlException < Test::Unit::TestCase
81
+
82
+ include ::RazorRisk::Razor::Control::Exceptions
83
+
84
+ def test_RazorControlException_is_a_class
85
+
86
+ assert_kind_of ::Class, RazorControlException
87
+ end
88
+
89
+ def test_RazorControlException_can_be_constructed
90
+
91
+ assert_nothing_raised do
92
+ RazorControlException.new 'some message'
93
+ end
94
+ end
95
+
96
+ def test_RazorControlException_can_thrown
97
+
98
+ msg = 'some message'
99
+ assert_raise_with_message(RazorControlException, msg) do
100
+
101
+ raise RazorControlException.new msg
102
+ end
103
+ end
104
+ end
105
+
106
+ class Test_Control_exception_hierarchy < Test::Unit::TestCase
107
+
108
+ include ::RazorRisk::Razor::Control::Exceptions
109
+
110
+ def test_inheritance_relationships
111
+
112
+ assert_subclass_of(ControlException, GemDeploymentException)
113
+ assert_subclass_of(ControlException, RazorControlException)
114
+ end
115
+ end
116
+ end
117
+
118
+ # ############################## end of file ############################# #
119
+
120
+