dk 0.0.1 → 0.1.0

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 (51) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +643 -1
  3. data/bin/dk +7 -0
  4. data/dk.gemspec +7 -3
  5. data/lib/dk/ansi.rb +98 -0
  6. data/lib/dk/cli.rb +173 -0
  7. data/lib/dk/config.rb +217 -0
  8. data/lib/dk/config_runner.rb +24 -0
  9. data/lib/dk/dk_runner.rb +13 -0
  10. data/lib/dk/dry_runner.rb +43 -0
  11. data/lib/dk/has_set_param.rb +42 -0
  12. data/lib/dk/has_ssh_opts.rb +36 -0
  13. data/lib/dk/has_the_runs.rb +23 -0
  14. data/lib/dk/has_the_stubs.rb +116 -0
  15. data/lib/dk/local.rb +84 -0
  16. data/lib/dk/null_logger.rb +13 -0
  17. data/lib/dk/remote.rb +132 -0
  18. data/lib/dk/runner.rb +202 -0
  19. data/lib/dk/task.rb +266 -0
  20. data/lib/dk/task_run.rb +17 -0
  21. data/lib/dk/test_runner.rb +54 -0
  22. data/lib/dk/tree_runner.rb +64 -0
  23. data/lib/dk/version.rb +1 -1
  24. data/lib/dk.rb +23 -1
  25. data/test/helper.rb +6 -1
  26. data/test/support/config/dk.rb +7 -0
  27. data/test/support/config/task_defs.rb +10 -0
  28. data/test/support/factory.rb +38 -0
  29. data/test/support/log/.gitkeep +0 -0
  30. data/test/system/has_the_stubs_tests.rb +355 -0
  31. data/test/system/runner_tests.rb +222 -0
  32. data/test/unit/ansi_tests.rb +40 -0
  33. data/test/unit/cli_tests.rb +317 -0
  34. data/test/unit/config_runner_tests.rb +60 -0
  35. data/test/unit/config_tests.rb +427 -0
  36. data/test/unit/dk_runner_tests.rb +34 -0
  37. data/test/unit/dk_tests.rb +49 -0
  38. data/test/unit/dry_runner_tests.rb +71 -0
  39. data/test/unit/has_set_param_tests.rb +46 -0
  40. data/test/unit/has_ssh_opts_tests.rb +81 -0
  41. data/test/unit/has_the_runs_tests.rb +37 -0
  42. data/test/unit/has_the_stubs_tests.rb +279 -0
  43. data/test/unit/local_tests.rb +174 -0
  44. data/test/unit/null_logger_tests.rb +17 -0
  45. data/test/unit/remote_tests.rb +330 -0
  46. data/test/unit/runner_tests.rb +398 -0
  47. data/test/unit/task_run_tests.rb +40 -0
  48. data/test/unit/task_tests.rb +943 -0
  49. data/test/unit/test_runner_tests.rb +189 -0
  50. data/test/unit/tree_runner_tests.rb +152 -0
  51. metadata +106 -9
