r10k 1.4.2 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (244) hide show
  1. data/.travis.yml +2 -0
  2. data/CHANGELOG.mkd +192 -0
  3. data/CONTRIBUTING.mkd +3 -3
  4. data/Gemfile +4 -0
  5. data/README.mkd +13 -6
  6. data/doc/dynamic-environments/configuration.mkd +77 -8
  7. data/doc/dynamic-environments/git-environments.mkd +12 -2
  8. data/doc/dynamic-environments/quickstart.mkd +6 -0
  9. data/doc/faq.mkd +6 -6
  10. data/doc/git/cloning-and-mirroring.mkd +60 -0
  11. data/doc/git/providers.mkd +68 -0
  12. data/integration/Gemfile +3 -0
  13. data/integration/README.mkd +29 -0
  14. data/integration/configs/README.mkd +7 -0
  15. data/integration/configs/pe/centos-6-64mda +25 -0
  16. data/integration/configs/pe/centos-7-64mda +25 -0
  17. data/integration/configs/pe/debian-6-64mda +25 -0
  18. data/integration/configs/pe/debian-7-64mda +25 -0
  19. data/integration/configs/pe/redhat-6-64mda +25 -0
  20. data/integration/configs/pe/redhat-7-64mda +25 -0
  21. data/integration/configs/pe/sles-11-64mda +25 -0
  22. data/integration/configs/pe/ubuntu-1004-64mda +25 -0
  23. data/integration/configs/pe/ubuntu-1204-64mda +25 -0
  24. data/integration/configs/pe/ubuntu-1404-64mda +25 -0
  25. data/integration/files/README.mkd +4 -0
  26. data/integration/files/hiera.yaml +8 -0
  27. data/integration/files/modules/helloworld/manifests/init.pp +3 -0
  28. data/integration/files/modules/hieratest/manifests/init.pp +3 -0
  29. data/integration/files/modules/unicode/files/pretend_unicode +1 -0
  30. data/integration/files/modules/unicode/manifests/init.pp +6 -0
  31. data/integration/files/pre-suite/prod_env.config +3 -0
  32. data/integration/files/r10k_conf.yaml.erb +9 -0
  33. data/integration/lib/README.mkd +4 -0
  34. data/integration/lib/git_utils.rb +205 -0
  35. data/integration/lib/master_manipulator.rb +205 -0
  36. data/integration/lib/r10k_utils.rb +166 -0
  37. data/integration/manifests/README.mkd +4 -0
  38. data/integration/pre-suite/00_pe_install.rb +4 -0
  39. data/integration/pre-suite/01_git_config.rb +59 -0
  40. data/integration/pre-suite/02_pe_r10k.rb +60 -0
  41. data/integration/pre-suite/03_test_utils.rb +17 -0
  42. data/integration/pre-suite/README.mkd +5 -0
  43. data/integration/test_run_scripts/README.mkd +5 -0
  44. data/integration/test_run_scripts/all_tests-rugged-pe-centos6.sh +20 -0
  45. data/integration/test_run_scripts/all_tests-rugged-pe-rhel7.sh +20 -0
  46. data/integration/test_run_scripts/all_tests-rugged-pe-sles11.sh +20 -0
  47. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1204.sh +20 -0
  48. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1404.sh +20 -0
  49. data/integration/test_run_scripts/all_tests-shellgit-pe-centos6.sh +20 -0
  50. data/integration/test_run_scripts/all_tests-shellgit-pe-rhel7.sh +20 -0
  51. data/integration/test_run_scripts/all_tests-shellgit-pe-sles11.sh +20 -0
  52. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1204.sh +20 -0
  53. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1404.sh +20 -0
  54. data/integration/test_run_scripts/basic_functionality/all_tests-pe-centos6.sh +20 -0
  55. data/integration/test_run_scripts/command_line/all_tests-pe-centos6.sh +20 -0
  56. data/integration/test_run_scripts/git_source/all_tests-pe-centos6.sh +20 -0
  57. data/integration/test_run_scripts/user_scenario/basic_workflow/all_tests-pe-centos6.sh +20 -0
  58. data/integration/test_run_scripts/user_scenario/complex_workflow/all_tests-pe-centos6.sh +20 -0
  59. data/integration/tests/README.mkd +4 -0
  60. data/integration/tests/basic_functionality/negative/neg_deploy_with_invalid_r10k_yaml.rb +46 -0
  61. data/integration/tests/basic_functionality/negative/neg_deploy_with_missing_r10k_yaml.rb +27 -0
  62. data/integration/tests/command_line/deploy_env_without_mod_update.rb +75 -0
  63. data/integration/tests/command_line/negative/neg_deploy_env_with_module_update.rb +76 -0
  64. data/integration/tests/command_line/negative/neg_invalid_cli_dep_flag.rb +22 -0
  65. data/integration/tests/command_line/negative/neg_invalid_cli_env_flag.rb +22 -0
  66. data/integration/tests/command_line/negative/neg_invalid_cmd_line_arg.rb +24 -0
  67. data/integration/tests/git_source/git_source_git.rb +123 -0
  68. data/integration/tests/git_source/git_source_ssh.rb +84 -0
  69. data/integration/tests/git_source/git_source_submodule.rb +69 -0
  70. data/integration/tests/git_source/negative/neg_git_broken_remote.rb +37 -0
  71. data/integration/tests/git_source/negative/neg_git_unauthorized_https.rb +45 -0
  72. data/integration/tests/git_source/negative/neg_git_unauthorized_ssh.rb +72 -0
  73. data/integration/tests/git_source/negative/neg_git_unicode_branch.rb +34 -0
  74. data/integration/tests/user_scenario/basic_workflow/multi_env_1000_branches.rb +66 -0
  75. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module.rb +110 -0
  76. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module_static.rb +113 -0
  77. data/integration/tests/user_scenario/basic_workflow/multi_env_hiera.rb +93 -0
  78. data/integration/tests/user_scenario/basic_workflow/multi_env_multi_source.rb +132 -0
  79. data/integration/tests/user_scenario/basic_workflow/multi_source_custom_forge_git_module.rb +160 -0
  80. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_basedir.rb +45 -0
  81. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_forge_module.rb +43 -0
  82. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module.rb +40 -0
  83. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module_ref.rb +42 -0
  84. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_remote.rb +44 -0
  85. data/integration/tests/user_scenario/basic_workflow/negative/neg_branch_name_collision.rb +63 -0
  86. data/integration/tests/user_scenario/basic_workflow/negative/neg_disk_full.rb +73 -0
  87. data/integration/tests/user_scenario/basic_workflow/negative/neg_duplicate_module_names.rb +45 -0
  88. data/integration/tests/user_scenario/basic_workflow/negative/neg_inaccessible_forge.rb +51 -0
  89. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_env_name.rb +33 -0
  90. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_puppet_file.rb +35 -0
  91. data/integration/tests/user_scenario/basic_workflow/negative/neg_module_specified_at_deleted_release.rb +44 -0
  92. data/integration/tests/user_scenario/basic_workflow/negative/neg_read_only.rb +57 -0
  93. data/integration/tests/user_scenario/basic_workflow/negative/neg_specify_deleted_forge_module.rb +44 -0
  94. data/integration/tests/user_scenario/basic_workflow/single_env_10000_files.rb +73 -0
  95. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_git_module.rb +103 -0
  96. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_module.rb +80 -0
  97. data/integration/tests/user_scenario/basic_workflow/single_env_custom_module.rb +48 -0
  98. data/integration/tests/user_scenario/basic_workflow/single_env_large_files.rb +73 -0
  99. data/integration/tests/user_scenario/basic_workflow/single_env_module_already_installed.rb +81 -0
  100. data/integration/tests/user_scenario/basic_workflow/single_env_module_last_release_deleted.rb +67 -0
  101. data/integration/tests/user_scenario/basic_workflow/single_env_non-existent_base_dir.rb +93 -0
  102. data/integration/tests/user_scenario/basic_workflow/single_env_purge_unmanaged_modules.rb +92 -0
  103. data/integration/tests/user_scenario/basic_workflow/single_env_switch_forge_git_module.rb +116 -0
  104. data/integration/tests/user_scenario/basic_workflow/single_env_unicode_paths.rb +59 -0
  105. data/integration/tests/user_scenario/basic_workflow/single_env_upgrade_forge_mod_revert_change.rb +165 -0
  106. data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +162 -0
  107. data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +110 -0
  108. data/lib/r10k/action/cri_runner.rb +10 -13
  109. data/lib/r10k/cli.rb +3 -8
  110. data/lib/r10k/cli/version.rb +10 -1
  111. data/lib/r10k/deployment/config.rb +26 -6
  112. data/lib/r10k/deployment/config/loader.rb +38 -29
  113. data/lib/r10k/deployment/source.rb +2 -4
  114. data/lib/r10k/environment/git.rb +10 -19
  115. data/lib/r10k/environment/name.rb +86 -0
  116. data/lib/r10k/errors.rb +8 -5
  117. data/lib/r10k/feature.rb +35 -0
  118. data/lib/r10k/feature/collection.rb +23 -0
  119. data/lib/r10k/features.rb +18 -0
  120. data/lib/r10k/git.rb +106 -12
  121. data/lib/r10k/git/alternates.rb +2 -2
  122. data/lib/r10k/git/cache.rb +43 -26
  123. data/lib/r10k/git/errors.rb +12 -6
  124. data/lib/r10k/git/head.rb +3 -0
  125. data/lib/r10k/git/ref.rb +3 -0
  126. data/lib/r10k/git/remote_head.rb +6 -0
  127. data/lib/r10k/git/repository.rb +6 -0
  128. data/lib/r10k/git/rugged.rb +17 -0
  129. data/lib/r10k/git/rugged/bare_repository.rb +86 -0
  130. data/lib/r10k/git/rugged/base_repository.rb +90 -0
  131. data/lib/r10k/git/rugged/cache.rb +11 -0
  132. data/lib/r10k/git/rugged/thin_repository.rb +72 -0
  133. data/lib/r10k/git/rugged/working_repository.rb +99 -0
  134. data/lib/r10k/git/shellgit.rb +9 -0
  135. data/lib/r10k/git/shellgit/bare_repository.rb +29 -0
  136. data/lib/r10k/git/shellgit/base_repository.rb +102 -0
  137. data/lib/r10k/git/shellgit/cache.rb +11 -0
  138. data/lib/r10k/git/shellgit/thin_repository.rb +56 -0
  139. data/lib/r10k/git/shellgit/working_repository.rb +73 -0
  140. data/lib/r10k/git/stateful_repository.rb +80 -0
  141. data/lib/r10k/git/tag.rb +3 -0
  142. data/lib/r10k/git/working_dir.rb +15 -2
  143. data/lib/r10k/logging.rb +73 -36
  144. data/lib/r10k/logging/terminaloutputter.rb +36 -0
  145. data/lib/r10k/module/forge.rb +10 -9
  146. data/lib/r10k/module/git.rb +14 -44
  147. data/lib/r10k/module/metadata_file.rb +31 -0
  148. data/lib/r10k/module/svn.rb +0 -1
  149. data/lib/r10k/module_repository/forge.rb +20 -7
  150. data/lib/r10k/puppetfile.rb +1 -1
  151. data/lib/r10k/settings/container.rb +6 -0
  152. data/lib/r10k/settings/mixin.rb +9 -0
  153. data/lib/r10k/source.rb +2 -3
  154. data/lib/r10k/source/base.rb +5 -5
  155. data/lib/r10k/source/git.rb +11 -86
  156. data/lib/r10k/source/svn.rb +8 -52
  157. data/lib/r10k/util/basedir.rb +4 -4
  158. data/lib/r10k/util/commands.rb +31 -0
  159. data/lib/r10k/util/exec_env.rb +36 -0
  160. data/lib/r10k/util/platform.rb +4 -0
  161. data/lib/r10k/util/purgeable.rb +2 -2
  162. data/lib/r10k/util/subprocess.rb +3 -7
  163. data/lib/r10k/util/subprocess/runner.rb +3 -28
  164. data/lib/r10k/util/subprocess/runner/posix.rb +103 -0
  165. data/lib/r10k/util/subprocess/runner/pump.rb +59 -0
  166. data/lib/r10k/util/subprocess/{windows/runner.rb → runner/windows.rb} +2 -11
  167. data/lib/r10k/util/symbolize_keys.rb +31 -0
  168. data/lib/r10k/version.rb +1 -1
  169. data/lib/shared/puppet/module_tool/metadata.rb +197 -0
  170. data/r10k.gemspec +7 -5
  171. data/spec/fixtures/integration/git/puppet-boolean-bare.tar +0 -0
  172. data/spec/fixtures/module/forge/bad_module/metadata.json +1 -0
  173. data/spec/fixtures/unit/util/subprocess/posix/runner/no-execute.sh +3 -0
  174. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/can_fetch_all_versions_of_a_given_module.yml +171 -26
  175. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/can_fetch_the_latest_version_of_a_given_module.yml +171 -26
  176. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/ignores_deleted_releases.yml +190 -0
  177. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/it_handles_errors_from_forgeapi_puppetlabs_com/raises_an_error_for_a_non-existant_module.yml +34 -0
  178. data/spec/fixtures/vcr/cassettes/R10K_Module_Forge/and_the_expected_version_is_latest/sets_the_expected_version_based_on_the_latest_forge_version.yml +87 -26
  179. data/spec/integration/git/rugged/bare_repository_spec.rb +13 -0
  180. data/spec/integration/git/rugged/thin_repository_spec.rb +14 -0
  181. data/spec/integration/git/rugged/working_repository_spec.rb +13 -0
  182. data/spec/integration/git/shellgit/bare_repository_spec.rb +13 -0
  183. data/spec/integration/git/shellgit/thin_repository_spec.rb +14 -0
  184. data/spec/integration/git/shellgit/working_repository_spec.rb +13 -0
  185. data/spec/integration/git/stateful_repository_spec.rb +104 -0
  186. data/spec/matchers/match_realpath.rb +18 -0
  187. data/spec/shared-contexts/git-fixtures.rb +55 -0
  188. data/spec/shared-examples/git-repository.rb +38 -0
  189. data/spec/shared-examples/git/bare_repository.rb +70 -0
  190. data/spec/shared-examples/git/thin_repository.rb +26 -0
  191. data/spec/shared-examples/git/working_repository.rb +115 -0
  192. data/spec/shared-examples/subprocess-runner.rb +83 -0
  193. data/spec/spec_helper.rb +13 -9
  194. data/spec/unit/action/cri_runner_spec.rb +0 -6
  195. data/spec/unit/action/puppetfile/{cri_action_spec.rb → cri_runner_spec.rb} +0 -0
  196. data/spec/unit/deployment/config/loader_spec.rb +48 -0
  197. data/spec/unit/deployment/config_spec.rb +49 -0
  198. data/spec/unit/environment/git_spec.rb +5 -39
  199. data/spec/unit/environment/name_spec.rb +135 -0
  200. data/spec/unit/feature_spec.rb +50 -0
  201. data/spec/unit/git/alternates_spec.rb +1 -1
  202. data/spec/unit/git/cache_spec.rb +32 -19
  203. data/spec/unit/git/commit_spec.rb +1 -0
  204. data/spec/unit/git/head_spec.rb +1 -6
  205. data/spec/unit/git/ref_spec.rb +0 -23
  206. data/spec/unit/git/rugged/cache_spec.rb +26 -0
  207. data/spec/unit/git/shellgit/cache_spec.rb +27 -0
  208. data/spec/unit/git/stateful_repository_spec.rb +43 -0
  209. data/spec/unit/git/tag_spec.rb +1 -0
  210. data/spec/unit/git/working_dir_spec.rb +1 -0
  211. data/spec/unit/git_spec.rb +74 -0
  212. data/spec/unit/logging/terminaloutputter_spec.rb +53 -0
  213. data/spec/unit/logging_spec.rb +68 -0
  214. data/spec/unit/module/forge_spec.rb +7 -38
  215. data/spec/unit/module/git_spec.rb +7 -38
  216. data/spec/unit/module/metadata_file_spec.rb +69 -0
  217. data/spec/unit/module/svn_spec.rb +0 -4
  218. data/spec/unit/module_repository/forge_spec.rb +22 -1
  219. data/spec/unit/puppet/module_tool/metadata_spec.rb +301 -0
  220. data/spec/unit/settings/container_spec.rb +17 -0
  221. data/spec/unit/source/git_spec.rb +0 -123
  222. data/spec/unit/source/svn_spec.rb +66 -0
  223. data/spec/unit/util/commands_spec.rb +61 -0
  224. data/spec/unit/util/exec_env_spec.rb +56 -0
  225. data/spec/unit/util/subprocess/runner/posix_spec.rb +7 -0
  226. data/spec/unit/util/subprocess/runner/pump_spec.rb +79 -0
  227. data/spec/unit/util/subprocess_spec.rb +3 -2
  228. data/spec/unit/util/symbolize_keys_spec.rb +51 -0
  229. metadata +226 -45
  230. data/lib/r10k/execution.rb +0 -47
  231. data/lib/r10k/module/metadata.rb +0 -47
  232. data/lib/r10k/util/core_ext/hash_ext.rb +0 -19
  233. data/lib/r10k/util/subprocess/io.rb +0 -7
  234. data/lib/r10k/util/subprocess/posix.rb +0 -4
  235. data/lib/r10k/util/subprocess/posix/io.rb +0 -7
  236. data/lib/r10k/util/subprocess/posix/runner.rb +0 -140
  237. data/lib/r10k/util/subprocess/windows.rb +0 -4
  238. data/lib/r10k/util/subprocess/windows/io.rb +0 -6
  239. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions.yml +0 -42
  240. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions/can_fetch_all_versions_of_a_given_module.yml +0 -42
  241. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions/can_fetch_the_latest_version_of_a_given_module.yml +0 -42
  242. data/spec/unit/deployment/source_spec.rb +0 -24
  243. data/spec/unit/module/metadata_spec.rb +0 -68
  244. data/spec/unit/util/core_ext/hash_ext_spec.rb +0 -63
