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
@@ -25,17 +25,20 @@ describe Kitchen::Provisioner::ChefZero do
25
25
 
26
26
  let(:logged_output) { StringIO.new }
27
27
  let(:logger) { Logger.new(logged_output) }
28
+ let(:platform) { stub(:os_type => nil) }
29
+ let(:suite) { stub(:name => "fries") }
28
30
 
29
31
  let(:config) do
30
32
  { :test_base_path => "/b", :kitchen_root => "/r", :log_level => :info }
31
33
  end
32
34
 
33
- let(:suite) do
34
- stub(:name => "fries")
35
- end
36
-
37
35
  let(:instance) do
38
- stub(:name => "coolbeans", :logger => logger, :suite => suite)
36
+ stub(
37
+ :name => "coolbeans",
38
+ :logger => logger,
39
+ :suite => suite,
40
+ :platform => platform
41
+ )
39
42
  end
40
43
 
41
44
  let(:provisioner) do
@@ -44,18 +47,44 @@ describe Kitchen::Provisioner::ChefZero do
44
47
 
45
48
  describe "default config" do
46
49
 
47
- it "sets :client_rb to an empty Hash" do
48
- provisioner[:client_rb].must_equal Hash.new
50
+ describe "for unix operating systems" do
51
+
52
+ before { platform.stubs(:os_type).returns("unix") }
53
+
54
+ it "sets :chef_client_path to a path using :chef_omnibus_root" do
55
+ config[:chef_omnibus_root] = "/nice/place"
56
+
57
+ provisioner[:chef_client_path].
58
+ must_equal "/nice/place/bin/chef-client"
59
+ end
60
+
61
+ it "sets :ruby_bindir to use an Omnibus Ruby" do
62
+ config[:chef_omnibus_root] = "/nice"
63
+
64
+ provisioner[:ruby_bindir].must_equal "/nice/embedded/bin"
65
+ end
49
66
  end
50
67
 
51
- it "sets :chef_client_path to a path using :chef_omnibus_root" do
52
- config[:chef_omnibus_root] = "/nice/place"
68
+ describe "for windows operating systems" do
69
+
70
+ before { platform.stubs(:os_type).returns("windows") }
71
+
72
+ it "sets :chef_client_path to a path using :chef_omnibus_root" do
73
+ config[:chef_omnibus_root] = "$env:systemdrive\\nice\\place"
74
+
75
+ provisioner[:chef_client_path].
76
+ must_equal "$env:systemdrive\\nice\\place\\bin\\chef-client.bat"
77
+ end
78
+
79
+ it "sets :ruby_bindir to use an Omnibus Ruby" do
80
+ config[:chef_omnibus_root] = "c:\\nice"
53
81
 
54
- provisioner[:chef_client_path].must_equal "/nice/place/bin/chef-client"
82
+ provisioner[:ruby_bindir].must_equal "c:\\nice\\embedded\\bin"
83
+ end
55
84
  end
56
85
 
57
- it "sets :ruby_bindir to use an Omnibus Ruby" do
58
- provisioner[:ruby_bindir].must_equal "/opt/chef/embedded/bin"
86
+ it "sets :client_rb to an empty Hash" do
87
+ provisioner[:client_rb].must_equal Hash.new
59
88
  end
60
89
 
61
90
  it "sets :json_attributes to true" do
@@ -113,64 +142,104 @@ describe Kitchen::Provisioner::ChefZero do
113
142
 
114
143
  describe "defaults" do
115
144
 
116
- before { provisioner.create_sandbox }
117
-
118
- it "sets node_name to the instance name" do
119
- file.must_include %{node_name "#{instance.name}"}
145
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
146
+ def self.common_client_rb_specs
147
+ it "sets node_name to the instance name" do
148
+ file.must_include %{node_name "#{instance.name}"}
149
+ end
150
+
151
+ it "sets checksum_path" do
152
+ file.must_include %{checksum_path "#{base}checksums"}
153
+ end
154
+
155
+ it "sets file_backup_path" do
156
+ file.must_include %{file_backup_path "#{base}backup"}
157
+ end
158
+
159
+ it "sets cookbook_path" do
160
+ file.must_include %{cookbook_path } +
161
+ %{["#{base}cookbooks", "#{base}site-cookbooks"]}
162
+ end
163
+
164
+ it "sets data_bag_path" do
165
+ file.must_include %{data_bag_path "#{base}data_bags"}
166
+ end
167
+
168
+ it "sets environment_path" do
169
+ file.must_include %{environment_path "#{base}environments"}
170
+ end
171
+
172
+ it "sets node_path" do
173
+ file.must_include %{node_path "#{base}nodes"}
174
+ end
175
+
176
+ it "sets role_path" do
177
+ file.must_include %{role_path "#{base}roles"}
178
+ end
179
+
180
+ it "sets client_path" do
181
+ file.must_include %{client_path "#{base}clients"}
182
+ end
183
+
184
+ it "sets user_path" do
185
+ file.must_include %{user_path "#{base}users"}
186
+ end
187
+
188
+ it "sets validation_key" do
189
+ file.must_include %{validation_key "#{base}validation.pem"}
190
+ end
191
+
192
+ it "sets client_key" do
193
+ file.must_include %{client_key "#{base}client.pem"}
194
+ end
195
+
196
+ it "sets chef_server_url" do
197
+ file.must_include %{chef_server_url "http://127.0.0.1:8889"}
198
+ end
199
+
200
+ it "sets encrypted_data_bag_secret" do
201
+ file.must_include %{encrypted_data_bag_secret } +
202
+ %{"#{base}encrypted_data_bag_secret"}
203
+ end
120
204
  end
