test-kitchen 1.23.3 → 1.23.4

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 (254) hide show
  1. checksums.yaml +4 -4
  2. data/lib/kitchen/version.rb +1 -1
  3. data/support/chef-client-zero.rb +1 -1
  4. metadata +5 -324
  5. data/.gitattributes +0 -3
  6. data/.github/ISSUE_TEMPLATE.md +0 -56
  7. data/.github/lock.yml +0 -1
  8. data/.gitignore +0 -38
  9. data/.gitmodules +0 -0
  10. data/.kitchen.appveyor.yml +0 -25
  11. data/.kitchen.dokken.yml +0 -31
  12. data/.kitchen.proxy.yml +0 -27
  13. data/.rubocop.yml +0 -5
  14. data/.travis.yml +0 -57
  15. data/.yardopts +0 -3
  16. data/Berksfile +0 -3
  17. data/CHANGELOG.md +0 -1510
  18. data/CONTRIBUTING.md +0 -14
  19. data/ECOSYSTEM.md +0 -93
  20. data/Gemfile +0 -40
  21. data/Gemfile.proxy_tests +0 -4
  22. data/Guardfile +0 -42
  23. data/MAINTAINERS.md +0 -29
  24. data/README.md +0 -138
  25. data/RELEASE_NOTES.md +0 -167
  26. data/Rakefile +0 -77
  27. data/appveyor.yml +0 -47
  28. data/docs/CONTRIBUTING.md +0 -8
  29. data/docs/LICENSE +0 -22
  30. data/docs/README.md +0 -78
  31. data/docs/archetypes/default.md +0 -6
  32. data/docs/config.toml +0 -36
  33. data/docs/content/docs/_index.md +0 -5
  34. data/docs/content/docs/drivers/_index.md +0 -27
  35. data/docs/content/docs/drivers/azurerm.md +0 -44
  36. data/docs/content/docs/drivers/vagrant.md +0 -39
  37. data/docs/content/docs/getting-started/00-introduction.md +0 -14
  38. data/docs/content/docs/getting-started/01-installing.md +0 -64
  39. data/docs/content/docs/getting-started/02-getting-help.md +0 -59
  40. data/docs/content/docs/getting-started/03-creating-cookbook.md +0 -46
  41. data/docs/content/docs/getting-started/04-kitchen-yml.md +0 -56
  42. data/docs/content/docs/getting-started/05-instances.md +0 -79
  43. data/docs/content/docs/getting-started/06-writing-recipe.md +0 -21
  44. data/docs/content/docs/getting-started/07-running-converge.md +0 -134
  45. data/docs/content/docs/getting-started/08-manually-verifying.md +0 -55
  46. data/docs/content/docs/getting-started/09-writing-test.md +0 -49
  47. data/docs/content/docs/getting-started/10-running-verify.md +0 -120
  48. data/docs/content/docs/getting-started/11-running-test.md +0 -168
  49. data/docs/content/docs/getting-started/12-adding-platform.md +0 -206
  50. data/docs/content/docs/getting-started/13-adding-feature.md +0 -30
  51. data/docs/content/docs/getting-started/14-adding-suite.md +0 -60
  52. data/docs/content/docs/getting-started/15-adding-test.md +0 -66
  53. data/docs/content/docs/getting-started/16-adding-recipe.md +0 -53
  54. data/docs/content/docs/getting-started/17-excluding-platforms.md +0 -101
  55. data/docs/content/docs/getting-started/18-next-steps.md +0 -23
  56. data/docs/content/docs/getting-started/_index.md +0 -5
  57. data/docs/content/docs/provisioners/_index.md +0 -36
  58. data/docs/content/docs/provisioners/chef.md +0 -69
  59. data/docs/content/docs/provisioners/shell.md +0 -31
  60. data/docs/content/docs/reference/_index.md +0 -5
  61. data/docs/content/docs/reference/configuration.md +0 -53
  62. data/docs/content/docs/reference/examples.md +0 -97
  63. data/docs/content/docs/reference/faq.md +0 -58
  64. data/docs/content/docs/reference/fixtures.md +0 -32
  65. data/docs/content/docs/reference/glossary.md +0 -34
  66. data/docs/content/docs/reference/lifecycle-hooks.md +0 -68
  67. data/docs/content/docs/reference/reboots.md +0 -24
  68. data/docs/content/docs/verifiers/_index.md +0 -14
  69. data/docs/content/docs/verifiers/inspec.md +0 -44
  70. data/docs/content/docs/verifiers/serverspec.md +0 -20
  71. data/docs/static/images/chef-logo.png +0 -0
  72. data/docs/static/images/chef-logo.svg +0 -1
  73. data/docs/static/images/github-banner.png +0 -0
  74. data/docs/static/images/github-banner.svg +0 -71
  75. data/docs/static/images/kitchen-logo.png +0 -0
  76. data/docs/static/images/logo-block.svg +0 -222
  77. data/docs/static/images/logo.png +0 -0
  78. data/docs/static/images/logos-group.png +0 -0
  79. data/docs/static/images/terminal-1.png +0 -0
  80. data/docs/static/images/terminal-1.svg +0 -589
  81. data/docs/static/images/terminal-2.png +0 -0
  82. data/docs/static/images/terminal-2.svg +0 -235
  83. data/docs/static/images/terminal-3.png +0 -0
  84. data/docs/static/images/terminal-3.svg +0 -439
  85. data/docs/static/index.html +0 -59
  86. data/docs/static/javascripts/all.js +0 -348
  87. data/docs/static/javascripts/vendor/foundation.min.js +0 -4
  88. data/docs/static/javascripts/vendor/jquery.min.js +0 -5
  89. data/docs/static/javascripts/vendor/what-input.js +0 -336
  90. data/docs/static/stylesheets/site.css +0 -4667
  91. data/docs/themes/kitchen/layouts/_default/baseof.html +0 -53
  92. data/docs/themes/kitchen/layouts/_default/list.html +0 -4
  93. data/docs/themes/kitchen/layouts/_default/redirect.html +0 -10
  94. data/docs/themes/kitchen/layouts/_default/single.html +0 -6
  95. data/docs/themes/kitchen/layouts/partials/core/head.html +0 -6
  96. data/docs/themes/kitchen/layouts/partials/kitchen/footer.html +0 -18
  97. data/docs/themes/kitchen/layouts/partials/kitchen/head.html +0 -4
  98. data/docs/themes/kitchen/layouts/partials/kitchen/header.html +0 -26
  99. data/docs/themes/kitchen/layouts/partials/search-docs.html +0 -3
  100. data/docs/themes/kitchen/layouts/partials/sidebar.html +0 -33
  101. data/docs/themes/kitchen/layouts/shortcodes/button.html +0 -1
  102. data/docs/themes/kitchen/layouts/shortcodes/codeblock.html +0 -8
  103. data/docs/themes/kitchen/layouts/shortcodes/cta.html +0 -5
  104. data/docs/themes/kitchen/layouts/shortcodes/danger.html +0 -1
  105. data/docs/themes/kitchen/layouts/shortcodes/example_fqdn.html +0 -1
  106. data/docs/themes/kitchen/layouts/shortcodes/info.html +0 -1
  107. data/docs/themes/kitchen/layouts/shortcodes/ol-styled.html +0 -3
  108. data/docs/themes/kitchen/layouts/shortcodes/success.html +0 -1
  109. data/docs/themes/kitchen/layouts/shortcodes/tip.html +0 -1
  110. data/docs/themes/kitchen/layouts/shortcodes/warning.html +0 -1
  111. data/docs/themes/kitchen/static/css/kitchen.css +0 -10
  112. data/docs/themes/kitchen/static/css/kitchen.css.map +0 -7
  113. data/docs/themes/kitchen/static/fonts/Muli-Bold.ttf +0 -0
  114. data/docs/themes/kitchen/static/fonts/Muli-Regular.ttf +0 -0
  115. data/docs/themes/kitchen/static/fonts/Muli-SemiBold.ttf +0 -0
  116. data/docs/themes/kitchen/static/fonts/fontawesome/fa-brands-400.eot +0 -0
  117. data/docs/themes/kitchen/static/fonts/fontawesome/fa-brands-400.svg +0 -1104
  118. data/docs/themes/kitchen/static/fonts/fontawesome/fa-brands-400.ttf +0 -0
  119. data/docs/themes/kitchen/static/fonts/fontawesome/fa-brands-400.woff +0 -0
  120. data/docs/themes/kitchen/static/fonts/fontawesome/fa-brands-400.woff2 +0 -0
  121. data/docs/themes/kitchen/static/fonts/fontawesome/fa-regular-400.eot +0 -0
  122. data/docs/themes/kitchen/static/fonts/fontawesome/fa-regular-400.svg +0 -372
  123. data/docs/themes/kitchen/static/fonts/fontawesome/fa-regular-400.ttf +0 -0
  124. data/docs/themes/kitchen/static/fonts/fontawesome/fa-regular-400.woff +0 -0
  125. data/docs/themes/kitchen/static/fonts/fontawesome/fa-regular-400.woff2 +0 -0
  126. data/docs/themes/kitchen/static/fonts/fontawesome/fa-solid-900.eot +0 -0
  127. data/docs/themes/kitchen/static/fonts/fontawesome/fa-solid-900.svg +0 -1896
  128. data/docs/themes/kitchen/static/fonts/fontawesome/fa-solid-900.ttf +0 -0
  129. data/docs/themes/kitchen/static/fonts/fontawesome/fa-solid-900.woff +0 -0
  130. data/docs/themes/kitchen/static/fonts/fontawesome/fa-solid-900.woff2 +0 -0
  131. data/docs/themes/kitchen/static/images/chef-logo-light.svg +0 -36
  132. data/docs/themes/kitchen/static/images/chef-logo-white.svg +0 -38
  133. data/docs/themes/kitchen/static/images/chef-logo.svg +0 -37
  134. data/docs/themes/kitchen/static/images/favicon.ico +0 -0
  135. data/docs/themes/kitchen/static/js/scripts-all.js +0 -7
  136. data/docs/themes/kitchen/static/js/source/chef-hugo.js +0 -116
  137. data/docs/themes/kitchen/static/js/source/omnitruck.js +0 -82
  138. data/docs/themes/kitchen/static/js/source/segment.js +0 -52
  139. data/docs/themes/kitchen/static/sass/_buttons.scss +0 -161
  140. data/docs/themes/kitchen/static/sass/_core.scss +0 -24
  141. data/docs/themes/kitchen/static/sass/_forms.scss +0 -14
  142. data/docs/themes/kitchen/static/sass/_mixins.scss +0 -133
  143. data/docs/themes/kitchen/static/sass/_typography.scss +0 -34
  144. data/docs/themes/kitchen/static/sass/_variables.scss +0 -82
  145. data/docs/themes/kitchen/static/sass/kitchen.scss +0 -7
  146. data/docs/themes/kitchen/static/sass/kitchen/_footer.scss +0 -50
  147. data/docs/themes/kitchen/static/sass/kitchen/_header.scss +0 -187
  148. data/docs/themes/kitchen/static/sass/kitchen/_homepage.scss +0 -27
  149. data/docs/themes/kitchen/static/sass/kitchen/_utility-bar.scss +0 -173
  150. data/docs/themes/kitchen/static/sass/partials/_alerts.scss +0 -32
  151. data/docs/themes/kitchen/static/sass/partials/_bg.scss +0 -19
  152. data/docs/themes/kitchen/static/sass/partials/_blurbs.scss +0 -25
  153. data/docs/themes/kitchen/static/sass/partials/_callout.scss +0 -15
  154. data/docs/themes/kitchen/static/sass/partials/_cards.scss +0 -54
  155. data/docs/themes/kitchen/static/sass/partials/_dropdown.scss +0 -77
  156. data/docs/themes/kitchen/static/sass/partials/_grid.scss +0 -87
  157. data/docs/themes/kitchen/static/sass/partials/_padding.scss +0 -73
  158. data/docs/themes/kitchen/static/sass/partials/_sidebar.scss +0 -71
  159. data/docs/themes/kitchen/static/sass/partials/_tabs.scss +0 -125
  160. data/docs/themes/kitchen/static/sass/typography/_chroma.scss +0 -366
  161. data/docs/themes/kitchen/static/sass/typography/_code.scss +0 -72
  162. data/docs/themes/kitchen/static/sass/typography/_headers.scss +0 -90
  163. data/docs/themes/kitchen/static/sass/typography/_links.scss +0 -127
  164. data/docs/themes/kitchen/static/sass/typography/_lists.scss +0 -155
  165. data/docs/themes/kitchen/static/sass/typography/_prose.scss +0 -29
  166. data/docs/themes/kitchen/static/sass/typography/_text.scss +0 -221
  167. data/docs/themes/kitchen/static/sass/vendor/fontawesome/_animated.scss +0 -20
  168. data/docs/themes/kitchen/static/sass/vendor/fontawesome/_bordered-pulled.scss +0 -20
  169. data/docs/themes/kitchen/static/sass/vendor/fontawesome/_core.scss +0 -16
  170. data/docs/themes/kitchen/static/sass/vendor/fontawesome/_fixed-width.scss +0 -6
  171. data/docs/themes/kitchen/static/sass/vendor/fontawesome/_icons.scss +0 -992
  172. data/docs/themes/kitchen/static/sass/vendor/fontawesome/_larger.scss +0 -23
  173. data/docs/themes/kitchen/static/sass/vendor/fontawesome/_list.scss +0 -18
  174. data/docs/themes/kitchen/static/sass/vendor/fontawesome/_mixins.scss +0 -57
  175. data/docs/themes/kitchen/static/sass/vendor/fontawesome/_rotated-flipped.scss +0 -23
  176. data/docs/themes/kitchen/static/sass/vendor/fontawesome/_screen-reader.scss +0 -5
  177. data/docs/themes/kitchen/static/sass/vendor/fontawesome/_stacked.scss +0 -31
  178. data/docs/themes/kitchen/static/sass/vendor/fontawesome/_variables.scss +0 -1005
  179. data/docs/themes/kitchen/static/sass/vendor/fontawesome/fa-brands.scss +0 -21
  180. data/docs/themes/kitchen/static/sass/vendor/fontawesome/fa-regular.scss +0 -22
  181. data/docs/themes/kitchen/static/sass/vendor/fontawesome/fa-solid.scss +0 -23
  182. data/docs/themes/kitchen/static/sass/vendor/fontawesome/fontawesome.scss +0 -16
  183. data/docs/themes/kitchen/theme.toml +0 -8
  184. data/features/kitchen_action_commands.feature +0 -164
  185. data/features/kitchen_command.feature +0 -16
  186. data/features/kitchen_console_command.feature +0 -35
  187. data/features/kitchen_defaults.feature +0 -38
  188. data/features/kitchen_diagnose_command.feature +0 -96
  189. data/features/kitchen_help_command.feature +0 -16
  190. data/features/kitchen_init_command.feature +0 -254
  191. data/features/kitchen_list_command.feature +0 -140
  192. data/features/kitchen_login_command.feature +0 -62
  193. data/features/kitchen_sink_command.feature +0 -30
  194. data/features/kitchen_test_command.feature +0 -88
  195. data/features/step_definitions/gem_steps.rb +0 -24
  196. data/features/step_definitions/git_steps.rb +0 -5
  197. data/features/step_definitions/output_steps.rb +0 -5
  198. data/features/support/env.rb +0 -74
  199. data/spec/kitchen/base64_stream_spec.rb +0 -74
  200. data/spec/kitchen/cli_spec.rb +0 -54
  201. data/spec/kitchen/collection_spec.rb +0 -76
  202. data/spec/kitchen/color_spec.rb +0 -51
  203. data/spec/kitchen/config_spec.rb +0 -434
  204. data/spec/kitchen/configurable_spec.rb +0 -1113
  205. data/spec/kitchen/data_munger_spec.rb +0 -2800
  206. data/spec/kitchen/diagnostic_spec.rb +0 -128
  207. data/spec/kitchen/driver/base_spec.rb +0 -132
  208. data/spec/kitchen/driver/dummy_spec.rb +0 -193
  209. data/spec/kitchen/driver/exec_spec.rb +0 -75
  210. data/spec/kitchen/driver/proxy_spec.rb +0 -127
  211. data/spec/kitchen/driver/ssh_base_spec.rb +0 -1136
  212. data/spec/kitchen/driver_spec.rb +0 -106
  213. data/spec/kitchen/errors_spec.rb +0 -317
  214. data/spec/kitchen/instance_spec.rb +0 -1372
  215. data/spec/kitchen/lazy_hash_spec.rb +0 -113
  216. data/spec/kitchen/lifecycle_hooks_spec.rb +0 -171
  217. data/spec/kitchen/loader/yaml_spec.rb +0 -787
  218. data/spec/kitchen/logger_spec.rb +0 -425
  219. data/spec/kitchen/logging_spec.rb +0 -56
  220. data/spec/kitchen/login_command_spec.rb +0 -67
  221. data/spec/kitchen/metadata_chopper_spec.rb +0 -79
  222. data/spec/kitchen/platform_spec.rb +0 -88
  223. data/spec/kitchen/provisioner/base_spec.rb +0 -393
  224. data/spec/kitchen/provisioner/chef/policyfile_spec.rb +0 -140
  225. data/spec/kitchen/provisioner/chef_apply_spec.rb +0 -131
  226. data/spec/kitchen/provisioner/chef_base_spec.rb +0 -1565
  227. data/spec/kitchen/provisioner/chef_solo_spec.rb +0 -602
  228. data/spec/kitchen/provisioner/chef_zero_spec.rb +0 -1013
  229. data/spec/kitchen/provisioner/dummy_spec.rb +0 -96
  230. data/spec/kitchen/provisioner/shell_spec.rb +0 -623
  231. data/spec/kitchen/provisioner_spec.rb +0 -101
  232. data/spec/kitchen/shell_out_spec.rb +0 -146
  233. data/spec/kitchen/ssh_spec.rb +0 -584
  234. data/spec/kitchen/state_file_spec.rb +0 -122
  235. data/spec/kitchen/suite_spec.rb +0 -61
  236. data/spec/kitchen/transport/base_spec.rb +0 -140
  237. data/spec/kitchen/transport/exec_spec.rb +0 -79
  238. data/spec/kitchen/transport/ssh_spec.rb +0 -1317
  239. data/spec/kitchen/transport/winrm_spec.rb +0 -1320
  240. data/spec/kitchen/transport_spec.rb +0 -106
  241. data/spec/kitchen/util_spec.rb +0 -250
  242. data/spec/kitchen/verifier/base_spec.rb +0 -346
  243. data/spec/kitchen/verifier/busser_spec.rb +0 -580
  244. data/spec/kitchen/verifier/dummy_spec.rb +0 -96
  245. data/spec/kitchen/verifier/shell_spec.rb +0 -157
  246. data/spec/kitchen/verifier_spec.rb +0 -114
  247. data/spec/kitchen_spec.rb +0 -112
  248. data/spec/spec_helper.rb +0 -110
  249. data/spec/support/powershell_max_size_spec.rb +0 -39
  250. data/test-kitchen.gemspec +0 -49
  251. data/test/cookbooks/test_cookbook/metadata.rb +0 -6
  252. data/test/cookbooks/test_cookbook/recipes/default.rb +0 -1
  253. data/test/integration/default/default_spec.rb +0 -3
  254. data/testing_windows.md +0 -38