@@ -65,4 +65,21 @@ describe R10K::Settings::Container do
65
65
  end
66
66
  end
67
67
  end
68
+
69
+ describe "resetting" do
70
+ before do
71
+ subject.add_valid_key :v
72
+ end
73
+
74
+ it "unsets all settings" do
75
+ subject[:v] = "hi"
76
+ subject.reset!
77
+ expect(subject[:v]).to be_nil
78
+ end
79
+
80
+ it "doesn't remove valid values" do
81
+ subject.reset!
82
+ expect(subject.valid_key?(:v)).to be_truthy
83
+ end
84
+ end
68
85
  end
@@ -149,126 +149,3 @@ describe R10K::Source::Git, 'registering as a source' do
149
149
  expect(R10K::Source.retrieve(nil)).to eq described_class
150
150
  end
151
151
  end
152
-
153
- describe R10K::Source::Git::BranchName do
154
- describe "prefixing" do
155
- it "uses the branch name as the dirname when prefixing is off" do
156
- bn = described_class.new('mybranch', {:prefix => false, :sourcename => 'foo'})
157
- expect(bn.dirname).to eq 'mybranch'
158
- end
159
-
160
- it "prepends the source name when prefixing is on" do
161
- bn = described_class.new('mybranch', {:prefix => true, :sourcename => 'foo'})
162
- expect(bn.dirname).to eq 'foo_mybranch'
163
- end
164
- end
165
-
166
- describe "determining the validate behavior with :invalid" do
167
- [
168
- ['correct_and_warn', {:validate => true, :correct => true}],
169
- ['correct', {:validate => false, :correct => true}],
170
- ['error', {:validate => true, :correct => false}],
171
- ].each do |(setting, outcome)|
172
- it "treats #{setting} as #{outcome.inspect}" do
173
- bn = described_class.new('mybranch', {:invalid => setting})
174
- expect(bn.validate?).to eq outcome[:validate]
175
- expect(bn.correct?).to eq outcome[:correct]
176
- end
177
- end
178
- end
179
-
180
- describe "determining if a branch is a valid environment name" do
181
- invalid_cases = [
182
- 'hyphenated-branch',
183
- 'dotted.branch',
184
- 'slashed/branch',
185
- 'at@branch',
186
- 'http://branch'
187
- ]
188
-
189
- valid_cases = [
190
- 'my_branchname',
191
- 'my_issue_346',
192
- ]
193
-
194
- describe "and validate is false" do
195
- invalid_cases.each do |branch|
196
- it "is valid if the branch is #{branch}" do
197
- bn = described_class.new(branch, {:validate => false})
198
- expect(bn).to be_valid
199
- end
200
- end
201
-
202
- valid_cases.each do |branch|
203
- it "is valid if the branch is #{branch}" do
204
- bn = described_class.new(branch, {:validate => false})
205
- expect(bn).to be_valid
206
- end
207
- end
208
- end
209
-
210
- describe "and validate is true" do
211
- invalid_cases.each do |branch|
212
- it "is invalid if the branch is #{branch}" do
213
- bn = described_class.new(branch, {:validate => true})
214
- expect(bn).to_not be_valid
215
- end
216
- end
217
-
218
- valid_cases.each do |branch|
219
- it "is valid if the branch is #{branch}" do
220
- bn = described_class.new(branch, {:validate => true})
221
- expect(bn).to be_valid
222
- end
223
- end
224
-
225
- end
226
- end
227
-
228
- describe "correcting branch names" do
229
- invalid_cases = [
230
- 'hyphenated-branch',
231
- 'dotted.branch',
232
- 'slashed/branch',
233
- 'at@branch',
234
- 'http://branch'
235
- ]
236
-
237
- valid_cases = [
238
- 'my_branchname',
239
- 'my_issue_346',
240
- ]
241
-
242
- describe "and correct is false" do
243
- invalid_cases.each do |branch|
244
- it "doesn't modify #{branch}" do
245
- bn = described_class.new(branch.dup, {:correct => false})
246
- expect(bn.dirname).to eq branch
247
- end
248
- end
249
-
250
- valid_cases.each do |branch|
251
- it "doesn't modify #{branch}" do
252
- bn = described_class.new(branch.dup, {:correct => false})
253
- expect(bn.dirname).to eq branch
254
- end
255
- end
256
- end
257
-
258
- describe "and correct is true" do
259
- invalid_cases.each do |branch|
260
- it "replaces invalid characters in #{branch} with underscores" do
261
- bn = described_class.new(branch.dup, {:correct => true})
262
- expect(bn.dirname).to eq branch.gsub(/\W/, '_')
263
- end
264
- end
265
-
266
- valid_cases.each do |branch|
267
- it "doesn't modify #{branch}" do
268
- bn = described_class.new(branch.dup, {:correct => true})
269
- expect(bn.dirname).to eq branch
270
- end
271
- end
272
- end
273
- end
274
- end
@@ -95,6 +95,72 @@ describe R10K::Source::SVN, 'when prefixing is enabled' do
95
95
  end