205
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
121
206
 
122
- it "sets checksum_path" do
123
- file.must_include %{checksum_path "/tmp/kitchen/checksums"}
124
- end
125
-
126
- it "sets file_backup_path" do
127
- file.must_include %{file_backup_path "/tmp/kitchen/backup"}
128
- end
207
+ describe "for unix os types" do
129
208
 
130
- it "sets cookbook_path" do
131
- file.must_include %{cookbook_path } +
132
- %{["/tmp/kitchen/cookbooks", "/tmp/kitchen/site-cookbooks"]}
133
- end
209
+ before do
210
+ platform.stubs(:os_type).returns("unix")
211
+ provisioner.create_sandbox
212
+ end
134
213
 
135
- it "sets data_bag_path" do
136
- file.must_include %{data_bag_path "/tmp/kitchen/data_bags"}
137
- end
214
+ let(:base) { "/tmp/kitchen/" }
138
215
 
139
- it "sets environment_path" do
140
- file.must_include %{environment_path "/tmp/kitchen/environments"}
216
+ common_client_rb_specs
141
217
  end
142
218
 
143
- it "sets node_path" do
144
- file.must_include %{node_path "/tmp/kitchen/nodes"}
145
- end
219
+ describe "for windows os types with full path" do
146
220
 
147
- it "sets role_path" do
148
- file.must_include %{role_path "/tmp/kitchen/roles"}
149
- end
221
+ before do
222
+ platform.stubs(:os_type).returns("windows")
223
+ config[:root_path] = "\\a\\b"
224
+ provisioner.create_sandbox
225
+ end
150
226
 
151
- it "sets client_path" do
152
- file.must_include %{client_path "/tmp/kitchen/clients"}
153
- end
227
+ let(:base) { "\\\\a\\\\b\\\\" }
154
228
 
155
- it "sets user_path" do
156
- file.must_include %{user_path "/tmp/kitchen/users"}
229
+ common_client_rb_specs
157
230
  end
158
231
 
159
- it "sets validation_key" do
160
- file.must_include %{validation_key "/tmp/kitchen/validation.pem"}
161
- end
232
+ describe "for windows os types with $env:TEMP prefixed paths" do
162
233
 
163
- it "sets client_key" do
164
- file.must_include %{client_key "/tmp/kitchen/client.pem"}
165
- end
234
+ before do
235
+ platform.stubs(:os_type).returns("windows")
236
+ config[:root_path] = "$env:TEMP\\a"
237
+ provisioner.create_sandbox
238
+ end
166
239
 
167
- it "sets chef_server_url" do
168
- file.must_include %{chef_server_url "http://127.0.0.1:8889"}
169
- end
240
+ let(:base) { "\#{ENV['TEMP']}\\\\a\\\\" }
170
241
 
171
- it "sets encrypted_data_bag_secret" do
172
- file.must_include %{encrypted_data_bag_secret } +
173
- %{"/tmp/kitchen/encrypted_data_bag_secret"}
242
+ common_client_rb_specs
174
243
  end
175
244
  end
176
245
 
@@ -316,101 +385,185 @@ describe Kitchen::Provisioner::ChefZero do
316
385
 
317
386
  describe "for old Chef versions" do
318
387
 
319
- before do
320
- config[:require_chef_omnibus] = "10.20"
321
- config[:ruby_bindir] = "/rbd"
322
- end
388
+ before { config[:require_chef_omnibus] = "10.20" }
323
389
 