@@ -1,140 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- # Author:: Noah Kantrowitz
4
- #
5
- # Copyright (C) 2016, Noah Kantrowitz
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
- require "kitchen/provisioner/chef/policyfile"
21
-
22
- describe Kitchen::Provisioner::Chef::Policyfile do
23
- let(:policyfile) { "" }
24
- let(:path) { "" }
25
- let(:null_logger) do
26
- stub(fatal: nil, error: nil, warn: nil, info: nil,
27
- debug: nil, banner: nil)
28
- end
29
- let(:described_object) do
30
- Kitchen::Provisioner::Chef::Policyfile.new(policyfile, path, logger: null_logger)
31
- end
32
- let(:os) { "" }
33
- before do
34
- @original_rbconfig = RbConfig::CONFIG
35
- verbose = $VERBOSE
36
- $VERBOSE = nil
37
- RbConfig.const_set(:CONFIG, "host_os" => os)
38
- $VERBOSE = verbose
39
- end
40
- after do
41
- verbose = $VERBOSE
42
- $VERBOSE = nil
43
- RbConfig.const_set(:CONFIG, @original_rbconfig)
44
- $VERBOSE = verbose
45
- end
46
-
47
- # rubocop:disable Metrics/LineLength
48
- describe "#resolve" do
49
- subject { described_object.resolve }
50
-
51
- describe "on Unix" do
52
- let(:os) { "linux-gnu" }
53
-
54
- describe "with simple paths" do
55
- let(:policyfile) { "/home/user/cookbook/Policyfile.rb" }
56
- let(:path) { "/tmp/kitchen/cookbooks" }
57
- it do
58
- described_object.expects(:run_command).with("chef export /home/user/cookbook/Policyfile.rb /tmp/kitchen/cookbooks --force")
59
- subject
60
- end
61
- end
62
-
63
- describe "with Jenkins-y paths" do
64
- let(:policyfile) { "/home/jenkins/My Chef Cookbook/workspace/current/Policyfile.rb" }
65
- let(:path) { "/tmp/kitchen/cookbooks" }
66
- it do
67
- described_object.expects(:run_command).with('chef export /home/jenkins/My\\ Chef\\ Cookbook/workspace/current/Policyfile.rb /tmp/kitchen/cookbooks --force')
68
- subject
69
- end
70
- end
71
- end
72
-
73
- describe "on Windows" do
74
- let(:os) { "mswin" }
75
-
76
- describe "with simple paths" do
77
- let(:policyfile) { 'C:\\cookbook\\Policyfile.rb' }
78
- let(:path) { 'C:\\Temp\\kitchen\\cookbooks' }
79
- it do
80
- described_object.expects(:run_command).with('chef export C:\\cookbook\\Policyfile.rb C:\\Temp\\kitchen\\cookbooks --force')
81
- subject
82
- end
83
- end
84
-
85
- describe "with Jenkins-y paths" do
86
- let(:policyfile) { 'C:\\Program Files\\Jenkins\\My Chef Cookbook\\workspace\\current\\Policyfile.rb' }
87
- let(:path) { 'C:\\Temp\\kitchen\\cookbooks' }
88
- it do
89
- described_object.expects(:run_command).with('chef export "C:\\\\Program\\ Files\\\\Jenkins\\\\My\\ Chef\\ Cookbook\\\\workspace\\\\current\\\\Policyfile.rb" C:\\Temp\\kitchen\\cookbooks --force')
90
- subject
91
- end
92
- end
93
- end
94
- end
95
-
96
- describe "#compile" do
97
- subject { described_object.compile }
98
-
99
- describe "on Unix" do
100
- let(:os) { "linux-gnu" }
101
-
102
- describe "with simple paths" do
103
- let(:policyfile) { "/home/user/cookbook/Policyfile.rb" }
104
- it do
105
- described_object.expects(:run_command).with("chef install /home/user/cookbook/Policyfile.rb")
106
- subject
107
- end
108
- end
109
-
110
- describe "with Jenkins-y paths" do
111
- let(:policyfile) { "/home/jenkins/My Chef Cookbook/workspace/current/Policyfile.rb" }
112
- it do
113
- described_object.expects(:run_command).with('chef install /home/jenkins/My\\ Chef\\ Cookbook/workspace/current/Policyfile.rb')
114
- subject
115
- end
116
- end
117
- end
118
-
119
- describe "on Windows" do
120
- let(:os) { "mswin" }
121
-
122
- describe "with simple paths" do
123
- let(:policyfile) { 'C:\\cookbook\\Policyfile.rb' }
124
- it do
125
- described_object.expects(:run_command).with('chef install C:\\cookbook\\Policyfile.rb')
126
- subject
127
- end
128
- end
129
-
130
- describe "with Jenkins-y paths" do
131
- let(:policyfile) { 'C:\\Program Files\\Jenkins\\My Chef Cookbook\\workspace\\current\\Policyfile.rb' }
132
- it do
133
- described_object.expects(:run_command).with('chef install "C:\\\\Program\\ Files\\\\Jenkins\\\\My\\ Chef\\ Cookbook\\\\workspace\\\\current\\\\Policyfile.rb"')
134
- subject
135
- end
136
- end
137
- end
138
- end
139
- # rubocop:enable Metrics/LineLength
140
- end
@@ -1,131 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- # Author:: SAWANOBORI Yukihiko <sawanoboriyu@higanworks.com>)
4
- #
5
- # Copyright (C) 2015, HiganWorks LLC
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_apply"
23
-
24
- describe Kitchen::Provisioner::ChefApply do
25
- let(:logged_output) { StringIO.new }
26
- let(:logger) { Logger.new(logged_output) }
27
- let(:platform) { stub(os_type: nil) }
28
- let(:suite) { stub(name: "fries") }
29
-
30
- let(:config) do
31
- { test_base_path: "/b", kitchen_root: "/r" }
32
- end
33
-
34
- let(:instance) do
35
- stub(
36
- name: "coolbeans",
37
- logger: logger,
38
- suite: suite,
39
- platform: platform
40
- )
41
- end
42
-
43
- let(:provisioner) do
44
- Kitchen::Provisioner::ChefApply.new(config).finalize_config!(instance)
45
- end
46
-
47
- it "provisioner api_version is 2" do
48
- provisioner.diagnose_plugin[:api_version].must_equal 2
49
- end
50
-
51
- it "plugin_version is set to Kitchen::VERSION" do
52
- provisioner.diagnose_plugin[:version].must_equal Kitchen::VERSION
53
- end
54
-
55
- describe "default config" do
56
- it "sets :chef_apply_path to a path using :chef_omnibus_root" do
57
- config[:chef_omnibus_root] = "/nice/place"
58
-
59
- provisioner[:chef_apply_path].must_equal "/nice/place/bin/chef-apply"
60
- end
61
- end
62
-
63
- describe "#create_sandbox" do
64
- before do
65
- @root = Dir.mktmpdir
66
- config[:kitchen_root] = @root
67
- end
68
-
69
- after do
70
- FileUtils.remove_entry(@root)
71
- begin
72
- provisioner.cleanup_sandbox
73
- rescue # rubocop:disable Lint/HandleExceptions
74
- end
75
- end
76
- end
77
-
78
- describe "#run_command" do
79
- before do
80
- config[:run_list] = %w{appry_recipe1 appry_recipe2}
81
- end
82
-
83
- let(:cmd) { provisioner.run_command }
84
-
85
- describe "for bourne shells" do
86
- before { platform.stubs(:shell_type).returns("bourne") }
87
-
88
- it "uses bourne shell" do
89
- cmd.must_match(/\Ash -c '$/)
90
- cmd.must_match(/'\Z/)
91
- end
92
-
93
- it "uses sudo for chef-apply when configured" do
94
- config[:chef_omnibus_root] = "/c"
95
- config[:sudo] = true
96
-
97
- cmd.must_match regexify("sudo -E /c/bin/chef-apply apply/appry_recipe1.rb ", :partial_line)
98
- cmd.must_match regexify("sudo -E /c/bin/chef-apply apply/appry_recipe2.rb ", :partial_line)
99
- end
100
-
101
- it "does not use sudo for chef-apply when configured" do
102
- config[:chef_omnibus_root] = "/c"
103
- config[:sudo] = false
104
-
105
- cmd.must_match regexify("chef-apply apply/appry_recipe1.rb ", :partial_line)
106
- cmd.must_match regexify("chef-apply apply/appry_recipe2.rb ", :partial_line)
107
- cmd.wont_match regexify("sudo -E /c/bin/chef-apply ")
108
- end
109
-
110
- it "sets log level flag on chef-apply to auto by default" do
111
- cmd.must_match regexify(" --log_level auto", :partial_line)
112
- end
113
-
114
- it "set log level flag for custom level" do
115
- config[:log_level] = :extreme
116
-
117
- cmd.must_match regexify(" --log_level extreme", :partial_line)
118
- end
119
-
120
- it "sets no color flag on chef-apply" do
121
- cmd.must_match regexify(" --no-color", :partial_line)
122
- end
123
- end
124
- end
125
-
126
- def regexify(str, line = :whole_line)
127
- r = Regexp.escape(str)
128
- r = "^\s*#{r}$" if line == :whole_line
129
- Regexp.new(r)
130
- end
131
- end
@@ -1,1565 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
4
- #
5
- # Copyright (C) 2014, Fletcher Nichol
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
-
19
- require_relative "../../spec_helper"
20
-
21
- require "kitchen"
22
- require "kitchen/provisioner/chef_base"
23
-
24
- describe Kitchen::Provisioner::ChefBase do
25
- let(:logged_output) { StringIO.new }
26
- let(:logger) { Logger.new(logged_output) }
27
- let(:platform) { stub(os_type: nil) }
28
- let(:driver) { stub(cache_directory: nil) }
29
- let(:suite) { stub(name: "fries") }
30
- let(:default_version) { true }
31
-
32
- let(:config) do
33
- { test_base_path: "/basist", kitchen_root: "/rooty" }
34
- end
35
-
36
- let(:instance) do
37
- stub(
38
- name: "coolbeans",
39
- logger: logger,
40
- suite: suite,
41
- platform: platform,
42
- driver: driver
43
- )
44
- end
45
-
46
- let(:provisioner) do
47
- Class.new(Kitchen::Provisioner::ChefBase) do
48
- def calculate_path(path, _opts = {})
49
- "<calculated>/#{path}"
50
- end
51
- end.new(config).finalize_config!(instance)
52
- end
53
-
54
- describe "configuration" do
55
- describe "for unix operating systems" do
56
- before { platform.stubs(:os_type).returns("unix") }
57
-
58
- it ":chef_omnibus_url has a default" do
59
- provisioner[:chef_omnibus_url]
60
- .must_equal "https://omnitruck.chef.io/install.sh"
61
- end
62
-
63
- it ":chef_metadata_url defaults to nil" do
64
- provisioner[:chef_metadata_url].must_be_nil
65
- end
66
- end
67
-
68
- describe "for windows operating systems" do
69
- before { platform.stubs(:os_type).returns("windows") }
70
-
71
- it ":chef_omnibus_url has a default" do
72
- provisioner[:chef_omnibus_url]
73
- .must_equal "https://omnitruck.chef.io/install.sh"
74
- end
75
- end
76
-
77
- it ":require_chef_omnibus defaults to true" do
78
- provisioner[:require_chef_omnibus].must_equal true
79
- end
80
-
81
- it ":chef_omnibus_install_options defaults to nil" do
82
- provisioner[:chef_omnibus_install_options].must_be_nil
83
- end
84
-
85
- it ":run_list defaults to an empty array" do
86
- provisioner[:run_list].must_equal []
87
- end
88
-
89
- it ":attributes defaults to an empty hash" do
90
- provisioner[:attributes].must_equal Hash.new
91
- end
92
-
93
- it ":log_level defaults to auto" do
94
- provisioner[:log_level].must_equal "auto"
95
- end
96
-
97
- it ":log_level is debug when in debug mode" do
98
- config[:debug] = true
99
- provisioner[:log_level].must_equal "debug"
100
- end
101
-
102
- it ":log_file defaults to nil" do
103
- provisioner[:log_file].must_be_nil
104
- end
105
-
106
- it ":cookbook_files_glob includes a metadata file" do
107
- provisioner[:cookbook_files_glob].must_match %r{,metadata.\{json,rb\}}
108
- end
109
-
110
- it ":data_path uses calculate_path and is expanded" do
111
- provisioner[:data_path]
112
- .must_equal os_safe_root_path("/rooty/<calculated>/data")
113
- end
114
-
115
- it ":data_bags_path uses calculate_path and is expanded" do
116
- provisioner[:data_bags_path]
117
- .must_equal os_safe_root_path("/rooty/<calculated>/data_bags")
118
- end
119
-
120
- it ":environments_path uses calculate_path and is expanded" do
121
- provisioner[:environments_path]
122
- .must_equal os_safe_root_path("/rooty/<calculated>/environments")
123
- end
124
-
125
- it ":nodes_path uses calculate_path and is expanded" do
126
- provisioner[:nodes_path]
127
- .must_equal os_safe_root_path("/rooty/<calculated>/nodes")
128
- end
129
-
130
- it ":roles_path uses calculate_path and is expanded" do
131
- provisioner[:roles_path]
132
- .must_equal os_safe_root_path("/rooty/<calculated>/roles")
133
- end
134
-
135
- it ":clients_path uses calculate_path and is expanded" do
136
- provisioner[:clients_path]
137
- .must_equal os_safe_root_path("/rooty/<calculated>/clients")
138
- end
139
-
140
- it "...secret_key_path uses calculate_path and is expanded" do
141
- provisioner[:encrypted_data_bag_secret_key_path]
142
- .must_equal os_safe_root_path("/rooty/<calculated>/encrypted_data_bag_secret_key")
143
- end
144
-
145
- it ":product_name default to nil" do
146
- provisioner[:product_name].must_be_nil
147
- end
148
-
149
- it ":product_version defaults to :latest" do
150
- provisioner[:product_version].must_equal :latest
151
- end
152
-
153
- it ":channel defaults to :stable" do
154
- provisioner[:channel].must_equal :stable
155
- end
156
-
157
- it ":platform default to nil" do
158
- provisioner[:platform].must_be_nil
159
- end
160
-
161
- it ":platform_version default to nil" do
162
- provisioner[:platform_version].must_be_nil
163
- end
164
-
165
- it ":architecture default to nil" do
166
- provisioner[:architecture].must_be_nil
167
- end
168
-
169
- it ":download_url default to nil" do
170
- provisioner[:download_url].must_be_nil
171
- end
172
-
173
- it ":checksum default to nil" do
174
- provisioner[:checksum].must_be_nil
175
- end
176
-
177
- it ":retry_on_exit_code defaults to standard values" do
178
- provisioner[:retry_on_exit_code].must_equal [35, 213]
179
- end
180
- end
181
-
182
- describe "#install_command" do
183
- before do
184
- platform.stubs(:shell_type).returns("bourne")
185
- Mixlib::Install::ScriptGenerator.stubs(:new).returns(installer)
186
- end
187
-
188
- let(:installer) { stub(root: "/rooty", install_command: "make_it_so") }
189
-
190
- let(:cmd) { provisioner.install_command }
191
-
192
- let(:install_opts) do
193
- { omnibus_url: "https://omnitruck.chef.io/install.sh",
194
- project: nil, install_flags: nil,
195
- sudo_command: "sudo -E", http_proxy: nil, https_proxy: nil
196
- }
197
- end
198
-
199
- it "returns nil if :require_chef_omnibus is falsey" do
200
- config[:require_chef_omnibus] = false
201
-
202
- installer.expects(:root).never
203
- installer.expects(:install_command).never
204
- cmd.must_be_nil
205
- end
206
-
207
- describe "common behaviour" do
208
- before do
209
- installer.expects(:root).at_least_once.returns("/opt/chef")
210
- installer.expects(:install_command)
211
- end
212
-
213
- it "passes sensible defaults" do
214
- Mixlib::Install::ScriptGenerator.expects(:new)
215
- .with(default_version, false, install_opts).returns(installer)
216
- cmd
217
- end
218
-
219
- it "exports http_proxy & HTTP_PROXY when :http_proxy is set" do
220
- config[:http_proxy] = "http://proxy"
221
- install_opts[:http_proxy] = "http://proxy"
222
-
223
- Mixlib::Install::ScriptGenerator.expects(:new)
224
- .with(default_version, false, install_opts).returns(installer)
225
- cmd
226
- end
227
-
228
- it "exports https_proxy & HTTPS_PROXY when :https_proxy is set" do
229
- config[:https_proxy] = "https://proxy"
230
- install_opts[:https_proxy] = "https://proxy"
231
-
232
- Mixlib::Install::ScriptGenerator.expects(:new)
233
- .with(default_version, false, install_opts).returns(installer)
234
- cmd
235
- end
236
-
237
- it "exports all http proxy variables when both are set" do
238
- config[:http_proxy] = "http://proxy"
239
- config[:https_proxy] = "https://proxy"
240
- install_opts[:http_proxy] = "http://proxy"
241
- install_opts[:https_proxy] = "https://proxy"
242
-
243
- Mixlib::Install::ScriptGenerator.expects(:new)
244
- .with(default_version, false, install_opts).returns(installer)
245
- cmd
246
- end
247
-
248
- it "installs chef using :chef_omnibus_url, if necessary" do
249
- config[:chef_omnibus_url] = "FROM_HERE"
250
- install_opts[:omnibus_url] = "FROM_HERE"
251
-
252
- Mixlib::Install::ScriptGenerator.expects(:new)
253
- .with(default_version, false, install_opts).returns(installer)
254
- cmd
255
- end
256
-
257
- it "will install a specific version of chef, if necessary" do
258
- config[:require_chef_omnibus] = "1.2.3"
259
-
260
- Mixlib::Install::ScriptGenerator.expects(:new)
261
- .with("1.2.3", false, install_opts).returns(installer)
262
- cmd
263
- end
264
-
265
- it "will install a major/minor version of chef, if necessary" do
266
- config[:require_chef_omnibus] = "11.10"
267
-
268
- Mixlib::Install::ScriptGenerator.expects(:new)
269
- .with("11.10", false, install_opts).returns(installer)
270
- cmd
271
- end
272
-
273
- it "will install a major version of chef, if necessary" do
274
- config[:require_chef_omnibus] = "12"
275
-
276
- Mixlib::Install::ScriptGenerator.expects(:new)
277
- .with("12", false, install_opts).returns(installer)
278
- cmd
279
- end
280
-
281
- it "will install a nightly, if necessary" do
282
- config[:require_chef_omnibus] =
283
- "12.5.0-current.0+20150721082808.git.14.c91b337-1"
284
-
285
- Mixlib::Install::ScriptGenerator.expects(:new).with(
286
- "12.5.0-current.0+20150721082808.git.14.c91b337-1",
287
- false,
288
- install_opts
289
- ).returns(installer)
290
- cmd
291
- end
292
-
293
- it "will install the latest chef, if necessary" do
294
- config[:require_chef_omnibus] = "latest"
295
-
296
- Mixlib::Install::ScriptGenerator.expects(:new)
297
- .with("latest", false, install_opts).returns(installer)
298
- cmd
299
- end
300
-
301
- it "will install a version of chef, unless it exists" do
302
- config[:require_chef_omnibus] = true
303
-
304
- Mixlib::Install::ScriptGenerator.expects(:new)
305
- .with(default_version, false, install_opts).returns(installer)
306
- cmd
307
- end
308
-
309
- it "will pass a project, when given" do
310
- config[:chef_omnibus_install_options] = "-P chefdk"
311
- install_opts[:install_flags] = "-P chefdk"
312
- install_opts[:project] = "chefdk"
313
-
314
- Mixlib::Install::ScriptGenerator.expects(:new)
315
- .with(default_version, false, install_opts).returns(installer)
316
- cmd
317
- end
318
-
319
- it "will pass install options and version info, when given" do
320
- config[:require_chef_omnibus] = "11"
321
- config[:chef_omnibus_install_options] = "-d /tmp/place"
322
- install_opts[:install_flags] = "-d /tmp/place"
323
-
324
- Mixlib::Install::ScriptGenerator.expects(:new)
325
- .with("11", false, install_opts).returns(installer)
326
- cmd
327
- end
328
-
329
- it "will set the install root" do
330
- config[:chef_omnibus_root] = "/tmp/test"
331
- install_opts[:root] = "/tmp/test"
332
-
333
- Mixlib::Install::ScriptGenerator.expects(:new)
334
- .with(default_version, false, install_opts).returns(installer)
335
- cmd
336
- end
337
-
338
- it "will set the msi url" do
339
- config[:install_msi_url] = "http://blah/blah.msi"
340
- install_opts[:install_msi_url] = "http://blah/blah.msi"
341
-
342
- Mixlib::Install::ScriptGenerator.expects(:new)
343
- .with(default_version, false, install_opts).returns(installer)
344
- cmd
345
- end
346
-
347
- it "prefixs the whole command with the command_prefix if set" do
348
- config[:command_prefix] = "my_prefix"
349
-
350
- cmd.must_match(/\Amy_prefix /)
351
- end
352
-
353
- it "does not prefix the command if command_prefix is not set" do
354
- config[:command_prefix] = nil
355
-
356
- cmd.wont_match(/\Amy_prefix /)
357
- end
358
-
359
- describe "when driver implements the cache_directory interface" do
360
- before { driver.stubs(:cache_directory).returns("/tmp/custom/place") }
361
-
362
- it "will use driver.cache_directory to provide a cache directory" do
363
- install_opts[:install_flags] = "-d /tmp/custom/place"
364
-
365
- Mixlib::Install::ScriptGenerator.expects(:new)
366
- .with(default_version, false, install_opts).returns(installer)
367
- cmd
368
- end
369
-
370
- it "will use driver.cache_directory even if other options are given" do
371
- config[:chef_omnibus_install_options] = "-P cool -v 123"
372
- install_opts[:install_flags] = "-P cool -v 123 -d /tmp/custom/place"
373
- install_opts[:project] = "cool"
374
-
375
- Mixlib::Install::ScriptGenerator.expects(:new)
376
- .with(default_version, false, install_opts).returns(installer)
377
- cmd
378
- end
379
-
380
- it "will not use driver.cache_directory if -d options is given" do
381
- config[:chef_omnibus_install_options] = "-P cool -d /path -v 123"
382
- install_opts[:install_flags] = "-P cool -d /path -v 123"
383
- install_opts[:project] = "cool"
384
-
385
- Mixlib::Install::ScriptGenerator.expects(:new)
386
- .with(default_version, false, install_opts).returns(installer)
387
- cmd
388
- end
389
- end
390
- end
391
-
392
- describe "for product" do
393
- before do
394
- installer.expects(:root).at_least_once.returns("/opt/chef")
395
- installer.expects(:install_command)
396
- config[:product_name] = "my_product"
397
- end
398
-
399
- it "will set the product name, version and channel" do
400
- config[:product_version] = "version"
401
- config[:channel] = "channel"
402
-
403
- Mixlib::Install.expects(:new).with do |opts|
404
- opts[:product_name].must_equal "my_product"
405
- opts[:product_version].must_equal "version"
406
- opts[:channel].must_equal :channel
407
- end.returns(installer)
408
- cmd
409
- end
410
-
411
- it "will set the architecture if given" do
412
- config[:architecture] = "architecture"
413
-
414
- Mixlib::Install.expects(:new).with do |opts|
415
- opts[:architecture].must_equal "architecture"
416
- end.returns(installer)
417
- cmd
418
- end
419
-
420
- it "will set the platform if given" do
421
- config[:platform] = "platform"
422
-
423
- Mixlib::Install.expects(:new).with do |opts|
424
- opts[:platform].must_equal "platform"
425
- end.returns(installer)
426
- cmd
427
- end
428
-
429
- it "will set the platform_version if given" do
430
- config[:platform_version] = "platform_version"
431
-
432
- Mixlib::Install.expects(:new).with do |opts|
433
- opts[:platform_version].must_equal "platform_version"
434
- end.returns(installer)
435
- cmd
436
- end
437
-
438
- it "will omit the architecture if not given" do
439
- Mixlib::Install.expects(:new).with do |opts|
440
- opts.key?(:architecture).must_equal false
441
- end.returns(installer)
442
- cmd
443
- end
444
-
445
- it "will omit the platform if not given" do
446
- Mixlib::Install.expects(:new).with do |opts|
447
- opts.key?(:platform).must_equal false
448
- end.returns(installer)
449
- cmd
450
- end
451
-
452
- it "will omit the platform_version if not given" do
453
- Mixlib::Install.expects(:new).with do |opts|
454
- opts.key?(:platform_version).must_equal false
455
- end.returns(installer)
456
- cmd
457
- end
458
-
459
- it "will use stable channel when none specified" do
460
- Mixlib::Install.expects(:new).with do |opts|
461
- opts[:channel].must_equal :stable
462
- end.returns(installer)
463
- cmd
464
- end
465
-
466
- it "will set install_strategy to once when not given" do
467
- Mixlib::Install.expects(:new).with do |opts|
468
- opts[:install_command_options][:install_strategy].must_equal "once"
469
- end.returns(installer)
470
- cmd
471
- end
472
-
473
- it "will set install_strategy when given" do
474
- config[:install_strategy] = "always"
475
- Mixlib::Install.expects(:new).with do |opts|
476
- opts[:install_command_options][:install_strategy].must_equal "always"
477
- end.returns(installer)
478
- cmd
479
- end
480
-
481
- it "will set the download_url and checksum if given" do
482
- config[:download_url] = "http://url/path"
483
- config[:checksum] = "abcd"
484
-
485
- Mixlib::Install.expects(:new).with do |opts|
486
- opts[:install_command_options][:download_url_override].must_equal "http://url/path"
487
- opts[:install_command_options][:checksum].must_equal "abcd"
488
- end.returns(installer)
489
- cmd
490
- end
491
-
492
- it "will set the http_proxy and https_proxy if given" do
493
- config[:http_proxy] = "http://url/path:8000"
494
- config[:https_proxy] = "http://url/path:8000"
495
-
496
- Mixlib::Install.expects(:new).with do |opts|
497
- opts[:install_command_options][:http_proxy].must_equal "http://url/path:8000"
498
- opts[:install_command_options][:https_proxy].must_equal "http://url/path:8000"
499
- end.returns(installer)
500
- cmd
501
- end
502
-
503
- it "will set the http_proxy only for powershell" do
504
- config[:http_proxy] = "http://url/path:8000"
505
- config[:https_proxy] = "http://url/path:8000"
506
- platform.stubs(:shell_type).returns("powershell")
507
- platform.stubs(:os_type).returns("windows")
508
-
509
- Mixlib::Install.expects(:new).with do |opts|
510
- opts[:install_command_options][:http_proxy].must_equal "http://url/path:8000"
511
- opts[:install_command_options][:https_proxy].must_be_nil
512
- end.returns(installer)
513
- cmd
514
- end
515
-
516
- it "will not set proxies when not given" do
517
- Mixlib::Install.expects(:new).with do |opts|
518
- opts[:install_command_options][:http_proxy].must_be_nil
519
- end.returns(installer)
520
- cmd
521
- end
522
-
523
- describe "when driver implements the cache_directory" do
524
-
525
- describe "for windows" do
526
- before { driver.stubs(:cache_directory).returns('$env:TEMP\\dummy\\place') }
527
-
528
- it "will have the set behavior on windows" do
529
- platform.stubs(:shell_type).returns("powershell")
530
- platform.stubs(:os_type).returns("windows")
531
-
532
- Mixlib::Install.expects(:new).with do |opts|
533
- opts[:install_command_options][:download_directory].must_equal '$env:TEMP\\dummy\\place'
534
- end.returns(installer)
535
- cmd
536
- end
537
- end
538
-
539
- describe "for shell" do
540
- before { driver.stubs(:cache_directory).returns("/tmp") }
541
-
542
- it "will have the set behavior on non-windows" do
543
- Mixlib::Install.expects(:new).with do |opts|
544
- opts[:install_command_options][:cmdline_dl_dir].must_equal "/tmp"
545
- end.returns(installer)
546
- cmd
547
- end
548
- end
549
- end
550
- end
551
-
552
- describe "when install_strategy is skipped" do
553
- before do
554
- config[:product_name] = "my_product"
555
- config[:install_strategy] = "skip"
556
- end
557
-
558
- it "will not return installer when install_strategy is set to skip" do
559
- Mixlib::Install.expects(:new).never
560
- cmd
561
- end
562
- end
563
-
564
- describe "for bourne shells" do
565
- before do
566
- installer.expects(:root).at_least_once.returns("/opt/chef")
567
- installer.expects(:install_command).returns("my_install_command")
568
- end
569
-
570
- it "prepends sudo for sh commands when :sudo is set" do
571
- config[:sudo] = true
572
- config[:sudo_command] = "my_sudo_command"
573
- install_opts_clone = install_opts.clone
574
- install_opts_clone[:sudo_command] = config[:sudo_command]
575
-
576
- Mixlib::Install::ScriptGenerator.expects(:new)
577
- .with(default_version, false, install_opts_clone).returns(installer)
578
- cmd.must_equal "my_sudo_command my_install_command"
579
- end
580
-
581
- it "does not pass shell type for product based command" do
582
- config[:product_name] = "product_name"
583
-
584
- Mixlib::Install.expects(:new).with do |opts|
585
- opts.key?(:shell_type).must_equal false
586
- end.returns(installer)
587
- cmd
588
- end
589
-
590
- it "does not sudo for sh commands when :sudo is falsey" do
591
- config[:sudo] = false
592
-
593
- install_opts_clone = install_opts.clone
594
- install_opts_clone[:sudo_command] = ""
595
- Mixlib::Install::ScriptGenerator.expects(:new)
596
- .with(default_version, false, install_opts_clone).returns(installer)
597
- cmd.must_equal "my_install_command"
598
- end
599
- end
600
-
601
- describe "for powershell shells on windows os types" do
602
- before do
603
- installer.expects(:root).at_least_once.returns("/opt/chef")
604
- installer.expects(:install_command)
605
- platform.stubs(:shell_type).returns("powershell")
606
- platform.stubs(:os_type).returns("windows")
607
- end
608
-
609
- it "sets the powershell flag for Mixlib::Install" do
610
- install_opts_clone = install_opts.clone
611
- install_opts_clone[:sudo_command] = ""
612
- Mixlib::Install::ScriptGenerator.expects(:new)
613
- .with(default_version, true, install_opts_clone).returns(installer)
614
- cmd
615
- end
616
-
617
- it "passes ps1 shell type for product based command" do
618
- config[:product_name] = "product_name"
619
-
620
- Mixlib::Install.expects(:new).with do |opts|
621
- opts[:shell_type].must_equal :ps1
622
- end.returns(installer)
623
- cmd
624
- end
625
-
626
- describe "when driver implements the cache_directory" do
627
- before { driver.stubs(:cache_directory).returns('$env:TEMP\\dummy\\place') }
628
-
629
- it "will have the same behavior on windows" do
630
- config[:chef_omnibus_install_options] = "-version 123"
631
- install_opts_clone = install_opts.clone
632
- install_opts_clone[:sudo_command] = ""
633
- install_opts_clone[:install_flags] = "-version 123"
634
- install_opts_clone[:install_flags] << ' -download_directory $env:TEMP\\dummy\\place'
635
- Mixlib::Install::ScriptGenerator.expects(:new)
636
- .with(default_version, true, install_opts_clone).returns(installer)
637
- cmd
638
- end
639
- end
640
- end
641
- end
642
-
643
- describe "#init_command" do
644
- let(:cmd) { provisioner.init_command }
645
-
646
- describe "common behavior" do
647
- before { platform.stubs(:shell_type).returns("fake") }
648
-
649
- it "prefixs the whole command with the command_prefix if set" do
650
- config[:command_prefix] = "my_prefix"
651
-
652
- cmd.must_match(/\Amy_prefix /)
653
- end
654
-
655
- it "does not prefix the command if command_prefix is not set" do
656
- config[:command_prefix] = nil
657
-
658
- cmd.wont_match(/\Amy_prefix /)
659
- end
660
- end
661
-
662
- describe "for bourne shells" do
663
- before { platform.stubs(:shell_type).returns("bourne") }
664
-
665
- it "uses bourne shell" do
666
- cmd.must_match(/\Ash -c '$/)
667
- cmd.must_match(/'\Z/)
668
- end
669
-
670
- it "ends with a single quote" do
671
- cmd.must_match(/'\Z/)
672
- end
673
-
674
- it "exports http_proxy & HTTP_PROXY when :http_proxy is set" do
675
- config[:http_proxy] = "http://proxy"
676
-
677
- cmd.lines.to_a[1..2].must_equal([
678
- %{http_proxy="http://proxy"; export http_proxy\n},
679
- %{HTTP_PROXY="http://proxy"; export HTTP_PROXY\n},
680
- ])
681
- end
682
-
683
- it "exports https_proxy & HTTPS_PROXY when :https_proxy is set" do
684
- config[:https_proxy] = "https://proxy"
685
-
686
- cmd.lines.to_a[1..2].must_equal([
687
- %{https_proxy="https://proxy"; export https_proxy\n},
688
- %{HTTPS_PROXY="https://proxy"; export HTTPS_PROXY\n},
689
- ])
690
- end
691
-
692
- it "exports all http proxy variables when both are set" do
693
- config[:http_proxy] = "http://proxy"
694
- config[:https_proxy] = "https://proxy"
695
-
696
- cmd.lines.to_a[1..4].must_equal([
697
- %{http_proxy="http://proxy"; export http_proxy\n},
698
- %{HTTP_PROXY="http://proxy"; export HTTP_PROXY\n},
699
- %{https_proxy="https://proxy"; export https_proxy\n},
700
- %{HTTPS_PROXY="https://proxy"; export HTTPS_PROXY\n},
701
- ])
702
- end
703
-
704
- it "prepends sudo for rm when :sudo is set" do
705
- config[:sudo] = true
706
-
707
- cmd.must_match regexify(%{sudo_rm="sudo -E rm"})
708
- end
709
-
710
- it "does not sudo for sh commands when :sudo is falsey" do
711
- config[:sudo] = false
712
-
713
- cmd.must_match regexify(%{sudo_rm="rm"})
714
- end
715
-
716
- it "sets chef component dirs for deletion" do
717
- config[:root_path] = "/route"
718
- dirs = %w{
719
- /route/clients /route/cookbooks /route/data /route/data_bags
720
- /route/encrypted_data_bag_secret /route/environments /route/roles
721
- }.join(" ")
722
-
723
- cmd.must_match regexify(%{dirs="#{dirs}"})
724
- end
725
-
726
- it "sets the root_path from :root_path" do
727
- config[:root_path] = "RIGHT_HERE"
728
-
729
- cmd.must_match regexify(%{root_path="RIGHT_HERE"})
730
- end
731
- end
732
-
733
- describe "for powershell shells on windows os types" do
734
- before do
735
- platform.stubs(:shell_type).returns("powershell")
736
- platform.stubs(:os_type).returns("windows")
737
- end
738
-
739
- it "exports http_proxy & HTTP_PROXY when :http_proxy is set" do
740
- config[:http_proxy] = "http://proxy"
741
-
742
- cmd.lines.to_a[0..1].must_equal([
743
- %{$env:http_proxy = "http://proxy"\n},
744
- %{$env:HTTP_PROXY = "http://proxy"\n},
745
- ])
746
- end
747
-
748
- it "exports https_proxy & HTTPS_PROXY when :https_proxy is set" do
749
- config[:https_proxy] = "https://proxy"
750
-
751
- cmd.lines.to_a[0..1].must_equal([
752
- %{$env:https_proxy = "https://proxy"\n},
753
- %{$env:HTTPS_PROXY = "https://proxy"\n},
754
- ])
755
- end
756
-
757
- it "exports all http proxy variables when both are set" do
758
- config[:http_proxy] = "http://proxy"
759
- config[:https_proxy] = "https://proxy"
760
-
761
- cmd.lines.to_a[0..3].must_equal([
762
- %{$env:http_proxy = "http://proxy"\n},
763
- %{$env:HTTP_PROXY = "http://proxy"\n},
764
- %{$env:https_proxy = "https://proxy"\n},
765
- %{$env:HTTPS_PROXY = "https://proxy"\n},
766
- ])
767
- end
768
-
769
- it "sets chef component dirs for deletion" do
770
- config[:root_path] = '\\route'
771
- dirs = %w{ clients cookbooks data data_bags encrypted_data_bag_secret
772
- environments roles
773
- }.map do |dir|
774
- "\\route\\#{dir}"
775
- end.join(", ")
776
-
777
- cmd.include? "$dirs = @(#{dirs})"
778
- end
779
-
780
- it "sets the root_path from :root_path" do
781
- config[:root_path] = "RIGHT_HERE"
782
-
783
- cmd.must_match regexify(%{$root_path = "RIGHT_HERE"})
784
- end
785
- end
786
- end
787
-
788
- describe "#create_sandbox" do
789
- before do
790
- @root = Dir.mktmpdir
791
- config[:kitchen_root] = @root
792
- end
793
-
794
- after do
795
- FileUtils.remove_entry(@root)
796
- begin
797
- provisioner.cleanup_sandbox
798
- rescue # rubocop:disable Lint/HandleExceptions
799
- end
800
- end
801
-
802
- let(:provisioner) do
803
- Class.new(Kitchen::Provisioner::ChefBase) do
804
- default_config :generic_rb, {}
805
-
806
- def create_sandbox
807
- super
808
-
809
- data = default_config_rb.merge(config[:generic_rb])
810
- File.open(File.join(sandbox_path, "generic.rb"), "wb") do |file|
811
- file.write(format_config_file(data))
812
- end
813
- end
814
- end.new(config).finalize_config!(instance)
815
- end
816
-
817
- describe "json file" do
818
- let(:json) { JSON.parse(IO.read(sandbox_path("dna.json"))) }
819
-
820
- it "creates a json file with node attributes" do
821
- config[:attributes] = { "one" => { "two" => "three" } }
822
- provisioner.create_sandbox
823
-
824
- json["one"].must_equal("two" => "three")
825
- end
826
-
827
- it "creates a json file with run_list" do
828
- config[:run_list] = %w{alpha bravo charlie}
829
- provisioner.create_sandbox
830
-
831
- json["run_list"].must_equal %w{alpha bravo charlie}
832
- end
833
-
834
- it "creates a json file with an empty run_list" do
835
- config[:run_list] = []
836
- provisioner.create_sandbox
837
-
838
- json["run_list"].must_equal []
839
- end
840
-
841
- it "logs a message on info" do
842
- provisioner.create_sandbox
843
-
844
- logged_output.string.must_match info_line("Preparing dna.json")
845
- end
846
-
847
- it "logs a message on debug" do
848
- config[:run_list] = ["yo"]
849
- provisioner.create_sandbox
850
-
851
- logged_output.string
852
- .must_match debug_line(%(Creating dna.json from {:run_list=>["yo"]}))
853
- end
854
- end
855
-
856
- it "creates a cache directory" do
857
- provisioner.create_sandbox
858
-
859
- sandbox_path("cache").directory?.must_equal true
860
- end
861
-
862
- %w{data data_bags environments nodes roles clients}.each do |thing|
863
- describe "#{thing} files" do
864
- before do
865
- create_files_under("#{config[:kitchen_root]}/my_#{thing}")
866
- config[:"#{thing}_path"] = "#{config[:kitchen_root]}/my_#{thing}"
867
- end
868
-
869
- it "skips directory creation if :#{thing}_path is not set" do
870
- config[:"#{thing}_path"] = nil
871
- provisioner.create_sandbox
872
-
873
- sandbox_path(thing).directory?.must_equal false
874
- end
875
-
876
- it "copies tree from :#{thing}_path into sandbox" do
877
- provisioner.create_sandbox
878
-
879
- sandbox_path("#{thing}/alpha.txt").file?.must_equal true
880
- IO.read(sandbox_path("#{thing}/alpha.txt")).must_equal "stuff"
881
- sandbox_path("#{thing}/sub").directory?.must_equal true
882
- sandbox_path("#{thing}/sub/bravo.txt").file?.must_equal true
883
- IO.read(sandbox_path("#{thing}/sub/bravo.txt")).must_equal "junk"
884
- end
885
-
886
- it "logs a message on info" do
887
- provisioner.create_sandbox
888
-
889
- logged_output.string.must_match info_line("Preparing #{thing}")
890
- end
891
-
892
- it "logs a message on debug" do
893
- provisioner.create_sandbox
894
-
895
- logged_output.string.must_match debug_line(
896
- "Using #{thing} from #{config[:kitchen_root]}/my_#{thing}")
897
- end
898
- end
899
- end
900
-
901
- describe "secret files" do
902
- before do
903
- config[:encrypted_data_bag_secret_key_path] =
904
- "#{config[:kitchen_root]}/my_secret"
905
- File.open("#{config[:kitchen_root]}/my_secret", "wb") do |file|
906
- file.write("p@ss")
907
- end
908
- end
909
-
910
- it "skips file if :encrypted_data_bag_secret_key_path is not set" do
911
- config[:encrypted_data_bag_secret_key_path] = nil
912
- provisioner.create_sandbox
913
-
914
- sandbox_path("encrypted_data_bag_secret").file?.must_equal false
915
- end
916
-
917
- it "copies file from :encrypted_data_bag_secret_key_path into sandbox" do
918
- provisioner.create_sandbox
919
-
920
- sandbox_path("encrypted_data_bag_secret").file?.must_equal true
921
- IO.read(sandbox_path("encrypted_data_bag_secret")).must_equal "p@ss"
922
- end
923
-
924
- it "logs a message on info" do
925
- provisioner.create_sandbox
926
-
927
- logged_output.string.must_match info_line("Preparing secret")
928
- end
929
-
930
- it "logs a message on debug" do
931
- provisioner.create_sandbox
932
-
933
- logged_output.string.must_match debug_line(
934
- "Using secret from #{config[:kitchen_root]}/my_secret")
935
- end
936
- end
937
-
938
- describe "cookbooks" do
939
- let(:kitchen_root) { config[:kitchen_root] }
940
-
941
- describe "with a cookbooks/ directory under kitchen_root" do
942
- it "copies cookbooks/" do
943
- create_cookbook("#{kitchen_root}/cookbooks/epache")
944
- create_cookbook("#{kitchen_root}/cookbooks/jahva")
945
- provisioner.create_sandbox
946
-
947
- sandbox_path("cookbooks/epache").directory?.must_equal true
948
- sandbox_path("cookbooks/epache/recipes/default.rb")
949
- .file?.must_equal true
950
- sandbox_path("cookbooks/jahva").directory?.must_equal true
951
- sandbox_path("cookbooks/jahva/recipes/default.rb")
952
- .file?.must_equal true
953
- end
954
-
955
- it "copies from kitchen_root as cookbook if it contains metadata.rb" do
956
- File.open("#{kitchen_root}/metadata.rb", "wb") do |file|
957
- file.write("name 'wat'")
958
- end
959
- create_cookbook("#{kitchen_root}/cookbooks/bk")
960
- provisioner.create_sandbox
961
-
962
- sandbox_path("cookbooks/bk").directory?.must_equal true
963
- sandbox_path("cookbooks/wat").directory?.must_equal true
964
- sandbox_path("cookbooks/wat/metadata.rb").file?.must_equal true
965
- end
966
-
967
- it "copies site-cookbooks/ if it exists" do
968
- create_cookbook("#{kitchen_root}/cookbooks/upstream")
969
- create_cookbook("#{kitchen_root}/site-cookbooks/mine")
970
- provisioner.create_sandbox
971
-
972
- sandbox_path("cookbooks/upstream").directory?.must_equal true
973
- sandbox_path("cookbooks/mine").directory?.must_equal true
974
- sandbox_path("cookbooks/mine/attributes/all.rb").file?.must_equal true
975
- end
976
-
977
- it "logs a message on info for cookbooks/ directory" do
978
- create_cookbook("#{kitchen_root}/cookbooks/epache")
979
- provisioner.create_sandbox
980
-
981
- logged_output.string.must_match info_line(
982
- "Preparing cookbooks from project directory")
983
- end
984
-
985
- it "logs a meesage on debug for cookbooks/ directory" do
986
- create_cookbook("#{kitchen_root}/cookbooks/epache")
987
- provisioner.create_sandbox
988
-
989
- logged_output.string.must_match debug_line(
990
- "Using cookbooks from #{kitchen_root}/cookbooks")
991
- end
992
-
993
- it "logs a message on info for site-cookbooks/ directory" do
994
- create_cookbook("#{kitchen_root}/cookbooks/epache")
995
- create_cookbook("#{kitchen_root}/site-cookbooks/mine")
996
- provisioner.create_sandbox
997
-
998
- logged_output.string.must_match info_line(
999
- "Preparing site-cookbooks from project directory")
1000
- end
1001
-
1002
- it "logs a meesage on debug for site-cookbooks/ directory" do
1003
- create_cookbook("#{kitchen_root}/cookbooks/epache")
1004
- create_cookbook("#{kitchen_root}/site-cookbooks/mine")
1005
- provisioner.create_sandbox
1006
-
1007
- logged_output.string.must_match debug_line(
1008
- "Using cookbooks from #{kitchen_root}/site-cookbooks")
1009
- end
1010
- end
1011
-
1012
- describe "with a cookbook as the project" do
1013
- before do
1014
- File.open("#{kitchen_root}/metadata.rb", "wb") do |file|
1015
- file.write("name 'wat'")
1016
- end
1017
- end
1018
-
1019
- it "copies from kitchen_root as cookbook if it contains metadata.rb" do
1020
- provisioner.create_sandbox
1021
-
1022
- sandbox_path("cookbooks/wat").directory?.must_equal true
1023
- sandbox_path("cookbooks/wat/metadata.rb").file?.must_equal true
1024
- end
1025
-
1026
- it "logs a message on info" do
1027
- provisioner.create_sandbox
1028
-
1029
- logged_output.string.must_match info_line(
1030
- "Preparing current project directory as a cookbook")
1031
- end
1032
-
1033
- it "logs a meesage on debug" do
1034
- provisioner.create_sandbox
1035
-
1036
- logged_output.string.must_match debug_line(
1037
- "Using metadata.rb from #{kitchen_root}/metadata.rb")
1038
- end
1039
-
1040
- it "raises a UserError is name cannot be determined from metadata.rb" do
1041
- File.open("#{kitchen_root}/metadata.rb", "wb") do |file|
1042
- file.write("nameeeeee 'wat'")
1043
- end
1044
-
1045
- proc { provisioner.create_sandbox }.must_raise Kitchen::UserError
1046
- end
1047
- end
1048
-
1049
- describe "with no referenced cookbooks" do
1050
- it "makes a fake cookbook" do
1051
- name = File.basename(@root)
1052
- provisioner.create_sandbox
1053
-
1054
- sandbox_path("cookbooks/#{name}").directory?.must_equal true
1055
- sandbox_path("cookbooks/#{name}/metadata.rb").file?.must_equal true
1056
- IO.read(sandbox_path("cookbooks/#{name}/metadata.rb"))
1057
- .must_equal %{name "#{name}"\n}
1058
- end
1059
-
1060
- it "logs a warning" do
1061
- provisioner.create_sandbox
1062
-
1063
- logged_output.string.must_match regexify(
1064
- "Berksfile, Cheffile, cookbooks/, or metadata.rb not found",
1065
- :partial_line
1066
- )
1067
- end
1068
- end
1069
-
1070
- describe "with a Policyfile under kitchen_root" do
1071
- let(:policyfile_path) { "#{kitchen_root}/Policyfile.rb" }
1072
- let(:policyfile_lock_path) { "#{kitchen_root}/Policyfile.lock.json" }
1073
- let(:resolver) do
1074
- stub(compile: true, resolve: true, lockfile: policyfile_lock_path)
1075
- end
1076
-
1077
- describe "with the default name `Policyfile.rb`" do
1078
- before do
1079
- File.open("#{kitchen_root}/Policyfile.rb", "wb") do |file|
1080
- file.write(<<~POLICYFILE)
1081
- name 'wat'
1082
- run_list 'wat'
1083
- cookbook 'wat'
1084
- POLICYFILE
1085
- end
1086
- File.open("#{kitchen_root}/Policyfile.lock.json", "wb") do |file|
1087
- file.write(<<~POLICYFILE)
1088
- {
1089
- "name": "wat"
1090
- }
1091
- POLICYFILE
1092
- end
1093
- Kitchen::Provisioner::Chef::Policyfile.stubs(:new).returns(resolver)
1094
- end
1095
-
1096
- describe "when the chef executable is not in the PATH" do
1097
- it "raises a UserError" do
1098
- Kitchen::Provisioner::Chef::Policyfile.stubs(:detect_chef_command!).with do
1099
- raise Kitchen::UserError, "Load failed"
1100
- end
1101
- proc { provisioner }.must_raise Kitchen::UserError
1102
- end
1103
- end
1104
-
1105
- describe "when using a provisoner that doesn't support policyfiles" do
1106
- # This is be the default, provisioners must opt-in.
1107
- it "raises a UserError" do
1108
- proc { provisioner.create_sandbox }.must_raise Kitchen::UserError
1109
- end
1110
- end
1111
-
1112
- describe "when the chef executable is in the PATH" do
1113
- before do
1114
- Kitchen::Provisioner::Chef::Policyfile.stubs(:load!)
1115
- provisioner.stubs(:supports_policyfile?).returns(true)
1116
- end
1117
-
1118
- it "logs on debug that it autodetected the policyfile" do
1119
- provisioner
1120
-
1121
- logged_output.string.must_match debug_line(
1122
- "Policyfile found at #{kitchen_root}/Policyfile.rb, "\
1123
- "using Policyfile to resolve dependencies")
1124
- end
1125
-
1126
- it "uses uses the policyfile to resolve dependencies" do
1127
- resolver.expects(:compile)
1128
- resolver.expects(:resolve)
1129
-
1130
- provisioner.create_sandbox
1131
- end
1132
-
1133
- it "uses Kitchen.mutex for resolving" do
1134
- Kitchen.mutex.expects(:synchronize).twice
1135
-
1136
- provisioner.create_sandbox
1137
- end
1138
-
1139
- it "injects policyfile configuration into the dna.json" do
1140
- provisioner.create_sandbox
1141
-
1142
- dna_json_file = File.join(provisioner.sandbox_path, "dna.json")
1143
- dna_json_data = JSON.parse(IO.read(dna_json_file))
1144
-
1145
- expected = {
1146
- "policy_name" => "wat",
1147
- "policy_group" => "local",
1148
- }
1149
-
1150
- dna_json_data.must_equal(expected)
1151
- end
1152
- end
1153
- end
1154
- describe "with a custom policyfile_path" do
1155
- let(:config) do
1156
- {
1157
- policyfile_path: "foo-policy.rb",
1158
- test_base_path: "/basist",
1159
- kitchen_root: "/rooty",
1160
- }
1161
- end
1162
-
1163
- before do
1164
- Kitchen::Provisioner::Chef::Policyfile.stubs(:load!)
1165
- Kitchen::Provisioner::Chef::Policyfile.stubs(:new).returns(resolver)
1166
- provisioner.stubs(:supports_policyfile?).returns(true)
1167
- end
1168
-
1169
- describe "when the policyfile exists" do
1170
- let(:policyfile_path) { "#{kitchen_root}/foo-policy.rb" }
1171
- let(:policyfile_lock_path) { "#{kitchen_root}/foo-policy.lock.json" }
1172
-
1173
- before do
1174
- File.open(policyfile_path, "wb") do |file|
1175
- file.write(<<~POLICYFILE)
1176
- name 'wat'
1177
- run_list 'wat'
1178
- cookbook 'wat'
1179
- POLICYFILE
1180
- end
1181
- File.open(policyfile_lock_path, "wb") do |file|
1182
- file.write(<<~POLICYFILE)
1183
- {
1184
- "name": "wat"
1185
- }
1186
- POLICYFILE
1187
- end
1188
- end
1189
-
1190
- it "uses uses the policyfile to resolve dependencies" do
1191
- Kitchen::Provisioner::Chef::Policyfile.stubs(:load!)
1192
- resolver.expects(:compile)
1193
- resolver.expects(:resolve)
1194
-
1195
- provisioner.create_sandbox
1196
- end
1197
-
1198
- it "passes the correct path to the policyfile resolver" do
1199
- Kitchen::Provisioner::Chef::Policyfile
1200
- .expects(:new)
1201
- .with(policyfile_path, instance_of(String), anything)
1202
- .returns(resolver)
1203
-
1204
- Kitchen::Provisioner::Chef::Policyfile.stubs(:load!)
1205
- resolver.expects(:compile)
1206
- resolver.expects(:resolve)
1207
-
1208
- provisioner.create_sandbox
1209
- end
1210
- end
1211
- describe "when the policyfile doesn't exist" do
1212
- it "raises a UserError" do
1213
- proc { provisioner.create_sandbox }.must_raise Kitchen::UserError
1214
- end
1215
- end
1216
- describe "when the policyfile lock doesn't exist" do
1217
- before do
1218
- File.open("#{kitchen_root}/Policyfile.rb", "wb") do |file|
1219
- file.write(<<-POLICYFILE)
1220
- name 'wat'
1221
- run_list 'wat'
1222
- cookbook 'wat'
1223
- POLICYFILE
1224
- end
1225
-
1226
- it "runs `chef install` to generate the lock" do
1227
- resolver.expects(:compile)
1228
- provisioner.create_sandbox
1229
- end
1230
- end
1231
- end
1232
- end
1233
- describe "with a fallback policyfile" do
1234
- let(:config) do
1235
- {
1236
- policyfile: "foo-policy.rb",
1237
- test_base_path: "/basist",
1238
- kitchen_root: "/rooty",
1239
- }
1240
- end
1241
-
1242
- before do
1243
- Kitchen::Provisioner::Chef::Policyfile.stubs(:load!)
1244
- Kitchen::Provisioner::Chef::Policyfile.stubs(:new).returns(resolver)
1245
- provisioner.stubs(:supports_policyfile?).returns(true)
1246
- end
1247
-
1248
- describe "when the policyfile exists" do
1249
- let(:policyfile_path) { "#{kitchen_root}/foo-policy.rb" }
1250
- let(:policyfile_lock_path) { "#{kitchen_root}/foo-policy.lock.json" }
1251
-
1252
- before do
1253
- File.open(policyfile_path, "wb") do |file|
1254
- file.write(<<~POLICYFILE)
1255
- name 'wat'
1256
- run_list 'wat'
1257
- cookbook 'wat'
1258
- POLICYFILE
1259
- end
1260
- File.open(policyfile_lock_path, "wb") do |file|
1261
- file.write(<<~POLICYFILE)
1262
- {
1263
- "name": "wat"
1264
- }
1265
- POLICYFILE
1266
- end
1267
- end
1268
-
1269
- it "uses uses the policyfile to resolve dependencies" do
1270
- Kitchen::Provisioner::Chef::Policyfile.stubs(:load!)
1271
- resolver.expects(:compile)
1272
- resolver.expects(:resolve)
1273
-
1274
- provisioner.create_sandbox
1275
- end
1276
-
1277
- it "passes the correct path to the policyfile resolver" do
1278
- Kitchen::Provisioner::Chef::Policyfile
1279
- .expects(:new)
1280
- .with(policyfile_path, instance_of(String), anything)
1281
- .returns(resolver)
1282
-
1283
- Kitchen::Provisioner::Chef::Policyfile.stubs(:load!)
1284
- resolver.expects(:compile)
1285
- resolver.expects(:resolve)
1286
-
1287
- provisioner.create_sandbox
1288
- end
1289
- end
1290
- describe "when the policyfile doesn't exist" do
1291
- it "raises a UserError" do
1292
- proc { provisioner.create_sandbox }.must_raise Kitchen::UserError
1293
- end
1294
- end
1295
- end
1296
- end
1297
-
1298
- describe "with a Berksfile under kitchen_root" do
1299
- let(:resolver) { stub(resolve: true) }
1300
-
1301
- before do
1302
- File.open("#{kitchen_root}/Berksfile", "wb") do |file|
1303
- file.write("cookbook 'wat'")
1304
- end
1305
- Kitchen::Provisioner::Chef::Berkshelf.stubs(:new).returns(resolver)
1306
- end
1307
-
1308
- it "raises a UserError if Berkshelf library can't be loaded" do
1309
- Kitchen::Provisioner::Chef::Berkshelf.stubs(:load_berkshelf!).with do
1310
- raise Kitchen::UserError, "Load failed"
1311
- end
1312
- proc { provisioner }.must_raise Kitchen::UserError
1313
- end
1314
-
1315
- it "logs on debug that Berkshelf is loading" do
1316
- Kitchen::Provisioner::Chef::Berkshelf.stubs(:load!)
1317
- provisioner
1318
-
1319
- logged_output.string.must_match debug_line(
1320
- "Berksfile found at #{kitchen_root}/Berksfile, loading Berkshelf")
1321
- end
1322
-
1323
- it "uses Berkshelf" do
1324
- Kitchen::Provisioner::Chef::Berkshelf.stubs(:load!)
1325
- resolver.expects(:resolve)
1326
-
1327
- provisioner.create_sandbox
1328
- end
1329
-
1330
- it "uses Kitchen.mutex for resolving" do
1331
- Kitchen::Provisioner::Chef::Berkshelf.stubs(:load!)
1332
- Kitchen.mutex.expects(:synchronize)
1333
-
1334
- provisioner.create_sandbox
1335
- end
1336
- end
1337
-
1338
- describe "with a Cheffile under kitchen_root" do
1339
- let(:resolver) { stub(resolve: true) }
1340
-
1341
- before do
1342
- File.open("#{kitchen_root}/Cheffile", "wb") do |file|
1343
- file.write("cookbook 'wat'")
1344
- end
1345
- Kitchen::Provisioner::Chef::Librarian.stubs(:new).returns(resolver)
1346
- end
1347
-
1348
- it "raises a UserError if Librarian library can't be loaded" do
1349
- proc { provisioner }.must_raise Kitchen::UserError
1350
- end
1351
-
1352
- it "logs on debug that Berkshelf is loading" do
1353
- Kitchen::Provisioner::Chef::Librarian.stubs(:load!)
1354
- provisioner
1355
-
1356
- logged_output.string.must_match debug_line(
1357
- "Cheffile found at #{kitchen_root}/Cheffile, loading Librarian-Chef"
1358
- )
1359
- end
1360
-
1361
- it "uses Librarian" do
1362
- Kitchen::Provisioner::Chef::Librarian.stubs(:load!)
1363
- resolver.expects(:resolve)
1364
-
1365
- provisioner.create_sandbox
1366
- end
1367
-
1368
- it "uses Kitchen.mutex for resolving" do
1369
- Kitchen::Provisioner::Chef::Librarian.stubs(:load!)
1370
- Kitchen.mutex.expects(:synchronize)
1371
-
1372
- provisioner.create_sandbox
1373
- end
1374
- end
1375
-
1376
- describe "filtering cookbooks files" do
1377
- it "retains all useful cookbook files" do
1378
- create_full_cookbook("#{kitchen_root}/cookbooks/full")
1379
- provisioner.create_sandbox
1380
-
1381
- full_cookbook_files.each do |file|
1382
- sandbox_path("cookbooks/full/#{file}").file?.must_equal true
1383
- end
1384
- end
1385
-
1386
- it "strips extra cookbook files" do
1387
- extras = %w{
1388
- .gitignore tmp/librarian chefignore .git/info/excludes
1389
- cookbooks/another/metadata.rb CONTRIBUTING.md metadata.py
1390
- }
1391
-
1392
- create_full_cookbook("#{kitchen_root}/cookbooks/full")
1393
- extras.each do |file|
1394
- create_file("#{kitchen_root}/cookbooks/full/#{file}")
1395
- end
1396
- provisioner.create_sandbox
1397
-
1398
- extras.each do |file|
1399
- sandbox_path("cookbooks/full/#{file}").file?.must_equal false
1400
- end
1401
- end
1402
-
1403
- it "logs on info" do
1404
- create_full_cookbook("#{kitchen_root}/cookbooks/full")
1405
- provisioner.create_sandbox
1406
-
1407
- logged_output.string.must_match info_line(
1408
- "Removing non-cookbook files before transfer")
1409
- end
1410
- end
1411
-
1412
- describe "Chef config files" do
1413
- let(:file) do
1414
- IO.read(sandbox_path("generic.rb")).lines.map(&:chomp)
1415
- end
1416
-
1417
- it "#create_sanbox creates a generic.rb" do
1418
- provisioner.create_sandbox
1419
-
1420
- sandbox_path("generic.rb").file?.must_equal true
1421
- end
1422
-
1423
- describe "defaults" do
1424
- before { provisioner.create_sandbox }
1425
-
1426
- it "sets node_name to the instance name" do
1427
- file.must_include %{node_name "#{instance.name}"}
1428
- end
1429
-
1430
- it "sets checksum_path" do
1431
- file.must_include %{checksum_path "/tmp/kitchen/checksums"}
1432
- end
1433
-
1434
- it "sets file_backup_path" do
1435
- file.must_include %{file_backup_path "/tmp/kitchen/backup"}
1436
- end
1437
-
1438
- it "sets cookbook_path" do
1439
- file.must_include %{cookbook_path } +
1440
- %{["/tmp/kitchen/cookbooks", "/tmp/kitchen/site-cookbooks"]}
1441
- end
1442
-
1443
- it "sets data_bag_path" do
1444
- file.must_include %{data_bag_path "/tmp/kitchen/data_bags"}
1445
- end
1446
-
1447
- it "sets environment_path" do
1448
- file.must_include %{environment_path "/tmp/kitchen/environments"}
1449
- end
1450
-
1451
- it "sets node_path" do
1452
- file.must_include %{node_path "/tmp/kitchen/nodes"}
1453
- end
1454
-
1455
- it "sets role_path" do
1456
- file.must_include %{role_path "/tmp/kitchen/roles"}
1457
- end
1458
-
1459
- it "sets client_path" do
1460
- file.must_include %{client_path "/tmp/kitchen/clients"}
1461
- end
1462
-
1463
- it "sets user_path" do
1464
- file.must_include %{user_path "/tmp/kitchen/users"}
1465
- end
1466
-
1467
- it "sets validation_key" do
1468
- file.must_include %{validation_key "/tmp/kitchen/validation.pem"}
1469
- end
1470
-
1471
- it "sets client_key" do
1472
- file.must_include %{client_key "/tmp/kitchen/client.pem"}
1473
- end
1474
-
1475
- it "sets chef_server_url" do
1476
- file.must_include %{chef_server_url "http://127.0.0.1:8889"}
1477
- end
1478
-
1479
- it "sets encrypted_data_bag_secret" do
1480
- file.must_include %{encrypted_data_bag_secret } +
1481
- %{"/tmp/kitchen/encrypted_data_bag_secret"}
1482
- end
1483
-
1484
- it "disables deprecation warnings" do
1485
- file.must_include %{treat_deprecation_warnings_as_errors false}
1486
- end
1487
- end
1488
-
1489
- it "supports overwriting defaults" do
1490
- config[:generic_rb] = {
1491
- node_name: "eagles",
1492
- user_path: "/a/b/c/u",
1493
- chef_server_url: "https://whereever.io",
1494
- }
1495
- provisioner.create_sandbox
1496
-
1497
- file.must_include %{node_name "eagles"}
1498
- file.must_include %{user_path "/a/b/c/u"}
1499
- file.must_include %{chef_server_url "https://whereever.io"}
1500
- end
1501
-
1502
- it " supports adding new configuration" do
1503
- config[:generic_rb] = {
1504
- dark_secret: "golang",
1505
- }
1506
- provisioner.create_sandbox
1507
-
1508
- file.must_include %{dark_secret "golang"}
1509
- end
1510
- end
1511
-
1512
- def create_cookbook(path)
1513
- %w{metadata.rb attributes/all.rb recipes/default.rb}.each do |file|
1514
- create_file(File.join(path, file))
1515
- end
1516
- end
1517
-
1518
- def full_cookbook_files
1519
- %w{
1520
- README.org metadata.rb attributes/all.rb definitions/def.rb
1521
- files/default/config.conf libraries/one.rb libraries/two.rb
1522
- providers/sweet.rb recipes/default.rb resources/sweet.rb
1523
- templates/ubuntu/12.04/nginx.conf.erb
1524
- }
1525
- end
1526
-
1527
- def create_full_cookbook(path)
1528
- full_cookbook_files.each { |file| create_file(File.join(path, file)) }
1529
- end
1530
-
1531
- def create_file(path)
1532
- FileUtils.mkdir_p(File.dirname(path))
1533
- File.open(path, "wb") { |f| f.write(path) }
1534
- end
1535
- end
1536
-
1537
- def sandbox_path(path)
1538
- Pathname.new(provisioner.sandbox_path).join(path)
1539
- end
1540
-
1541
- def create_files_under(path)
1542
- FileUtils.mkdir_p(File.join(path, "sub"))
1543
- File.open(File.join(path, "alpha.txt"), "wb") do |file|
1544
- file.write("stuff")
1545
- end
1546
- File.open(File.join(path, "sub", "bravo.txt"), "wb") do |file|
1547
- file.write("junk")
1548
- end
1549
- end
1550
-
1551
- def info_line(msg)
1552
- /^I, .* : #{Regexp.escape(msg)}$/
1553
- end
1554
-
1555
- def debug_line(msg)
1556
- /^D, .* : #{Regexp.escape(msg)}$/
1557
- end
1558
- end
1559
-
1560
- def regexify(str, line = :whole_line)
1561
- r = Regexp.escape(str)
1562
- r = "^\s*#{r}$" if line == :whole_line
1563
- Regexp.new(r)
1564
- end
1565
- end