r10k 2.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. checksums.yaml +8 -8
  2. data/CHANGELOG.mkd +150 -0
  3. data/README.mkd +10 -1
  4. data/doc/dynamic-environments/configuration.mkd +31 -0
  5. data/doc/dynamic-environments/quickstart.mkd +33 -79
  6. data/doc/faq.mkd +67 -0
  7. data/doc/git/providers.mkd +37 -0
  8. data/doc/puppetfile.mkd +73 -0
  9. data/integration/lib/r10k_utils.rb +47 -2
  10. data/integration/pre-suite/01_git_config.rb +9 -8
  11. data/integration/pre-suite/02_pe_r10k.rb +5 -8
  12. data/integration/scripts/setup_r10k_env_centos5.sh +1 -1
  13. data/integration/scripts/setup_r10k_env_centos6.sh +1 -1
  14. data/integration/scripts/setup_r10k_env_rhel7.sh +1 -1
  15. data/integration/scripts/setup_r10k_env_sles11.sh +1 -1
  16. data/integration/scripts/setup_r10k_env_sles12.sh +1 -1
  17. data/integration/scripts/setup_r10k_env_ubuntu1004.sh +1 -1
  18. data/integration/scripts/setup_r10k_env_ubuntu1204.sh +1 -1
  19. data/integration/scripts/setup_r10k_env_ubuntu1404.sh +1 -1
  20. data/integration/test_run_scripts/all_tests-rugged-pe-centos6.sh +1 -1
  21. data/integration/test_run_scripts/all_tests-rugged-pe-rhel7.sh +1 -1
  22. data/integration/test_run_scripts/all_tests-rugged-pe-sles11.sh +1 -1
  23. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1204.sh +1 -1
  24. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1404.sh +1 -1
  25. data/integration/test_run_scripts/all_tests-shellgit-pe-centos6.sh +1 -1
  26. data/integration/test_run_scripts/all_tests-shellgit-pe-rhel7.sh +1 -1
  27. data/integration/test_run_scripts/all_tests-shellgit-pe-sles11.sh +1 -1
  28. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1204.sh +1 -1
  29. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1404.sh +1 -1
  30. data/integration/test_run_scripts/basic_functionality/all_tests-pe-centos6.sh +1 -1
  31. data/integration/test_run_scripts/command_line/all_tests-pe-centos6.sh +1 -1
  32. data/integration/test_run_scripts/git_source/all_tests-pe-centos6.sh +1 -1
  33. data/integration/test_run_scripts/user_scenario/basic_workflow/all_tests-pe-centos6.sh +1 -1
  34. data/integration/test_run_scripts/user_scenario/complex_workflow/all_tests-pe-centos6.sh +1 -1
  35. data/integration/tests/basic_functionality/install_pe_only_module_with_puppetfile.rb +83 -0
  36. data/integration/tests/basic_functionality/negative/attempt_to_install_peonly_module_without_license.rb +71 -0
  37. data/integration/tests/basic_functionality/negative/neg_deploy_with_invalid_r10k_yaml.rb +7 -2
  38. data/integration/tests/basic_functionality/negative/neg_deploy_with_missing_r10k_yaml.rb +3 -2
  39. data/integration/tests/basic_functionality/negative/neg_invalid_git_provider.rb +3 -2
  40. data/integration/tests/basic_functionality/negative/negative_bad_proxy.rb +56 -0
  41. data/integration/tests/basic_functionality/proxy_specified_in_configuration.rb +103 -0
  42. data/integration/tests/basic_functionality/proxy_with_puppetfile.rb +61 -0
  43. data/integration/tests/basic_functionality/rugged_git_provider_with_ssh.rb +2 -1
  44. data/integration/tests/basic_functionality/rugged_git_provider_without_ssh.rb +2 -1
  45. data/integration/tests/command_line/deploy_env_without_mod_update.rb +3 -2
  46. data/integration/tests/command_line/negative/neg_deploy_env_with_module_update.rb +3 -2
  47. data/integration/tests/command_line/negative/neg_invalid_cli_dep_flag.rb +2 -1
  48. data/integration/tests/command_line/negative/neg_invalid_cli_env_flag.rb +2 -1
  49. data/integration/tests/command_line/negative/neg_invalid_cmd_line_arg.rb +3 -4
  50. data/integration/tests/git_source/git_source_git.rb +7 -2
  51. data/integration/tests/git_source/git_source_ssh.rb +3 -2
  52. data/integration/tests/git_source/git_source_submodule.rb +2 -1
  53. data/integration/tests/git_source/negative/neg_git_broken_remote.rb +2 -1
  54. data/integration/tests/git_source/negative/neg_git_unauthorized_https.rb +2 -1
  55. data/integration/tests/git_source/negative/neg_git_unauthorized_ssh.rb +2 -1
  56. data/integration/tests/git_source/negative/neg_git_unicode_branch.rb +2 -1
  57. data/integration/tests/user_scenario/basic_workflow/multi_env_1000_branches.rb +3 -3
  58. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module.rb +2 -1
  59. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module_static.rb +9 -5
  60. data/integration/tests/user_scenario/basic_workflow/multi_env_hiera.rb +9 -2
  61. data/integration/tests/user_scenario/basic_workflow/multi_env_multi_source.rb +2 -1
  62. data/integration/tests/user_scenario/basic_workflow/multi_source_custom_forge_git_module.rb +2 -1
  63. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_basedir.rb +2 -1
  64. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_forge_module.rb +7 -2
  65. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module.rb +3 -4
  66. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module_ref.rb +2 -1
  67. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_remote.rb +2 -1
  68. data/integration/tests/user_scenario/basic_workflow/negative/neg_branch_name_collision.rb +2 -1
  69. data/integration/tests/user_scenario/basic_workflow/negative/neg_disk_full.rb +2 -1
  70. data/integration/tests/user_scenario/basic_workflow/negative/neg_duplicate_module_names.rb +10 -4
  71. data/integration/tests/user_scenario/basic_workflow/negative/neg_inaccessible_forge.rb +9 -2
  72. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_env_name.rb +2 -1
  73. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_puppet_file.rb +2 -1
  74. data/integration/tests/user_scenario/basic_workflow/negative/neg_module_specified_at_deleted_release.rb +7 -2
  75. data/integration/tests/user_scenario/basic_workflow/negative/neg_read_only.rb +2 -1
  76. data/integration/tests/user_scenario/basic_workflow/negative/neg_specify_deleted_forge_module.rb +9 -2
  77. data/integration/tests/user_scenario/basic_workflow/single_env_10000_files.rb +2 -1
  78. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_git_module.rb +2 -1
  79. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_module.rb +2 -1
  80. data/integration/tests/user_scenario/basic_workflow/single_env_custom_module.rb +2 -1
  81. data/integration/tests/user_scenario/basic_workflow/single_env_large_files.rb +2 -1
  82. data/integration/tests/user_scenario/basic_workflow/single_env_module_already_installed.rb +2 -1
  83. data/integration/tests/user_scenario/basic_workflow/single_env_module_last_release_deleted.rb +2 -1
  84. data/integration/tests/user_scenario/basic_workflow/single_env_non-existent_base_dir.rb +2 -1
  85. data/integration/tests/user_scenario/basic_workflow/single_env_purge_unmanaged_modules.rb +3 -2
  86. data/integration/tests/user_scenario/basic_workflow/single_env_switch_forge_git_module.rb +3 -2
  87. data/integration/tests/user_scenario/basic_workflow/single_env_unicode_paths.rb +2 -1
  88. data/integration/tests/user_scenario/basic_workflow/single_env_upgrade_forge_mod_revert_change.rb +4 -3
  89. data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +3 -2
  90. data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +4 -3
  91. data/integration/tests/user_scenario/complex_workflow/multi_env_unamanaged.rb +3 -2
  92. data/integration/tests/user_scenario/complex_workflow/single_env_git_module_update.rb +3 -2
  93. data/lib/r10k/action/base.rb +31 -0
  94. data/lib/r10k/action/deploy/deploy_helpers.rb +34 -0
  95. data/lib/r10k/action/deploy/display.rb +57 -75
  96. data/lib/r10k/action/deploy/environment.rb +52 -15
  97. data/lib/r10k/action/deploy/module.rb +13 -18
  98. data/lib/r10k/action/puppetfile/check.rb +8 -18
  99. data/lib/r10k/action/puppetfile/install.rb +13 -27
  100. data/lib/r10k/action/puppetfile/purge.rb +8 -17
  101. data/lib/r10k/action/runner.rb +39 -3
  102. data/lib/r10k/cli.rb +1 -3
  103. data/lib/r10k/cli/deploy.rb +3 -1
  104. data/lib/r10k/cli/puppetfile.rb +2 -2
  105. data/lib/r10k/deployment.rb +8 -6
  106. data/lib/r10k/deployment/config.rb +18 -65
  107. data/lib/r10k/environment/base.rb +19 -0
  108. data/lib/r10k/environment/git.rb +9 -0
  109. data/lib/r10k/environment/svn.rb +9 -0
  110. data/lib/r10k/forge/module_release.rb +21 -14
  111. data/lib/r10k/git.rb +6 -0
  112. data/lib/r10k/git/alternates.rb +20 -6
  113. data/lib/r10k/git/cache.rb +1 -1
  114. data/lib/r10k/git/rugged/bare_repository.rb +5 -0
  115. data/lib/r10k/git/rugged/base_repository.rb +6 -20
  116. data/lib/r10k/git/rugged/credentials.rb +66 -0
  117. data/lib/r10k/git/rugged/thin_repository.rb +16 -11
  118. data/lib/r10k/git/rugged/working_repository.rb +15 -7
  119. data/lib/r10k/git/shellgit/bare_repository.rb +9 -4
  120. data/lib/r10k/git/shellgit/thin_repository.rb +8 -10
  121. data/lib/r10k/git/stateful_repository.rb +1 -1
  122. data/lib/r10k/initializers.rb +55 -0
  123. data/lib/r10k/module.rb +1 -0
  124. data/lib/r10k/module/base.rb +3 -2
  125. data/lib/r10k/module/forge.rb +14 -6
  126. data/lib/r10k/module/local.rb +36 -0
  127. data/lib/r10k/module/metadata_file.rb +2 -2
  128. data/lib/r10k/puppetfile.rb +1 -1
  129. data/lib/r10k/settings.rb +86 -0
  130. data/lib/r10k/settings/collection.rb +118 -0
  131. data/lib/r10k/settings/definition.rb +112 -0
  132. data/lib/r10k/settings/enum_definition.rb +22 -0
  133. data/lib/r10k/settings/loader.rb +96 -0
  134. data/lib/r10k/settings/uri_definition.rb +19 -0
  135. data/lib/r10k/util/subprocess/runner/windows.rb +4 -4
  136. data/lib/r10k/version.rb +1 -1
  137. data/r10k.gemspec +2 -3
  138. data/spec/fixtures/unit/puppetfile/argument-error/Puppetfile +1 -0
  139. data/spec/fixtures/unit/util/subprocess/{posix/runner → runner}/no-execute.sh +0 -0
  140. data/spec/integration/git/rugged/thin_repository_spec.rb +2 -2
  141. data/spec/integration/git/rugged/working_repository_spec.rb +9 -0
  142. data/spec/integration/git/shellgit/thin_repository_spec.rb +2 -2
  143. data/spec/integration/git/stateful_repository_spec.rb +1 -1
  144. data/spec/r10k-mocks/mock_config.rb +10 -13
  145. data/spec/r10k-mocks/mock_env.rb +8 -0
  146. data/spec/shared-examples/deploy-actions.rb +69 -0
  147. data/spec/shared-examples/puppetfile-action.rb +17 -0
  148. data/spec/unit/action/cri_runner_spec.rb +3 -1
  149. data/spec/unit/action/deploy/deploy_helpers_spec.rb +38 -0
  150. data/spec/unit/action/deploy/display_spec.rb +31 -0
  151. data/spec/unit/action/deploy/environment_spec.rb +56 -0
  152. data/spec/unit/action/deploy/module_spec.rb +17 -0
  153. data/spec/unit/action/puppetfile/check_spec.rb +26 -0
  154. data/spec/unit/action/puppetfile/install_spec.rb +68 -0
  155. data/spec/unit/action/puppetfile/purge_spec.rb +19 -0
  156. data/spec/unit/action/runner_spec.rb +10 -9
  157. data/spec/unit/deployment/config_spec.rb +20 -44
  158. data/spec/unit/deployment_spec.rb +1 -1
  159. data/spec/unit/environment/git_spec.rb +20 -0
  160. data/spec/unit/environment/svn_spec.rb +20 -0
  161. data/spec/unit/forge/module_release_spec.rb +6 -3
  162. data/spec/unit/git/alternates_spec.rb +38 -12
  163. data/spec/unit/git/cache_spec.rb +4 -0
  164. data/spec/unit/git/rugged/credentials_spec.rb +74 -0
  165. data/spec/unit/initializers_spec.rb +68 -0
  166. data/spec/unit/module/base_spec.rb +2 -2
  167. data/spec/unit/module/forge_spec.rb +11 -3
  168. data/spec/unit/module/metadata_file_spec.rb +0 -1
  169. data/spec/unit/puppetfile_spec.rb +11 -0
  170. data/spec/unit/settings/collection_spec.rb +122 -0
  171. data/spec/unit/settings/definition_spec.rb +78 -0
  172. data/spec/unit/settings/enum_definition_spec.rb +20 -0
  173. data/spec/unit/{deployment/config → settings}/loader_spec.rb +50 -2
  174. data/spec/unit/settings/uri_definition_spec.rb +23 -0
  175. data/spec/unit/settings_spec.rb +151 -0
  176. data/spec/unit/util/subprocess/runner/posix_spec.rb +1 -1
  177. data/spec/unit/util/subprocess/runner/windows_spec.rb +7 -0
  178. metadata +53 -90
  179. data/lib/r10k/deployment/config/loader.rb +0 -59
  180. data/lib/shared/puppet/module_tool/metadata.rb +0 -197
  181. data/lib/shared/puppet_forge/connection.rb +0 -64
  182. data/lib/shared/puppet_forge/connection/connection_failure.rb +0 -26
  183. data/lib/shared/puppet_forge/error.rb +0 -41
  184. data/lib/shared/puppet_forge/tar.rb +0 -10
  185. data/lib/shared/puppet_forge/tar/mini.rb +0 -81
  186. data/lib/shared/puppet_forge/unpacker.rb +0 -68
  187. data/lib/shared/puppet_forge/v3.rb +0 -13
  188. data/lib/shared/puppet_forge/v3/module.rb +0 -69
  189. data/lib/shared/puppet_forge/v3/module_release.rb +0 -85
  190. data/lib/shared/puppet_forge/version.rb +0 -3
  191. data/spec/unit/puppet/module_tool/metadata_spec.rb +0 -301
  192. data/spec/unit/puppet_forge/connection/connection_failure_spec.rb +0 -28
  193. data/spec/unit/puppet_forge/connection_spec.rb +0 -41
  194. data/spec/unit/puppet_forge/tar/mini_spec.rb +0 -87
  195. data/spec/unit/puppet_forge/tar_spec.rb +0 -9
  196. data/spec/unit/puppet_forge/unpacker_spec.rb +0 -59
  197. data/spec/unit/puppet_forge/v3/module_release_spec.rb +0 -83
  198. data/spec/unit/puppet_forge/v3/module_spec.rb +0 -75
