test-kitchen 1.7.0 → 1.7.1.dev

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 (181) hide show
  1. checksums.yaml +4 -4
  2. data/.cane +8 -8
  3. data/.gitattributes +3 -0
  4. data/.github/ISSUE_TEMPLATE.md +55 -55
  5. data/.gitignore +28 -28
  6. data/.kitchen.ci.yml +23 -23
  7. data/.kitchen.proxy.yml +27 -27
  8. data/.rubocop.yml +3 -3
  9. data/.travis.yml +70 -70
  10. data/.yardopts +3 -3
  11. data/Berksfile +3 -3
  12. data/CHANGELOG.md +1090 -1083
  13. data/CONTRIBUTING.md +14 -14
  14. data/Gemfile +19 -19
  15. data/Gemfile.proxy_tests +4 -4
  16. data/Guardfile +42 -42
  17. data/LICENSE +15 -15
  18. data/MAINTAINERS.md +23 -23
  19. data/README.md +135 -135
  20. data/Rakefile +61 -61
  21. data/appveyor.yml +44 -44
  22. data/features/kitchen_action_commands.feature +164 -164
  23. data/features/kitchen_command.feature +16 -16
  24. data/features/kitchen_console_command.feature +34 -34
  25. data/features/kitchen_defaults.feature +38 -38
  26. data/features/kitchen_diagnose_command.feature +96 -96
  27. data/features/kitchen_driver_create_command.feature +64 -64
  28. data/features/kitchen_driver_discover_command.feature +25 -25
  29. data/features/kitchen_help_command.feature +16 -16
  30. data/features/kitchen_init_command.feature +274 -274
  31. data/features/kitchen_list_command.feature +104 -104
  32. data/features/kitchen_login_command.feature +62 -62
  33. data/features/kitchen_sink_command.feature +30 -30
  34. data/features/kitchen_test_command.feature +88 -88
  35. data/features/step_definitions/gem_steps.rb +36 -36
  36. data/features/step_definitions/git_steps.rb +5 -5
  37. data/features/step_definitions/output_steps.rb +5 -5
  38. data/features/support/env.rb +75 -75
  39. data/lib/kitchen.rb +150 -150
  40. data/lib/kitchen/base64_stream.rb +55 -55
  41. data/lib/kitchen/cli.rb +419 -419
  42. data/lib/kitchen/collection.rb +55 -55
  43. data/lib/kitchen/color.rb +65 -65
  44. data/lib/kitchen/command.rb +185 -185
  45. data/lib/kitchen/command/action.rb +45 -45
  46. data/lib/kitchen/command/console.rb +58 -58
  47. data/lib/kitchen/command/diagnose.rb +92 -92
  48. data/lib/kitchen/command/driver_discover.rb +105 -105
  49. data/lib/kitchen/command/exec.rb +41 -41
  50. data/lib/kitchen/command/list.rb +119 -119
  51. data/lib/kitchen/command/login.rb +43 -43
  52. data/lib/kitchen/command/sink.rb +54 -54
  53. data/lib/kitchen/command/test.rb +51 -51
  54. data/lib/kitchen/config.rb +322 -322
  55. data/lib/kitchen/configurable.rb +529 -529
  56. data/lib/kitchen/data_munger.rb +959 -959
  57. data/lib/kitchen/diagnostic.rb +141 -141
  58. data/lib/kitchen/driver.rb +56 -56
  59. data/lib/kitchen/driver/base.rb +134 -134
  60. data/lib/kitchen/driver/dummy.rb +108 -108
  61. data/lib/kitchen/driver/proxy.rb +72 -72
  62. data/lib/kitchen/driver/ssh_base.rb +357 -357
  63. data/lib/kitchen/errors.rb +229 -229
  64. data/lib/kitchen/generator/driver_create.rb +177 -177
  65. data/lib/kitchen/generator/init.rb +296 -296
  66. data/lib/kitchen/instance.rb +662 -662
  67. data/lib/kitchen/lazy_hash.rb +142 -142
  68. data/lib/kitchen/loader/yaml.rb +349 -349
  69. data/lib/kitchen/logger.rb +423 -423
  70. data/lib/kitchen/logging.rb +56 -56
  71. data/lib/kitchen/login_command.rb +52 -52
  72. data/lib/kitchen/metadata_chopper.rb +52 -52
  73. data/lib/kitchen/platform.rb +67 -67
  74. data/lib/kitchen/provisioner.rb +54 -54
  75. data/lib/kitchen/provisioner/base.rb +236 -236
  76. data/lib/kitchen/provisioner/chef/berkshelf.rb +114 -114
  77. data/lib/kitchen/provisioner/chef/common_sandbox.rb +322 -322
  78. data/lib/kitchen/provisioner/chef/librarian.rb +112 -112
  79. data/lib/kitchen/provisioner/chef_apply.rb +124 -124
  80. data/lib/kitchen/provisioner/chef_base.rb +341 -341
  81. data/lib/kitchen/provisioner/chef_solo.rb +88 -88
  82. data/lib/kitchen/provisioner/chef_zero.rb +245 -245
  83. data/lib/kitchen/provisioner/dummy.rb +79 -79
  84. data/lib/kitchen/provisioner/shell.rb +138 -138
  85. data/lib/kitchen/rake_tasks.rb +63 -63
  86. data/lib/kitchen/shell_out.rb +93 -93
  87. data/lib/kitchen/ssh.rb +276 -276
  88. data/lib/kitchen/state_file.rb +120 -120
  89. data/lib/kitchen/suite.rb +51 -51
  90. data/lib/kitchen/thor_tasks.rb +66 -66
  91. data/lib/kitchen/transport.rb +54 -54
  92. data/lib/kitchen/transport/base.rb +176 -176
  93. data/lib/kitchen/transport/dummy.rb +79 -79
  94. data/lib/kitchen/transport/ssh.rb +364 -364
  95. data/lib/kitchen/transport/winrm.rb +486 -486
  96. data/lib/kitchen/util.rb +147 -147
  97. data/lib/kitchen/verifier.rb +55 -55
  98. data/lib/kitchen/verifier/base.rb +235 -235
  99. data/lib/kitchen/verifier/busser.rb +277 -277
  100. data/lib/kitchen/verifier/dummy.rb +79 -79
  101. data/lib/kitchen/verifier/shell.rb +101 -101
  102. data/lib/kitchen/version.rb +21 -21
  103. data/lib/vendor/hash_recursive_merge.rb +82 -82
  104. data/spec/kitchen/base64_stream_spec.rb +77 -77
  105. data/spec/kitchen/cli_spec.rb +56 -56
  106. data/spec/kitchen/collection_spec.rb +80 -80
  107. data/spec/kitchen/color_spec.rb +54 -54
  108. data/spec/kitchen/config_spec.rb +408 -408
  109. data/spec/kitchen/configurable_spec.rb +1095 -1095
  110. data/spec/kitchen/data_munger_spec.rb +2694 -2694
  111. data/spec/kitchen/diagnostic_spec.rb +129 -129
  112. data/spec/kitchen/driver/base_spec.rb +121 -121
  113. data/spec/kitchen/driver/dummy_spec.rb +199 -199
  114. data/spec/kitchen/driver/proxy_spec.rb +138 -138
  115. data/spec/kitchen/driver/ssh_base_spec.rb +1115 -1115
  116. data/spec/kitchen/driver_spec.rb +112 -112
  117. data/spec/kitchen/errors_spec.rb +309 -309
  118. data/spec/kitchen/instance_spec.rb +1419 -1419
  119. data/spec/kitchen/lazy_hash_spec.rb +117 -117
  120. data/spec/kitchen/loader/yaml_spec.rb +774 -774
  121. data/spec/kitchen/logger_spec.rb +429 -429
  122. data/spec/kitchen/logging_spec.rb +59 -59
  123. data/spec/kitchen/login_command_spec.rb +68 -68
  124. data/spec/kitchen/metadata_chopper_spec.rb +82 -82
  125. data/spec/kitchen/platform_spec.rb +89 -89
  126. data/spec/kitchen/provisioner/base_spec.rb +386 -386
  127. data/spec/kitchen/provisioner/chef_apply_spec.rb +136 -136
  128. data/spec/kitchen/provisioner/chef_base_spec.rb +1161 -1161
  129. data/spec/kitchen/provisioner/chef_solo_spec.rb +557 -557
  130. data/spec/kitchen/provisioner/chef_zero_spec.rb +1001 -1001
  131. data/spec/kitchen/provisioner/dummy_spec.rb +99 -99
  132. data/spec/kitchen/provisioner/shell_spec.rb +566 -566
  133. data/spec/kitchen/provisioner_spec.rb +107 -107
  134. data/spec/kitchen/shell_out_spec.rb +150 -150
  135. data/spec/kitchen/ssh_spec.rb +693 -693
  136. data/spec/kitchen/state_file_spec.rb +129 -129
  137. data/spec/kitchen/suite_spec.rb +62 -62
  138. data/spec/kitchen/transport/base_spec.rb +89 -89
  139. data/spec/kitchen/transport/ssh_spec.rb +1255 -1255
  140. data/spec/kitchen/transport/winrm_spec.rb +1143 -1143
  141. data/spec/kitchen/transport_spec.rb +112 -112
  142. data/spec/kitchen/util_spec.rb +165 -165
  143. data/spec/kitchen/verifier/base_spec.rb +362 -362
  144. data/spec/kitchen/verifier/busser_spec.rb +610 -610
  145. data/spec/kitchen/verifier/dummy_spec.rb +99 -99
  146. data/spec/kitchen/verifier/shell_spec.rb +160 -160
  147. data/spec/kitchen/verifier_spec.rb +120 -120
  148. data/spec/kitchen_spec.rb +114 -114
  149. data/spec/spec_helper.rb +85 -85
  150. data/spec/support/powershell_max_size_spec.rb +40 -40
  151. data/support/busser_install_command.ps1 +14 -14
  152. data/support/busser_install_command.sh +14 -14
  153. data/support/chef-client-zero.rb +77 -77
  154. data/support/chef_base_init_command.ps1 +18 -18
  155. data/support/chef_base_init_command.sh +2 -2
  156. data/support/chef_base_install_command.ps1 +85 -85
  157. data/support/chef_base_install_command.sh +229 -229
  158. data/support/chef_zero_prepare_command_legacy.ps1 +9 -9
  159. data/support/chef_zero_prepare_command_legacy.sh +10 -10
  160. data/support/download_helpers.sh +109 -109
  161. data/support/dummy-validation.pem +27 -27
  162. data/templates/driver/CHANGELOG.md.erb +3 -3
  163. data/templates/driver/Gemfile.erb +3 -3
  164. data/templates/driver/README.md.erb +64 -64
  165. data/templates/driver/Rakefile.erb +21 -21
  166. data/templates/driver/driver.rb.erb +23 -23
  167. data/templates/driver/gemspec.erb +29 -29
  168. data/templates/driver/gitignore.erb +17 -17
  169. data/templates/driver/license_apachev2.erb +15 -15
  170. data/templates/driver/license_lgplv3.erb +16 -16
  171. data/templates/driver/license_mit.erb +22 -22
  172. data/templates/driver/license_reserved.erb +5 -5
  173. data/templates/driver/tailor.erb +4 -4
  174. data/templates/driver/travis.yml.erb +11 -11
  175. data/templates/driver/version.rb.erb +12 -12
  176. data/templates/init/chefignore.erb +1 -1
  177. data/templates/init/kitchen.yml.erb +18 -18
  178. data/test-kitchen.gemspec +62 -62
  179. data/test/integration/default/default_spec.rb +3 -3
  180. data/testing_windows.md +37 -37
  181. metadata +5 -4