96
96
  end
97
97
 
98
+ describe R10K::Source::SVN, 'when prefixing is disabled' do
99
+ subject do
100
+ described_class.new(
101
+ 'mysource',
102
+ '/some/nonexistent/dir',
103
+ {
104
+ :remote => 'https://svn-server.site/repo',
105
+ :prefix => false
106
+ }
107
+ )
108
+ end
109
+
110
+ describe "generating environments" do
111
+ before do
112
+ allow(subject.svn_remote).to receive(:branches).and_return %w[apache dns robobutler]
113
+ end
114
+
115
+ let(:environments) { subject.generate_environments }
116
+
117
+ it "creates an environment for each branch and the trunk" do
118
+ expect(environments.size).to eq(4)
119
+ end
120
+
121
+ it "does not prefix environments" do
122
+ expect(environments[0].dirname).to eq 'production'
123
+ expect(environments[1].dirname).to eq 'apache'
124
+ expect(environments[2].dirname).to eq 'dns'
125
+ expect(environments[3].dirname).to eq 'robobutler'
126
+ end
127
+ end
128
+ end
129
+
130
+
131
+ describe R10K::Source::SVN, 'when prefixing is overridden' do
132
+ subject do
133
+ described_class.new(
134
+ 'mysource',
135
+ '/some/nonexistent/dir',
136
+ {
137
+ :remote => 'https://svn-server.site/repo',
138
+ :prefix => "tenant1"
139
+ }
140
+ )
141
+ end
142
+
143
+ describe "generating prefixed environments" do
144
+ before do
145
+ allow(subject.svn_remote).to receive(:branches).and_return %w[apache dns robobutler]
146
+ end
147
+
148
+ let(:environments) { subject.generate_environments }
149
+
150
+ it "creates an environment for each branch and the trunk" do
151
+ expect(environments.size).to eq(4)
152
+ end
153
+
154
+ it "prefixes the prefix name to environments" do
155
+ expect(environments[0].dirname).to eq 'tenant1_production'
156
+ expect(environments[1].dirname).to eq 'tenant1_apache'
157
+ expect(environments[2].dirname).to eq 'tenant1_dns'
158
+ expect(environments[3].dirname).to eq 'tenant1_robobutler'
159
+ end
160
+ end
161
+ end
162
+
163
+
98
164
  describe R10K::Source::SVN, 'registering as a source' do
