test-kitchen 1.3.1 → 1.4.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.cane +2 -0
  3. data/.gitignore +4 -0
  4. data/CHANGELOG.md +45 -0
  5. data/Rakefile +15 -0
  6. data/features/kitchen_action_commands.feature +12 -9
  7. data/features/kitchen_defaults.feature +38 -0
  8. data/features/kitchen_init_command.feature +0 -1
  9. data/features/kitchen_list_command.feature +2 -2
  10. data/features/kitchen_login_command.feature +7 -1
  11. data/features/kitchen_test_command.feature +4 -4
  12. data/lib/kitchen.rb +40 -11
  13. data/lib/kitchen/cli.rb +38 -22
  14. data/lib/kitchen/command/list.rb +5 -2
  15. data/lib/kitchen/config.rb +45 -18
  16. data/lib/kitchen/configurable.rb +137 -1
  17. data/lib/kitchen/data_munger.rb +248 -17
  18. data/lib/kitchen/driver.rb +1 -1
  19. data/lib/kitchen/driver/base.rb +1 -83
  20. data/lib/kitchen/driver/dummy.rb +0 -5
  21. data/lib/kitchen/driver/ssh_base.rb +177 -22
  22. data/lib/kitchen/instance.rb +140 -20
  23. data/lib/kitchen/logger.rb +43 -8
  24. data/lib/kitchen/login_command.rb +14 -5
  25. data/lib/kitchen/platform.rb +19 -0
  26. data/lib/kitchen/provisioner.rb +5 -3
  27. data/lib/kitchen/provisioner/base.rb +46 -48
  28. data/lib/kitchen/provisioner/chef/common_sandbox.rb +322 -0
  29. data/lib/kitchen/provisioner/chef_base.rb +179 -286
  30. data/lib/kitchen/provisioner/chef_solo.rb +11 -5
  31. data/lib/kitchen/provisioner/chef_zero.rb +108 -94
  32. data/lib/kitchen/provisioner/dummy.rb +47 -0
  33. data/lib/kitchen/provisioner/shell.rb +45 -12
  34. data/lib/kitchen/rake_tasks.rb +1 -1
  35. data/lib/kitchen/ssh.rb +1 -1
  36. data/lib/kitchen/thor_tasks.rb +1 -1
  37. data/lib/kitchen/transport.rb +54 -0
  38. data/lib/kitchen/transport/base.rb +146 -0
  39. data/lib/kitchen/transport/dummy.rb +75 -0
  40. data/lib/kitchen/transport/ssh.rb +325 -0
  41. data/lib/kitchen/transport/winrm.rb +508 -0
  42. data/lib/kitchen/transport/winrm/command_executor.rb +188 -0
  43. data/lib/kitchen/transport/winrm/file_transporter.rb +454 -0
  44. data/lib/kitchen/transport/winrm/logging.rb +50 -0
  45. data/lib/kitchen/transport/winrm/template.rb +74 -0
  46. data/lib/kitchen/transport/winrm/tmp_zip.rb +187 -0
  47. data/lib/kitchen/verifier.rb +55 -0
  48. data/lib/kitchen/verifier/base.rb +191 -0
  49. data/lib/kitchen/verifier/busser.rb +266 -0
  50. data/lib/kitchen/verifier/dummy.rb +75 -0
  51. data/lib/kitchen/version.rb +1 -1
  52. data/spec/kitchen/cli_spec.rb +56 -0
  53. data/spec/kitchen/config_spec.rb +61 -20
  54. data/spec/kitchen/configurable_spec.rb +327 -1
  55. data/spec/kitchen/data_munger_spec.rb +777 -14
  56. data/spec/kitchen/driver/base_spec.rb +7 -38
  57. data/spec/kitchen/driver/dummy_spec.rb +0 -29
  58. data/spec/kitchen/driver/ssh_base_spec.rb +580 -236
  59. data/spec/kitchen/driver_spec.rb +1 -0
  60. data/spec/kitchen/instance_spec.rb +383 -83
  61. data/spec/kitchen/login_command_spec.rb +29 -10
  62. data/spec/kitchen/platform_spec.rb +58 -2
  63. data/spec/kitchen/provisioner/base_spec.rb +170 -18
  64. data/spec/kitchen/provisioner/chef_base_spec.rb +454 -104
  65. data/spec/kitchen/provisioner/chef_solo_spec.rb +307 -104
  66. data/spec/kitchen/provisioner/chef_zero_spec.rb +561 -230
  67. data/spec/kitchen/provisioner/dummy_spec.rb +91 -0
  68. data/spec/kitchen/provisioner/shell_spec.rb +158 -56
  69. data/spec/kitchen/provisioner_spec.rb +37 -0
  70. data/spec/kitchen/ssh_spec.rb +19 -19
  71. data/spec/kitchen/transport/base_spec.rb +89 -0
  72. data/spec/kitchen/transport/ssh_spec.rb +1147 -0
  73. data/spec/kitchen/transport/winrm/command_executor_spec.rb +400 -0
  74. data/spec/kitchen/transport/winrm/file_transporter_spec.rb +876 -0
  75. data/spec/kitchen/transport/winrm/logging_spec.rb +92 -0
  76. data/spec/kitchen/transport/winrm/template_spec.rb +51 -0
  77. data/spec/kitchen/transport/winrm/tmp_zip_spec.rb +132 -0
  78. data/spec/kitchen/transport/winrm_spec.rb +1069 -0
  79. data/spec/kitchen/transport_spec.rb +112 -0
  80. data/spec/kitchen/verifier/base_spec.rb +310 -0
  81. data/spec/kitchen/verifier/busser_spec.rb +540 -0
  82. data/spec/kitchen/verifier/dummy_spec.rb +91 -0
  83. data/spec/kitchen/verifier_spec.rb +120 -0
  84. data/spec/kitchen_spec.rb +7 -0
  85. data/spec/spec_helper.rb +8 -0
  86. data/spec/support/powershell_max_size_spec.rb +40 -0
  87. data/support/busser_install_command.ps1 +14 -0
  88. data/support/busser_install_command.sh +15 -0
  89. data/support/check_files.ps1.erb +48 -0
  90. data/support/chef_base_init_command.ps1 +18 -0
  91. data/support/chef_base_init_command.sh +2 -0
  92. data/support/chef_base_install_command.ps1 +76 -0
  93. data/support/chef_base_install_command.sh +137 -0
  94. data/support/chef_zero_prepare_command_legacy.ps1 +9 -0
  95. data/support/chef_zero_prepare_command_legacy.sh +10 -0
  96. data/support/decode_files.ps1.erb +61 -0
  97. data/test-kitchen.gemspec +2 -0
  98. metadata +97 -8
  99. data/lib/kitchen/busser.rb +0 -316
  100. data/spec/kitchen/busser_spec.rb +0 -490
  101. data/support/chef_helpers.sh +0 -16