@@ -1,1001 +1,1001 @@
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"
22
- require "kitchen/provisioner/chef_zero"
23
-
24
- describe Kitchen::Provisioner::ChefZero do
25
-
26
- let(:logged_output) { StringIO.new }
27
- let(:logger) { Logger.new(logged_output) }
28
- let(:platform) { stub(:os_type => nil) }
29
- let(:suite) { stub(:name => "fries") }
30
-
31
- let(:config) do
32
- { :test_base_path => "/b", :kitchen_root => "/r" }
33
- end
34
-
35
- let(:instance) do
36
- stub(
37
- :name => "coolbeans",
38
- :logger => logger,
39
- :suite => suite,
40
- :platform => platform
41
- )
42
- end
43
-
44
- let(:provisioner) do
45
- Kitchen::Provisioner::ChefZero.new(config).finalize_config!(instance)
46
- end
47
-
48
- it "provisioner api_version is 2" do
49
- provisioner.diagnose_plugin[:api_version].must_equal 2
50
- end
51
-
52
- it "plugin_version is set to Kitchen::VERSION" do
53
- provisioner.diagnose_plugin[:version].must_equal Kitchen::VERSION
54
- end
55
-
56
- describe "default config" do
57
-
58
- describe "for unix operating systems" do
59
-
60
- before { platform.stubs(:os_type).returns("unix") }
61
-
62
- it "sets :chef_client_path to a path using :chef_omnibus_root" do
63
- config[:chef_omnibus_root] = "/nice/place"
64
-
65
- provisioner[:chef_client_path].
66
- must_equal "/nice/place/bin/chef-client"
67
- end
68
-
69
- it "sets :ruby_bindir to use an Omnibus Ruby" do
70
- config[:chef_omnibus_root] = "/nice"
71
-
72
- provisioner[:ruby_bindir].must_equal "/nice/embedded/bin"
73
- end
74
- end
75
-
76
- describe "for windows operating systems" do
77
-
78
- before { platform.stubs(:os_type).returns("windows") }
79
-
80
- it "sets :chef_client_path to a path using :chef_omnibus_root" do
81
- config[:chef_omnibus_root] = "$env:systemdrive\\nice\\place"
82
-
83
- provisioner[:chef_client_path].
84
- must_equal "$env:systemdrive\\nice\\place\\bin\\chef-client.bat"
85
- end
86
-
87
- it "sets :ruby_bindir to use an Omnibus Ruby" do
88
- config[:chef_omnibus_root] = "c:\\nice"
89
-
90
- provisioner[:ruby_bindir].must_equal "c:\\nice\\embedded\\bin"
91
- end
92
- end
93
-
94
- it "sets :client_rb to an empty Hash" do
95
- provisioner[:client_rb].must_equal Hash.new
96
- end
97
-
98
- it "sets :json_attributes to true" do
99
- provisioner[:json_attributes].must_equal true
100
- end
101
-
102
- it "does not set :chef_zero_host" do
103
- provisioner[:chef_zero_host].must_equal nil
104
- end
105
-
106
- it "sets :chef_zero_port to 8889" do
107
- provisioner[:chef_zero_port].must_equal 8889
108
- end
109
- end
110
-
111
- describe "#create_sandbox" do
112
-
113
- before do
114
- @root = Dir.mktmpdir
115
- config[:kitchen_root] = @root
116
- end
117
-
118
- after do
119
- FileUtils.remove_entry(@root)
120
- begin
121
- provisioner.cleanup_sandbox
122
- rescue # rubocop:disable Lint/HandleExceptions
123
- end
124
- end
125
-
126
- describe "client.rb file" do
127
-
128
- let(:file) do
129
- IO.read(sandbox_path("client.rb")).lines.map(&:chomp)
130
- end
131
-
132
- it "creates a client.rb" do
133
- provisioner.create_sandbox
134
-
135
- sandbox_path("client.rb").file?.must_equal true
136
- end
137
-
138
- it "logs a message on info" do
139
- provisioner.create_sandbox
140
-
141
- logged_output.string.must_match info_line("Preparing client.rb")
142
- end
143
-
144
- it "logs a message on debug" do
145
- provisioner.create_sandbox
146
-
147
- logged_output.string.
148
- must_match debug_line_starting_with("Creating client.rb from {")
149
- end
150
-
151
- describe "defaults" do
152
-
153
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
154
- def self.common_client_rb_specs
155
- it "sets node_name to the instance name" do
156
- file.must_include %{node_name "#{instance.name}"}
157
- end
158
-
159
- it "sets checksum_path" do
160
- file.must_include %{checksum_path "#{base}checksums"}
161
- end
162
-
163
- it "sets file_backup_path" do
164
- file.must_include %{file_backup_path "#{base}backup"}
165
- end
166
-
167
- it "sets cookbook_path" do
168
- file.must_include %{cookbook_path } +
169
- %{["#{base}cookbooks", "#{base}site-cookbooks"]}
170
- end
171
-
172
- it "sets data_bag_path" do
173
- file.must_include %{data_bag_path "#{base}data_bags"}
174
- end
175
-
176
- it "sets environment_path" do
177
- file.must_include %{environment_path "#{base}environments"}
178
- end
179
-
180
- it "sets node_path" do
181
- file.must_include %{node_path "#{base}nodes"}
182
- end
183
-
184
- it "sets role_path" do
185
- file.must_include %{role_path "#{base}roles"}
186
- end
187
-
188
- it "sets client_path" do
189
- file.must_include %{client_path "#{base}clients"}
190
- end
191
-
192
- it "sets user_path" do
193
- file.must_include %{user_path "#{base}users"}
194
- end
195
-
196
- it "sets validation_key" do
197
- file.must_include %{validation_key "#{base}validation.pem"}
198
- end
199
-
200
- it "sets client_key" do
201
- file.must_include %{client_key "#{base}client.pem"}
202
- end
203
-
204
- it "sets chef_server_url" do
205
- file.must_include %{chef_server_url "http://127.0.0.1:8889"}
206
- end
207
-
208
- it "sets encrypted_data_bag_secret" do
209
- file.must_include %{encrypted_data_bag_secret } +
210
- %{"#{base}encrypted_data_bag_secret"}
211
- end
212
- end
213
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
214
-
215
- describe "for unix os types" do
216
-
217
- before do
218
- platform.stubs(:os_type).returns("unix")
219
- provisioner.create_sandbox
220
- end
221
-
222
- let(:base) { "/tmp/kitchen/" }
223
-
224
- common_client_rb_specs
225
- end
226
-
227
- describe "for windows os types with full path" do
228
-
229
- before do
230
- platform.stubs(:os_type).returns("windows")
231
- config[:root_path] = "\\a\\b"
232
- provisioner.create_sandbox
233
- end
234
-
235
- let(:base) { "\\\\a\\\\b\\\\" }
236
-
237
- common_client_rb_specs
238
- end
239
-
240
- describe "for windows os types with $env:TEMP prefixed paths" do
241
-
242
- before do
243
- platform.stubs(:os_type).returns("windows")
244
- config[:root_path] = "$env:TEMP\\a"
245
- provisioner.create_sandbox
246
- end
247
-
248
- let(:base) { "\#{ENV['TEMP']}\\\\a\\\\" }
249
-
250
- common_client_rb_specs
251
- end
252
- end
253
-
254
- it "supports overwriting defaults" do
255
- config[:client_rb] = {
256
- :node_name => "eagles",
257
- :user_path => "/a/b/c/u",
258
- :client_key => "lol"
259
- }
260
- provisioner.create_sandbox
261
-
262
- file.must_include %{node_name "eagles"}
263
- file.must_include %{user_path "/a/b/c/u"}
264
- file.must_include %{client_key "lol"}
265
- end
266
-
267
- it " supports adding new configuration" do
268
- config[:client_rb] = {
269
- :dark_secret => "golang"
270
- }
271
- provisioner.create_sandbox
272
-
273
- file.must_include %{dark_secret "golang"}
274
- end
275
-
276
- it "formats array values correctly" do
277
- config[:client_rb] = {
278
- :foos => %w[foo1 foo2]
279
- }
280
- provisioner.create_sandbox
281
-
282
- file.must_include %{foos ["foo1", "foo2"]}
283
- end
284
-
285
- it "formats integer values correctly" do
286
- config[:client_rb] = {
287
- :foo => 7
288
- }
289
- provisioner.create_sandbox
290
-
291
- file.must_include %{foo 7}
292
- end
293
-
294
- it "formats symbol-looking string values correctly" do
295
- config[:client_rb] = {
296
- :foo => ":bar"
297
- }
298
- provisioner.create_sandbox
299
-
300
- file.must_include %{foo :bar}
301
- end
302
-
303
- it "formats boolean values correctly" do
304
- config[:client_rb] = {
305
- :foo => false,
306
- :bar => true
307
- }
308
- provisioner.create_sandbox
309
-
310
- file.must_include %{foo false}
311
- file.must_include %{bar true}
312
- end
313
- end
314
-
315
- describe "validation.pem file" do
316
-
317
- it "creates file" do
318
- provisioner.create_sandbox
319
-
320
- sandbox_path("validation.pem").file?.must_equal true
321
- end
322
-
323
- it "logs a message on info" do
324
- provisioner.create_sandbox
325
-
326
- logged_output.string.must_match info_line("Preparing validation.pem")
327
- end
328
-
329
- it "logs a message on debug" do
330
- provisioner.create_sandbox
331
-
332
- logged_output.string.
333
- must_match debug_line_starting_with("Using a dummy validation.pem")
334
- end
335
- end
336
-
337
- describe "chef-client-zero.rb file" do
338
-
339
- describe "for modern Chef versions" do
340
-
341
- before { config[:require_chef_omnibus] = "11.10" }
342
-
343
- it "does not create the file" do
344
- provisioner.create_sandbox
345
-
346
- sandbox_path("chef-client-zero.rb").file?.must_equal false
347
- end
348
-
349
- it "a version of '11' is still considered modern" do
350
- config[:require_chef_omnibus] = "11"
351
- provisioner.create_sandbox
352
-
353
- sandbox_path("chef-client-zero.rb").file?.must_equal false
354
- end
355
-
356
- it "a version of 11 is still considered modern" do
357
- config[:require_chef_omnibus] = 11
358
- provisioner.create_sandbox
359
-
360
- sandbox_path("chef-client-zero.rb").file?.must_equal false
361
- end
362
- end
363
-
364
- describe "for old Chef versions" do
365
-
366
- before { config[:require_chef_omnibus] = "10.20" }
367
-
368
- it "creates the file when using an old Chef version" do
369
- provisioner.create_sandbox
370
-
371
- sandbox_path("chef-client-zero.rb").file?.must_equal true
372
- end
373
-
374
- it "logs a message on info" do
375
- provisioner.create_sandbox
376
-
377
- logged_output.string.
378
- must_match info_line("Preparing chef-client-zero.rb")
379
- end
380
-
381
- it "logs a message on debug" do
382
- provisioner.create_sandbox
383
-
384
- logged_output.string.must_match debug_line_starting_with(
385
- "Using a vendored chef-client-zero.rb")
386
- end
387
- end
388
- end
389
-
390
- def sandbox_path(path)
391
- Pathname.new(provisioner.sandbox_path).join(path)
392
- end
393
- end
394
-
395
- describe "#prepare_command" do
396
-
397
- let(:cmd) { provisioner.prepare_command }
398
-
399
- describe "for modern Chef versions" do
400
-
401
- before { config[:require_chef_omnibus] = "11.10" }
402
-
403
- it "returns nil" do
404
- cmd.must_equal nil
405
- end
406
- end
407
-
408
- describe "for old Chef versions" do
409
-
410
- before { config[:require_chef_omnibus] = "10.20" }
411
-
412
- describe "for bourne shells" do
413
-
414
- before do
415
- platform.stubs(:shell_type).returns("bourne")
416
- config[:ruby_bindir] = "/rbd"
417
- end
418
-
419
- it "uses bourne shell" do
420
- cmd.must_match(/\Ash -c '$/)
421
- cmd.must_match(/'\Z/)
422
- end
423
-
424
- it "ends with a single quote" do
425
- cmd.must_match(/'\Z/)
426
- end
427
-
428
- it "exports http_proxy & HTTP_PROXY when :http_proxy is set" do
429
- config[:http_proxy] = "http://proxy"
430
-
431
- cmd.lines.to_a[1..2].must_equal([
432
- %{http_proxy="http://proxy"; export http_proxy\n},
433
- %{HTTP_PROXY="http://proxy"; export HTTP_PROXY\n}
434
- ])
435
- end
436
-
437
- it "exports https_proxy & HTTPS_PROXY when :https_proxy is set" do
438
- config[:https_proxy] = "https://proxy"
439
-
440
- cmd.lines.to_a[1..2].must_equal([
441
- %{https_proxy="https://proxy"; export https_proxy\n},
442
- %{HTTPS_PROXY="https://proxy"; export HTTPS_PROXY\n}
443
- ])
444
- end
445
-
446
- it "exports all http proxy variables when both are set" do
447
- config[:http_proxy] = "http://proxy"
448
- config[:https_proxy] = "https://proxy"
449
-
450
- cmd.lines.to_a[1..4].must_equal([
451
- %{http_proxy="http://proxy"; export http_proxy\n},
452
- %{HTTP_PROXY="http://proxy"; export HTTP_PROXY\n},
453
- %{https_proxy="https://proxy"; export https_proxy\n},
454
- %{HTTPS_PROXY="https://proxy"; export HTTPS_PROXY\n}
455
- ])
456
- end
457
-
458
- it "sets the CHEF_REPO_PATH environment variable" do
459
- config[:root_path] = "/r"
460
-
461
- cmd.must_match regexify(
462
- %{CHEF_REPO_PATH="/r"; export CHEF_REPO_PATH})
463
- end
464
-
465
- it "sets the GEM_HOME environment variable" do
466
- config[:root_path] = "/r"
467
-
468
- cmd.must_match regexify(
469
- %{GEM_HOME="/r/chef-client-zero-gems"; export GEM_HOME})
470
- end
471
-
472
- it "sets the GEM_PATH environment variable" do
473
- config[:root_path] = "/r"
474
-
475
- cmd.must_match regexify(
476
- %{GEM_PATH="/r/chef-client-zero-gems"; export GEM_PATH})
477
- end
478
-
479
- it "sets the GEM_CACHE environment variable" do
480
- config[:root_path] = "/r"
481
-
482
- cmd.must_match regexify(
483
- %{GEM_CACHE="/r/chef-client-zero-gems/cache"; export GEM_CACHE})
484
- end
485
-
486
- it "prepends sudo for gem command when :sudo is set" do
487
- config[:sudo] = true
488
-
489
- cmd.must_match regexify(%{gem="sudo -E /rbd/gem"})
490
- end
491
-
492
- it "does not sudo for gem commands when :sudo is falsey" do
493
- config[:sudo] = false
494
-
495
- cmd.must_match regexify(%{gem="/rbd/gem"})
496
- end
497
- end
498
-
499
- describe "for powershell shells on windows os types" do
500
-
501
- before do
502
- platform.stubs(:shell_type).returns("powershell")
503
- platform.stubs(:os_type).returns("windows")
504
- config[:root_path] = "\\r"
505
- config[:ruby_bindir] = "\\rbd"
506
- end
507
-
508
- it "exports http_proxy & HTTP_PROXY when :http_proxy is set" do
509
- config[:http_proxy] = "http://proxy"
510
-
511
- cmd.lines.to_a[0..1].must_equal([
512
- %{$env:http_proxy = "http://proxy"\n},
513
- %{$env:HTTP_PROXY = "http://proxy"\n}
514
- ])
515
- end
516
-
517
- it "exports https_proxy & HTTPS_PROXY when :https_proxy is set" do
518
- config[:https_proxy] = "https://proxy"
519
-
520
- cmd.lines.to_a[0..1].must_equal([
521
- %{$env:https_proxy = "https://proxy"\n},
522
- %{$env:HTTPS_PROXY = "https://proxy"\n}
523
- ])
524
- end
525
-
526
- it "exports all http proxy variables when both are set" do
527
- config[:http_proxy] = "http://proxy"
528
- config[:https_proxy] = "https://proxy"
529
-
530
- cmd.lines.to_a[0..3].must_equal([
531
- %{$env:http_proxy = "http://proxy"\n},
532
- %{$env:HTTP_PROXY = "http://proxy"\n},
533
- %{$env:https_proxy = "https://proxy"\n},
534
- %{$env:HTTPS_PROXY = "https://proxy"\n}
535
- ])
536
- end
537
-
538
- it "sets the CHEF_REPO_PATH environment variable" do
539
- config[:root_path] = "\\r"
540
-
541
- cmd.must_match regexify(
542
- %{$env:CHEF_REPO_PATH = "\\r"})
543
- end
544
-
545
- it "sets the GEM_HOME environment variable" do
546
- config[:root_path] = "\\r"
547
-
548
- cmd.must_match regexify(
549
- %{$env:GEM_HOME = "\\r\\chef-client-zero-gems"})
550
- end
551
-
552
- it "sets the GEM_PATH environment variable" do
553
- config[:root_path] = "\\r"
554
-
555
- cmd.must_match regexify(
556
- %{$env:GEM_PATH = "\\r\\chef-client-zero-gems"})
557
- end
558
-
559
- it "sets the GEM_CACHE environment variable" do
560
- config[:root_path] = "\\r"
561
-
562
- cmd.must_match regexify(
563
- %{$env:GEM_CACHE = "\\r\\chef-client-zero-gems\\cache"})
564
- end
565
-
566
- it "sets the path to the gem command" do
567
- cmd.must_match regexify(%{$gem = "\\rbd\\gem.bat"})
568
- end
569
- end
570
- end
571
- end
572
-
573
- describe "#run_command" do
574
-
575
- let(:cmd) { provisioner.run_command }
576
-
577
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
578
- def self.common_shell_specs
579
- it "sets config flag on chef-client" do
580
- cmd.must_match regexify(
581
- " --config #{base}client.rb", :partial_line)
582
- end
583
-
584
- it "sets config flag for custom root_path" do
585
- config[:root_path] = custom_root
586
-
587
- cmd.must_match regexify(
588
- " --config #{custom_base}client.rb", :partial_line)
589
- end
590
-
591
- it "sets log level flag on chef-client to auto by default" do
592
- cmd.must_match regexify(" --log_level auto", :partial_line)
593
- end
594
-
595
- it "set log level flag for custom level" do
596
- config[:log_level] = :extreme
597
-
598
- cmd.must_match regexify(" --log_level extreme", :partial_line)
599
- end
600
-
601
- it "sets force formatter flag on chef-solo" do
602
- cmd.must_match regexify(" --force-formatter", :partial_line)
603
- end
604
-
605
- it "sets no color flag on chef-solo" do
606
- cmd.must_match regexify(" --no-color", :partial_line)
607
- end
608
-
609
- it "sets json attributes flag on chef-client" do
610
- cmd.must_match regexify(
611
- " --json-attributes #{base}dna.json", :partial_line)
612
- end
613
-
614
- it "sets json attribtes flag for custom root_path" do
615
- config[:root_path] = custom_root
616
-
617
- cmd.must_match regexify(
618
- " --json-attributes #{custom_base}dna.json", :partial_line)
619
- end
620
-
621
- it "does not set json attributes flag if config is falsey" do
622
- config[:json_attributes] = false
623
-
624
- cmd.wont_match regexify(" --json-attributes ", :partial_line)
625
- end
626
-
627
- it "sets logfile flag for custom value" do
628
- config[:log_file] = "#{custom_base}out.log"
629
-
630
- cmd.must_match regexify(
631
- " --logfile #{custom_base}out.log", :partial_line)
632
- end
633
-
634
- it "does not set logfile flag by default" do
635
- cmd.wont_match regexify(" --logfile ", :partial_line)
636
- end
637
-
638
- it "prefixs the whole command with the command_prefix if set" do
639
- config[:command_prefix] = "my_prefix"
640
-
641
- cmd.must_match(/\Amy_prefix /)
642
- end
643
-
644
- it "does not prefix the command if command_prefix is not set" do
645
- config[:command_prefix] = nil
646
-
647
- cmd.wont_match(/\Amy_prefix /)
648
- end
649
- end
650
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
651
-
652
- describe "for modern Chef versions" do
653
-
654
- before { config[:require_chef_omnibus] = "11.10" }
655
-
656
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
657
- def self.common_modern_shell_specs
658
- it "sets local mode flag on chef-client" do
659
- cmd.must_match regexify(" --local-mode", :partial_line)
660
- end
661
-
662
- it "sets chef zero port flag on chef-client" do
663
- cmd.must_match regexify(" --chef-zero-port 8889", :partial_line)
664
- end
665
-
666
- it "sets chef zero host flag for custom host" do
667
- config[:chef_zero_host] = "192.168.0.1"
668
-
669
- cmd.must_match regexify(" --chef-zero-host 192.168.0.1", :partial_line)
670
- end
671
-
672
- it "sets chef zero port flag for custom port" do
673
- config[:chef_zero_port] = 123
674
-
675
- cmd.must_match regexify(" --chef-zero-port 123", :partial_line)
676
- end
677
-
678
- it "does not set chef zero host flag when value is falsey" do
679
- config[:chef_zero_host] = nil
680
-
681
- cmd.wont_match regexify(" --chef-zero-host ", :partial_line)
682
- end
683
-
684
- it "does not set chef zero port flag when value is falsey" do
685
- config[:chef_zero_port] = nil
686
-
687
- cmd.wont_match regexify(" --chef-zero-port ", :partial_line)
688
- end
689
-
690
- it "sets profile-ruby flag when config element is set" do
691
- config[:profile_ruby] = true
692
-
693
- cmd.must_match regexify(
694
- " --profile-ruby", :partial_line)
695
- end
696
-
697
- it "does not set profile-ruby flag when config element is falsey" do
698
- config[:profile_ruby] = false
699
-
700
- cmd.wont_match regexify(" --profile-ruby", :partial_line)
701
- end
702
- end
703
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
704
-
705
- describe "for bourne shells" do
706
-
707
- before { platform.stubs(:shell_type).returns("bourne") }
708
-
709
- let(:base) { "/tmp/kitchen/" }
710
- let(:custom_base) { "/a/b/" }
711
- let(:custom_root) { "/a/b" }
712
-
713
- common_shell_specs
714
- common_modern_shell_specs
715
-
716
- it "uses bourne shell" do
717
- cmd.must_match(/\Ash -c '$/)
718
- cmd.must_match(/'\Z/)
719
- end
720
-
721
- it "ends with a single quote" do
722
- cmd.must_match(/'\Z/)
723
- end
724
-
725
- it "exports http_proxy & HTTP_PROXY when :http_proxy is set" do
726
- config[:http_proxy] = "http://proxy"
727
-
728
- cmd.lines.to_a[1..2].must_equal([
729
- %{http_proxy="http://proxy"; export http_proxy\n},
730
- %{HTTP_PROXY="http://proxy"; export HTTP_PROXY\n}
731
- ])
732
- end
733
-
734
- it "exports https_proxy & HTTPS_PROXY when :https_proxy is set" do
735
- config[:https_proxy] = "https://proxy"
736
-
737
- cmd.lines.to_a[1..2].must_equal([
738
- %{https_proxy="https://proxy"; export https_proxy\n},
739
- %{HTTPS_PROXY="https://proxy"; export HTTPS_PROXY\n}
740
- ])
741
- end
742
-
743
- it "exports all http proxy variables when both are set" do
744
- config[:http_proxy] = "http://proxy"
745
- config[:https_proxy] = "https://proxy"
746
-
747
- cmd.lines.to_a[1..4].must_equal([
748
- %{http_proxy="http://proxy"; export http_proxy\n},
749
- %{HTTP_PROXY="http://proxy"; export HTTP_PROXY\n},
750
- %{https_proxy="https://proxy"; export https_proxy\n},
751
- %{HTTPS_PROXY="https://proxy"; export HTTPS_PROXY\n}
752
- ])
753
- end
754
-
755
- it "does no powershell PATH reloading for older chef omnibus packages" do
756
- cmd.wont_match regexify(%{[System.Environment]::})
757
- end
758
-
759
- it "uses sudo for chef-client when configured" do
760
- config[:chef_omnibus_root] = "/c"
761
- config[:sudo] = true
762
-
763
- cmd.must_match regexify("sudo -E /c/bin/chef-client ", :partial_line)
764
- end
765
-
766
- it "does not use sudo for chef-client when configured" do
767
- config[:chef_omnibus_root] = "/c"
768
- config[:sudo] = false
769
-
770
- cmd.must_match regexify("/c/bin/chef-client ", :partial_line)
771
- cmd.wont_match regexify("sudo -E /c/bin/chef-client ", :partial_line)
772
- end
773
- end
774
-
775
- describe "for powershell shells on windows os types" do
776
-
777
- before do
778
- platform.stubs(:shell_type).returns("powershell")
779
- platform.stubs(:os_type).returns("windows")
780
- end
781
-
782
- let(:base) { "$env:TEMP\\kitchen\\" }
783
- let(:custom_base) { "\\a\\b\\" }
784
- let(:custom_root) { "\\a\\b" }
785
-
786
- common_shell_specs
787
- common_modern_shell_specs
788
-
789
- it "exports http_proxy & HTTP_PROXY when :http_proxy is set" do
790
- config[:http_proxy] = "http://proxy"
791
-
792
- cmd.lines.to_a[0..1].must_equal([
793
- %{$env:http_proxy = "http://proxy"\n},
794
- %{$env:HTTP_PROXY = "http://proxy"\n}
795
- ])
796
- end
797
-
798
- it "exports https_proxy & HTTPS_PROXY when :https_proxy is set" do
799
- config[:https_proxy] = "https://proxy"
800
-
801
- cmd.lines.to_a[0..1].must_equal([
802
- %{$env:https_proxy = "https://proxy"\n},
803
- %{$env:HTTPS_PROXY = "https://proxy"\n}
804
- ])
805
- end
806
-
807
- it "exports all http proxy variables when both are set" do
808
- config[:http_proxy] = "http://proxy"
809
- config[:https_proxy] = "https://proxy"
810
-
811
- cmd.lines.to_a[0..3].must_equal([
812
- %{$env:http_proxy = "http://proxy"\n},
813
- %{$env:HTTP_PROXY = "http://proxy"\n},
814
- %{$env:https_proxy = "https://proxy"\n},
815
- %{$env:HTTPS_PROXY = "https://proxy"\n}
816
- ])
817
- end
818
-
819
- it "reloads PATH for older chef omnibus packages" do
820
- cmd.must_match regexify("$env:PATH = " +
821
- %{[System.Environment]::GetEnvironmentVariable("PATH","Machine")})
822
- end
823
-
824
- it "calls the chef-client command from :chef_client_path" do
825
- config[:chef_client_path] = "\\r\\chef-client.bat"
826
-
827
- cmd.must_match regexify("& \\r\\chef-client.bat ", :partial_line)
828
- end
829
- end
830
- end
831
-
832
- describe "for old Chef versions" do
833
-
834
- before do
835
- config[:require_chef_omnibus] = "10.20"
836
- end
837
-
838
- def self.common_old_shell_specs
839
- it "does not set local mode flag" do
840
- cmd.wont_match regexify(" --local-mode", :partial_line)
841
- end
842
-
843
- it "does not set chef zero host flag for custom host" do
844
- config[:chef_zero_host] = "192.168.0.1"
845
-
846
- cmd.wont_match regexify(" --chef-zero-host 192.168.0.1", :partial_line)
847
- end
848
-
849
- it "does not set chef zero port flag for custom port" do
850
- config[:chef_zero_port] = 123
851
-
852
- cmd.wont_match regexify(" --chef-zero-port 123", :partial_line)
853
- end
854
- end
855
-
856
- describe "for bourne shells" do
857
-
858
- before do
859
- platform.stubs(:shell_type).returns("bourne")
860
- config[:ruby_bindir] = "/r/bin"
861
- end
862
-
863
- let(:base) { "/tmp/kitchen/" }
864
- let(:custom_base) { "/a/b/" }
865
- let(:custom_root) { "/a/b" }
866
-
867
- common_shell_specs
868
- common_old_shell_specs
869
-
870
- it "uses bourne shell" do
871
- cmd.must_match(/\Ash -c '$/)
872
- cmd.must_match(/'\Z/)
873
- end
874
-
875
- it "ends with a single quote" do
876
- cmd.must_match(/'\Z/)
877
- end
878
-
879
- it "uses sudo for ruby when configured" do
880
- config[:root_path] = "/x"
881
- config[:sudo] = true
882
-
883
- cmd.must_match regexify(
884
- "sudo -E /r/bin/ruby /x/chef-client-zero.rb ", :partial_line)
885
- end
886
-
887
- it "does not use sudo for ruby when configured" do
888
- config[:root_path] = "/x"
889
- config[:sudo] = false
890
-
891
- cmd.must_match regexify(
892
- "/r/bin/ruby /x/chef-client-zero.rb ", :partial_line)
893
- cmd.wont_match regexify(
894
- "sudo -E /r/bin/ruby /x/chef-client-zero.rb ", :partial_line)
895
- end
896
-
897
- it "sets the CHEF_REPO_PATH environment variable" do
898
- config[:root_path] = "/r"
899
-
900
- cmd.must_match regexify(
901
- %{CHEF_REPO_PATH="/r"; export CHEF_REPO_PATH})
902
- end
903
-
904
- it "sets the GEM_HOME environment variable" do
905
- config[:root_path] = "/r"
906
-
907
- cmd.must_match regexify(
908
- %{GEM_HOME="/r/chef-client-zero-gems"; export GEM_HOME})
909
- end
910
-
911
- it "sets the GEM_PATH environment variable" do
912
- config[:root_path] = "/r"
913
-
914
- cmd.must_match regexify(
915
- %{GEM_PATH="/r/chef-client-zero-gems"; export GEM_PATH})
916
- end
917
-
918
- it "sets the GEM_CACHE environment variable" do
919
- config[:root_path] = "/r"
920
-
921
- cmd.must_match regexify(
922
- %{GEM_CACHE="/r/chef-client-zero-gems/cache"; export GEM_CACHE})
923
- end
924
-
925
- it "does no powershell PATH reloading for older chef omnibus packages" do
926
- cmd.wont_match regexify(%{[System.Environment]::})
927
- end
928
- end
929
-
930
- describe "for powershell shells on windows os types" do
931
-
932
- before do
933
- platform.stubs(:shell_type).returns("powershell")
934
- platform.stubs(:os_type).returns("windows")
935
- config[:ruby_bindir] = "\\r\\bin"
936
- end
937
-
938
- let(:base) { "$env:TEMP\\kitchen\\" }
939
- let(:custom_base) { "\\a\\b\\" }
940
- let(:custom_root) { "\\a\\b" }
941
-
942
- common_shell_specs
943
- common_old_shell_specs
944
-
945
- it "calls ruby from :ruby_bindir" do
946
- config[:root_path] = "\\x"
947
-
948
- cmd.must_match regexify(
949
- "\\r\\bin\\ruby.exe \\x\\chef-client-zero.rb ", :partial_line)
950
- end
951
-
952
- it "sets the CHEF_REPO_PATH environment variable" do
953
- config[:root_path] = "\\r"
954
-
955
- cmd.must_match regexify(
956
- %{$env:CHEF_REPO_PATH = "\\r"})
957
- end
958
-
959
- it "sets the GEM_HOME environment variable" do
960
- config[:root_path] = "\\r"
961
-
962
- cmd.must_match regexify(
963
- %{$env:GEM_HOME = "\\r\\chef-client-zero-gems"})
964
- end
965
-
966
- it "sets the GEM_PATH environment variable" do
967
- config[:root_path] = "\\r"
968
-
969
- cmd.must_match regexify(
970
- %{$env:GEM_PATH = "\\r\\chef-client-zero-gems"})
971
- end
972
-
973
- it "sets the GEM_CACHE environment variable" do
974
- config[:root_path] = "\\r"
975
-
976
- cmd.must_match regexify(
977
- %{$env:GEM_CACHE = "\\r\\chef-client-zero-gems\\cache"})
978
- end
979
-
980
- it "reloads PATH for older chef omnibus packages" do
981
- cmd.must_match regexify("$env:PATH = " +
982
- %{[System.Environment]::GetEnvironmentVariable("PATH","Machine")})
983
- end
984
- end
985
- end
986
- end
987
-
988
- def info_line(msg)
989
- %r{^I, .* : #{Regexp.escape(msg)}$}
990
- end
991
-
992
- def debug_line_starting_with(msg)
993
- %r{^D, .* : #{Regexp.escape(msg)}}
994
- end
995
-
996
- def regexify(str, line = :whole_line)
997
- r = Regexp.escape(str)
998
- r = "^\s*#{r}$" if line == :whole_line
999
- Regexp.new(r)
1000
- end
1001
- end
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"
22
+ require "kitchen/provisioner/chef_zero"
23
+
24
+ describe Kitchen::Provisioner::ChefZero do
25
+
26
+ let(:logged_output) { StringIO.new }
27
+ let(:logger) { Logger.new(logged_output) }
28
+ let(:platform) { stub(:os_type => nil) }
29
+ let(:suite) { stub(:name => "fries") }
30
+
31
+ let(:config) do
32
+ { :test_base_path => "/b", :kitchen_root => "/r" }
33
+ end
34
+
35
+ let(:instance) do
36
+ stub(
37
+ :name => "coolbeans",
38
+ :logger => logger,
39
+ :suite => suite,
40
+ :platform => platform
41
+ )
42
+ end
43
+
44
+ let(:provisioner) do
45
+ Kitchen::Provisioner::ChefZero.new(config).finalize_config!(instance)
46
+ end
47
+
48
+ it "provisioner api_version is 2" do
49
+ provisioner.diagnose_plugin[:api_version].must_equal 2
50
+ end
51
+
52
+ it "plugin_version is set to Kitchen::VERSION" do
53
+ provisioner.diagnose_plugin[:version].must_equal Kitchen::VERSION
54
+ end
55
+
56
+ describe "default config" do
57
+
58
+ describe "for unix operating systems" do
59
+
60
+ before { platform.stubs(:os_type).returns("unix") }
61
+
62
+ it "sets :chef_client_path to a path using :chef_omnibus_root" do
63
+ config[:chef_omnibus_root] = "/nice/place"
64
+
65
+ provisioner[:chef_client_path].
66
+ must_equal "/nice/place/bin/chef-client"
67
+ end
68
+
69
+ it "sets :ruby_bindir to use an Omnibus Ruby" do
70
+ config[:chef_omnibus_root] = "/nice"
71
+
72
+ provisioner[:ruby_bindir].must_equal "/nice/embedded/bin"
73
+ end
74
+ end
75
+
76
+ describe "for windows operating systems" do
77
+
78
+ before { platform.stubs(:os_type).returns("windows") }
79
+
80
+ it "sets :chef_client_path to a path using :chef_omnibus_root" do
81
+ config[:chef_omnibus_root] = "$env:systemdrive\\nice\\place"
82
+
83
+ provisioner[:chef_client_path].
84
+ must_equal "$env:systemdrive\\nice\\place\\bin\\chef-client.bat"
85
+ end
86
+
87
+ it "sets :ruby_bindir to use an Omnibus Ruby" do
88
+ config[:chef_omnibus_root] = "c:\\nice"
89
+
90
+ provisioner[:ruby_bindir].must_equal "c:\\nice\\embedded\\bin"
91
+ end
92
+ end
93
+
94
+ it "sets :client_rb to an empty Hash" do
95
+ provisioner[:client_rb].must_equal Hash.new
96
+ end
97
+
98
+ it "sets :json_attributes to true" do
99
+ provisioner[:json_attributes].must_equal true
100
+ end
101
+
102
+ it "does not set :chef_zero_host" do
103
+ provisioner[:chef_zero_host].must_equal nil
104
+ end
105
+
106
+ it "sets :chef_zero_port to 8889" do
107
+ provisioner[:chef_zero_port].must_equal 8889
108
+ end
109
+ end
110
+
111
+ describe "#create_sandbox" do
112
+
113
+ before do
114
+ @root = Dir.mktmpdir
115
+ config[:kitchen_root] = @root
116
+ end
117
+
118
+ after do
119
+ FileUtils.remove_entry(@root)
120
+ begin
121
+ provisioner.cleanup_sandbox
122
+ rescue # rubocop:disable Lint/HandleExceptions
123
+ end
124
+ end
125
+
126
+ describe "client.rb file" do
127
+
128
+ let(:file) do
129
+ IO.read(sandbox_path("client.rb")).lines.map(&:chomp)
130
+ end
131
+
132
+ it "creates a client.rb" do
133
+ provisioner.create_sandbox
134
+
135
+ sandbox_path("client.rb").file?.must_equal true
136
+ end
137
+
138
+ it "logs a message on info" do
139
+ provisioner.create_sandbox
140
+
141
+ logged_output.string.must_match info_line("Preparing client.rb")
142
+ end
143
+
144
+ it "logs a message on debug" do
145
+ provisioner.create_sandbox
146
+
147
+ logged_output.string.
148
+ must_match debug_line_starting_with("Creating client.rb from {")
149
+ end
150
+
151
+ describe "defaults" do
152
+
153
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
154
+ def self.common_client_rb_specs
155
+ it "sets node_name to the instance name" do
156
+ file.must_include %{node_name "#{instance.name}"}
157
+ end
158
+
159
+ it "sets checksum_path" do
160
+ file.must_include %{checksum_path "#{base}checksums"}
161
+ end
162
+
163
+ it "sets file_backup_path" do
164
+ file.must_include %{file_backup_path "#{base}backup"}
165
+ end
166
+
167
+ it "sets cookbook_path" do
168
+ file.must_include %{cookbook_path } +
169
+ %{["#{base}cookbooks", "#{base}site-cookbooks"]}
170
+ end
171
+
172
+ it "sets data_bag_path" do
173
+ file.must_include %{data_bag_path "#{base}data_bags"}
174
+ end
175
+
176
+ it "sets environment_path" do
177
+ file.must_include %{environment_path "#{base}environments"}
178
+ end
179
+
180
+ it "sets node_path" do
181
+ file.must_include %{node_path "#{base}nodes"}
182
+ end
183
+
184
+ it "sets role_path" do
185
+ file.must_include %{role_path "#{base}roles"}
186
+ end
187
+
188
+ it "sets client_path" do
189
+ file.must_include %{client_path "#{base}clients"}
190
+ end
191
+
192
+ it "sets user_path" do
193
+ file.must_include %{user_path "#{base}users"}
194
+ end
195
+
196
+ it "sets validation_key" do
197
+ file.must_include %{validation_key "#{base}validation.pem"}
198
+ end
199
+
200
+ it "sets client_key" do
201
+ file.must_include %{client_key "#{base}client.pem"}
202
+ end
203
+
204
+ it "sets chef_server_url" do
205
+ file.must_include %{chef_server_url "http://127.0.0.1:8889"}
206
+ end
207
+
208
+ it "sets encrypted_data_bag_secret" do
209
+ file.must_include %{encrypted_data_bag_secret } +
210
+ %{"#{base}encrypted_data_bag_secret"}
211
+ end
212
+ end
213
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
214
+
215
+ describe "for unix os types" do
216
+
217
+ before do
218
+ platform.stubs(:os_type).returns("unix")
219
+ provisioner.create_sandbox
220
+ end
221
+
222
+ let(:base) { "/tmp/kitchen/" }
223
+
224
+ common_client_rb_specs
225
+ end
226
+
227
+ describe "for windows os types with full path" do
228
+
229
+ before do
230
+ platform.stubs(:os_type).returns("windows")
231
+ config[:root_path] = "\\a\\b"
232
+ provisioner.create_sandbox
233
+ end
234
+
235
+ let(:base) { "\\\\a\\\\b\\\\" }
236
+
237
+ common_client_rb_specs
238
+ end
239
+
240
+ describe "for windows os types with $env:TEMP prefixed paths" do
241
+
242
+ before do
243
+ platform.stubs(:os_type).returns("windows")
244
+ config[:root_path] = "$env:TEMP\\a"
245
+ provisioner.create_sandbox
246
+ end
247
+
248
+ let(:base) { "\#{ENV['TEMP']}\\\\a\\\\" }
249
+
250
+ common_client_rb_specs
251
+ end
252
+ end
253
+
254
+ it "supports overwriting defaults" do
255
+ config[:client_rb] = {
256
+ :node_name => "eagles",
257
+ :user_path => "/a/b/c/u",
258
+ :client_key => "lol"
259
+ }
260
+ provisioner.create_sandbox
261
+
262
+ file.must_include %{node_name "eagles"}
263
+ file.must_include %{user_path "/a/b/c/u"}
264
+ file.must_include %{client_key "lol"}
265
+ end
266
+
267
+ it " supports adding new configuration" do
268
+ config[:client_rb] = {
269
+ :dark_secret => "golang"
270
+ }
271
+ provisioner.create_sandbox
272
+
273
+ file.must_include %{dark_secret "golang"}
274
+ end
275
+
276
+ it "formats array values correctly" do
277
+ config[:client_rb] = {
278
+ :foos => %w[foo1 foo2]
279
+ }
280
+ provisioner.create_sandbox
281
+
282
+ file.must_include %{foos ["foo1", "foo2"]}
283
+ end
284
+
285
+ it "formats integer values correctly" do
286
+ config[:client_rb] = {
287
+ :foo => 7
288
+ }
289
+ provisioner.create_sandbox
290
+
291
+ file.must_include %{foo 7}
292
+ end
293
+
294
+ it "formats symbol-looking string values correctly" do
295
+ config[:client_rb] = {
296
+ :foo => ":bar"
297
+ }
298
+ provisioner.create_sandbox
299
+
300
+ file.must_include %{foo :bar}
301
+ end
302
+
303
+ it "formats boolean values correctly" do
304
+ config[:client_rb] = {
305
+ :foo => false,
306
+ :bar => true
307
+ }
308
+ provisioner.create_sandbox
309
+
310
+ file.must_include %{foo false}
311
+ file.must_include %{bar true}
312
+ end
313
+ end
314
+
315
+ describe "validation.pem file" do
316
+
317
+ it "creates file" do
318
+ provisioner.create_sandbox
319
+
320
+ sandbox_path("validation.pem").file?.must_equal true
321
+ end
322
+
323
+ it "logs a message on info" do
324
+ provisioner.create_sandbox
325
+
326
+ logged_output.string.must_match info_line("Preparing validation.pem")
327
+ end
328
+
329
+ it "logs a message on debug" do
330
+ provisioner.create_sandbox
331
+
332
+ logged_output.string.
333
+ must_match debug_line_starting_with("Using a dummy validation.pem")
334
+ end
335
+ end
336
+
337
+ describe "chef-client-zero.rb file" do
338
+
339
+ describe "for modern Chef versions" do
340
+
341
+ before { config[:require_chef_omnibus] = "11.10" }
342
+
343
+ it "does not create the file" do
344
+ provisioner.create_sandbox
345
+
346
+ sandbox_path("chef-client-zero.rb").file?.must_equal false
347
+ end
348
+
349
+ it "a version of '11' is still considered modern" do
350
+ config[:require_chef_omnibus] = "11"
351
+ provisioner.create_sandbox
352
+
353
+ sandbox_path("chef-client-zero.rb").file?.must_equal false
354
+ end
355
+
356
+ it "a version of 11 is still considered modern" do
357
+ config[:require_chef_omnibus] = 11
358
+ provisioner.create_sandbox
359
+
360
+ sandbox_path("chef-client-zero.rb").file?.must_equal false
361
+ end
362
+ end
363
+
364
+ describe "for old Chef versions" do
365
+
366
+ before { config[:require_chef_omnibus] = "10.20" }
367
+
368
+ it "creates the file when using an old Chef version" do
369
+ provisioner.create_sandbox
370
+
371
+ sandbox_path("chef-client-zero.rb").file?.must_equal true
372
+ end
373
+
374
+ it "logs a message on info" do
375
+ provisioner.create_sandbox
376
+
377
+ logged_output.string.
378
+ must_match info_line("Preparing chef-client-zero.rb")
379
+ end
380
+
381
+ it "logs a message on debug" do
382
+ provisioner.create_sandbox
383
+
384
+ logged_output.string.must_match debug_line_starting_with(
385
+ "Using a vendored chef-client-zero.rb")
386
+ end
387
+ end
388
+ end
389
+
390
+ def sandbox_path(path)
391
+ Pathname.new(provisioner.sandbox_path).join(path)
392
+ end
393
+ end
394
+
395
+ describe "#prepare_command" do
396
+
397
+ let(:cmd) { provisioner.prepare_command }
398
+
399
+ describe "for modern Chef versions" do
400
+
401
+ before { config[:require_chef_omnibus] = "11.10" }
402
+
403
+ it "returns nil" do
404
+ cmd.must_equal nil
405
+ end
406
+ end
407
+
408
+ describe "for old Chef versions" do
409
+
410
+ before { config[:require_chef_omnibus] = "10.20" }
411
+
412
+ describe "for bourne shells" do
413
+
414
+ before do
415
+ platform.stubs(:shell_type).returns("bourne")
416
+ config[:ruby_bindir] = "/rbd"
417
+ end
418
+
419
+ it "uses bourne shell" do
420
+ cmd.must_match(/\Ash -c '$/)
421
+ cmd.must_match(/'\Z/)
422
+ end
423
+
424
+ it "ends with a single quote" do
425
+ cmd.must_match(/'\Z/)
426
+ end
427
+
428
+ it "exports http_proxy & HTTP_PROXY when :http_proxy is set" do
429
+ config[:http_proxy] = "http://proxy"
430
+
431
+ cmd.lines.to_a[1..2].must_equal([
432
+ %{http_proxy="http://proxy"; export http_proxy\n},
433
+ %{HTTP_PROXY="http://proxy"; export HTTP_PROXY\n}
434
+ ])
435
+ end
436
+
437
+ it "exports https_proxy & HTTPS_PROXY when :https_proxy is set" do
438
+ config[:https_proxy] = "https://proxy"
439
+
440
+ cmd.lines.to_a[1..2].must_equal([
441
+ %{https_proxy="https://proxy"; export https_proxy\n},
442
+ %{HTTPS_PROXY="https://proxy"; export HTTPS_PROXY\n}
443
+ ])
444
+ end
445
+
446
+ it "exports all http proxy variables when both are set" do
447
+ config[:http_proxy] = "http://proxy"
448
+ config[:https_proxy] = "https://proxy"
449
+
450
+ cmd.lines.to_a[1..4].must_equal([
451
+ %{http_proxy="http://proxy"; export http_proxy\n},
452
+ %{HTTP_PROXY="http://proxy"; export HTTP_PROXY\n},
453
+ %{https_proxy="https://proxy"; export https_proxy\n},
454
+ %{HTTPS_PROXY="https://proxy"; export HTTPS_PROXY\n}
455
+ ])
456
+ end
457
+
458
+ it "sets the CHEF_REPO_PATH environment variable" do
459
+ config[:root_path] = "/r"
460
+
461
+ cmd.must_match regexify(
462
+ %{CHEF_REPO_PATH="/r"; export CHEF_REPO_PATH})
463
+ end
464
+
465
+ it "sets the GEM_HOME environment variable" do
466
+ config[:root_path] = "/r"
467
+
468
+ cmd.must_match regexify(
469
+ %{GEM_HOME="/r/chef-client-zero-gems"; export GEM_HOME})
470
+ end
471
+
472
+ it "sets the GEM_PATH environment variable" do
473
+ config[:root_path] = "/r"
474
+
475
+ cmd.must_match regexify(
476
+ %{GEM_PATH="/r/chef-client-zero-gems"; export GEM_PATH})
477
+ end
478
+
479
+ it "sets the GEM_CACHE environment variable" do
480
+ config[:root_path] = "/r"
481
+
482
+ cmd.must_match regexify(
483
+ %{GEM_CACHE="/r/chef-client-zero-gems/cache"; export GEM_CACHE})
484
+ end
485
+
486
+ it "prepends sudo for gem command when :sudo is set" do
487
+ config[:sudo] = true
488
+
489
+ cmd.must_match regexify(%{gem="sudo -E /rbd/gem"})
490
+ end
491
+
492
+ it "does not sudo for gem commands when :sudo is falsey" do
493
+ config[:sudo] = false
494
+
495
+ cmd.must_match regexify(%{gem="/rbd/gem"})
496
+ end
497
+ end
498
+
499
+ describe "for powershell shells on windows os types" do
500
+
501
+ before do
502
+ platform.stubs(:shell_type).returns("powershell")
503
+ platform.stubs(:os_type).returns("windows")
504
+ config[:root_path] = "\\r"
505
+ config[:ruby_bindir] = "\\rbd"
506
+ end
507
+
508
+ it "exports http_proxy & HTTP_PROXY when :http_proxy is set" do
509
+ config[:http_proxy] = "http://proxy"
510
+
511
+ cmd.lines.to_a[0..1].must_equal([
512
+ %{$env:http_proxy = "http://proxy"\n},
513
+ %{$env:HTTP_PROXY = "http://proxy"\n}
514
+ ])
515
+ end
516
+
517
+ it "exports https_proxy & HTTPS_PROXY when :https_proxy is set" do
518
+ config[:https_proxy] = "https://proxy"
519
+
520
+ cmd.lines.to_a[0..1].must_equal([
521
+ %{$env:https_proxy = "https://proxy"\n},
522
+ %{$env:HTTPS_PROXY = "https://proxy"\n}
523
+ ])
524
+ end
525
+
526
+ it "exports all http proxy variables when both are set" do
527
+ config[:http_proxy] = "http://proxy"
528
+ config[:https_proxy] = "https://proxy"
529
+
530
+ cmd.lines.to_a[0..3].must_equal([
531
+ %{$env:http_proxy = "http://proxy"\n},
532
+ %{$env:HTTP_PROXY = "http://proxy"\n},
533
+ %{$env:https_proxy = "https://proxy"\n},
534
+ %{$env:HTTPS_PROXY = "https://proxy"\n}
535
+ ])
536
+ end
537
+
538
+ it "sets the CHEF_REPO_PATH environment variable" do
539
+ config[:root_path] = "\\r"
540
+
541
+ cmd.must_match regexify(
542
+ %{$env:CHEF_REPO_PATH = "\\r"})
543
+ end
544
+
545
+ it "sets the GEM_HOME environment variable" do
546
+ config[:root_path] = "\\r"
547
+
548
+ cmd.must_match regexify(
549
+ %{$env:GEM_HOME = "\\r\\chef-client-zero-gems"})
550
+ end
551
+
552
+ it "sets the GEM_PATH environment variable" do
553
+ config[:root_path] = "\\r"
554
+
555
+ cmd.must_match regexify(
556
+ %{$env:GEM_PATH = "\\r\\chef-client-zero-gems"})
557
+ end
558
+
559
+ it "sets the GEM_CACHE environment variable" do
560
+ config[:root_path] = "\\r"
561
+
562
+ cmd.must_match regexify(
563
+ %{$env:GEM_CACHE = "\\r\\chef-client-zero-gems\\cache"})
564
+ end
565
+
566
+ it "sets the path to the gem command" do
567
+ cmd.must_match regexify(%{$gem = "\\rbd\\gem.bat"})
568
+ end
569
+ end
570
+ end
571
+ end
572
+
573
+ describe "#run_command" do
574
+
575
+ let(:cmd) { provisioner.run_command }
576
+
577
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
578
+ def self.common_shell_specs
579
+ it "sets config flag on chef-client" do
580
+ cmd.must_match regexify(
581
+ " --config #{base}client.rb", :partial_line)
582
+ end
583
+
584
+ it "sets config flag for custom root_path" do
585
+ config[:root_path] = custom_root
586
+
587
+ cmd.must_match regexify(
588
+ " --config #{custom_base}client.rb", :partial_line)
589
+ end
590
+
591
+ it "sets log level flag on chef-client to auto by default" do
592
+ cmd.must_match regexify(" --log_level auto", :partial_line)
593
+ end
594
+
595
+ it "set log level flag for custom level" do
596
+ config[:log_level] = :extreme
597
+
598
+ cmd.must_match regexify(" --log_level extreme", :partial_line)
599
+ end
600
+
601
+ it "sets force formatter flag on chef-solo" do
602
+ cmd.must_match regexify(" --force-formatter", :partial_line)
603
+ end
604
+
605
+ it "sets no color flag on chef-solo" do
606
+ cmd.must_match regexify(" --no-color", :partial_line)
607
+ end
608
+
609
+ it "sets json attributes flag on chef-client" do
610
+ cmd.must_match regexify(
611
+ " --json-attributes #{base}dna.json", :partial_line)
612
+ end
613
+
614
+ it "sets json attribtes flag for custom root_path" do
615
+ config[:root_path] = custom_root
616
+
617
+ cmd.must_match regexify(
618
+ " --json-attributes #{custom_base}dna.json", :partial_line)
619
+ end
620
+
621
+ it "does not set json attributes flag if config is falsey" do
622
+ config[:json_attributes] = false
623
+
624
+ cmd.wont_match regexify(" --json-attributes ", :partial_line)
625
+ end
626
+
627
+ it "sets logfile flag for custom value" do
628
+ config[:log_file] = "#{custom_base}out.log"
629
+
630
+ cmd.must_match regexify(
631
+ " --logfile #{custom_base}out.log", :partial_line)
632
+ end
633
+
634
+ it "does not set logfile flag by default" do
635
+ cmd.wont_match regexify(" --logfile ", :partial_line)
636
+ end
637
+
638
+ it "prefixs the whole command with the command_prefix if set" do
639
+ config[:command_prefix] = "my_prefix"
640
+
641
+ cmd.must_match(/\Amy_prefix /)
642
+ end
643
+
644
+ it "does not prefix the command if command_prefix is not set" do
645
+ config[:command_prefix] = nil
646
+
647
+ cmd.wont_match(/\Amy_prefix /)
648
+ end
649
+ end
650
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
651
+
652
+ describe "for modern Chef versions" do
653
+
654
+ before { config[:require_chef_omnibus] = "11.10" }
655
+
656
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
657
+ def self.common_modern_shell_specs
658
+ it "sets local mode flag on chef-client" do
659
+ cmd.must_match regexify(" --local-mode", :partial_line)
660
+ end
661
+
662
+ it "sets chef zero port flag on chef-client" do
663
+ cmd.must_match regexify(" --chef-zero-port 8889", :partial_line)
664
+ end
665
+
666
+ it "sets chef zero host flag for custom host" do
667
+ config[:chef_zero_host] = "192.168.0.1"
668
+
669
+ cmd.must_match regexify(" --chef-zero-host 192.168.0.1", :partial_line)
670
+ end
671
+
672
+ it "sets chef zero port flag for custom port" do
673
+ config[:chef_zero_port] = 123
674
+
675
+ cmd.must_match regexify(" --chef-zero-port 123", :partial_line)
676
+ end
677
+
678
+ it "does not set chef zero host flag when value is falsey" do
679
+ config[:chef_zero_host] = nil
680
+
681
+ cmd.wont_match regexify(" --chef-zero-host ", :partial_line)
682
+ end
683
+
684
+ it "does not set chef zero port flag when value is falsey" do
685
+ config[:chef_zero_port] = nil
686
+
687
+ cmd.wont_match regexify(" --chef-zero-port ", :partial_line)
688
+ end
689
+
690
+ it "sets profile-ruby flag when config element is set" do
691
+ config[:profile_ruby] = true
692
+
693
+ cmd.must_match regexify(
694
+ " --profile-ruby", :partial_line)
695
+ end
696
+
697
+ it "does not set profile-ruby flag when config element is falsey" do
698
+ config[:profile_ruby] = false
699
+
700
+ cmd.wont_match regexify(" --profile-ruby", :partial_line)
701
+ end
702
+ end
703
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
704
+
705
+ describe "for bourne shells" do
706
+
707
+ before { platform.stubs(:shell_type).returns("bourne") }
708
+
709
+ let(:base) { "/tmp/kitchen/" }
710
+ let(:custom_base) { "/a/b/" }
711
+ let(:custom_root) { "/a/b" }
712
+
713
+ common_shell_specs
714
+ common_modern_shell_specs
715
+
716
+ it "uses bourne shell" do
717
+ cmd.must_match(/\Ash -c '$/)
718
+ cmd.must_match(/'\Z/)
719
+ end
720
+
721
+ it "ends with a single quote" do
722
+ cmd.must_match(/'\Z/)
723
+ end
724
+
725
+ it "exports http_proxy & HTTP_PROXY when :http_proxy is set" do
726
+ config[:http_proxy] = "http://proxy"
727
+
728
+ cmd.lines.to_a[1..2].must_equal([
729
+ %{http_proxy="http://proxy"; export http_proxy\n},
730
+ %{HTTP_PROXY="http://proxy"; export HTTP_PROXY\n}
731
+ ])
732
+ end
733
+
734
+ it "exports https_proxy & HTTPS_PROXY when :https_proxy is set" do
735
+ config[:https_proxy] = "https://proxy"
736
+
737
+ cmd.lines.to_a[1..2].must_equal([
738
+ %{https_proxy="https://proxy"; export https_proxy\n},
739
+ %{HTTPS_PROXY="https://proxy"; export HTTPS_PROXY\n}
740
+ ])
741
+ end
742
+
743
+ it "exports all http proxy variables when both are set" do
744
+ config[:http_proxy] = "http://proxy"
745
+ config[:https_proxy] = "https://proxy"
746
+
747
+ cmd.lines.to_a[1..4].must_equal([
748
+ %{http_proxy="http://proxy"; export http_proxy\n},
749
+ %{HTTP_PROXY="http://proxy"; export HTTP_PROXY\n},
750
+ %{https_proxy="https://proxy"; export https_proxy\n},
751
+ %{HTTPS_PROXY="https://proxy"; export HTTPS_PROXY\n}
752
+ ])
753
+ end
754
+
755
+ it "does no powershell PATH reloading for older chef omnibus packages" do
756
+ cmd.wont_match regexify(%{[System.Environment]::})
757
+ end
758
+
759
+ it "uses sudo for chef-client when configured" do
760
+ config[:chef_omnibus_root] = "/c"
761
+ config[:sudo] = true
762
+
763
+ cmd.must_match regexify("sudo -E /c/bin/chef-client ", :partial_line)
764
+ end
765
+
766
+ it "does not use sudo for chef-client when configured" do
767
+ config[:chef_omnibus_root] = "/c"
768
+ config[:sudo] = false
769
+
770
+ cmd.must_match regexify("/c/bin/chef-client ", :partial_line)
771
+ cmd.wont_match regexify("sudo -E /c/bin/chef-client ", :partial_line)
772
+ end
773
+ end
774
+
775
+ describe "for powershell shells on windows os types" do
776
+
777
+ before do
778
+ platform.stubs(:shell_type).returns("powershell")
779
+ platform.stubs(:os_type).returns("windows")
780
+ end
781
+
782
+ let(:base) { "$env:TEMP\\kitchen\\" }
783
+ let(:custom_base) { "\\a\\b\\" }
784
+ let(:custom_root) { "\\a\\b" }
785
+
786
+ common_shell_specs
787
+ common_modern_shell_specs
788
+
789
+ it "exports http_proxy & HTTP_PROXY when :http_proxy is set" do
790
+ config[:http_proxy] = "http://proxy"
791
+
792
+ cmd.lines.to_a[0..1].must_equal([
793
+ %{$env:http_proxy = "http://proxy"\n},
794
+ %{$env:HTTP_PROXY = "http://proxy"\n}
795
+ ])
796
+ end
797
+
798
+ it "exports https_proxy & HTTPS_PROXY when :https_proxy is set" do
799
+ config[:https_proxy] = "https://proxy"
800
+
801
+ cmd.lines.to_a[0..1].must_equal([
802
+ %{$env:https_proxy = "https://proxy"\n},
803
+ %{$env:HTTPS_PROXY = "https://proxy"\n}
804
+ ])
805
+ end
806
+
807
+ it "exports all http proxy variables when both are set" do
808
+ config[:http_proxy] = "http://proxy"
809
+ config[:https_proxy] = "https://proxy"
810
+
811
+ cmd.lines.to_a[0..3].must_equal([
812
+ %{$env:http_proxy = "http://proxy"\n},
813
+ %{$env:HTTP_PROXY = "http://proxy"\n},
814
+ %{$env:https_proxy = "https://proxy"\n},
815
+ %{$env:HTTPS_PROXY = "https://proxy"\n}
816
+ ])
817
+ end
818
+
819
+ it "reloads PATH for older chef omnibus packages" do
820
+ cmd.must_match regexify("$env:PATH = " +
821
+ %{[System.Environment]::GetEnvironmentVariable("PATH","Machine")})
822
+ end
823
+
824
+ it "calls the chef-client command from :chef_client_path" do
825
+ config[:chef_client_path] = "\\r\\chef-client.bat"
826
+
827
+ cmd.must_match regexify("& \\r\\chef-client.bat ", :partial_line)
828
+ end
829
+ end
830
+ end
831
+
832
+ describe "for old Chef versions" do
833
+
834
+ before do
835
+ config[:require_chef_omnibus] = "10.20"
836
+ end
837
+
838
+ def self.common_old_shell_specs
839
+ it "does not set local mode flag" do
840
+ cmd.wont_match regexify(" --local-mode", :partial_line)
841
+ end
842
+
843
+ it "does not set chef zero host flag for custom host" do
844
+ config[:chef_zero_host] = "192.168.0.1"
845
+
846
+ cmd.wont_match regexify(" --chef-zero-host 192.168.0.1", :partial_line)
847
+ end
848
+
849
+ it "does not set chef zero port flag for custom port" do
850
+ config[:chef_zero_port] = 123
851
+
852
+ cmd.wont_match regexify(" --chef-zero-port 123", :partial_line)
853
+ end
854
+ end
855
+
856
+ describe "for bourne shells" do
857
+
858
+ before do
859
+ platform.stubs(:shell_type).returns("bourne")
860
+ config[:ruby_bindir] = "/r/bin"
861
+ end
862
+
863
+ let(:base) { "/tmp/kitchen/" }
864
+ let(:custom_base) { "/a/b/" }
865
+ let(:custom_root) { "/a/b" }
866
+
867
+ common_shell_specs
868
+ common_old_shell_specs
869
+
870
+ it "uses bourne shell" do
871
+ cmd.must_match(/\Ash -c '$/)
872
+ cmd.must_match(/'\Z/)
873
+ end
874
+
875
+ it "ends with a single quote" do
876
+ cmd.must_match(/'\Z/)
877
+ end
878
+
879
+ it "uses sudo for ruby when configured" do
880
+ config[:root_path] = "/x"
881
+ config[:sudo] = true
882
+
883
+ cmd.must_match regexify(
884
+ "sudo -E /r/bin/ruby /x/chef-client-zero.rb ", :partial_line)
885
+ end
886
+
887
+ it "does not use sudo for ruby when configured" do
888
+ config[:root_path] = "/x"
889
+ config[:sudo] = false
890
+
891
+ cmd.must_match regexify(
892
+ "/r/bin/ruby /x/chef-client-zero.rb ", :partial_line)
893
+ cmd.wont_match regexify(
894
+ "sudo -E /r/bin/ruby /x/chef-client-zero.rb ", :partial_line)
895
+ end
896
+
897
+ it "sets the CHEF_REPO_PATH environment variable" do
898
+ config[:root_path] = "/r"
899
+
900
+ cmd.must_match regexify(
901
+ %{CHEF_REPO_PATH="/r"; export CHEF_REPO_PATH})
902
+ end
903
+
904
+ it "sets the GEM_HOME environment variable" do
905
+ config[:root_path] = "/r"
906
+
907
+ cmd.must_match regexify(
908
+ %{GEM_HOME="/r/chef-client-zero-gems"; export GEM_HOME})
909
+ end
910
+
911
+ it "sets the GEM_PATH environment variable" do
912
+ config[:root_path] = "/r"
913
+
914
+ cmd.must_match regexify(
915
+ %{GEM_PATH="/r/chef-client-zero-gems"; export GEM_PATH})
916
+ end
917
+
918
+ it "sets the GEM_CACHE environment variable" do
919
+ config[:root_path] = "/r"
920
+
921
+ cmd.must_match regexify(
922
+ %{GEM_CACHE="/r/chef-client-zero-gems/cache"; export GEM_CACHE})
923
+ end
924
+
925
+ it "does no powershell PATH reloading for older chef omnibus packages" do
926
+ cmd.wont_match regexify(%{[System.Environment]::})
927
+ end
928
+ end
929
+
930
+ describe "for powershell shells on windows os types" do
931
+
932
+ before do
933
+ platform.stubs(:shell_type).returns("powershell")
934
+ platform.stubs(:os_type).returns("windows")
935
+ config[:ruby_bindir] = "\\r\\bin"
936
+ end
937
+
938
+ let(:base) { "$env:TEMP\\kitchen\\" }
939
+ let(:custom_base) { "\\a\\b\\" }
940
+ let(:custom_root) { "\\a\\b" }
941
+
942
+ common_shell_specs
943
+ common_old_shell_specs
944
+
945
+ it "calls ruby from :ruby_bindir" do
946
+ config[:root_path] = "\\x"
947
+
948
+ cmd.must_match regexify(
949
+ "\\r\\bin\\ruby.exe \\x\\chef-client-zero.rb ", :partial_line)
950
+ end
951
+
952
+ it "sets the CHEF_REPO_PATH environment variable" do
953
+ config[:root_path] = "\\r"
954
+
955
+ cmd.must_match regexify(
956
+ %{$env:CHEF_REPO_PATH = "\\r"})
957
+ end
958
+
959
+ it "sets the GEM_HOME environment variable" do
960
+ config[:root_path] = "\\r"
961
+
962
+ cmd.must_match regexify(
963
+ %{$env:GEM_HOME = "\\r\\chef-client-zero-gems"})
964
+ end
965
+
966
+ it "sets the GEM_PATH environment variable" do
967
+ config[:root_path] = "\\r"
968
+
969
+ cmd.must_match regexify(
970
+ %{$env:GEM_PATH = "\\r\\chef-client-zero-gems"})
971
+ end
972
+
973
+ it "sets the GEM_CACHE environment variable" do
974
+ config[:root_path] = "\\r"
975
+
976
+ cmd.must_match regexify(
977
+ %{$env:GEM_CACHE = "\\r\\chef-client-zero-gems\\cache"})
978
+ end
979
+
980
+ it "reloads PATH for older chef omnibus packages" do
981
+ cmd.must_match regexify("$env:PATH = " +
982
+ %{[System.Environment]::GetEnvironmentVariable("PATH","Machine")})
983
+ end
984
+ end
985
+ end
986
+ end
987
+
988
+ def info_line(msg)
989
+ %r{^I, .* : #{Regexp.escape(msg)}$}
990
+ end
991
+
992
+ def debug_line_starting_with(msg)
993
+ %r{^D, .* : #{Regexp.escape(msg)}}
994
+ end
995
+
996
+ def regexify(str, line = :whole_line)
997
+ r = Regexp.escape(str)
998
+ r = "^\s*#{r}$" if line == :whole_line
999
+ Regexp.new(r)
1000
+ end
1001
+ end