99
165
  it "registers with the :svn key" do
100
166
  expect(R10K::Source.retrieve(:svn)).to eq described_class
@@ -0,0 +1,61 @@
1
+ require 'r10k/util/commands'
2
+ require 'r10k/util/exec_env'
3
+
4
+ require 'tmpdir'
5
+
6
+ describe R10K::Util::Commands do
7
+ describe "#which" do
8
+
9
+ before do
10
+ allow(File).to receive(:executable?).and_return false
11
+ allow(File).to receive(:file?).and_return false
12
+ end
13
+
14
+ def stub_executable(exe)
15
+ allow(File).to receive(:executable?).with(exe).and_return true
16
+ allow(File).to receive(:file?).with(exe).and_return true
17
+ end
18
+
19
+ describe "when ENV['PATHEXT'] is unset" do
20
+ let(:path) { Dir.mktmpdir }
21
+
22
+ around(:each) do |example|
23
+ R10K::Util::ExecEnv.withenv('PATHEXT' => nil, 'PATH' => path) do
24
+ example.run
25
+ end
26
+ end
27
+
28
+ it "returns the first matching command in PATH" do
29
+ exe = File.join(path, 'git')
30
+ stub_executable(exe)
31
+ expect(described_class.which("git")).to eq exe
32
+ end
33
+
34
+ it "returns nil if the command could not be found" do
35
+ exe = File.join(path, 'git')
36
+ expect(described_class.which("git")).to be_nil
37
+ end
38
+ end
39
+
40
+ describe "when ENV['PATHEXT'] is set" do
41
+ let(:path) { Dir.mktmpdir }
42
+
43
+ around(:each) do |example|
44
+ R10K::Util::ExecEnv.withenv('PATHEXT' => '.bat;.exe;.cmd', 'PATH' => path) do
45
+ example.run
46
+ end
47
+ end
48
+
49
+ it "returns the first matching command in PATH" do
50
+ exe = File.join(path, 'git.exe')
51
+ stub_executable(exe)
52
+ expect(described_class.which("git")).to eq exe
53
+ end
54
+
55
+ it "returns nil if the command could not be found" do
56
+ exe = File.join(path, 'git.exe')
57
+ expect(described_class.which("git")).to be_nil
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,56 @@
1
+ require 'r10k/util/exec_env'
2
+
3
+ describe R10K::Util::ExecEnv do
4
+ describe "withenv" do
5
+ it "adds the keys to the environment during the block" do
6
+ val = nil
7
+ described_class.withenv('VAL' => 'something') do
8
+ val = ENV['VAL']
9
+ end
10
+ expect(val).to eq 'something'
11
+ end
12
+
13
+ it "doesn't modify values that were not modified by the passed hash" do
14
+ origpath = ENV['PATH']
15
+ path = nil
16
+ described_class.withenv('VAL' => 'something') do
17
+ path = ENV['PATH']
18
+ end
19
+ expect(path).to eq origpath
20
+ end
21
+
22
+ it "removes new values after the block" do
23
+ val = nil
24
+ described_class.withenv('VAL' => 'something') { }
25
+ expect(ENV['VAL']).to be_nil
26
+ end
27
+
28
+ it "restores old values after the block" do
29
+ path = ENV['PATH']
30
+ described_class.withenv('PATH' => '/usr/bin') { }
31
+ expect(ENV['PATH']).to eq path
32
+ end
33
+ end
34
+
35
+ describe "reset" do
36
+
37
+ after { ENV.delete('VAL') }
38
+
39
+ it "replaces environment keys with the specified keys" do
40
+ ENV['VAL'] = 'hi'
41
+
42
+ newenv = ENV.to_hash
43
+ newenv['VAL'] = 'bye'
44
+
45
+ described_class.reset(newenv)
46
+ expect(ENV['VAL']).to eq 'bye'
47
+ end
48
+
49
+ it "removes any keys that were not provided" do
50
+ env = ENV.to_hash
51
+ ENV['VAL'] = 'hi'
52
+ described_class.reset(env)
53
+ expect(ENV['VAL']).to be_nil
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+ require 'r10k/util/subprocess/runner'
3
+
4
+ describe R10K::Util::Subprocess::Runner::POSIX, :if => R10K::Util::Platform.posix? do
5
+ fixture_root = File.expand_path('spec/fixtures/unit/util/subprocess/posix/runner', PROJECT_ROOT)
6
+ it_behaves_like 'a subprocess runner', fixture_root
7
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+ require 'r10k/util/subprocess/runner/pump'
3
+
4
+ describe R10K::Util::Subprocess::Runner::Pump do
5
+
6
+ let(:pair) { IO.pipe }
7
+ let(:r) { pair.first }
8
+ let(:w) { pair.last }
9
+
10
+ after do
11
+ pair.each { |io| io.close unless io.closed? }
12
+ end
13
+
14
+ subject { described_class.new(r) }
15
+
16
+ it "returns an empty string if nothing has been read" do
17
+ expect(subject.string).to eq('')
18
+ end
19
+
20
+ describe "reading all data in the stream" do
21
+ it "reads data until the stream reaches EOF" do
22
+ subject.start
23
+ w << "hello"
24
+ w << " "
25
+ w << "world!"
26
+ w.close
27
+ subject.wait
28
+ expect(subject.string).to eq("hello world!")
29
+ end
30
+ end
31
+
32
+ describe "halting" do
33
+ it "does not read any more information read off the pipe" do
34
+ subject.min_delay = 0.01
35
+ subject.start
36
+ w << "hello"
37
+
38
+ # This should ensure that we yield to the pumping thread. If this test
39
+ # sporadically fails then we may need to increase the timeout.
40
+ sleep 0.1
41
+ subject.halt!
42
+ w << " world!"
43
+
44
+ expect(subject.string).to eq("hello")
45
+ end
46
+ end
47
+
48
+ describe "backing off" do
49
+ it "does not back off more than the max delay time" do
50
+ max_delay = subject.min_delay * 2
51
+ subject.max_delay = max_delay
52
+ subject.start
53
+ sleep max_delay * 2
54
+
55
+ Timeout.timeout(max_delay * 1.5) do
56
+ subject.halt!
57
+ end
58
+
59
+ end
60
+ end
61
+
62
+ # Linux 2.6.11+ has a maximum pipe capacity of 64 KiB, and writing to the
63
+ # pipe when the pipe is at capacity will block. To make sure the pump is
64
+ # actively removing contents from the pipe we need to attempt to fill up
65
+ # the entire pipe.
66
+ #
67
+ # See man pipe(7)
68
+ it "does not block if more than 64 kilobytes are fed into the pipe" do
69
+ # The maximum pipe buffer size is 2 ** 16 bytes, so that's the minimum
70
+ # amount of data needed to cause further writes to block. We then double
71
+ # this value to make sure that we are continuously emptying the pipe.
72
+ pipe_buffer_size = 2 ** 17
73
+ blob = "buffalo!" * pipe_buffer_size
74
+ subject.start
75
+ Timeout.timeout(60) { w << blob }
76
+ w.close
77
+ subject.wait
78
+ end
79
+ end
@@ -6,11 +6,12 @@ describe R10K::Util::Subprocess do
6
6
  describe "selecting the runner implementation" do