@@ -1,490 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
4
- #
5
- # Copyright (C) 2014, Fletcher Nichol
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
-
19
- require_relative "../spec_helper"
20
-
21
- require "kitchen/busser"
22
- # @TODO: this can be remove once Kitchen::DEFAULT_TEST_DIR is removed
23
- require "kitchen"
24
-
25
- describe Kitchen::Busser do
26
-
27
- let(:suite_name) { "germany" }
28
- let(:config) { Hash.new }
29
-
30
- let(:busser) do
31
- Kitchen::Busser.new(suite_name, config)
32
- end
33
-
34
- describe ".new" do
35
-
36
- it "raises a ClientError if a suite name is not provided" do
37
- proc {
38
- Kitchen::Busser.new(nil, config)
39
- }.must_raise Kitchen::ClientError
40
- end
41
-
42
- it "raises a UserError if the suite name is 'helper'" do
43
- proc {
44
- Kitchen::Busser.new("helper", config)
45
- }.must_raise Kitchen::UserError
46
- end
47
- end
48
-
49
- it "#name returns the name of the suite" do
50
- busser.name.must_equal "germany"
51
- end
52
-
53
- it "#config_keys returns an array of config key names" do
54
- busser.config_keys.sort.must_equal [
55
- :busser_bin, :kitchen_root, :root_path, :ruby_bindir, :sudo,
56
- :suite_name, :test_base_path, :version
57
- ]
58
- end
59
-
60
- describe "configuration" do
61
-
62
- it ":kitchen_root defaults to current directory" do
63
- busser[:kitchen_root].must_equal Dir.pwd
64
- end
65
-
66
- it ":test_base_path defaults to an expanded path" do
67
- busser[:test_base_path].must_equal File.join(Dir.pwd, "test/integration")
68
- end
69
-
70
- it ":suite_name defaults to the passed in suite name" do
71
- busser[:suite_name].must_equal "germany"
72
- end
73
-
74
- it ":sudo defaults to true" do
75
- busser[:sudo].must_equal true
76
- end
77
-
78
- it ":ruby_bindir defaults the an Omnibus Chef installation" do
79
- busser[:ruby_bindir].must_equal "/opt/chef/embedded/bin"
80
- end
81
-
82
- it ":root_path defaults to '/tmp/busser'" do
83
- busser[:root_path].must_equal "/tmp/busser"
84
- end
85
-
86
- it ":version defaults to 'busser'" do
87
- busser[:version].must_equal "busser"
88
- end
89
-
90
- it ":busser_bin defaults to a binstub under :root_path" do
91
- config[:root_path] = "/beep"
92
-
93
- busser[:busser_bin].must_equal "/beep/bin/busser"
94
- end
95
- end
96
-
97
- describe "#diagnose" do
98
-
99
- it "returns a hash with sorted keys" do
100
- busser.diagnose.keys.must_equal [
101
- :busser_bin, :kitchen_root, :root_path, :ruby_bindir, :sudo,
102
- :suite_name, :test_base_path, :version
103
- ]
104
- end
105
- end
106
-
107
- describe "#setup_cmd" do
108
-
109
- before do
110
- @root = Dir.mktmpdir
111
- config[:test_base_path] = @root
112
- end
113
-
114
- after do
115
- FileUtils.remove_entry(@root)
116
- end
117
-
118
- let(:cmd) { busser.setup_cmd }
119
-
120
- describe "with no suite test files" do
121
-
122
- it "returns nil" do
123
- cmd.must_equal nil
124
- end
125
- end
126
-
127
- describe "with suite test files" do
128
-
129
- before do
130
- base = "#{config[:test_base_path]}/germany"
131
-
132
- FileUtils.mkdir_p "#{base}/mondospec"
133
- File.open("#{base}/mondospec/charlie", "wb") { |f| f.write("charlie") }
134
- FileUtils.mkdir_p "#{base}/minispec"
135
- File.open("#{base}/minispec/beta", "wb") { |f| f.write("beta") }
136
- FileUtils.mkdir_p "#{base}/abba"
137
- File.open("#{base}/abba/alpha", "wb") { |f| f.write("alpha") }
138
-
139
- config[:ruby_bindir] = "/r"
140
- end
141
-
142
- it "uses bourne shell" do
143
- cmd.must_match(/\Ash -c '$/)
144
- cmd.must_match(/'\Z/)
145
- end
146
-
147
- it "sets the BUSSER_ROOT environment variable" do
148
- config[:root_path] = "/r"
149
-
150
- cmd.must_match regexify(%{BUSSER_ROOT="/r"}, :partial_line)
151
- end
152
-
153
- it "sets the GEM_HOME environment variable" do
154
- config[:root_path] = "/r"
155
-
156
- cmd.must_match regexify(%{GEM_HOME="/r/gems" }, :partial_line)
157
- end
158
-
159
- it "sets the GEM_PATH environment variable" do
160
- config[:root_path] = "/r"
161
-
162
- cmd.must_match regexify(%{GEM_PATH="/r/gems" }, :partial_line)
163
- end
164
-
165
- it "sets the GEM_CACHE environment variable" do
166
- config[:root_path] = "/r"
167
-
168
- cmd.must_match regexify(%{GEM_CACHE="/r/gems/cache" }, :partial_line)
169
- end
170
-
171
- it "exports all the environment variables" do
172
- cmd.must_match regexify(
173
- "export BUSSER_ROOT GEM_HOME GEM_PATH GEM_CACHE", :partial_line)
174
- end
175
-
176
- it "checks if busser is installed" do
177
- cmd.must_match regexify(
178
- %{if ! sudo -E /r/gem list busser -i >/dev/null;}, :partial_line)
179
- end
180
-
181
- describe "installing busser" do
182
-
183
- it "installs the latest busser gem by default" do
184
- cmd.must_match regexify(
185
- %{sudo -E /r/gem install busser --no-rdoc --no-ri}, :partial_line)
186
- end
187
-
188
- it "installs a specific busser version gem" do
189
- config[:version] = "4.0.7"
190
-
191
- cmd.must_match regexify(
192
- %{sudo -E /r/gem install busser --version 4.0.7 --no-rdoc --no-ri},
193
- :partial_line)
194
- end
195
-
196
- it "installs a specific busser version gem with @ syntax" do
197
- config[:version] = "busser@1.2.3"
198
-
199
- cmd.must_match regexify(
200
- %{sudo -E /r/gem install busser --version 1.2.3 --no-rdoc --no-ri},
201
- :partial_line)
202
- end
203
-
204
- it "installs an arbitrary gem and version with @ syntax" do
205
- config[:version] = "foo@9.0.1"
206
-
207
- cmd.must_match regexify(
208
- %{sudo -E /r/gem install foo --version 9.0.1 --no-rdoc --no-ri},
209
- :partial_line)
210
- end
211
- end
212
-
213
- it "calculates RubyGem's bindir" do
214
- cmd.must_match regexify(
215
- %{gem_bindir=`/r/ruby -rrubygems -e "puts Gem.bindir"`},
216
- :partial_line)
217
- end
218
-
219
- it "runs busser setup from the installed gem_bindir binstub" do
220
- cmd.must_match regexify(
221
- %{sudo -E ${gem_bindir}/busser setup}, :partial_line)
222
- end
223
-
224
- it "runs busser plugin install with the :busser_bindir command" do
225
- config[:busser_bin] = "/b/b"
226
-
227
- cmd.must_match regexify(
228
- %{sudo -E /b/b plugin install } +
229
- %{busser-abba busser-minispec busser-mondospec},
230
- :partial_line)
231
- end
232
- end
233
- end
234
-
235
- describe "#sync_cmd" do
236
-
237
- before do
238
- @root = Dir.mktmpdir
239
- config[:test_base_path] = @root
240
- end
241
-
242
- after do
243
- FileUtils.remove_entry(@root)
244
- end
245
-
246
- let(:cmd) { busser.sync_cmd }
247
-
248
- describe "with no suite test files" do
249
-
250
- it "returns nil" do
251
- cmd.must_equal nil
252
- end
253
- end
254
-
255
- describe "with suite test files" do
256
-
257
- before do
258
- base = "#{config[:test_base_path]}/germany"
259
- hbase = "#{config[:test_base_path]}/helpers"
260
-
261
- files.map { |f, md| [File.join(base, f), md] }.each do |f, md|
262
- create_file(f, md[:content], md[:perms])
263
- end
264
- helper_files.map { |f, md| [File.join(hbase, f), md] }.each do |f, md|
265
- create_file(f, md[:content], md[:perms])
266
- end
267
-
268
- config[:ruby_bindir] = "/r"
269
- end
270
-
271
- let(:files) do
272
- {
273
- "mondospec/charlie" => {
274
- :content => "charlie",
275
- :perms => "0764",
276
- :base64 => "Y2hhcmxpZQ==",
277
- :md5 => "bf779e0933a882808585d19455cd7937"
278
- },
279
- "minispec/beta" => {
280
- :content => "beta",
281
- :perms => "0644",
282
- :base64 => "YmV0YQ==",
283
- :md5 => "987bcab01b929eb2c07877b224215c92"
284
- },
285
- "abba/alpha" => {
286
- :content => "alpha",
287
- :perms => "0440",
288
- :base64 => "YWxwaGE=",
289
- :md5 => "2c1743a391305fbf367df8e4f069f9f9"
290
- }
291
- }
292
- end
293
-
294
- let(:helper_files) do
295
- {
296
- "minispec/spec_helper" => {
297
- :content => "helping",
298
- :perms => "0644",
299
- :base64 => "aGVscGluZw==",
300
- :md5 => "111c081293c11cb7c2ac6fbf841805cb"
301
- },
302
- "abba/common" => {
303
- :content => "yeppers",
304
- :perms => "0664",
305
- :base64 => "eWVwcGVycw==",
306
- :md5 => "7c3157de4890b1abcb7a6a3695eb6dd2"
307
- }
308
- }
309
- end
310
-
311
- it "uses bourne shell" do
312
- cmd.must_match(/\Ash -c '$/)
313
- cmd.must_match(/'\Z/)
314
- end
315
-
316
- it "sets the BUSSER_ROOT environment variable" do
317
- config[:root_path] = "/r"
318
-
319
- cmd.must_match regexify(%{BUSSER_ROOT="/r"}, :partial_line)
320
- end
321
-
322
- it "sets the GEM_HOME environment variable" do
323
- config[:root_path] = "/r"
324
-
325
- cmd.must_match regexify(%{GEM_HOME="/r/gems" }, :partial_line)
326
- end
327
-
328
- it "sets the GEM_PATH environment variable" do
329
- config[:root_path] = "/r"
330
-
331
- cmd.must_match regexify(%{GEM_PATH="/r/gems" }, :partial_line)
332
- end
333
-
334
- it "sets the GEM_CACHE environment variable" do
335
- config[:root_path] = "/r"
336
-
337
- cmd.must_match regexify(%{GEM_CACHE="/r/gems/cache" }, :partial_line)
338
- end
339
-
340
- it "exports all the environment variables" do
341
- cmd.must_match regexify(
342
- "export BUSSER_ROOT GEM_HOME GEM_PATH GEM_CACHE", :partial_line)
343
- end
344
-
345
- it "logs a message for each file" do
346
- config[:busser_bin] = "/b/busser"
347
-
348
- files.each do |f, md|
349
- cmd.must_match regexify([
350
- %{echo "Uploading `sudo -E /b/busser suite path`/#{f}},
351
- %{(mode=#{md[:perms]})"}
352
- ].join(" "))
353
- end
354
- end
355
-
356
- it "logs a message for each helper file" do
357
- config[:busser_bin] = "/b/busser"
358
-
359
- helper_files.each do |f, md|
360
- cmd.must_match regexify([
361
- %{echo "Uploading `sudo -E /b/busser suite path`/#{f}},
362
- %{(mode=#{md[:perms]})"}
363
- ].join(" "))
364
- end
365
- end
366
-
367
- it "base64 encodes each file for deserializing with busser" do
368
- config[:busser_bin] = "/b/busser"
369
-
370
- files.each do |f, md|
371
- cmd.must_match regexify([
372
- %{echo "#{md[:base64]}" | sudo -E /b/busser deserialize},
373
- %{--destination=`sudo -E /b/busser suite path`/#{f}},
374
- %{--md5sum=#{md[:md5]} --perms=#{md[:perms]}}
375
- ].join(" "))
376
- end
377
- end
378
-
379
- it "base64 encodes each helper file for deserializing with busser" do
380
- config[:busser_bin] = "/b/busser"
381
-
382
- helper_files.each do |f, md|
383
- cmd.must_match regexify([
384
- %{echo "#{md[:base64]}" | sudo -E /b/busser deserialize},
385
- %{--destination=`sudo -E /b/busser suite path`/#{f}},
386
- %{--md5sum=#{md[:md5]} --perms=#{md[:perms]}}
387
- ].join(" "))
388
- end
389
- end
390
-
391
- def create_file(file, content, perms)
392
- FileUtils.mkdir_p(File.dirname(file))
393
- File.open(file, "wb") { |f| f.write(content) }
394
- FileUtils.chmod(perms.to_i(8), file)
395
- end
396
- end
397
- end
398
-
399
- describe "#run_cmd" do
400
-
401
- before do
402
- @root = Dir.mktmpdir
403
- config[:test_base_path] = @root
404
- end
405
-
406
- after do
407
- FileUtils.remove_entry(@root)
408
- end
409
-
410
- let(:cmd) { busser.run_cmd }
411
-
412
- describe "with no suite test files" do
413
-
414
- it "returns nil" do
415
- cmd.must_equal nil
416
- end
417
- end
418
-
419
- describe "with suite test files" do
420
-
421
- before do
422
- base = "#{config[:test_base_path]}/germany"
423
-
424
- FileUtils.mkdir_p "#{base}/mondospec"
425
- File.open("#{base}/mondospec/charlie", "wb") { |f| f.write("charlie") }
426
- FileUtils.mkdir_p "#{base}/minispec"
427
- File.open("#{base}/minispec/beta", "wb") { |f| f.write("beta") }
428
- FileUtils.mkdir_p "#{base}/abba"
429
- File.open("#{base}/abba/alpha", "wb") { |f| f.write("alpha") }
430
-
431
- config[:ruby_bindir] = "/r"
432
- end
433
-
434
- it "uses bourne shell" do
435
- cmd.must_match(/\Ash -c '$/)
436
- cmd.must_match(/'\Z/)
437
- end
438
-
439
- it "sets the BUSSER_ROOT environment variable" do
440
- config[:root_path] = "/r"
441
-
442
- cmd.must_match regexify(%{BUSSER_ROOT="/r"}, :partial_line)
443
- end
444
-
445
- it "sets the GEM_HOME environment variable" do
446
- config[:root_path] = "/r"
447
-
448
- cmd.must_match regexify(%{GEM_HOME="/r/gems" }, :partial_line)
449
- end
450
-
451
- it "sets the GEM_PATH environment variable" do
452
- config[:root_path] = "/r"
453
-
454
- cmd.must_match regexify(%{GEM_PATH="/r/gems" }, :partial_line)
455
- end
456
-
457
- it "sets the GEM_CACHE environment variable" do
458
- config[:root_path] = "/r"
459
-
460
- cmd.must_match regexify(%{GEM_CACHE="/r/gems/cache" }, :partial_line)
461
- end
462
-
463
- it "exports all the environment variables" do
464
- cmd.must_match regexify(
465
- "export BUSSER_ROOT GEM_HOME GEM_PATH GEM_CACHE", :partial_line)
466
- end
467
-
468
- it "uses sudo for busser test when configured" do
469
- config[:sudo] = true
470
- config[:busser_bin] = "/p/b"
471
-
472
- cmd.must_match regexify("sudo -E /p/b test", :partial_line)
473
- end
474
-
475
- it "does not use sudo for busser test when configured" do
476
- config[:sudo] = false
477
- config[:busser_bin] = "/p/b"
478
-
479
- cmd.must_match regexify("/p/b test", :partial_line)
480
- cmd.wont_match regexify("sudo -E /p/b test", :partial_line)
481
- end
482
- end
483
- end
484
-
485
- def regexify(str, line = :whole_line)
486
- r = Regexp.escape(str)
487
- r = "^\s*#{r}$" if line == :whole_line
488
- Regexp.new(r)
489
- end
490
- end