@@ -110,4 +110,24 @@ describe R10K::Environment::SVN do
110
110
  expect(subject.status).to eq :insync
111
111
  end
112
112
  end
113
+
114
+ describe "environment signature" do
115
+ it "returns the svn revision of the branch" do
116
+ expect(working_dir).to receive(:revision).and_return '1337'
117
+ expect(subject.signature).to eq '1337'
118
+ end
119
+ end
120
+
121
+ describe "info hash" do
122
+ let(:info_hash) { subject.info }
123
+
124
+ before(:each) do
125
+ expect(working_dir).to receive(:revision).and_return '1337'
126
+ end
127
+
128
+ it "includes name and signature" do
129
+ expect(info_hash.keys).to include :name, :signature
130
+ expect(info_hash).not_to have_value(nil)
131
+ end
132
+ end
113
133
  end
@@ -1,10 +1,13 @@
1
1
  require 'spec_helper'
2
2
  require 'r10k/forge/module_release'
3
3
  require 'r10k/util/exec_env'
4
+ require 'puppet_forge'
4
5
 
5
6
  describe R10K::Forge::ModuleRelease do
6
7
  subject { described_class.new('branan-eight_hundred', '8.0.0') }
7
8
 
9
+ let(:forge_release_class) { PuppetForge::V3::Release }
10
+
8
11
  let(:download_path) { instance_double('Pathname') }
