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.
- checksums.yaml +5 -5
- data/README.md +643 -1
- data/bin/dk +7 -0
- data/dk.gemspec +7 -3
- data/lib/dk/ansi.rb +98 -0
- data/lib/dk/cli.rb +173 -0
- data/lib/dk/config.rb +217 -0
- data/lib/dk/config_runner.rb +24 -0
- data/lib/dk/dk_runner.rb +13 -0
- data/lib/dk/dry_runner.rb +43 -0
- data/lib/dk/has_set_param.rb +42 -0
- data/lib/dk/has_ssh_opts.rb +36 -0
- data/lib/dk/has_the_runs.rb +23 -0
- data/lib/dk/has_the_stubs.rb +116 -0
- data/lib/dk/local.rb +84 -0
- data/lib/dk/null_logger.rb +13 -0
- data/lib/dk/remote.rb +132 -0
- data/lib/dk/runner.rb +202 -0
- data/lib/dk/task.rb +266 -0
- data/lib/dk/task_run.rb +17 -0
- data/lib/dk/test_runner.rb +54 -0
- data/lib/dk/tree_runner.rb +64 -0
- data/lib/dk/version.rb +1 -1
- data/lib/dk.rb +23 -1
- data/test/helper.rb +6 -1
- data/test/support/config/dk.rb +7 -0
- data/test/support/config/task_defs.rb +10 -0
- data/test/support/factory.rb +38 -0
- data/test/support/log/.gitkeep +0 -0
- data/test/system/has_the_stubs_tests.rb +355 -0
- data/test/system/runner_tests.rb +222 -0
- data/test/unit/ansi_tests.rb +40 -0
- data/test/unit/cli_tests.rb +317 -0
- data/test/unit/config_runner_tests.rb +60 -0
- data/test/unit/config_tests.rb +427 -0
- data/test/unit/dk_runner_tests.rb +34 -0
- data/test/unit/dk_tests.rb +49 -0
- data/test/unit/dry_runner_tests.rb +71 -0
- data/test/unit/has_set_param_tests.rb +46 -0
- data/test/unit/has_ssh_opts_tests.rb +81 -0
- data/test/unit/has_the_runs_tests.rb +37 -0
- data/test/unit/has_the_stubs_tests.rb +279 -0
- data/test/unit/local_tests.rb +174 -0
- data/test/unit/null_logger_tests.rb +17 -0
- data/test/unit/remote_tests.rb +330 -0
- data/test/unit/runner_tests.rb +398 -0
- data/test/unit/task_run_tests.rb +40 -0
- data/test/unit/task_tests.rb +943 -0
- data/test/unit/test_runner_tests.rb +189 -0
- data/test/unit/tree_runner_tests.rb +152 -0
- metadata +106 -9
@@ -0,0 +1,355 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'dk/has_the_stubs'
|
3
|
+
|
4
|
+
require 'stringio'
|
5
|
+
require 'dk/config'
|
6
|
+
require 'dk/dry_runner'
|
7
|
+
require 'dk/tree_runner'
|
8
|
+
require 'dk/test_runner'
|
9
|
+
|
10
|
+
module Dk::HasTheStubs
|
11
|
+
|
12
|
+
class SystemTests < Assert::Context
|
13
|
+
desc "Dk::HasTheStubs"
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
class RunnerTests < SystemTests
|
18
|
+
desc "used by a runner"
|
19
|
+
setup do
|
20
|
+
@runner_class = [
|
21
|
+
Dk::DryRunner,
|
22
|
+
Dk::TreeRunner,
|
23
|
+
Dk::TestRunner
|
24
|
+
].sample
|
25
|
+
|
26
|
+
# turn off the stdout logging
|
27
|
+
@dk_config = Dk::Config.new
|
28
|
+
@logger = Dk::NullLogger.new
|
29
|
+
Assert.stub(@dk_config, :dk_logger){ @logger }
|
30
|
+
|
31
|
+
@task_class = StubTestTask
|
32
|
+
@runner = build_runner(@task_class)
|
33
|
+
|
34
|
+
@cmd_str = Factory.string
|
35
|
+
@cmd_input = Factory.string
|
36
|
+
@cmd_opts = { Factory.string => Factory.string }
|
37
|
+
|
38
|
+
@params = {
|
39
|
+
'use_bang' => false,
|
40
|
+
'cmd_str' => @cmd_str,
|
41
|
+
'cmd_input' => @cmd_input,
|
42
|
+
'cmd_opts' => @cmd_opts
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def build_runner(task_class)
|
49
|
+
if @runner_class == Dk::TestRunner
|
50
|
+
@runner_class.new(:logger => @logger).tap{ |r| r.task_class = task_class }
|
51
|
+
elsif @runner_class == Dk::TreeRunner
|
52
|
+
@runner_class.new(@dk_config, StringIO.new)
|
53
|
+
else
|
54
|
+
@runner_class.new(@dk_config)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def run_runner(runner, task_class, params)
|
59
|
+
if @runner_class == Dk::TestRunner
|
60
|
+
runner.run(params)
|
61
|
+
else
|
62
|
+
runner.run(task_class, params)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def add_stubs(runner, local)
|
67
|
+
method = local ? :stub_cmd : :stub_ssh
|
68
|
+
|
69
|
+
@only_cmd_stdout = Factory.stdout
|
70
|
+
@only_cmd_stderr = Factory.stderr
|
71
|
+
@only_cmd_success = Factory.boolean
|
72
|
+
@only_cmd_spy = nil
|
73
|
+
@runner.send(method, @cmd_str) do |spy|
|
74
|
+
spy.stdout = @only_cmd_stdout
|
75
|
+
spy.stderr = @only_cmd_stderr
|
76
|
+
spy.exitstatus = @only_cmd_success ? 0 : 1
|
77
|
+
@only_cmd_spy = spy
|
78
|
+
end
|
79
|
+
|
80
|
+
@with_input_cmd_stdout = Factory.stdout
|
81
|
+
@with_input_cmd_stderr = Factory.stderr
|
82
|
+
@with_input_cmd_success = Factory.boolean
|
83
|
+
@with_input_cmd_spy = nil
|
84
|
+
@runner.send(method, @cmd_str, :input => @cmd_input) do |spy|
|
85
|
+
spy.stdout = @with_input_cmd_stdout
|
86
|
+
spy.stderr = @with_input_cmd_stderr
|
87
|
+
spy.exitstatus = @with_input_cmd_success ? 0 : 1
|
88
|
+
@with_input_cmd_spy = spy
|
89
|
+
end
|
90
|
+
|
91
|
+
@with_opts_cmd_stdout = Factory.stdout
|
92
|
+
@with_opts_cmd_stderr = Factory.stderr
|
93
|
+
@with_opts_cmd_success = Factory.boolean
|
94
|
+
@with_opts_cmd_spy = nil
|
95
|
+
@runner.send(method, @cmd_str, :opts => @cmd_opts) do |spy|
|
96
|
+
spy.stdout = @with_opts_cmd_stdout
|
97
|
+
spy.stderr = @with_opts_cmd_stderr
|
98
|
+
spy.exitstatus = @with_opts_cmd_success ? 0 : 1
|
99
|
+
@with_opts_cmd_spy = spy
|
100
|
+
end
|
101
|
+
|
102
|
+
@with_all_cmd_stdout = Factory.stdout
|
103
|
+
@with_all_cmd_stderr = Factory.stderr
|
104
|
+
@with_all_cmd_success = Factory.boolean
|
105
|
+
@with_all_cmd_spy = nil
|
106
|
+
@runner.send(method, @cmd_str, {
|
107
|
+
:input => @cmd_input,
|
108
|
+
:opts => @cmd_opts
|
109
|
+
}) do |spy|
|
110
|
+
spy.stdout = @with_all_cmd_stdout
|
111
|
+
spy.stderr = @with_all_cmd_stderr
|
112
|
+
spy.exitstatus = @with_all_cmd_success ? 0 : 1
|
113
|
+
@with_all_cmd_spy = spy
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
class CmdStubTests < RunnerTests
|
120
|
+
setup do
|
121
|
+
@params.merge!('local' => true)
|
122
|
+
add_stubs(@runner, @params['local'])
|
123
|
+
end
|
124
|
+
|
125
|
+
should "allow stubbing `cmd` calls" do
|
126
|
+
task = run_runner(@runner, @task_class, @params)
|
127
|
+
|
128
|
+
# ensure calls return the cmd spy they are stubbed with
|
129
|
+
assert_same @only_cmd_spy, task.only_cmd
|
130
|
+
assert_same @with_input_cmd_spy, task.with_input_cmd
|
131
|
+
assert_same @with_opts_cmd_spy, task.with_opts_cmd
|
132
|
+
assert_same @with_all_cmd_spy, task.with_all_cmd
|
133
|
+
|
134
|
+
# ensure the cmd spies are local spies
|
135
|
+
assert_false @only_cmd_spy.ssh?
|
136
|
+
assert_false @with_input_cmd_spy.ssh?
|
137
|
+
assert_false @with_opts_cmd_spy.ssh?
|
138
|
+
assert_false @with_all_cmd_spy.ssh?
|
139
|
+
|
140
|
+
# ensure cmd spies are run
|
141
|
+
assert_true @only_cmd_spy.run_called?
|
142
|
+
assert_true @with_input_cmd_spy.run_called?
|
143
|
+
assert_true @with_opts_cmd_spy.run_called?
|
144
|
+
assert_true @with_all_cmd_spy.run_called?
|
145
|
+
|
146
|
+
# ensure stubs can set stdout
|
147
|
+
assert_equal @only_cmd_stdout, @only_cmd_spy.stdout
|
148
|
+
assert_equal @with_input_cmd_stdout, @with_input_cmd_spy.stdout
|
149
|
+
assert_equal @with_opts_cmd_stdout, @with_opts_cmd_spy.stdout
|
150
|
+
assert_equal @with_all_cmd_stdout, @with_all_cmd_spy.stdout
|
151
|
+
|
152
|
+
# ensure stubs can set stderr
|
153
|
+
assert_equal @only_cmd_stderr, @only_cmd_spy.stderr
|
154
|
+
assert_equal @with_input_cmd_stderr, @with_input_cmd_spy.stderr
|
155
|
+
assert_equal @with_opts_cmd_stderr, @with_opts_cmd_spy.stderr
|
156
|
+
assert_equal @with_all_cmd_stderr, @with_all_cmd_spy.stderr
|
157
|
+
|
158
|
+
# ensure stubs can set exitstatus
|
159
|
+
assert_equal @only_cmd_success, @only_cmd_spy.success?
|
160
|
+
assert_equal @with_input_cmd_success, @with_input_cmd_spy.success?
|
161
|
+
assert_equal @with_opts_cmd_success, @with_opts_cmd_spy.success?
|
162
|
+
assert_equal @with_all_cmd_success, @with_all_cmd_spy.success?
|
163
|
+
end
|
164
|
+
|
165
|
+
should "allow stubbing `cmd!` calls" do
|
166
|
+
@params['use_bang'] = true
|
167
|
+
task = run_runner(@runner, @task_class, @params)
|
168
|
+
|
169
|
+
# ensure stubs can control whether a `cmd!` raises an error or not
|
170
|
+
|
171
|
+
if @only_cmd_success
|
172
|
+
assert_equal @only_cmd_spy, task.only_cmd
|
173
|
+
else
|
174
|
+
assert_true task.only_cmd_failed
|
175
|
+
end
|
176
|
+
|
177
|
+
if @with_input_cmd_success
|
178
|
+
assert_equal @with_input_cmd_spy, task.with_input_cmd
|
179
|
+
else
|
180
|
+
assert_true task.with_input_cmd_failed
|
181
|
+
end
|
182
|
+
|
183
|
+
if @with_opts_cmd_success
|
184
|
+
assert_equal @with_opts_cmd_spy, task.with_opts_cmd
|
185
|
+
else
|
186
|
+
assert_true task.with_opts_cmd_failed
|
187
|
+
end
|
188
|
+
|
189
|
+
if @with_all_cmd_success
|
190
|
+
assert_equal @with_all_cmd_spy, task.with_all_cmd
|
191
|
+
else
|
192
|
+
assert_true task.with_all_cmd_failed
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
should "unstub all cmd spies" do
|
197
|
+
@runner.unstub_all_cmds
|
198
|
+
@params['use_bang'] = Factory.boolean
|
199
|
+
task = run_runner(@runner, @task_class, @params)
|
200
|
+
|
201
|
+
assert_not_same @only_cmd_spy, task.only_cmd
|
202
|
+
assert_not_same @with_input_cmd_spy, task.with_input_cmd
|
203
|
+
assert_not_same @with_opts_cmd_spy, task.with_opts_cmd
|
204
|
+
assert_not_same @with_all_cmd_spy, task.with_all_cmd
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
class SshStubTests < RunnerTests
|
210
|
+
setup do
|
211
|
+
@cmd_opts = Factory.ssh_cmd_opts
|
212
|
+
@params.merge!({
|
213
|
+
'local' => false,
|
214
|
+
'cmd_opts' => @cmd_opts
|
215
|
+
})
|
216
|
+
add_stubs(@runner, @params['local'])
|
217
|
+
end
|
218
|
+
|
219
|
+
should "allow stubbing `ssh` calls" do
|
220
|
+
task = run_runner(@runner, @task_class, @params)
|
221
|
+
|
222
|
+
# ensure calls return the cmd spy they are stubbed with
|
223
|
+
assert_same @only_cmd_spy, task.only_cmd
|
224
|
+
assert_same @with_input_cmd_spy, task.with_input_cmd
|
225
|
+
assert_same @with_opts_cmd_spy, task.with_opts_cmd
|
226
|
+
assert_same @with_all_cmd_spy, task.with_all_cmd
|
227
|
+
|
228
|
+
# ensure the cmd spies are remote spies
|
229
|
+
assert_true @only_cmd_spy.ssh?
|
230
|
+
assert_true @with_input_cmd_spy.ssh?
|
231
|
+
assert_true @with_opts_cmd_spy.ssh?
|
232
|
+
assert_true @with_all_cmd_spy.ssh?
|
233
|
+
|
234
|
+
# ensure cmd spies are run
|
235
|
+
assert_true @only_cmd_spy.run_called?
|
236
|
+
assert_true @with_input_cmd_spy.run_called?
|
237
|
+
assert_true @with_opts_cmd_spy.run_called?
|
238
|
+
assert_true @with_all_cmd_spy.run_called?
|
239
|
+
|
240
|
+
# ensure stubs can set stdout
|
241
|
+
assert_equal @only_cmd_stdout, @only_cmd_spy.stdout
|
242
|
+
assert_equal @with_input_cmd_stdout, @with_input_cmd_spy.stdout
|
243
|
+
assert_equal @with_opts_cmd_stdout, @with_opts_cmd_spy.stdout
|
244
|
+
assert_equal @with_all_cmd_stdout, @with_all_cmd_spy.stdout
|
245
|
+
|
246
|
+
# ensure stubs can set stderr
|
247
|
+
assert_equal @only_cmd_stderr, @only_cmd_spy.stderr
|
248
|
+
assert_equal @with_input_cmd_stderr, @with_input_cmd_spy.stderr
|
249
|
+
assert_equal @with_opts_cmd_stderr, @with_opts_cmd_spy.stderr
|
250
|
+
assert_equal @with_all_cmd_stderr, @with_all_cmd_spy.stderr
|
251
|
+
|
252
|
+
# ensure stubs can set exitstatus
|
253
|
+
assert_equal @only_cmd_success, @only_cmd_spy.success?
|
254
|
+
assert_equal @with_input_cmd_success, @with_input_cmd_spy.success?
|
255
|
+
assert_equal @with_opts_cmd_success, @with_opts_cmd_spy.success?
|
256
|
+
assert_equal @with_all_cmd_success, @with_all_cmd_spy.success?
|
257
|
+
end
|
258
|
+
|
259
|
+
should "allow stubbing `ssh!` calls" do
|
260
|
+
@params['use_bang'] = true
|
261
|
+
task = run_runner(@runner, @task_class, @params)
|
262
|
+
|
263
|
+
# ensure stubs can control whether a `ssh!` raises an error or not
|
264
|
+
|
265
|
+
if @only_cmd_success
|
266
|
+
assert_equal @only_cmd_spy, task.only_cmd
|
267
|
+
else
|
268
|
+
assert_true task.only_cmd_failed
|
269
|
+
end
|
270
|
+
|
271
|
+
if @with_input_cmd_success
|
272
|
+
assert_equal @with_input_cmd_spy, task.with_input_cmd
|
273
|
+
else
|
274
|
+
assert_true task.with_input_cmd_failed
|
275
|
+
end
|
276
|
+
|
277
|
+
if @with_opts_cmd_success
|
278
|
+
assert_equal @with_opts_cmd_spy, task.with_opts_cmd
|
279
|
+
else
|
280
|
+
assert_true task.with_opts_cmd_failed
|
281
|
+
end
|
282
|
+
|
283
|
+
if @with_all_cmd_success
|
284
|
+
assert_equal @with_all_cmd_spy, task.with_all_cmd
|
285
|
+
else
|
286
|
+
assert_true task.with_all_cmd_failed
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
should "unstub all cmd spies" do
|
291
|
+
@runner.unstub_all_ssh
|
292
|
+
@params['use_bang'] = Factory.boolean
|
293
|
+
task = run_runner(@runner, @task_class, @params)
|
294
|
+
|
295
|
+
assert_not_same @only_cmd_spy, task.only_cmd
|
296
|
+
assert_not_same @with_input_cmd_spy, task.with_input_cmd
|
297
|
+
assert_not_same @with_opts_cmd_spy, task.with_opts_cmd
|
298
|
+
assert_not_same @with_all_cmd_spy, task.with_all_cmd
|
299
|
+
end
|
300
|
+
|
301
|
+
end
|
302
|
+
|
303
|
+
class StubTestTask
|
304
|
+
include Dk::Task
|
305
|
+
|
306
|
+
attr_reader :only_cmd, :with_input_cmd, :with_opts_cmd, :with_all_cmd
|
307
|
+
attr_reader :only_cmd_failed, :with_input_cmd_failed
|
308
|
+
attr_reader :with_opts_cmd_failed, :with_all_cmd_failed
|
309
|
+
|
310
|
+
ssh_hosts 'test'
|
311
|
+
|
312
|
+
def run!
|
313
|
+
method = if params['local']
|
314
|
+
params['use_bang'] ? :cmd! : :cmd
|
315
|
+
else
|
316
|
+
params['use_bang'] ? :ssh! : :ssh
|
317
|
+
end
|
318
|
+
|
319
|
+
begin
|
320
|
+
@only_cmd = send(method, params['cmd_str'])
|
321
|
+
@only_cmd_failed = false
|
322
|
+
rescue CmdRunError, SSHRunError
|
323
|
+
@only_cmd_failed = true
|
324
|
+
end
|
325
|
+
|
326
|
+
begin
|
327
|
+
@with_input_cmd = send(method, params['cmd_str'], params['cmd_input'])
|
328
|
+
@with_input_cmd_failed = false
|
329
|
+
rescue CmdRunError, SSHRunError
|
330
|
+
@with_input_cmd_failed = true
|
331
|
+
end
|
332
|
+
|
333
|
+
begin
|
334
|
+
@with_opts_cmd = send(method, params['cmd_str'], params['cmd_opts'])
|
335
|
+
@with_opts_cmd_failed = false
|
336
|
+
rescue CmdRunError, SSHRunError
|
337
|
+
@with_opts_cmd_failed = true
|
338
|
+
end
|
339
|
+
|
340
|
+
begin
|
341
|
+
@with_all_cmd = send(
|
342
|
+
method,
|
343
|
+
params['cmd_str'],
|
344
|
+
params['cmd_input'],
|
345
|
+
params['cmd_opts']
|
346
|
+
)
|
347
|
+
@with_all_cmd_failed = false
|
348
|
+
rescue CmdRunError, SSHRunError
|
349
|
+
@with_all_cmd_failed = true
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
end
|
354
|
+
|
355
|
+
end
|
@@ -0,0 +1,222 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'dk/runner'
|
3
|
+
|
4
|
+
require 'stringio'
|
5
|
+
require 'dk/config'
|
6
|
+
require 'dk/dk_runner'
|
7
|
+
require 'dk/dry_runner'
|
8
|
+
require 'dk/null_logger'
|
9
|
+
require 'dk/task'
|
10
|
+
require 'dk/test_runner'
|
11
|
+
require 'dk/tree_runner'
|
12
|
+
|
13
|
+
class Dk::Runner
|
14
|
+
|
15
|
+
class SystemTests < Assert::Context
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
class DryTreeRunSystemTests < SystemTests
|
20
|
+
setup do
|
21
|
+
@task_class = Class.new do
|
22
|
+
include Dk::Task
|
23
|
+
ssh_hosts Factory.string
|
24
|
+
|
25
|
+
attr_reader :regular_cmd, :dry_tree_run_cmd, :stubbed_cmd
|
26
|
+
attr_reader :regular_ssh, :dry_tree_run_ssh, :stubbed_ssh
|
27
|
+
|
28
|
+
def run!
|
29
|
+
@regular_cmd = cmd!(params['cmd_str'])
|
30
|
+
@dry_tree_run_cmd = cmd!(params['cmd_str'], :dry_tree_run => true)
|
31
|
+
@stubbed_cmd = cmd!(params['stubbed_cmd_str'], :dry_tree_run => true)
|
32
|
+
@regular_ssh = ssh!(params['cmd_str'])
|
33
|
+
@dry_tree_run_ssh = ssh!(params['cmd_str'], :dry_tree_run => true)
|
34
|
+
@stubbed_ssh = ssh!(params['stubbed_cmd_str'], :dry_tree_run => true)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# turn off the stdout logging
|
39
|
+
@dk_config = Dk::Config.new
|
40
|
+
@logger = Dk::NullLogger.new
|
41
|
+
Assert.stub(@dk_config, :dk_logger){ @logger }
|
42
|
+
|
43
|
+
@params = {
|
44
|
+
'cmd_str' => Factory.string,
|
45
|
+
'stubbed_cmd_str' => Factory.string
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class DTRDkRunnerSystemTests < DryTreeRunSystemTests
|
51
|
+
desc "DkRunner"
|
52
|
+
setup do
|
53
|
+
@runner = Dk::DkRunner.new(@dk_config)
|
54
|
+
@task = @runner.run(@task_class, @params)
|
55
|
+
end
|
56
|
+
subject{ @task }
|
57
|
+
|
58
|
+
should "run all cmds/ssh regardless of the `dry_tree_run` opt" do
|
59
|
+
# scmd is in test mode so we can test its spy and see if it was run
|
60
|
+
# called; if scmd was run then as far as dk is concerned it ran the cmd
|
61
|
+
assert_instance_of Dk::Local::Cmd, @task.regular_cmd
|
62
|
+
assert_true @task.regular_cmd.scmd.run_called?
|
63
|
+
assert_instance_of Dk::Local::Cmd, @task.dry_tree_run_cmd
|
64
|
+
assert_true @task.dry_tree_run_cmd.scmd.run_called?
|
65
|
+
assert_instance_of Dk::Local::Cmd, @task.stubbed_cmd
|
66
|
+
assert_true @task.stubbed_cmd.scmd.run_called?
|
67
|
+
|
68
|
+
# check that the first local cmd of the remote cmd was run
|
69
|
+
assert_instance_of Dk::Remote::Cmd, @task.regular_ssh
|
70
|
+
assert_true @task.regular_ssh.local_cmds.values.first.scmd.start_called?
|
71
|
+
assert_instance_of Dk::Remote::Cmd, @task.dry_tree_run_ssh
|
72
|
+
assert_true @task.dry_tree_run_ssh.local_cmds.values.first.scmd.start_called?
|
73
|
+
assert_instance_of Dk::Remote::Cmd, @task.stubbed_ssh
|
74
|
+
assert_true @task.stubbed_ssh.local_cmds.values.first.scmd.start_called?
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
class DTRDryRunnerSystemTests < DryTreeRunSystemTests
|
80
|
+
desc "DryRunner"
|
81
|
+
setup do
|
82
|
+
@runner = Dk::DryRunner.new(@dk_config)
|
83
|
+
|
84
|
+
stub_cmd_str = [
|
85
|
+
@params['stubbed_cmd_str'],
|
86
|
+
proc{ params['stubbed_cmd_str']}
|
87
|
+
].sample
|
88
|
+
|
89
|
+
# stub a cmd/ssh using `dry_tree_run` so we can test that the stub takes
|
90
|
+
# precedence over the `dry_tree_run` opt
|
91
|
+
@runner.stub_cmd(stub_cmd_str, {
|
92
|
+
:opts => { :dry_tree_run => true }
|
93
|
+
}) do |s|
|
94
|
+
s.stdout = Factory.string
|
95
|
+
end
|
96
|
+
@runner.stub_ssh(stub_cmd_str, {
|
97
|
+
:opts => { :dry_tree_run => true }
|
98
|
+
}) do |s|
|
99
|
+
s.stdout = Factory.string
|
100
|
+
end
|
101
|
+
|
102
|
+
@task = @runner.run(@task_class, @params)
|
103
|
+
end
|
104
|
+
subject{ @task }
|
105
|
+
|
106
|
+
should "not spy cmds that use the `dry_tree_run` opt" do
|
107
|
+
# scmd is in test mode so we can test its spy and see if it was run
|
108
|
+
# called; if scmd was run then as far as dk is concerned it ran the cmd
|
109
|
+
assert_instance_of Dk::Local::Cmd, @task.dry_tree_run_cmd
|
110
|
+
assert_true @task.dry_tree_run_cmd.scmd.run_called?
|
111
|
+
# check that the first local cmd of the remote cmd was run
|
112
|
+
assert_instance_of Dk::Remote::Cmd, @task.dry_tree_run_ssh
|
113
|
+
assert_true @task.dry_tree_run_ssh.local_cmds.values.first.scmd.start_called?
|
114
|
+
end
|
115
|
+
|
116
|
+
should "spy cmds that don't use the `dry_tree_run` opt" do
|
117
|
+
assert_instance_of Dk::Local::CmdSpy, @task.regular_cmd
|
118
|
+
assert_true @task.regular_cmd.run_called?
|
119
|
+
assert_instance_of Dk::Remote::CmdSpy, @task.regular_ssh
|
120
|
+
assert_true @task.regular_ssh.run_called?
|
121
|
+
end
|
122
|
+
|
123
|
+
should "spy cmds that are stubbed and use the `dry_tree_run` opt" do
|
124
|
+
assert_instance_of Dk::Local::CmdSpy, @task.stubbed_cmd
|
125
|
+
assert_true @task.stubbed_cmd.run_called?
|
126
|
+
assert_instance_of Dk::Remote::CmdSpy, @task.stubbed_ssh
|
127
|
+
assert_true @task.stubbed_ssh.run_called?
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
class DTRTreeRunnerSystemTests < DryTreeRunSystemTests
|
133
|
+
desc "TreeRunner"
|
134
|
+
setup do
|
135
|
+
@runner = Dk::TreeRunner.new(@dk_config, StringIO.new)
|
136
|
+
|
137
|
+
stub_cmd_str = [
|
138
|
+
@params['stubbed_cmd_str'],
|
139
|
+
proc{ params['stubbed_cmd_str']}
|
140
|
+
].sample
|
141
|
+
|
142
|
+
# stub a cmd/ssh using `dry_tree_run` so we can test that the stub takes
|
143
|
+
# precedence over the `dry_tree_run` opt
|
144
|
+
@runner.stub_cmd(stub_cmd_str, {
|
145
|
+
:opts => { :dry_tree_run => true }
|
146
|
+
}) do |s|
|
147
|
+
s.stdout = Factory.string
|
148
|
+
end
|
149
|
+
@runner.stub_ssh(stub_cmd_str, {
|
150
|
+
:opts => { :dry_tree_run => true }
|
151
|
+
}) do |s|
|
152
|
+
s.stdout = Factory.string
|
153
|
+
end
|
154
|
+
|
155
|
+
@task = @runner.run(@task_class, @params)
|
156
|
+
end
|
157
|
+
subject{ @task }
|
158
|
+
|
159
|
+
should "not spy cmds that use the `dry_tree_run` opt" do
|
160
|
+
# scmd is in test mode so we can test its spy and see if it was run
|
161
|
+
# called; if scmd was run then as far as dk is concerned it ran the cmd
|
162
|
+
assert_instance_of Dk::Local::Cmd, @task.dry_tree_run_cmd
|
163
|
+
assert_true @task.dry_tree_run_cmd.scmd.run_called?
|
164
|
+
# check that the first local cmd of the remote cmd was run
|
165
|
+
assert_instance_of Dk::Remote::Cmd, @task.dry_tree_run_ssh
|
166
|
+
assert_true @task.dry_tree_run_ssh.local_cmds.values.first.scmd.start_called?
|
167
|
+
end
|
168
|
+
|
169
|
+
should "spy cmds that don't use the `dry_tree_run` opt" do
|
170
|
+
assert_instance_of Dk::Local::CmdSpy, @task.regular_cmd
|
171
|
+
assert_true @task.regular_cmd.run_called?
|
172
|
+
assert_instance_of Dk::Remote::CmdSpy, @task.regular_ssh
|
173
|
+
assert_true @task.regular_ssh.run_called?
|
174
|
+
end
|
175
|
+
|
176
|
+
should "spy cmds that are stubbed and use the `dry_tree_run` opt" do
|
177
|
+
assert_instance_of Dk::Local::CmdSpy, @task.stubbed_cmd
|
178
|
+
assert_true @task.stubbed_cmd.run_called?
|
179
|
+
assert_instance_of Dk::Remote::CmdSpy, @task.stubbed_ssh
|
180
|
+
assert_true @task.stubbed_ssh.run_called?
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
class DTRTestRunnerSystemTests < DryTreeRunSystemTests
|
186
|
+
desc "TestRunner"
|
187
|
+
setup do
|
188
|
+
@runner = Dk::TestRunner.new(:logger => @logger)
|
189
|
+
@runner.task_class = @task_class
|
190
|
+
|
191
|
+
# stub a cmd/ssh using `dry_tree_run` so we can test that the stub takes
|
192
|
+
# precedence over the `dry_tree_run` opt
|
193
|
+
@runner.stub_cmd(@params['stubbed_cmd_str'], :dry_tree_run => true) do |s|
|
194
|
+
s.stdout = Factory.string
|
195
|
+
end
|
196
|
+
@runner.stub_ssh(@params['stubbed_cmd_str'], :dry_tree_run => true) do |s|
|
197
|
+
s.stdout = Factory.string
|
198
|
+
end
|
199
|
+
|
200
|
+
@task = @runner.run(@params)
|
201
|
+
end
|
202
|
+
subject{ @task }
|
203
|
+
|
204
|
+
should "spy all cmds/ssh regardless of the `dry_tree_run` opt" do
|
205
|
+
assert_instance_of Dk::Local::CmdSpy, @task.dry_tree_run_cmd
|
206
|
+
assert_true @task.dry_tree_run_cmd.run_called?
|
207
|
+
assert_instance_of Dk::Local::CmdSpy, @task.regular_cmd
|
208
|
+
assert_true @task.regular_cmd.run_called?
|
209
|
+
assert_instance_of Dk::Local::CmdSpy, @task.stubbed_cmd
|
210
|
+
assert_true @task.stubbed_cmd.run_called?
|
211
|
+
|
212
|
+
assert_instance_of Dk::Remote::CmdSpy, @task.dry_tree_run_ssh
|
213
|
+
assert_true @task.dry_tree_run_cmd.run_called?
|
214
|
+
assert_instance_of Dk::Remote::CmdSpy, @task.regular_ssh
|
215
|
+
assert_true @task.regular_ssh.run_called?
|
216
|
+
assert_instance_of Dk::Remote::CmdSpy, @task.stubbed_ssh
|
217
|
+
assert_true @task.stubbed_ssh.run_called?
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'dk/ansi'
|
3
|
+
|
4
|
+
module Dk::Ansi
|
5
|
+
|
6
|
+
class UnitTests < Assert::Context
|
7
|
+
desc "Dk::Ansi"
|
8
|
+
subject{ Dk::Ansi }
|
9
|
+
|
10
|
+
should have_imeths :styled_msg, :code_for
|
11
|
+
|
12
|
+
should "know its codes" do
|
13
|
+
assert_not_empty subject::CODES
|
14
|
+
end
|
15
|
+
|
16
|
+
should "map its code style names to ansi code strings" do
|
17
|
+
styles = Factory.integer(3).times.map{ subject::CODES.keys.sample }
|
18
|
+
exp = styles.map{ |n| "\e[#{subject::CODES[n]}m" }.join('')
|
19
|
+
assert_equal exp, subject.code_for(*styles)
|
20
|
+
|
21
|
+
styles = Factory.integer(3).times.map{ Factory.string }
|
22
|
+
assert_equal '', subject.code_for(*styles)
|
23
|
+
|
24
|
+
styles = []
|
25
|
+
assert_equal '', subject.code_for(*styles)
|
26
|
+
end
|
27
|
+
|
28
|
+
should "know how to build ansi styled messages" do
|
29
|
+
msg = Factory.string
|
30
|
+
assert_equal msg, subject.styled_msg(msg)
|
31
|
+
|
32
|
+
styles = Factory.integer(3).times.map{ subject::CODES.keys.sample }
|
33
|
+
exp_code = subject.code_for(*styles)
|
34
|
+
exp = exp_code + msg + subject.code_for(:reset)
|
35
|
+
assert_equal exp, subject.styled_msg(msg, *styles)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|