@@ -0,0 +1,427 @@
1
+ require 'assert'
2
+ require 'dk/config'
3
+
4
+ require 'logsly'
5
+ require 'dk/has_set_param'
6
+ require 'dk/has_ssh_opts'
7
+ require 'dk/task'
8
+
9
+ class Dk::Config
10
+
11
+ class UnitTests < Assert::Context
12
+ desc "Dk::Config"
13
+ setup do
14
+ @config_class = Dk::Config
15
+ end
16
+ subject{ @config_class }
17
+
18
+ should "include HasSetParam" do
19
+ assert_includes Dk::HasSetParam, subject
20
+ end
21
+
22
+ should "include HasSSHOpts" do
23
+ assert_includes Dk::HasSSHOpts, subject
24
+ end
25
+
26
+ should "know its defaults" do
27
+ assert_equal Array.new, subject::DEFAULT_INIT_PROCS
28
+ assert_equal Hash.new, subject::DEFAULT_PARAMS
29
+ assert_equal Hash.new, subject::DEFAULT_CALLBACKS
30
+ assert_equal Hash.new, subject::DEFAULT_SSH_HOSTS
31
+ assert_equal '', subject::DEFAULT_SSH_ARGS
32
+ assert_equal Hash.new, subject::DEFAULT_HOST_SSH_ARGS
33
+ assert_equal Hash.new, subject::DEFAULT_TASKS
34
+ assert_equal "%m\n", subject::DEFAULT_LOG_PATTERN
35
+ assert_equal '[%d %-5l] : %m\n', subject::DEFAULT_LOG_FILE_PATTERN
36
+ assert_equal 'info', subject::DEFAULT_STDOUT_LOG_LEVEL
37
+ assert_equal Array.new, subject::DEFAULT_STUBS
38
+ end
39
+
40
+ should "know the file output log level" do
41
+ assert_equal 'debug', subject::FILE_LOG_LEVEL
42
+ end
43
+
44
+ end
45
+
46
+ class InitTests < UnitTests
47
+ desc "when init"
48
+ setup do
49
+ @config = @config_class.new
50
+ end
51
+ subject{ @config }
52
+
53
+ should have_readers :init_procs, :params
54
+ should have_readers :before_callbacks, :prepend_before_callbacks
55
+ should have_readers :after_callbacks, :prepend_after_callbacks
56
+ should have_readers :tasks, :dry_tree_cmd_stubs, :dry_tree_ssh_stubs
57
+ should have_imeths :init
58
+ should have_imeths :before, :prepend_before, :after, :prepend_after
59
+ should have_imeths :before_callback_task_classes
60
+ should have_imeths :prepend_before_callback_task_classes
61
+ should have_imeths :after_callback_task_classes
62
+ should have_imeths :prepend_after_callback_task_classes
63
+ should have_imeths :task, :stdout_log_level
64
+ should have_imeths :log_pattern, :log_file, :log_file_pattern
65
+ should have_imeths :stub_dry_tree_cmd, :stub_dry_tree_ssh
66
+ should have_imeths :dk_logger_stdout_output_name, :dk_logger_file_output_name
67
+ should have_imeths :dk_logger
68
+
69
+ should "default its attrs" do
70
+ assert_equal @config_class::DEFAULT_INIT_PROCS, subject.init_procs
71
+ assert_equal @config_class::DEFAULT_PARAMS, subject.params
72
+ assert_equal @config_class::DEFAULT_CALLBACKS, subject.before_callbacks
73
+ assert_equal @config_class::DEFAULT_CALLBACKS, subject.prepend_before_callbacks
74
+ assert_equal @config_class::DEFAULT_CALLBACKS, subject.after_callbacks
75
+ assert_equal @config_class::DEFAULT_CALLBACKS, subject.prepend_after_callbacks
76
+ assert_equal @config_class::DEFAULT_SSH_HOSTS, subject.ssh_hosts
77
+ assert_equal @config_class::DEFAULT_SSH_ARGS, subject.ssh_args
78
+ assert_equal @config_class::DEFAULT_HOST_SSH_ARGS, subject.host_ssh_args
79
+ assert_equal @config_class::DEFAULT_TASKS, subject.tasks
80
+ assert_equal @config_class::DEFAULT_STDOUT_LOG_LEVEL, subject.stdout_log_level
81
+ assert_equal @config_class::DEFAULT_LOG_PATTERN, subject.log_pattern
82
+ assert_equal @config_class::DEFAULT_LOG_FILE_PATTERN, subject.log_file_pattern
83
+ assert_equal @config_class::DEFAULT_STUBS, subject.dry_tree_cmd_stubs
84
+ assert_equal @config_class::DEFAULT_STUBS, subject.dry_tree_ssh_stubs
85
+
86
+ assert_nil subject.log_file
87
+ end
88
+
89
+ should "instance eval its init procs on init" do
90
+ init_self = nil
91
+ subject.init_procs << proc{ init_self = self }
92
+
93
+ subject.init
94
+ assert_equal @config, init_self
95
+ end
96
+
97
+ should "append callback tasks to other tasks" do
98
+ subj_task_class = Class.new{ include Dk::Task }
99
+ other_task_class = Factory.string
100
+ cb_task_class = Factory.string
101
+ cb_params = Factory.string
102
+
103
+ subject.before(subj_task_class, other_task_class)
104
+ subject.before(subj_task_class, cb_task_class, cb_params)
105
+
106
+ cb = subject.before_callbacks[subj_task_class].last
107
+ assert_equal cb_task_class, cb.task_class
108
+ assert_equal cb_params, cb.params
109
+
110
+ subject.after(subj_task_class, other_task_class)
111
+ subject.after(subj_task_class, cb_task_class, cb_params)
112
+
113
+ cb = subject.after_callbacks[subj_task_class].last
114
+ assert_equal cb_task_class, cb.task_class
115
+ assert_equal cb_params, cb.params
116
+
117
+ exp = [other_task_class, cb_task_class]
118
+ assert_equal exp, subject.before_callback_task_classes(subj_task_class)
119
+ assert_equal exp, subject.after_callback_task_classes(subj_task_class)
120
+ end
121
+
122
+ should "prepend callback tasks to other tasks" do
123
+ subj_task_class = Class.new{ include Dk::Task }
124
+ other_task_class = Factory.string
125
+ cb_task_class = Factory.string
126
+ cb_params = Factory.string
127
+
128
+ subject.prepend_before(subj_task_class, other_task_class)
129
+ subject.prepend_before(subj_task_class, cb_task_class, cb_params)
130
+
131
+ cb = subject.prepend_before_callbacks[subj_task_class].first
132
+ assert_equal cb_task_class, cb.task_class
133
+ assert_equal cb_params, cb.params
134
+
135
+ subject.prepend_after(subj_task_class, other_task_class)
136
+ subject.prepend_after(subj_task_class, cb_task_class, cb_params)
137
+
138
+ cb = subject.prepend_after_callbacks[subj_task_class].first
139
+ assert_equal cb_task_class, cb.task_class
140
+ assert_equal cb_params, cb.params
141
+
142
+ exp = [other_task_class, cb_task_class].reverse
143
+ assert_equal exp, subject.prepend_before_callback_task_classes(subj_task_class)
144
+ assert_equal exp, subject.prepend_after_callback_task_classes(subj_task_class)
145
+ end
146
+
147
+ should "not duplicate callback tasks if they've already been added" do
148
+ subj_task_class = Class.new{ include Dk::Task }
149
+ other_task_class = Factory.string
150
+ cb_task_class = Factory.string
151
+ cb_params = Factory.string
152
+
153
+ subject.before(subj_task_class, other_task_class)
154
+ subject.before(subj_task_class, other_task_class)
155
+ assert_equal 1, subject.before_callbacks[subj_task_class].size
156
+
157
+ subject.before(subj_task_class, cb_task_class, cb_params)
158
+ subject.before(subj_task_class, cb_task_class, cb_params)
159
+ assert_equal 2, subject.before_callbacks[subj_task_class].size
160
+
161
+ subject.after(subj_task_class, other_task_class)
162
+ subject.after(subj_task_class, other_task_class)
163
+ assert_equal 1, subject.after_callbacks[subj_task_class].size
164
+
165
+ subject.after(subj_task_class, cb_task_class, cb_params)
166
+ subject.after(subj_task_class, cb_task_class, cb_params)
167
+ assert_equal 2, subject.after_callbacks[subj_task_class].size
168
+
169
+ subject.prepend_before(subj_task_class, other_task_class)
170
+ subject.prepend_before(subj_task_class, other_task_class)
171
+ assert_equal 1, subject.prepend_before_callbacks[subj_task_class].size
172
+
173
+ subject.prepend_before(subj_task_class, cb_task_class, cb_params)
174
+ subject.prepend_before(subj_task_class, cb_task_class, cb_params)
175
+ assert_equal 2, subject.prepend_before_callbacks[subj_task_class].size
176
+
177
+ subject.prepend_after(subj_task_class, other_task_class)
178
+ subject.prepend_after(subj_task_class, other_task_class)
179
+ assert_equal 1, subject.prepend_after_callbacks[subj_task_class].size
180
+
181
+ subject.prepend_after(subj_task_class, cb_task_class, cb_params)
182
+ subject.prepend_after(subj_task_class, cb_task_class, cb_params)
183
+ assert_equal 2, subject.prepend_after_callbacks[subj_task_class].size
184
+ end
185
+
186
+ should "add callable tasks" do
187
+ assert_empty subject.tasks
188
+
189
+ task_name = Factory.string
190
+ task_class = Class.new{ include Dk::Task }
191
+ subject.task(task_name, task_class)
192
+
193
+ assert_equal task_class, subject.task(task_name)
194
+ end
195
+
196
+ should "complain when adding a callable task that isn't a Dk::Task" do
197
+ assert_raises(ArgumentError) do
198
+ subject.task(Factory.string, Factory.string)
199
+ end
200
+ assert_raises(ArgumentError) do
201
+ subject.task(Factory.string, Class.new)
202
+ end
203
+ end
204
+
205
+ should "complain when looking up a named task that hasn't been configured" do
206
+ assert_raises(UnknownTaskError) do
207
+ subject.task(Factory.string)
208
+ end
209
+ end
210
+
211
+ should "know its stdout log level" do
212
+ level = Factory.string
213
+
214
+ assert_equal @config_class::DEFAULT_STDOUT_LOG_LEVEL, subject.stdout_log_level
215
+ assert_equal level, subject.stdout_log_level(level)
216
+ assert_equal level, subject.stdout_log_level
217
+ end
218
+
219
+ should "know its log pattern" do
220
+ pattern = Factory.string
221
+
222
+ assert_equal @config_class::DEFAULT_LOG_PATTERN, subject.log_pattern
223
+ assert_equal pattern, subject.log_pattern(pattern)
224
+ assert_equal pattern, subject.log_pattern
225
+ end
226
+
227
+ should "know its log file" do
228
+ file = Factory.file_path
229
+
230
+ assert_nil subject.log_file
231
+ assert_equal file, subject.log_file(file)
232
+ assert_equal file, subject.log_file
233
+ end
234
+
235
+ should "know its log file pattern" do
236
+ pattern = Factory.string
237
+
238
+ assert_equal @config_class::DEFAULT_LOG_FILE_PATTERN, subject.log_file_pattern
239
+ assert_equal pattern, subject.log_file_pattern(pattern)
240
+ assert_equal pattern, subject.log_file_pattern
241
+ end
242
+
243
+ should "know its logger output names" do
244
+ exp = "dk-config-#{subject.object_id}-stdout"
245
+ assert_equal exp, subject.dk_logger_stdout_output_name
246
+
247
+ exp = "dk-config-#{subject.object_id}-file"
248
+ assert_equal exp, subject.dk_logger_file_output_name
249
+ end
250
+
251
+ should "know its logger" do
252
+ logger = subject.dk_logger
253
+
254
+ assert_instance_of LogslyLogger, logger
255
+ assert_equal subject, logger.config
256
+ end
257
+
258
+ end
259
+
260
+ class DryTreeStubsTests < InitTests
261
+ setup do
262
+ raw_cmd_str = Factory.string
263
+ raw_input = Factory.string
264
+ raw_given_opts = { Factory.string => Factory.string }
265
+
266
+ @cmd_str = [@raw_cmd_str, proc{ "#{raw_cmd_str},#{some_attr}" }].sample
267
+ @input = [@raw_input, proc{ "#{raw_input},#{some_attr}" }].sample
268
+ @given_opts = [
269
+ @raw_given_opts,
270
+ proc{ raw_given_opts.merge('some_attr' => some_attr) }
271
+ ].sample
272
+ @ssh_opts = { :hosts => Factory.hosts }
273
+ @stub_block = Proc.new{ |s| Factory.string }
274
+
275
+ task_class = Class.new{ def some_attr; @some_attr ||= Factory.string; end }
276
+ @task = task_class.new
277
+ end
278
+
279
+ should "allow adding dry tree runner cmd stubs" do
280
+ assert_equal 0, subject.dry_tree_cmd_stubs.size
281
+
282
+ cmd_str = get_raw_value(@cmd_str)
283
+ input = get_raw_value(@input)
284
+ given_opts = get_raw_value(@given_opts)
285
+
286
+ subject.stub_dry_tree_cmd(@cmd_str, &@stub_block)
287
+ assert_equal 1, subject.dry_tree_cmd_stubs.size
288
+ assert_equal @stub_block, lookup_cmd_stub_block(cmd_str, nil, nil)
289
+
290
+ subject.stub_dry_tree_cmd(@cmd_str, :input => @input, &@stub_block)
291
+ assert_equal 2, subject.dry_tree_cmd_stubs.size
292
+ assert_equal @stub_block, lookup_cmd_stub_block(cmd_str, input, nil)
293
+
294
+ subject.stub_dry_tree_cmd(@cmd_str, :opts => @given_opts, &@stub_block)
295
+ assert_equal 3, subject.dry_tree_cmd_stubs.size
296
+ assert_equal @stub_block, lookup_cmd_stub_block(cmd_str, nil, given_opts)
297
+
298
+ subject.stub_dry_tree_cmd(@cmd_str, {
299
+ :input => @input,
300
+ :opts => @given_opts
301
+ }, &@stub_block)
302
+ assert_equal 4, subject.dry_tree_cmd_stubs.size
303
+ assert_equal @stub_block, lookup_cmd_stub_block(cmd_str, input, given_opts)
304
+ end
305
+
306
+ should "allow adding dry tree runner ssh stubs" do
307
+ assert_equal 0, subject.dry_tree_ssh_stubs.size
308
+
309
+ cmd_str = get_raw_value(@cmd_str)
310
+ input = get_raw_value(@input)
311
+ given_opts = get_raw_value(@given_opts)
312
+
313
+ subject.stub_dry_tree_ssh(@cmd_str, &@stub_block)
314
+ assert_equal 1, subject.dry_tree_ssh_stubs.size
315
+ assert_equal @stub_block, lookup_ssh_stub_block(cmd_str, nil, nil)
316
+
317
+ subject.stub_dry_tree_ssh(@cmd_str, :input => @input, &@stub_block)
318
+ assert_equal 2, subject.dry_tree_ssh_stubs.size
319
+ assert_equal @stub_block, lookup_ssh_stub_block(cmd_str, input, nil)
320
+
321
+ subject.stub_dry_tree_ssh(@cmd_str, :opts => @given_opts, &@stub_block)
322
+ assert_equal 3, subject.dry_tree_ssh_stubs.size
323
+ assert_equal @stub_block, lookup_ssh_stub_block(cmd_str, nil, given_opts)
324
+
325
+ subject.stub_dry_tree_ssh(@cmd_str, {
326
+ :input => @input,
327
+ :opts => @given_opts
328
+ }, &@stub_block)
329
+ assert_equal 4, subject.dry_tree_ssh_stubs.size
330
+ assert_equal @stub_block, lookup_ssh_stub_block(cmd_str, input, given_opts)
331
+ end
332
+
333
+ private
334
+
335
+ def get_raw_value(value)
336
+ value.kind_of?(::Proc) ? @task.instance_eval(&value) : value
337
+ end
338
+
339
+ def lookup_cmd_stub_block(cmd_str, input, given_opts)
340
+ stubs = @config.dry_tree_cmd_stubs
341
+ find_cmd_ssh_stub_block(stubs, @task, cmd_str, input, given_opts)
342
+ end
343
+
344
+ def lookup_ssh_stub_block(cmd_str, input, given_opts)
345
+ stubs = @config.dry_tree_ssh_stubs
346
+ find_cmd_ssh_stub_block(stubs, @task, cmd_str, input, given_opts)
347
+ end
348
+
349
+ def find_cmd_ssh_stub_block(stubs, task, cmd_str, input, given_opts)
350
+ stub = stubs.find do |stub|
351
+ task.instance_eval(&stub.cmd_str_proc) == cmd_str &&
352
+ task.instance_eval(&stub.input_proc) == input &&
353
+ task.instance_eval(&stub.given_opts_proc) == given_opts
354
+ end
355
+ stub ? stub.block : nil
356
+ end
357
+
358
+ end
359
+
360
+ class LogslyLoggerTests < UnitTests
361
+ desc "LogslyLogger"
362
+ setup do
363
+ @logger_class = LogslyLogger
364
+ end
365
+ subject{ @logger_class }
366
+
367
+ should "be a logsly logger and know its log type" do
368
+ assert_includes Logsly, subject
369
+ assert_equal 'dk', subject::LOG_TYPE
370
+ end
371
+
372
+ end
373
+
374
+ class LogslyLoggerInitTests < LogslyLoggerTests
375
+ desc "when init"
376
+ setup do
377
+ @config = @config_class.new
378
+ @logger = @logger_class.new(@config)
379
+ end
380
+ subject{ @logger }
381
+
382
+ should "know its log type" do
383
+ assert_equal @logger_class::LOG_TYPE, subject.log_type
384
+ end
385
+
386
+ should "have only a logsly stdout output" do
387
+ assert_equal 1, subject.outputs.size
388
+ assert_equal @config.dk_logger_stdout_output_name, subject.outputs.first
389
+
390
+ out = Logsly.outputs(@config.dk_logger_stdout_output_name)
391
+ assert_instance_of Logsly::Outputs::Stdout, out
392
+
393
+ data = out.data(subject)
394
+ assert_equal @config.stdout_log_level, data.level
395
+ assert_equal @config.log_pattern, data.pattern
396
+ end
397
+
398
+ end
399
+
400
+ class LogslyLoggerInitWithLogFileTests < LogslyLoggerInitTests
401
+ desc "with a log file"
402
+ setup do
403
+ @config.log_file Factory.log_file
404
+ @logger = @logger_class.new(@config)
405
+ end
406
+ teardown do
407
+ @config.log_file.delete
408
+ end
409
+
410
+ should "have a logsly file output in addition to the stdout output" do
411
+ assert_equal 2, subject.outputs.size
412
+ assert_equal @config.dk_logger_stdout_output_name, subject.outputs.first
413
+ assert_equal @config.dk_logger_file_output_name, subject.outputs.last
414
+
415
+ out = Logsly.outputs(@config.dk_logger_file_output_name)
416
+ assert_instance_of Logsly::Outputs::File, out
417
+
418
+ data = out.data(subject)
419
+ exp = File.expand_path(@config.log_file, ENV['PWD'])
420
+ assert_equal exp, data.path
421
+ assert_equal @config_class::FILE_LOG_LEVEL, data.level
422
+ assert_equal @config.log_file_pattern, data.pattern
423
+ end
424
+
425
+ end
426
+
427
+ end
@@ -0,0 +1,34 @@
1
+ require 'assert'
2
+ require 'dk/dk_runner'
3
+
4
+ require 'dk/config_runner'
5
+
6
+ class Dk::DkRunner
7
+
8
+ class UnitTests < Assert::Context
9
+ desc "Dk::DkRunner"
10
+ setup do
11
+ @runner_class = Dk::DkRunner
12
+ end
13
+ subject{ @runner_class }
14
+
15
+ should "be a Dk::ConfigRunner" do
16
+ assert_true subject < Dk::ConfigRunner
17
+ end
18
+
19
+ end
20
+
21
+ class InitTests < UnitTests
22
+ desc "when init"
23
+ setup do
24
+ @config = Dk::Config.new
25
+ end
26
+
27
+ should "be init with a config instance" do
28
+ assert_nothing_raised{ @runner_class.new(@config) }
29
+ assert_raises(ArgumentError){ @runner_class.new }
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,49 @@
1
+ require 'assert'
2
+ require 'dk'
3
+
4
+ require 'dk/config'
5
+
6
+ module Dk
7
+
8
+ class UnitTests < Assert::Context
9
+ desc "Dk"
10
+ setup do
11
+ @dk_module = Dk
12
+ end
13
+ subject{ @dk_module }
14
+
15
+ should have_imeths :config, :configure, :init, :reset
16
+
17
+ should "know its config" do
18
+ assert_instance_of Config, subject.config
19
+ end
20
+
21
+ should "add init procs to its config on `configure`" do
22
+ assert_equal [], subject.config.init_procs
23
+
24
+ init_block = proc{}
25
+ subject.configure(&init_block)
26
+
27
+ assert_equal [init_block], subject.config.init_procs
28
+ end
29
+
30
+ should "instance eval its init procs on init" do
31
+ config_init_called = false
32
+ Assert.stub(subject.config, :init){ config_init_called = true }
33
+
34
+ subject.init
35
+ assert_true config_init_called
36
+ end
37
+
38
+ should "reset itself by rewriting the config with a new instance" do
39
+ config_obj_id = subject.config.object_id
40
+ subject.init
41
+ assert_equal config_obj_id, subject.config.object_id
42
+
43
+ subject.reset
44
+ assert_not_equal config_obj_id, subject.config.object_id
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,71 @@
1
+ require 'assert'
2
+ require 'dk/dry_runner'
3
+
4
+ require 'dk/config'
5
+ require 'dk/config_runner'
6
+ require 'dk/has_the_stubs'
7
+
8
+ class Dk::DryRunner
9
+
10
+ class UnitTests < Assert::Context
11
+ desc "Dk::DryRunner"
12
+ setup do
13
+ @runner_class = Dk::DryRunner
14
+ end
15
+ subject{ @runner_class }
16
+
17
+ should "be a Dk::ConfigRunner" do
18
+ assert_true subject < Dk::ConfigRunner
19
+ end
20
+
21
+ should "have the stubs" do
22
+ assert_includes Dk::HasTheStubs, subject
23
+ end
24
+
25
+ end
26
+
27
+ class InitTests < UnitTests
28
+ desc "when init"
29
+ setup do
30
+ @dk_config = Dk::Config.new
31
+ Factory.integer(3).times.each do
32
+ @dk_config.stub_dry_tree_cmd(Factory.string, {
33
+ :input => Factory.string,
34
+ :opts => { Factory.string => Factory.string }
35
+ }){ |s| Factory.string }
36
+ end
37
+ Factory.integer(3).times.each do
38
+ @dk_config.stub_dry_tree_ssh(Factory.string, {
39
+ :input => Factory.string,
40
+ :opts => { Factory.string => Factory.string }
41
+ }){ |s| Factory.string }
42
+ end
43
+
44
+ @runner = @runner_class.new(@dk_config)
45
+ end
46
+ subject{ @runner }
47
+
48
+ should "add cmd/ssh dry tree stubs from its config" do
49
+ @dk_config.dry_tree_cmd_stubs.each do |stub|
50
+ exp = Dk::HasTheStubs::Stub.new(
51
+ stub.cmd_str_proc,
52
+ stub.input_proc,
53
+ stub.given_opts_proc,
54
+ stub.block
55
+ )
56
+ assert_includes exp, @runner.local_cmd_stubs
57
+ end
58
+ @dk_config.dry_tree_ssh_stubs.each do |stub|
59
+ exp = Dk::HasTheStubs::Stub.new(
60
+ stub.cmd_str_proc,
61
+ stub.input_proc,
62
+ stub.given_opts_proc,
63
+ stub.block
64
+ )
65
+ assert_includes exp, @runner.remote_cmd_stubs
66
+ end
67
+ end
68
+
69
+ end
70
+
71
+ end
@@ -0,0 +1,46 @@
1
+ require 'assert'
2
+ require 'dk/has_set_param'
3
+
4
+ require 'much-plugin'
5
+
6
+ module Dk::HasSetParam
7
+
8
+ class UnitTests < Assert::Context
9
+ desc "Dk::HasSetParam"
10
+ setup do
11
+ @mixin_class = Dk::HasSetParam
12
+
13
+ @params_class = Class.new do
14
+ include Dk::HasSetParam
15
+ attr_reader :params
16
+ def initialize; @params = {}; end
17
+ end
18
+ end
19
+ subject{ @params_class }
20
+
21
+ should "use much-plugin" do
22
+ assert_includes MuchPlugin, subject
23
+ end
24
+
25
+ end
26
+
27
+ class InitTests < UnitTests
28
+ desc "when init"
29
+ setup do
30
+ @params = @params_class.new
31
+ end
32
+ subject{ @params }
33
+
34
+ should have_imeths :set_param
35
+
36
+ should "stringify and set param values with `set_param`" do
37
+ key, value = Factory.string.to_sym, Factory.string
38
+ subject.set_param(key, value)
39
+
40
+ assert_equal value, subject.params[key.to_s]
41
+ assert_nil subject.params[key]
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,81 @@
1
+ require 'assert'
2
+ require 'dk/has_ssh_opts'
3
+
4
+ require 'much-plugin'
5
+ require 'dk/config'
6
+
7
+ module Dk::HasSSHOpts
8
+
9
+ class UnitTests < Assert::Context
10
+ desc "Dk::HasSSHOpts"
11
+ setup do
12
+ @mixin_class = Dk::HasSSHOpts
13
+
14
+ @opts_class = Class.new do
15
+ include Dk::HasSSHOpts
16
+ def initialize
17
+ @ssh_hosts = Dk::Config::DEFAULT_SSH_HOSTS.dup
18
+ @ssh_args = Dk::Config::DEFAULT_SSH_ARGS.dup
19
+ @host_ssh_args = Dk::Config::DEFAULT_HOST_SSH_ARGS.dup
20
+ end
21
+ end
22
+ end
23
+ subject{ @opts_class }
24
+
25
+ should "use much-plugin" do
26
+ assert_includes MuchPlugin, subject
27
+ end
28
+
29
+ end
30
+
31
+ class InitTests < UnitTests
32
+ desc "when init"
33
+ setup do
34
+ @opts = @opts_class.new
35
+ end
36
+ subject{ @opts }
37
+
38
+ should have_imeths :ssh_hosts, :ssh_args, :host_ssh_args
39
+
40
+ should "know its ssh hosts" do
41
+ group_name = Factory.string
42
+ hosts = Factory.hosts
43
+
44
+ assert_equal Dk::Config::DEFAULT_SSH_HOSTS, subject.ssh_hosts
45
+ assert_nil subject.ssh_hosts(group_name)
46
+
47
+ assert_equal hosts, subject.ssh_hosts(group_name, hosts)
48
+ assert_equal hosts, subject.ssh_hosts(group_name)
49
+
50
+ assert_equal hosts, subject.ssh_hosts(group_name, *hosts)
51
+ assert_equal hosts, subject.ssh_hosts(group_name)
52
+
53
+ exp = { group_name => hosts }
54
+ assert_equal exp, subject.ssh_hosts
55
+ end
56
+
57
+ should "know its ssh args" do
58
+ args = Factory.string
59
+
60
+ assert_equal Dk::Config::DEFAULT_SSH_ARGS, subject.ssh_args
61
+ assert_equal args, subject.ssh_args(args)
62
+ assert_equal args, subject.ssh_args
63
+ end
64
+
65
+ should "know its host ssh args" do
66
+ host_name = Factory.string
67
+ args = Factory.string
68
+
69
+ assert_equal Hash.new, subject.host_ssh_args
70
+ assert_equal Dk::Config::DEFAULT_SSH_ARGS, subject.host_ssh_args(host_name)
71
+
72
+ assert_equal args, subject.host_ssh_args(host_name, args)
73
+ assert_equal args, subject.host_ssh_args(host_name)
74
+
75
+ exp = { host_name => args }
76
+ assert_equal exp, subject.host_ssh_args
77
+ end
78
+
79
+ end
80
+
81
+ end