9
12
  let(:unpack_path) { instance_double('Pathname') }
10
13
  let(:target_dir) { instance_double('Pathname') }
@@ -20,7 +23,7 @@ describe R10K::Forge::ModuleRelease do
20
23
  it "respects the #{env_var} environment variable" do
21
24
  R10K::Util::ExecEnv.withenv(env_var => "http://proxy.value") do
22
25
  subject = described_class.new('branan-eight_hundred', '8.0.0')
23
- proxy_uri = subject.forge_release.conn.proxy.uri
26
+ proxy_uri = forge_release_class.conn.proxy.uri
24
27
  expect(proxy_uri.to_s).to eq "http://proxy.value"
25
28
  end
26
29
  end
@@ -32,14 +35,14 @@ describe R10K::Forge::ModuleRelease do
32
35
 
33
36
  it 'has a setting for the forge proxy' do
34
37
  subject = described_class.new('branan-eight_hundred', '8.0.0')
35
- proxy_uri = subject.forge_release.conn.proxy.uri
38
+ proxy_uri = forge_release_class.conn.proxy.uri
36
39
  expect(proxy_uri.to_s).to eq "http://proxy.setting"
37
40
  end
38
41
 
39
42
  it 'prefers the proxy setting over an environment variable' do
40
43
  R10K::Util::ExecEnv.withenv('HTTPS_PROXY' => "http://proxy.from.env") do