7
7
  it "uses the windows implementation on Windows platforms" do
8
8
  expect(R10K::Util::Platform).to receive(:windows?).and_return true
9
- expect(described_class.runner).to eq R10K::Util::Subprocess::Windows::Runner
9
+ expect(described_class.runner).to eq R10K::Util::Subprocess::Runner::Windows
10
10
  end
11
+
11
12
  it "uses the posix implementation when not on windows" do
12
13
  expect(R10K::Util::Platform).to receive(:windows?).and_return true
13
- expect(described_class.runner).to eq R10K::Util::Subprocess::Windows::Runner
14
+ expect(described_class.runner).to eq R10K::Util::Subprocess::Runner::Windows
14
15
  end
15
16
  end
16
17
 
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'r10k/util/symbolize_keys'
3
+
4
+ describe R10K::Util::SymbolizeKeys do
5
+ it "deletes all keys that are strings" do
6
+ hash = {'foo' => 'bar', :baz => 'quux'}
7
+ described_class.symbolize_keys!(hash)
8
+ expect(hash).to_not have_key('foo')
9
+ end
10
+
11
+ it "replaces the deleted keys with interned strings" do
12
+ hash = {'foo' => 'bar', :baz => 'quux'}
13
+
14
+ described_class.symbolize_keys!(hash)
15
+ expect(hash[:foo]).to eq 'bar'
16
+ end
17
+
18
+ it "raises an error if there is an existing symbol for a given string key" do
19
+ hash = {'foo' => 'bar', :foo => 'quux'}
20
+
21
+ expect {
22
+ described_class.symbolize_keys!(hash)
23
+ }.to raise_error(TypeError, /An existing interned key/)
24
+ end
25
+
26
+ it "does not modify existing symbol entries" do
27
+ hash = {'foo' => 'bar', :baz => 'quux'}
28
+
29
+ described_class.symbolize_keys!(hash)
30
+ expect(hash[:baz]).to eq 'quux'
31
+ end
32
+
33
+ it "does not modify keys that are not strings or symbols" do
34
+ key = %w[foo]
35
+ hash = {key => 'bar', :baz => 'quux'}
36
+ described_class.symbolize_keys!(hash)
37
+ expect(hash[key]).to eq 'bar'
38
+ end
39
+
40
+ it "can recursively symbolize keys in nested hash values" do
41
+ hash = {'foo' => {'bar' => 'baz'}}
42
+ described_class.symbolize_keys!(hash, true)
43
+ expect(hash).to eq({:foo => {:bar => 'baz'}})
44
+ end
45
+
46
+ it "recurses into hash values that had symbol keys" do
47
+ hash = {:foo => {'bar' => {'baz' => 'quux'}}}
48
+ described_class.symbolize_keys!(hash, true)
49
+ expect(hash).to eq({:foo => {:bar => {:baz => 'quux'}}})
50
+ end
51
+ end