324
- it "uses bourne shell" do
325
- cmd.must_match(/\Ash -c '$/)
326
- cmd.must_match(/'\Z/)
327
- end
390
+ describe "for bourne shells" do
328
391
 
329
- it "sets the CHEF_REPO_PATH environment variable" do
330
- config[:root_path] = "/r"
392
+ before do
393
+ platform.stubs(:shell_type).returns("bourne")
394
+ config[:ruby_bindir] = "/rbd"
395
+ end
331
396
 
332
- cmd.must_match regexify(%{CHEF_REPO_PATH="/r" }, :partial_line)
333
- end
397
+ it "uses bourne shell" do
398
+ cmd.must_match(/\Ash -c '$/)
399
+ cmd.must_match(/'\Z/)
400
+ end
334
401
 
335
- it "sets the GEM_HOME environment variable" do
336
- config[:root_path] = "/r"
402
+ it "ends with a single quote" do
403
+ cmd.must_match(/'\Z/)
404
+ end
337
405
 
338
- cmd.must_match regexify(
339
- %{GEM_HOME="/r/chef-client-zero-gems" }, :partial_line)
340
- end
406
+ it "exports http_proxy & HTTP_PROXY when :http_proxy is set" do
407
+ config[:http_proxy] = "http://proxy"
341
408
 
342
- it "sets the GEM_PATH environment variable" do
343
- config[:root_path] = "/r"
409
+ cmd.lines.to_a[1..2].must_equal([
410
+ %{http_proxy="http://proxy"; export http_proxy\n},
411
+ %{HTTP_PROXY="http://proxy"; export HTTP_PROXY\n}
412
+ ])
413
+ end
344
414
 
345
- cmd.must_match regexify(
346
- %{GEM_PATH="/r/chef-client-zero-gems" }, :partial_line)
347
- end
415
+ it "exports https_proxy & HTTPS_PROXY when :https_proxy is set" do
416
+ config[:https_proxy] = "https://proxy"
348
417
 
349
- it "sets the GEM_CACHE environment variable" do
350
- config[:root_path] = "/r"
418
+ cmd.lines.to_a[1..2].must_equal([
419
+ %{https_proxy="https://proxy"; export https_proxy\n},
420
+ %{HTTPS_PROXY="https://proxy"; export HTTPS_PROXY\n}
421
+ ])
422
+ end
351
423
 
352
- cmd.must_match regexify(
353
- %{GEM_CACHE="/r/chef-client-zero-gems/cache" }, :partial_line)
354
- end
424
+ it "exports all http proxy variables when both are set" do
425
+ config[:http_proxy] = "http://proxy"
426
+ config[:https_proxy] = "https://proxy"
355
427
 
356
- it "exports all the environment variables" do
357
- cmd.must_match regexify(
358
- "export CHEF_REPO_PATH GEM_HOME GEM_PATH GEM_CACHE;", :partial_line)
359
- end
428
+ cmd.lines.to_a[1..4].must_equal([
429
+ %{http_proxy="http://proxy"; export http_proxy\n},
430
+ %{HTTP_PROXY="http://proxy"; export HTTP_PROXY\n},
431
+ %{https_proxy="https://proxy"; export https_proxy\n},
432
+ %{HTTPS_PROXY="https://proxy"; export HTTPS_PROXY\n}
433
+ ])
434
+ end
360
435
 
361
- it "checks if chef-zero is installed" do
362
- cmd.must_match regexify(
363
- %{if ! sudo -E /rbd/gem list chef-zero -i >/dev/null; then})
364
- end
436
+ it "sets the CHEF_REPO_PATH environment variable" do
437
+ config[:root_path] = "/r"
365
438
 
366
- it "installs the chef gem" do
367
- cmd.must_match regexify(
368
- %{sudo -E /rbd/gem install chef --no-ri --no-rdoc --conservative})
369
- end
370
- end
371
- end
439
+ cmd.must_match regexify(
440
+ %{CHEF_REPO_PATH="/r"; export CHEF_REPO_PATH})
441
+ end
372
442
 
373
- describe "#run_command" do
443
+ it "sets the GEM_HOME environment variable" do
444
+ config[:root_path] = "/r"
374
445
 
375
- let(:cmd) { provisioner.run_command }
446
+ cmd.must_match regexify(
447
+ %{GEM_HOME="/r/chef-client-zero-gems"; export GEM_HOME})
448
+ end
376
449
 
377
- describe "for modern Chef versions" do
450
+ it "sets the GEM_PATH environment variable" do
451
+ config[:root_path] = "/r"
378
452
 
379
- before { config[:require_chef_omnibus] = "11.10" }
453
+ cmd.must_match regexify(
454
+ %{GEM_PATH="/r/chef-client-zero-gems"; export GEM_PATH})
455
+ end
380
456
 
381
- it "uses bourne shell" do
382
- cmd.must_match(/\Ash -c '$/)
383
- cmd.must_match(/'\Z/)
384
- end
457
+ it "sets the GEM_CACHE environment variable" do
458
+ config[:root_path] = "/r"
385
459
 
386
- it "uses sudo for chef-client when configured" do
387
- config[:chef_omnibus_root] = "/c"
388
- config[:sudo] = true
460
+ cmd.must_match regexify(
461
+ %{GEM_CACHE="/r/chef-client-zero-gems/cache"; export GEM_CACHE})
462
+ end
389
463
 
390
- cmd.must_match regexify("sudo -E /c/bin/chef-client ", :partial_line)
391
- end
464
+ it "prepends sudo for gem command when :sudo is set" do
465
+ config[:sudo] = true
466
+
467
+ cmd.must_match regexify(%{gem="sudo -E /rbd/gem"})
468
+ end
392
469
 
393
- it "does not use sudo for chef-client when configured" do
394
- config[:chef_omnibus_root] = "/c"
395
- config[:sudo] = false
470
+ it "does not sudo for gem commands when :sudo is falsey" do
471
+ config[:sudo] = false
396
472
 
397
- cmd.must_match regexify("/c/bin/chef-client ", :partial_line)
398
- cmd.wont_match regexify("sudo -E /c/bin/chef-client ", :partial_line)
473
+ cmd.must_match regexify(%{gem="/rbd/gem"})
474
+ end
399
475
  end
400
476
 
401
- it "sets local mode flag on chef-client" do
402
- cmd.must_match regexify(" --local-mode", :partial_line)
477
+ describe "for powershell shells on windows os types" do
478
+
479
+ before do
480
+ platform.stubs(:shell_type).returns("powershell")
481
+ platform.stubs(:os_type).returns("windows")
482
+ config[:root_path] = "\\r"
483
+ config[:ruby_bindir] = "\\rbd"
484
+ end
485
+
486
+ it "exports http_proxy & HTTP_PROXY when :http_proxy is set" do
487
+ config[:http_proxy] = "http://proxy"
488
+
489
+ cmd.lines.to_a[0..1].must_equal([
490
+ %{$env:http_proxy = "http://proxy"\n},
491
+ %{$env:HTTP_PROXY = "http://proxy"\n}
492
+ ])
493
+ end
494
+
495
+ it "exports https_proxy & HTTPS_PROXY when :https_proxy is set" do
496
+ config[:https_proxy] = "https://proxy"
497
+
498
+ cmd.lines.to_a[0..1].must_equal([
499
+ %{$env:https_proxy = "https://proxy"\n},
500
+ %{$env:HTTPS_PROXY = "https://proxy"\n}
501
+ ])
502
+ end
503
+
504
+ it "exports all http proxy variables when both are set" do
505
+ config[:http_proxy] = "http://proxy"
506
+ config[:https_proxy] = "https://proxy"
507
+
508
+ cmd.lines.to_a[0..3].must_equal([
509
+ %{$env:http_proxy = "http://proxy"\n},
510
+ %{$env:HTTP_PROXY = "http://proxy"\n},
511
+ %{$env:https_proxy = "https://proxy"\n},
512
+ %{$env:HTTPS_PROXY = "https://proxy"\n}
513
+ ])
514
+ end
515
+
516
+ it "sets the CHEF_REPO_PATH environment variable" do
517
+ config[:root_path] = "\\r"
518
+
519
+ cmd.must_match regexify(
520
+ %{$env:CHEF_REPO_PATH = "\\r"})
521
+ end
522
+
523
+ it "sets the GEM_HOME environment variable" do
524
+ config[:root_path] = "\\r"
525
+
526
+ cmd.must_match regexify(
527
+ %{$env:GEM_HOME = "\\r\\chef-client-zero-gems"})
528
+ end
529
+
530
+ it "sets the GEM_PATH environment variable" do
531
+ config[:root_path] = "\\r"
532
+
533
+ cmd.must_match regexify(
534
+ %{$env:GEM_PATH = "\\r\\chef-client-zero-gems"})
535
+ end
536
+
537
+ it "sets the GEM_CACHE environment variable" do
538
+ config[:root_path] = "\\r"
539
+
540
+ cmd.must_match regexify(
541
+ %{$env:GEM_CACHE = "\\r\\chef-client-zero-gems\\cache"})
542
+ end
543
+
544
+ it "sets the path to the gem command" do
545
+ cmd.must_match regexify(%{$gem = "\\rbd\\gem.bat"})
546
+ end
403
547
  end
548
+ end
549
+ end
404
550
 
551
+ describe "#run_command" do
552
+
553
+ let(:cmd) { provisioner.run_command }
554
+
555
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
556
+ def self.common_shell_specs
405
557
  it "sets config flag on chef-client" do
406
558
  cmd.must_match regexify(
407
- " --config /tmp/kitchen/client.rb", :partial_line)
559
+ " --config #{base}client.rb", :partial_line)
408
560
  end
409
561
 
410
562
  it "sets config flag for custom root_path" do
411
- config[:root_path] = "/a/b"
563
+ config[:root_path] = custom_root
412
564
 
413
- cmd.must_match regexify(" --config /a/b/client.rb", :partial_line)
565
+ cmd.must_match regexify(
566
+ " --config #{custom_base}client.rb", :partial_line)
414
567
  end
415
568
 
416
569
  it "sets log level flag on chef-client to auto by default" do
@@ -431,60 +584,201 @@ describe Kitchen::Provisioner::ChefZero do
431
584
  cmd.must_match regexify(" --no-color", :partial_line)
432
585
  end
433
586
 
434
- it "sets chef zero port flag on chef-client" do
435
- cmd.must_match regexify(" --chef-zero-port 8889", :partial_line)
587
+ it "sets json attributes flag on chef-client" do
588
+ cmd.must_match regexify(
589
+ " --json-attributes #{base}dna.json", :partial_line)
436
590
  end
437
591
 
438
- it "sets chef zero host flag for custom host" do
439
- config[:chef_zero_host] = "192.168.0.1"
592
+ it "sets json attribtes flag for custom root_path" do
593
+ config[:root_path] = custom_root
440
594
 
441
- cmd.must_match regexify(" --chef-zero-host 192.168.0.1", :partial_line)
595
+ cmd.must_match regexify(
596
+ " --json-attributes #{custom_base}dna.json", :partial_line)
442
597
  end
443
598
 
444
- it "sets chef zero port flag for custom port" do
445
- config[:chef_zero_port] = 123
599
+ it "does not set json attributes flag if config is falsey" do
600
+ config[:json_attributes] = false
446
601
 
447
- cmd.must_match regexify(" --chef-zero-port 123", :partial_line)
602
+ cmd.wont_match regexify(" --json-attributes ", :partial_line)
448
603
  end
449
604
 
450
- it "does not set chef zero host flag when value is falsey" do
451
- config[:chef_zero_host] = nil
605
+ it "sets logfile flag for custom value" do
606
+ config[:log_file] = "#{custom_base}out.log"
452
607
 
453
- cmd.wont_match regexify(" --chef-zero-host ", :partial_line)
608
+ cmd.must_match regexify(
609
+ " --logfile #{custom_base}out.log", :partial_line)
454
610
  end
455
611
 
456
- it "does not set chef zero port flag when value is falsey" do
457
- config[:chef_zero_port] = nil
458
-
459
- cmd.wont_match regexify(" --chef-zero-port ", :partial_line)
612
+ it "does not set logfile flag by default" do
613
+ cmd.wont_match regexify(" --logfile ", :partial_line)
460
614
  end
615
+ end
616
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
461
617
 
462
- it "sets json attributes flag on chef-client" do
463
- cmd.must_match regexify(
464
- " --json-attributes /tmp/kitchen/dna.json", :partial_line)
465
- end
618
+ describe "for modern Chef versions" do
466
619
 
467
- it "sets json attribtes flag for custom root_path" do
468
- config[:root_path] = "/booyah"
620
+ before { config[:require_chef_omnibus] = "11.10" }
469
621
 
470
- cmd.must_match regexify(
471
- " --json-attributes /booyah/dna.json", :partial_line)
472
- end
622
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
623
+ def self.common_modern_shell_specs
624
+ it "sets local mode flag on chef-client" do
625
+ cmd.must_match regexify(" --local-mode", :partial_line)
626
+ end
473
627
 
474
- it "does not set json attributes flag if config is falsey" do
475
- config[:json_attributes] = false
628
+ it "sets chef zero port flag on chef-client" do
629
+ cmd.must_match regexify(" --chef-zero-port 8889", :partial_line)
630
+ end
476
631
 
477
- cmd.wont_match regexify(" --json-attributes ", :partial_line)
632
+ it "sets chef zero host flag for custom host" do
633
+ config[:chef_zero_host] = "192.168.0.1"
634
+
635
+ cmd.must_match regexify(" --chef-zero-host 192.168.0.1", :partial_line)
636
+ end
637
+
638
+ it "sets chef zero port flag for custom port" do
639
+ config[:chef_zero_port] = 123
640
+
641
+ cmd.must_match regexify(" --chef-zero-port 123", :partial_line)
642
+ end
643
+
644
+ it "does not set chef zero host flag when value is falsey" do
645
+ config[:chef_zero_host] = nil
646
+
647
+ cmd.wont_match regexify(" --chef-zero-host ", :partial_line)
648
+ end
649
+
650
+ it "does not set chef zero port flag when value is falsey" do
651
+ config[:chef_zero_port] = nil
652
+
653
+ cmd.wont_match regexify(" --chef-zero-port ", :partial_line)
654
+ end
478
655
  end
656
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
479
657
 
480
- it "does not set logfile flag by default" do
481
- cmd.wont_match regexify(" --logfile ", :partial_line)
658
+ describe "for bourne shells" do
659
+
660
+ before { platform.stubs(:shell_type).returns("bourne") }
661
+
662
+ let(:base) { "/tmp/kitchen/" }
663
+ let(:custom_base) { "/a/b/" }
664
+ let(:custom_root) { "/a/b" }
665
+
666
+ common_shell_specs
667
+ common_modern_shell_specs
668
+
669
+ it "uses bourne shell" do
670
+ cmd.must_match(/\Ash -c '$/)
671
+ cmd.must_match(/'\Z/)
672
+ end
673
+
674
+ it "ends with a single quote" do
675
+ cmd.must_match(/'\Z/)
676
+ end
677
+
678
+ it "exports http_proxy & HTTP_PROXY when :http_proxy is set" do
679
+ config[:http_proxy] = "http://proxy"
680
+
681
+ cmd.lines.to_a[1..2].must_equal([
682
+ %{http_proxy="http://proxy"; export http_proxy\n},
683
+ %{HTTP_PROXY="http://proxy"; export HTTP_PROXY\n}
684
+ ])
685
+ end
686
+
687
+ it "exports https_proxy & HTTPS_PROXY when :https_proxy is set" do
688
+ config[:https_proxy] = "https://proxy"
689
+
690
+ cmd.lines.to_a[1..2].must_equal([
691
+ %{https_proxy="https://proxy"; export https_proxy\n},
692
+ %{HTTPS_PROXY="https://proxy"; export HTTPS_PROXY\n}
693
+ ])
694
+ end
695
+
696
+ it "exports all http proxy variables when both are set" do
697
+ config[:http_proxy] = "http://proxy"
698
+ config[:https_proxy] = "https://proxy"
699
+
700
+ cmd.lines.to_a[1..4].must_equal([
701
+ %{http_proxy="http://proxy"; export http_proxy\n},
702
+ %{HTTP_PROXY="http://proxy"; export HTTP_PROXY\n},
703
+ %{https_proxy="https://proxy"; export https_proxy\n},
704
+ %{HTTPS_PROXY="https://proxy"; export HTTPS_PROXY\n}
705
+ ])
706
+ end
707
+
708
+ it "does no powershell PATH reloading for older chef omnibus packages" do
709
+ cmd.wont_match regexify(%{[System.Environment]::})
710
+ end
711
+
712
+ it "uses sudo for chef-client when configured" do
713
+ config[:chef_omnibus_root] = "/c"
714
+ config[:sudo] = true
715
+
716
+ cmd.must_match regexify("sudo -E /c/bin/chef-client ", :partial_line)
717
+ end
718
+
719
+ it "does not use sudo for chef-client when configured" do
720
+ config[:chef_omnibus_root] = "/c"
721
+ config[:sudo] = false
722
+
723
+ cmd.must_match regexify("/c/bin/chef-client ", :partial_line)
724
+ cmd.wont_match regexify("sudo -E /c/bin/chef-client ", :partial_line)
725
+ end
482
726
  end
483
727
 
484
- it "sets logfile flag for custom value" do
485
- config[:log_file] = "/a/out.log"
728
+ describe "for powershell shells on windows os types" do
729
+
730
+ before do
731
+ platform.stubs(:shell_type).returns("powershell")
732
+ platform.stubs(:os_type).returns("windows")
733
+ end
734
+
735
+ let(:base) { "$env:TEMP\\kitchen\\" }
736
+ let(:custom_base) { "\\a\\b\\" }
737
+ let(:custom_root) { "\\a\\b" }
738
+
739
+ common_shell_specs
740
+ common_modern_shell_specs
741
+
742
+ it "exports http_proxy & HTTP_PROXY when :http_proxy is set" do
743
+ config[:http_proxy] = "http://proxy"
744
+
745
+ cmd.lines.to_a[0..1].must_equal([
746
+ %{$env:http_proxy = "http://proxy"\n},
747
+ %{$env:HTTP_PROXY = "http://proxy"\n}
748
+ ])
749
+ end
750
+
751
+ it "exports https_proxy & HTTPS_PROXY when :https_proxy is set" do
752
+ config[:https_proxy] = "https://proxy"
753
+
754
+ cmd.lines.to_a[0..1].must_equal([
755
+ %{$env:https_proxy = "https://proxy"\n},
756
+ %{$env:HTTPS_PROXY = "https://proxy"\n}
757
+ ])
758
+ end
486
759
 
487
- cmd.must_match regexify(" --logfile /a/out.log", :partial_line)
760
+ it "exports all http proxy variables when both are set" do
761
+ config[:http_proxy] = "http://proxy"
762
+ config[:https_proxy] = "https://proxy"
763
+
764
+ cmd.lines.to_a[0..3].must_equal([
765
+ %{$env:http_proxy = "http://proxy"\n},
766
+ %{$env:HTTP_PROXY = "http://proxy"\n},
767
+ %{$env:https_proxy = "https://proxy"\n},
768
+ %{$env:HTTPS_PROXY = "https://proxy"\n}
769
+ ])
770
+ end
771
+
772
+ it "reloads PATH for older chef omnibus packages" do
773
+ cmd.must_match regexify("$env:PATH = " +
774
+ %{[System.Environment]::GetEnvironmentVariable("PATH","Machine")})
775
+ end
776
+
777
+ it "calls the chef-client command from :chef_client_path" do
778
+ config[:chef_client_path] = "\\r\\chef-client.bat"
779
+
780
+ cmd.must_match regexify("& \\r\\chef-client.bat ", :partial_line)
781
+ end
488
782
  end
489
783
  end
490
784
 
@@ -492,118 +786,155 @@ describe Kitchen::Provisioner::ChefZero do
492
786
 
493
787
  before do
494
788
  config[:require_chef_omnibus] = "10.20"
495
- config[:ruby_bindir] = "/r/bin"
496
789
  end
497
790
 
498
- it "uses bourne shell" do
499
- cmd.must_match(/\Ash -c '$/)
500
- cmd.must_match(/'\Z/)
501
- end
791
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
792
+ def self.common_old_shell_specs
793
+ it "does not set local mode flag" do
794
+ cmd.wont_match regexify(" --local-mode", :partial_line)
795
+ end
502
796
 
503
- it "uses sudo for ruby when configured" do
504
- config[:root_path] = "/x"
505
- config[:sudo] = true
797
+ it "does not set chef zero host flag for custom host" do
798
+ config[:chef_zero_host] = "192.168.0.1"
506
799
 
507
- cmd.must_match regexify(
508
- "sudo -E /r/bin/ruby /x/chef-client-zero.rb ", :partial_line)
509
- end
800
+ cmd.wont_match regexify(" --chef-zero-host 192.168.0.1", :partial_line)
801
+ end
510
802
 
511
- it "does not use sudo for ruby when configured" do
512
- config[:root_path] = "/x"
513
- config[:sudo] = false
803
+ it "does not set chef zero port flag for custom port" do
804
+ config[:chef_zero_port] = 123
514
805
 
515
- cmd.must_match regexify(
516
- "/r/bin/ruby /x/chef-client-zero.rb ", :partial_line)
517
- cmd.wont_match regexify(
518
- "sudo -E /r/bin/ruby /x/chef-client-zero.rb ", :partial_line)
806
+ cmd.wont_match regexify(" --chef-zero-port 123", :partial_line)
807
+ end
519
808
  end
520
809
 
521
- it "does not set local mode flag" do
522
- cmd.wont_match regexify(" --local-mode", :partial_line)
523
- end
810
+ describe "for bourne shells" do
524
811
 
525
- it "sets config flag on chef-client" do
526
- cmd.must_match regexify(
527
- " --config /tmp/kitchen/client.rb", :partial_line)
528
- end
812
+ before do
813
+ platform.stubs(:shell_type).returns("bourne")
814
+ config[:ruby_bindir] = "/r/bin"
815
+ end
529
816
 
530
- it "sets config flag for custom root_path" do
531
- config[:root_path] = "/a/b"
817
+ let(:base) { "/tmp/kitchen/" }
818
+ let(:custom_base) { "/a/b/" }
819
+ let(:custom_root) { "/a/b" }
532
820
 
533
- cmd.must_match regexify(" --config /a/b/client.rb", :partial_line)
534
- end
821
+ common_shell_specs
822
+ common_old_shell_specs
535
823
 
536
- it "sets log level flag on chef-client to auto by default" do
537
- cmd.must_match regexify(" --log_level auto", :partial_line)
538
- end
824
+ it "uses bourne shell" do
825
+ cmd.must_match(/\Ash -c '$/)
826
+ cmd.must_match(/'\Z/)
827
+ end
539
828
 
540
- it "set log level flag for custom level" do
541
- config[:log_level] = :extreme
829
+ it "ends with a single quote" do
830
+ cmd.must_match(/'\Z/)
831
+ end
542
832
 
543
- cmd.must_match regexify(" --log_level extreme", :partial_line)
544
- end
833
+ it "uses sudo for ruby when configured" do
834
+ config[:root_path] = "/x"
835
+ config[:sudo] = true
545
836
 
546
- it "sets force formatter flag on chef-solo" do
547
- cmd.must_match regexify(" --force-formatter", :partial_line)
548
- end
837
+ cmd.must_match regexify(
838
+ "sudo -E /r/bin/ruby /x/chef-client-zero.rb ", :partial_line)
839
+ end
549
840
 
550
- it "sets no color flag on chef-solo" do
551
- cmd.must_match regexify(" --no-color", :partial_line)
552
- end
841
+ it "does not use sudo for ruby when configured" do
842
+ config[:root_path] = "/x"
843
+ config[:sudo] = false
553
844
 
554
- it "sets json attributes flag on chef-client" do
555
- cmd.must_match regexify(
556
- " --json-attributes /tmp/kitchen/dna.json", :partial_line)
557
- end
845
+ cmd.must_match regexify(
846
+ "/r/bin/ruby /x/chef-client-zero.rb ", :partial_line)
847
+ cmd.wont_match regexify(
848
+ "sudo -E /r/bin/ruby /x/chef-client-zero.rb ", :partial_line)
849
+ end
558
850
 
559
- it "sets json attribtes flag for custom root_path" do
560
- config[:root_path] = "/booyah"
851
+ it "sets the CHEF_REPO_PATH environment variable" do
852
+ config[:root_path] = "/r"
561
853
 
562
- cmd.must_match regexify(
563
- " --json-attributes /booyah/dna.json", :partial_line)
564
- end
854
+ cmd.must_match regexify(
855
+ %{CHEF_REPO_PATH="/r"; export CHEF_REPO_PATH})
856
+ end
565
857
 
566
- it "does not set json attributes flag if config is falsey" do
567
- config[:json_attributes] = false
858
+ it "sets the GEM_HOME environment variable" do
859
+ config[:root_path] = "/r"
568
860
 
569
- cmd.wont_match regexify(" --json-attributes ", :partial_line)
570
- end
861
+ cmd.must_match regexify(
862
+ %{GEM_HOME="/r/chef-client-zero-gems"; export GEM_HOME})
863
+ end
571
864
 
572
- it "does not set logfile flag by default" do
573
- cmd.wont_match regexify(" --logfile ", :partial_line)
574
- end
865
+ it "sets the GEM_PATH environment variable" do
866
+ config[:root_path] = "/r"
575
867
 
576
- it "sets logfile flag for custom value" do
577
- config[:log_file] = "/a/out.log"
868
+ cmd.must_match regexify(
869
+ %{GEM_PATH="/r/chef-client-zero-gems"; export GEM_PATH})
870
+ end
578
871
 
579
- cmd.must_match regexify(" --logfile /a/out.log", :partial_line)
580
- end
872
+ it "sets the GEM_CACHE environment variable" do
873
+ config[:root_path] = "/r"
581
874
 
582
- it "sets the CHEF_REPO_PATH environment variable" do
583
- config[:root_path] = "/r"
875
+ cmd.must_match regexify(
876
+ %{GEM_CACHE="/r/chef-client-zero-gems/cache"; export GEM_CACHE})
877
+ end
584
878
 
585
- cmd.must_match regexify(%{CHEF_REPO_PATH="/r" }, :partial_line)
879
+ it "does no powershell PATH reloading for older chef omnibus packages" do
880
+ cmd.wont_match regexify(%{[System.Environment]::})
881
+ end
586
882
  end
587
883
 
588
- it "sets the GEM_HOME environment variable" do
589
- config[:root_path] = "/r"
884
+ describe "for powershell shells on windows os types" do
590
885
 
591
- cmd.must_match regexify(
592
- %{GEM_HOME="/r/chef-client-zero-gems" }, :partial_line)
593
- end
886
+ before do
887
+ platform.stubs(:shell_type).returns("powershell")
888
+ platform.stubs(:os_type).returns("windows")
889
+ config[:ruby_bindir] = "\\r\\bin"
890
+ end
594
891
 
595
- it "sets the GEM_PATH environment variable" do
596
- config[:root_path] = "/r"
892
+ let(:base) { "$env:TEMP\\kitchen\\" }
893
+ let(:custom_base) { "\\a\\b\\" }
894
+ let(:custom_root) { "\\a\\b" }
597
895
 
598
- cmd.must_match regexify(
599
- %{GEM_PATH="/r/chef-client-zero-gems" }, :partial_line)
600
- end
896
+ common_shell_specs
897
+ common_old_shell_specs
601
898
 
602
- it "sets the GEM_CACHE environment variable" do
603
- config[:root_path] = "/r"
899
+ it "calls ruby from :ruby_bindir" do
900
+ config[:root_path] = "\\x"
604
901
 
605
- cmd.must_match regexify(
606
- %{GEM_CACHE="/r/chef-client-zero-gems/cache" }, :partial_line)
902
+ cmd.must_match regexify(
903
+ "\\r\\bin\\ruby.exe \\x\\chef-client-zero.rb ", :partial_line)
904
+ end
905
+
906
+ it "sets the CHEF_REPO_PATH environment variable" do
907
+ config[:root_path] = "\\r"
908
+
909
+ cmd.must_match regexify(
910
+ %{$env:CHEF_REPO_PATH = "\\r"})
911
+ end
912
+
913
+ it "sets the GEM_HOME environment variable" do
914
+ config[:root_path] = "\\r"
915
+
916
+ cmd.must_match regexify(
917
+ %{$env:GEM_HOME = "\\r\\chef-client-zero-gems"})
918
+ end
919
+
920
+ it "sets the GEM_PATH environment variable" do
921
+ config[:root_path] = "\\r"
922
+
923
+ cmd.must_match regexify(
924
+ %{$env:GEM_PATH = "\\r\\chef-client-zero-gems"})
925
+ end
926
+
927
+ it "sets the GEM_CACHE environment variable" do
928
+ config[:root_path] = "\\r"
929
+
930
+ cmd.must_match regexify(
931
+ %{$env:GEM_CACHE = "\\r\\chef-client-zero-gems\\cache"})
932
+ end
933
+
934
+ it "reloads PATH for older chef omnibus packages" do
935
+ cmd.must_match regexify("$env:PATH = " +
936
+ %{[System.Environment]::GetEnvironmentVariable("PATH","Machine")})
937
+ end
607
938
  end
608
939
  end
609
940
  end