41
44
  subject = described_class.new('branan-eight_hundred', '8.0.0')
42
- proxy_uri = subject.forge_release.conn.proxy.uri
45
+ proxy_uri = forge_release_class.conn.proxy.uri
43
46
  expect(proxy_uri.to_s).to eq "http://proxy.setting"
44
47
  end
45
48
  end
@@ -17,7 +17,7 @@ describe R10K::Git::Alternates do
17
17
  "/vagrant/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git\n",
18
18
  ])
19
19
 
20
- expect(subject.to_a).to eq([
20
+ expect(subject.read).to eq([
21
21
  "/var/cache/r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
22
22
  "/vagrant/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
23
23
  ])
@@ -47,11 +47,12 @@ describe R10K::Git::Alternates do
47
47
  end
48
48
  end
49
49
 
50
- describe "appending a new alternate object entry" do
50
+
51
+ describe "writing alternate entries" do
51
52
  describe "and the git objects/info directory does not exist" do
52
53
  it "raises an error when the parent directory does not exist" do
53
54
  expect {
54
- subject << "/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git"
55
+ subject.write(["/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git"])
55
56
  }.to raise_error(R10K::Git::GitError,"Cannot write /some/nonexistent/path/.git/objects/info/alternates; parent directory does not exist")
56
57
  end
57
58
  end
@@ -64,20 +65,15 @@ describe R10K::Git::Alternates do
64
65
  expect(subject.file).to receive_message_chain(:parent, :directory?).and_return true
65
66
  end
66
67
 
67
-
68
68
  it "creates the alternates file with the new entry when not present" do
69
- expect(subject).to receive(:to_a).and_return([])
70
- subject << "/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git"
71
-
69
+ subject.write(["/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git"])
72
70
  expect(io.string).to eq("/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git\n")
73
71
  end
74
72
 
75
73
  it "rewrites the file with all alternate entries" do
76
- expect(subject).to receive(:to_a).and_return([
77
- "/var/cache/r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
78
- "/vagrant/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
79
- ])
80
- subject << "/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git"
74
+ subject.write(["/var/cache/r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
75
+ "/vagrant/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
76
+ "/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git"])
81
77
 
82
78
  expect(io.string).to eq(<<-EOD)
83
79
  /var/cache/r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git
@@ -86,5 +82,35 @@ describe R10K::Git::Alternates do
86
82
  EOD
87
83
  end
88
84
  end
85
+
86
+ describe "appending a new alternate object entry" do
87
+ it "re-writes the file with the new entry concatenated to the file" do
88
+ expect(subject).to receive(:to_a).and_return(["/var/cache/r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
89
+ "/vagrant/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git"])
90
+
91
+ expect(subject).to receive(:write).with(["/var/cache/r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
92
+ "/vagrant/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
93
+ "/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git"])
94
+
95
+ subject.add("/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git")
96
+ end
97
+ end
98
+ end
99
+
100
+ describe "conditionally appending a new alternate object entry" do
101
+ before do
102
+ expect(subject).to receive(:read).and_return(%w[/var/cache/r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git])
103
+ end
104
+
105
+ it "adds the entry and returns true when the entry doesn't exist" do
106
+ expect(subject).to receive(:write).with(["/var/cache/r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
107
+ "/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git"])
108
+ expect(subject.add?("/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git")).to eq true
109
+ end
110
+
111
+ it "doesn't modify the file and returns false when the entry exists" do
112
+ expect(subject).to_not receive(:write)
113
+ expect(subject.add?("/var/cache/r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git")).to eq false
114
+ end
89
115
  end
90
116
  end
@@ -31,6 +31,10 @@ describe R10K::Git::Cache do
31
31
  expect_delegation(:git_dir)
32
32
  end
33
33
 
34
+ it "delegates #objects_dir" do
35
+ expect_delegation(:objects_dir)
36
+ end
37
+
34
38
  it "delegates #branches" do
35
39
  expect_delegation(:branches)
36
40
  end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+ require 'r10k/git/rugged/credentials'
3
+ require 'rugged/credentials'
4
+
5
+ describe R10K::Git::Rugged::Credentials do
6
+
7
+ let(:repo) { R10K::Git::Rugged::BareRepository.new("/some/nonexistent/path", "repo.git") }
8
+
9
+ subject { described_class.new(repo) }
10
+
11
+ after(:all) { R10K::Git.settings.reset! }
12
+
13
+ describe "determining the username" do
14
+ before { R10K::Git.settings[:username] = "moderns" }
15
+ after { R10K::Git.settings.reset! }
16
+
17
+ it "prefers a username from the URL" do
18
+ user = subject.get_git_username("https://tessier-ashpool.freeside/repo.git", "ashpool")
19
+ expect(user).to eq "ashpool"
20
+ end
21
+
22
+ it "uses the username from the Git config when specified" do
23
+ user = subject.get_git_username("https://tessier-ashpool.freeside/repo.git", nil)
24
+ expect(user).to eq "moderns"
25
+ end
26
+
27
+ it "falls back to the current user" do
28
+ R10K::Git.settings.reset!
29
+ expect(Etc).to receive(:getlogin).and_return("finn")
30
+ user = subject.get_git_username("https://tessier-ashpool.freeside/repo.git", nil)
31
+ expect(user).to eq "finn"
32
+ end
33
+ end
34
+
35
+ describe "generating ssh key credentials" do
36
+ after { R10K::Git.settings.reset! }
37
+
38
+ it "raises an error if no key has been set" do
39
+ R10K::Git.settings[:private_key] = nil
40
+ expect {
41
+ subject.get_ssh_key_credentials("https://tessier-ashpool.freeside/repo.git", nil)
42
+ }.to raise_error(R10K::Git::GitError, /no private key was given/)
43
+ end
44
+
45
+ it "generates the rugged sshkey credential type" do
46
+ R10K::Git.settings[:private_key] = "/some/nonexistent/.ssh/key"
47
+ creds = subject.get_ssh_key_credentials("https://tessier-ashpool.freeside/repo.git", nil)
48
+ expect(creds).to be_a_kind_of(Rugged::Credentials::SshKey)
49
+ expect(creds.instance_variable_get(:@privatekey)).to eq("/some/nonexistent/.ssh/key")
50
+ end
51
+ end
52
+
53
+ describe "generating default credentials" do
54
+ it "generates the rugged default credential type" do
55
+ creds = subject.get_default_credentials("https://azurediamond:hunter2@tessier-ashpool.freeside/repo.git", "azurediamond")
56
+ expect(creds).to be_a_kind_of(Rugged::Credentials::Default)
57
+ end
58
+ end
59
+
60
+ describe "generating credentials" do
61
+ it "creates ssh key credentials for the sshkey allowed type" do
62
+ R10K::Git.settings[:private_key] = "/some/nonexistent/.ssh/key"
63
+ expect(subject.call("https://tessier-ashpool.freeside/repo.git", nil, [:ssh_key])).to be_a_kind_of(Rugged::Credentials::SshKey)
64
+ end
65
+
66
+ it "creates user/password credentials for the default allowed type" do
67
+ expect(subject.call("https://tessier-ashpool.freeside/repo.git", nil, [:plaintext])).to be_a_kind_of(Rugged::Credentials::UserPassword)
68
+ end
69
+
70
+ it "creates default credentials when no other types are allowed" do
71
+ expect(subject.call("https://tessier-ashpool.freeside/repo.git", nil, [])).to be_a_kind_of(Rugged::Credentials::Default)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+ require 'r10k/initializers'
3
+
4
+ describe R10K::Initializers::GitInitializer do
5
+ it "configures the Git provider" do
6
+ subject = described_class.new({:provider => :rugged})
7
+ expect(R10K::Git).to receive(:provider=).with(:rugged)
8
+ subject.call
9
+ end
10
+
11
+ it "configures the Git username" do
12
+ subject = described_class.new({:username => 'git'})
13
+ expect(R10K::Git.settings).to receive(:[]=).with(:username, 'git')
14
+ subject.call
15
+ end
16
+
17
+ it "configures the Git private key" do
18
+ subject = described_class.new({:private_key => '/etc/puppetlabs/r10k/id_rsa'})
19
+ expect(R10K::Git.settings).to receive(:[]=).with(:private_key, '/etc/puppetlabs/r10k/id_rsa')
20
+ subject.call
21
+ end
22
+ end
23
+
24
+ describe R10K::Initializers::ForgeInitializer do
25
+ it "configures the Forge proxy" do
26
+ subject = described_class.new({:proxy => 'http://my.site.proxy:3128'})
27
+ expect(R10K::Forge::ModuleRelease.settings).to receive(:[]=).with(:proxy, 'http://my.site.proxy:3128')
28
+ subject.call
29
+ end
30
+
31
+ it "configures the Forge baseurl" do
32
+ subject = described_class.new({:baseurl => 'https://my.site.forge'})
33
+ expect(R10K::Forge::ModuleRelease.settings).to receive(:[]=).with(:baseurl, 'https://my.site.forge')
34
+ subject.call
35
+ end
36
+ end
37
+
38
+ describe R10K::Initializers::GlobalInitializer do
39
+ it "logs a warning if purgedirs was set" do
40
+ subject = described_class.new({:purgedirs => 'This setting has been deprecated for over two years :('})
41
+ expect(subject.logger).to receive(:warn).with('the purgedirs key in r10k.yaml is deprecated. it is currently ignored.')
42
+ subject.call
43
+ end
44
+
45
+ it "sets the Git cache_root" do
46
+ subject = described_class.new({:cachedir => '/var/cache/r10k'})
47
+ expect(R10K::Git::Cache.settings).to receive(:[]=).with(:cache_root, '/var/cache/r10k')
48
+ subject.call
49
+ end
50
+
51
+ it "delegates git settings to the Git initializer" do
52
+ git = instance_double('R10K::Initializers::GitInitializer')
53
+ expect(git).to receive(:call)
54
+ expect(R10K::Initializers::GitInitializer).to receive(:new).and_return(git)
55
+
56
+ subject = described_class.new({:git => {}})
57
+ subject.call
58
+ end
59
+
60
+ it "delegates forge settings to the Forge initializer" do
61
+ forge = instance_double('R10K::Initializers::ForgeInitializer')
62
+ expect(forge).to receive(:call)
63
+ expect(R10K::Initializers::ForgeInitializer).to receive(:new).and_return(forge)
64
+
65
+ subject = described_class.new({:forge => {}})
66
+ subject.call
67
+ end
68
+ end
@@ -48,7 +48,7 @@ describe R10K::Module::Base do
48
48
  end
49
49
 
50
50
  it "aliases full_name to title" do
51
- expect(subject.full_name).to eq 'branan/eight_hundred'
51
+ expect(subject.full_name).to eq 'branan-eight_hundred'
52
52
  end
53
53
 
54
54
  it "aliases author to owner" do
@@ -61,7 +61,7 @@ describe R10K::Module::Base do
61
61
  end
62
62
 
63
63
  describe "accepting a visitor" do
64
- subject { described_class.new('branan/eight_hundred', '/moduledir', []) }
64
+ subject { described_class.new('branan-eight_hundred', '/moduledir', []) }
65
65
 
66
66
  it "passes itself to the visitor" do
67
67
  visitor = spy('visitor')
@@ -38,7 +38,7 @@ describe R10K::Module::Forge do
38
38
  end
39
39
 
40
40
  it "sets the title" do
41
- expect(subject.title).to eq 'branan/eight_hundred'
41
+ expect(subject.title).to eq 'branan-eight_hundred'
42
42
  end
43
43
  end
44
44
 
@@ -67,7 +67,7 @@ describe R10K::Module::Forge do
67
67
 
68
68
  it "uses the latest version from the forge when the version is :latest" do
69
69
  subject = described_class.new('branan/eight_hundred', fixture_modulepath, :latest)
70
- expect(subject.v3_module).to receive(:latest_version).and_return('8.8.8')
70
+ expect(subject.v3_module).to receive_message_chain(:current_release, :version).and_return('8.8.8')
71
71
  expect(subject.expected_version).to eq '8.8.8'
72
72
  end
73
73
  end
@@ -88,9 +88,16 @@ describe R10K::Module::Forge do
88
88
  expect(subject.status).to eq :mismatched
89
89
  end
90
90
 
91
+ it "is :mismatched if module was previously a git checkout" do
92
+ allow(File).to receive(:directory?).and_return true
93
+
94
+ expect(subject.status).to eq :mismatched
95
+ end
96
+
91
97
  it "is :mismatched if the metadata author doesn't match the expected author" do
92
98
  allow(subject).to receive(:exist?).and_return true
93
99
 
100
+ allow(subject.instance_variable_get(:@metadata_file)).to receive(:read).and_return subject.metadata
94
101
  allow(subject.metadata).to receive(:full_module_name).and_return 'blargh-blargh'
95
102
 
96
103
  expect(subject.status).to eq :mismatched
@@ -99,6 +106,7 @@ describe R10K::Module::Forge do
99
106
  it "is :outdated if the metadata version doesn't match the expected version" do
100
107
  allow(subject).to receive(:exist?).and_return true
101
108
 
109
+ allow(subject.instance_variable_get(:@metadata_file)).to receive(:read).and_return subject.metadata
102
110
  allow(subject.metadata).to receive(:version).and_return '7.0.0'
103
111
  expect(subject.status).to eq :outdated
104
112
  end
@@ -145,7 +153,7 @@ describe R10K::Module::Forge do
145
153
  it 'installs the module from the forge' do
146
154
  subject = described_class.new('branan/eight_hundred', fixture_modulepath, '8.0.0')
147
155
  release = instance_double('R10K::Forge::ModuleRelease')
148
- expect(R10K::Forge::ModuleRelease).to receive(:new).with('branan/eight_hundred', '8.0.0').and_return(release)
156
+ expect(R10K::Forge::ModuleRelease).to receive(:new).with('branan-eight_hundred', '8.0.0').and_return(release)
149
157
  expect(release).to receive(:install).with(subject.path)
150
158
  subject.install
151
159
  end
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'shared/puppet/module_tool/metadata'
3
2
 
4
3
  describe R10K::Module::MetadataFile do
5
4
 
@@ -55,6 +55,17 @@ describe R10K::Puppetfile do
55
55
  expect_wrapped_error(e, pf_path, LoadError)
56
56
  end
57
57
  end
58
+
59
+ it "wraps and re-raises argument errors" do
60
+ path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'argument-error')
61
+ pf_path = File.join(path, 'Puppetfile')
62
+ subject = described_class.new(path)
63
+ expect {
64
+ subject.load!
65
+ }.to raise_error do |e|
66
+ expect_wrapped_error(e, pf_path, ArgumentError)
67
+ end
68
+ end
58
69
  end
59
70
 
60
71
  describe "accepting a visitor" do
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+ require 'r10k/settings/collection'
3
+ require 'r10k/settings/definition'
4
+
5
+ describe R10K::Settings::Collection do
6
+
7
+ let(:symbol_defn) { R10K::Settings::Definition.new(:symbol_defn, :validate => lambda { |x| raise TypeError unless x.is_a?(Symbol) }) }
8
+ let(:default_defn) { R10K::Settings::Definition.new(:default_defn, :default => lambda { "Defaults are fun" }) }
9
+
10
+ subject do
11
+ described_class.new(:collection, [symbol_defn, default_defn])
12
+ end
13
+
14
+ describe "#evaluate" do
15
+ it "assigns values, validates them, and resolves a final value" do
16
+ expect(subject).to receive(:assign).with({:default_defn => :squid})
17
+ expect(subject).to receive(:validate)
18
+ expect(subject).to receive(:resolve)
19
+ subject.evaluate({:default_defn => :squid})
20
+ end
21
+ end
22
+
23
+
24
+ describe '#assign' do
25
+ it "assigns values to the appropriate setting" do
26
+ subject.assign({:symbol_defn => :hello})
27
+ expect(symbol_defn.value).to eq :hello
28
+ end
29
+
30
+ it "can accept invalid settings" do
31
+ subject.assign({:hardly_a_setting => "nope nope nope"})
32
+ end
33
+
34
+ it "silently ignores attempts to assign nil" do
35
+ subject.assign(nil)
36
+ end
37
+ end
38
+
39
+ describe '#validate' do
40
+ it "raises an error containing a hash of nested validation errors" do
41
+ subject.assign({:symbol_defn => "Definitely not a symbol"})
42
+ expect {
43
+ errors = subject.validate
44
+ }.to raise_error do |error|
45
+ expect(error).to be_a_kind_of(R10K::Settings::Collection::ValidationError)
46
+ errors = error.errors
47
+ expect(errors.size).to eq 1
48
+ expect(errors[:symbol_defn]).to be_a_kind_of(TypeError)
49
+ end
50
+ end
51
+
52
+ it "it does not raise an error if no errors were found" do
53
+ subject.assign({:default_defn => "yep"})
54
+ expect(subject.validate).to be_nil
55
+ end
56
+ end
57
+
58
+ describe '#resolve' do
59
+ it "returns a frozen hash of all settings" do
60
+ subject.assign({:symbol_defn => :some_value})
61
+ rv = subject.resolve
62
+ expect(rv).to be_frozen
63
+ expect(rv).to eq({:symbol_defn => :some_value, :default_defn => "Defaults are fun"})
64
+ end
65
+ end
66
+ end
67
+
68
+ describe R10K::Settings::Collection::ValidationError do
69
+
70
+
71
+ let(:flat_errors) do
72
+ described_class.new("Validation failures for some group", errors: {
73
+ some_defn: ArgumentError.new("some_defn is wrong, somehow."),
74
+ uri_setting: ArgumentError.new("uri_setting NOTAURI is not a URI.")
75
+ })
76
+ end
77
+
78
+ let(:flat_error_text) do
79
+ [
80
+ "Validation failures for some group:",
81
+ " some_defn:",
82
+ " some_defn is wrong, somehow.",
83
+ " uri_setting:",
84
+ " uri_setting NOTAURI is not a URI."]
85
+ .join("\n")
86
+ end
87
+
88
+ let(:nested_errors) do
89
+ described_class.new("Validation failures for some nesting group", errors: {
90
+ file_setting: ArgumentError.new("file_setting is a potato, not a file."),
91
+ nested: flat_errors
92
+ })
93
+ end
94
+
95
+ let(:nested_error_text) do
96
+ [
97
+ "Validation failures for some nesting group:",
98
+ " file_setting:",
99
+ " file_setting is a potato, not a file.",
100
+ " nested:",
101
+ " Validation failures for some group:",
102
+ " some_defn:",
103
+ " some_defn is wrong, somehow.",
104
+ " uri_setting:",
105
+ " uri_setting NOTAURI is not a URI."
106
+ ].join("\n")
107
+ end
108
+
109
+ describe "formatting a human readable error message" do
110
+ describe "no with no nested validation errors" do
111
+ it "generates a human readable set of validation errors." do
112
+ expect(flat_errors.format).to eq flat_error_text
113
+ end
114
+ end
115
+
116
+ describe "with nested validation errors" do
117
+ it "generates a human readable set of validation errors." do
118
+ expect(nested_errors.format).to eq nested_error_text
119
+ end
120
+ end
121
+ end
122
+ end