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
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for "a puppetfile action" do
4
+ describe "initializing" do
5
+ it "accepts the :root option" do
6
+ described_class.new({root: "/some/nonexistent/path"}, [])
7
+ end
8
+
9
+ it "accepts the :puppetfile option" do
10
+ described_class.new({puppetfile: "/some/nonexistent/path/Puppetfile"}, [])
11
+ end
12
+
13
+ it "accepts the :moduledir option" do
14
+ described_class.new({moduledir: "/some/nonexistent/path/modules"}, [])
15
+ end
16
+ end
17
+ end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'r10k/action/base'
2
3
  require 'r10k/action/cri_runner'
3
4
 
4
5
  describe R10K::Action::CriRunner do
@@ -8,9 +9,10 @@ describe R10K::Action::CriRunner do
8
9
  attr_reader :opts
9
10
  attr_reader :argv
10
11
 
11
- def initialize(opts, argv)
12
+ def initialize(opts, argv, settings = {})
12
13
  @opts = opts
13
14
  @argv = argv
15
+ @settings = {}
14
16
  end
15
17
 
16
18
  def call
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ require 'r10k/logging'
4
+ require 'r10k/action/deploy/deploy_helpers'
5
+
6
+ describe R10K::Action::Deploy::DeployHelpers do
7
+ subject do
8
+ Object.new.tap do |o|
9
+ o.extend(R10K::Logging)
10
+ o.extend(described_class)
11
+ end
12
+ end
13
+
14
+ describe "checking for a config file" do
15
+ it "logs a warning and exits when no config file was set" do
16
+ logger = subject.logger
17
+
18
+ expect(logger).to receive(:fatal).with("No configuration file given, no config file found in current directory, and no global config present")
19
+
20
+ expect {
21
+ subject.expect_config!
22
+ }.to exit_with(8)
23
+ end
24
+ end
25
+
26
+ describe "checking the write lock setting" do
27
+ it "logs a warning and exits when the write lock is set" do
28
+ logger = subject.logger
29
+
30
+ expect(logger).to receive(:fatal).with("Making changes to deployed environments has been administratively disabled.")
31
+ expect(logger).to receive(:fatal).with("Reason: r10k is sleepy and wants to take a nap")
32
+
33
+ expect {
34
+ subject.check_write_lock!(deploy: {write_lock: "r10k is sleepy and wants to take a nap"})
35
+ }.to exit_with(16)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ require 'r10k/action/deploy/display'
4
+
5
+ describe R10K::Action::Deploy::Display do
6
+ describe "initializing" do
7
+ it "accepts a puppetfile option" do
8
+ described_class.new({puppetfile: true}, [])
9
+ end
10
+
11
+ it "accepts a detail option" do
12
+ described_class.new({detail: true}, [])
13
+ end
14
+
15
+ it "accepts a format option" do
16
+ described_class.new({format: "json"}, [])
17
+ end
18
+
19
+ it "accepts a fetch option" do
20
+ described_class.new({fetch: true}, [])
21
+ end
22
+ end
23
+
24
+ subject { described_class.new({config: "/some/nonexistent/path"}, []) }
25
+
26
+ before do
27
+ allow(subject).to receive(:puts)
28
+ end
29
+
30
+ it_behaves_like "a deploy action that requires a config file"
31
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ require 'r10k/deployment'
4
+ require 'r10k/action/deploy/environment'
5
+
6
+ describe R10K::Action::Deploy::Environment do
7
+
8
+ subject { described_class.new({config: "/some/nonexistent/path"}, []) }
9
+
10
+ it_behaves_like "a deploy action that can be write locked"
11
+ it_behaves_like "a deploy action that requires a config file"
12
+
13
+ describe "initializing" do
14
+ it "can accept a cachedir option" do
15
+ described_class.new({cachedir: "/some/nonexistent/cachedir"}, [])
16
+ end
17
+
18
+ it "can accept a puppetfile option" do
19
+ described_class.new({puppetfile: true}, [])
20
+ end
21
+
22
+ it "normalizes environment names in the arg vector"
23
+ end
24
+
25
+ describe "when called" do
26
+ describe "with an environment that doesn't exist" do
27
+ let(:config) do
28
+ R10K::Deployment::MockConfig.new(
29
+ :sources => {
30
+ :control => {
31
+ :type => :mock,
32
+ :basedir => '/some/nonexistent/path/control',
33
+ :environments => %w[first second third],
34
+ }
35
+ }
36
+ )
37
+ end
38
+
39
+ let(:deployment) do
40
+ R10K::Deployment.new(config)
41
+ end
42
+
43
+ before do
44
+ expect(R10K::Deployment).to receive(:new).and_return(deployment)
45
+ end
46
+
47
+ subject { described_class.new({config: "/some/nonexistent/path", purge: false}, %w[not_an_environment]) }
48
+
49
+ it "logs that the environments can't be deployed and returns false" do
50
+ expect(subject.logger).to receive(:error).with("Environment(s) 'not_an_environment' cannot be found in any source and will not be deployed.")
51
+ logger = subject.logger
52
+ expect(subject.call).to eq false
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ require 'r10k/action/deploy/module'
4
+
5
+ describe R10K::Action::Deploy::Module do
6
+
7
+ subject { described_class.new({config: "/some/nonexistent/path"}, []) }
8
+
9
+ it_behaves_like "a deploy action that requires a config file"
10
+ it_behaves_like "a deploy action that can be write locked"
11
+
12
+ describe "initializing" do
13
+ it "accepts an environment option" do
14
+ described_class.new({environment: "production"}, [])
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+ require 'r10k/action/puppetfile/check'
3
+
4
+ describe R10K::Action::Puppetfile::Check do
5
+
6
+ subject { described_class.new({root: "/some/nonexistent/path"}, []) }
7
+
8
+ let(:puppetfile) { instance_double('R10K::Puppetfile') }
9
+
10
+ before { allow(R10K::Puppetfile).to receive(:new).with("/some/nonexistent/path", nil, nil).and_return(puppetfile) }
11
+
12
+ it_behaves_like "a puppetfile action"
13
+
14
+ it "prints 'Syntax OK' when the Puppetfile syntax could be validated" do
15
+ expect(puppetfile).to receive(:load!)
16
+ expect($stderr).to receive(:puts).with("Syntax OK")
17
+ subject.call
18
+ end
19
+
20
+ it "prints an error message when validating the Puppetfile syntax raised an error" do
21
+ expect(puppetfile).to receive(:load!).and_raise(R10K::Error.new("Boom!"))
22
+ expect(R10K::Errors::Formatting).to receive(:format_exception).with(instance_of(R10K::Error), anything).and_return("Formatted error message")
23
+ expect($stderr).to receive(:puts).with("Formatted error message")
24
+ subject.call
25
+ end
26
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+ require 'r10k/action/puppetfile/install'
3
+
4
+ describe R10K::Action::Puppetfile::Install do
5
+
6
+ subject { described_class.new({root: "/some/nonexistent/path"}, []) }
7
+
8
+ let(:puppetfile) { R10K::Puppetfile.new('/some/nonexistent/path', nil, nil) }
9
+
10
+ before do
11
+ allow(R10K::Puppetfile).to receive(:new).with("/some/nonexistent/path", nil, nil).and_return(puppetfile)
12
+ end
13
+
14
+ it_behaves_like "a puppetfile action"
15
+
16
+ describe "installing modules" do
17
+ let(:modules) do
18
+ Array.new(4, R10K::Module::Base.new('author/modname', "/some/nonexistent/path/modname", nil))
19
+ end
20
+
21
+ before do
22
+ allow(puppetfile).to receive(:purge!)
23
+ allow(puppetfile).to receive(:modules).and_return(modules)
24
+ end
25
+
26
+ it "syncs each module in the Puppetfile" do
27
+ expect(puppetfile).to receive(:load!)
28
+ modules.each { |m| expect(m).to receive(:sync) }
29
+ expect(subject.call).to eq true
30
+ end
31
+
32
+ it "returns false if a module failed to install" do
33
+ expect(puppetfile).to receive(:load!)
34
+
35
+ modules[0..2].each { |m| expect(m).to receive(:sync) }
36
+ expect(modules[3]).to receive(:sync).and_raise
37
+ expect(subject.call).to eq false
38
+ end
39
+ end
40
+
41
+ describe "purging" do
42
+ before do
43
+ allow(puppetfile).to receive(:load!)
44
+ allow(puppetfile).to receive(:modules).and_return([])
45
+ end
46
+
47
+ it "purges the moduledir after installation" do
48
+ expect(puppetfile).to receive(:purge!)
49
+ subject.call
50
+ end
51
+ end
52
+
53
+ describe "using custom paths" do
54
+ let(:puppetfile) { instance_double("R10K::Puppetfile", load!: nil, accept: nil, purge!: nil) }
55
+
56
+ it "can use a custom puppetfile path" do
57
+ subject = described_class.new({root: "/some/nonexistent/path", puppetfile: "/some/other/path/Puppetfile"}, [])
58
+ expect(R10K::Puppetfile).to receive(:new).with("/some/nonexistent/path", nil, "/some/other/path/Puppetfile").and_return(puppetfile)
59
+ subject.call
60
+ end
61
+
62
+ it "can use a custom moduledir path" do
63
+ subject = described_class.new({root: "/some/nonexistent/path", moduledir: "/some/other/path/site-modules"}, [])
64
+ expect(R10K::Puppetfile).to receive(:new).with("/some/nonexistent/path", "/some/other/path/site-modules", nil).and_return(puppetfile)
65
+ subject.call
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ require 'r10k/action/puppetfile/purge'
3
+
4
+ describe R10K::Action::Puppetfile::Purge do
5
+
6
+ subject { described_class.new({root: "/some/nonexistent/path"}, []) }
7
+
8
+ let(:puppetfile) { instance_double('R10K::Puppetfile') }
9
+
10
+ before { allow(R10K::Puppetfile).to receive(:new).with("/some/nonexistent/path", nil, nil).and_return(puppetfile) }
11
+
12
+ it_behaves_like "a puppetfile action"
13
+
14
+ it "purges unmanaged entries in the Puppetfile moduledir" do
15
+ allow(puppetfile).to receive(:load!)
16
+ expect(puppetfile).to receive(:purge!)
17
+ subject.call
18
+ end
19
+ end
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
- require 'r10k/action/runner'
2
+ require 'r10k/action/base'
3
+ require 'puppet_forge/connection'
3
4
 
5
+ require 'r10k/action/runner'
4
6
 
5
7
  describe R10K::Action::Runner do
6
8
 
@@ -9,9 +11,10 @@ describe R10K::Action::Runner do
9
11
  attr_reader :opts
10
12
  attr_reader :argv
11
13
 
12
- def initialize(opts, argv)
14
+ def initialize(opts, argv, settings = {})
13
15
  @opts = opts
14
16
  @argv = argv
17
+ @settings = {}
15
18
  end
16
19
 
17
20
  def call
@@ -49,6 +52,11 @@ describe R10K::Action::Runner do
49
52
  runner.call
50
53
  end
51
54
 
55
+ it "configures forge authorization" do
56
+ expect(runner).to receive(:setup_authorization)
57
+ runner.call
58
+ end
59
+
52
60
  it "returns the result of the wrapped class #call method" do
53
61
  expect(runner.call).to eq %w[ARGS YES]
54
62
  end
@@ -67,13 +75,6 @@ describe R10K::Action::Runner do
67
75
  end
68
76
  end
69
77
 
70
- describe "configuring settings" do
71
- it "configures authorization" do
72
- expect(runner).to receive(:setup_authorization)
73
- runner.setup_settings
74
- end
75
- end
76
-
77
78
  describe "configuration authorization" do
78
79
  context "when license is not present" do
79
80
  before(:each) do
@@ -1,57 +1,33 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe R10K::Deployment::Config do
4
-
5
- describe "reading settings" do
6
- # Try all permutations of string/symbol values as arguments to #setting and
7
- # values in the config file
8
- x = [:key, "key"]
9
- matrix = x.product(x)
10
-
11
- matrix.each do |(searchvalue, configvalue)|
12
- it "treats #{searchvalue.inspect}:#{searchvalue.class} and #{configvalue.inspect}:#{configvalue.class} as equivalent" do
13
- expect(YAML).to receive(:load_file).with('foo/bar').and_return(configvalue => 'some/cache')
14
- subject = described_class.new('foo/bar')
15
- expect(subject.setting(searchvalue)).to eq 'some/cache'
16
- end
17
- end
18
- end
4
+ let(:loader) { instance_double('R10K::Settings::Loader') }
5
+ let(:initializer) { instance_double('R10K::Initializers::GlobalInitializer') }
19
6
 
20
7
  describe "applying global settings" do
21
- describe "for the cachedir" do
22
- it "sets the git cache root when given" do
23
- expect(YAML).to receive(:load_file).with('foo/bar').and_return('cachedir' => 'some/cache')
24
- expect(R10K::Git::Cache.settings).to receive(:[]=).with(:cache_root, 'some/cache')
25
- described_class.new('foo/bar')
26
- end
8
+ before do
9
+ expect(R10K::Settings::Loader).to receive(:new).and_return(loader)
10
+ expect(R10K::Initializers::GlobalInitializer).to receive(:new).and_return(initializer)
27
11
  end
28
12
 
29
- describe "for the forge" do
30
- it "sets the proxy when given" do
31
- expect(YAML).to receive(:load_file).with('foo/bar').and_return('forge' => {'proxy' => 'https://proxy.url'})
32
- expect(R10K::Forge::ModuleRelease.settings).to receive(:[]=).with(:proxy, 'https://proxy.url')
33
- described_class.new('foo/bar')
34
- end
13
+ it 'runs application initialization' do
14
+ config = instance_double('Hash')
15
+ allow(loader).to receive(:read).and_return({})
16
+ expect(initializer).to receive(:call)
17
+ described_class.new('some/path')
35
18
  end
19
+ end
36
20
 
37
- describe "for git" do
38
- it "sets the git provider when given" do
39
- expect(YAML).to receive(:load_file).with('foo/bar').and_return('git' => {'provider' => 'rugged'})
40
- expect(R10K::Git).to receive(:provider=).with(:rugged)
41
- described_class.new('foo/bar')
42
- end
43
-
44
- it "sets the git ssh username when given" do
45
- expect(YAML).to receive(:load_file).with('foo/bar').and_return('git' => {'username' => 'grit'})
46
- expect(R10K::Git.settings).to receive(:[]=).with(:username, 'grit')
47
- described_class.new('foo/bar')
48
- end
21
+ describe "overriding settings" do
22
+ before do
23
+ expect(R10K::Settings::Loader).to receive(:new).and_return(loader)
24
+ end
49
25
 
50
- it "sets the git private key when given" do
51
- expect(YAML).to receive(:load_file).with('foo/bar').and_return('git' => {'private_key' => '/home/user/.ssh/id_rsa'})
52
- expect(R10K::Git.settings).to receive(:[]=).with(:private_key, '/home/user/.ssh/id_rsa')
53
- described_class.new('foo/bar')
54
- end
26
+ it 'allows settings from config to be overridden' do
27
+ allow(loader).to receive(:read).and_return({:cachedir => 'fromfile'})
28
+ expect(R10K::Initializers::GlobalInitializer).to receive(:new).with(hash_including(:cachedir => 'fromoverride')).and_return(initializer)
29
+ expect(initializer).to receive(:call)
30
+ described_class.new('some/path', {:cachedir => 'fromoverride'})
55
31
  end
56
32
  end
57
33
  end
@@ -155,7 +155,7 @@ describe R10K::Deployment, "checking the 'sources' key" do
155
155
  it "raises an error when enumerating sources" do
156
156
  expect {
157
157
  deployment.sources
158
- }.to raise_error(R10K::Error, "'sources' key in /some/nonexistent/config_file missing or empty.")
158
+ }.to raise_error(R10K::Error, "Unable to load sources; the supplied configuration does not define the 'sources' key")
159
159
  end
160
160
  end
161
161
  end
@@ -74,4 +74,24 @@ describe R10K::Environment::Git do
74
74
  expect(subject.status).to eq :some_status
75
75
  end
76
76
  end
77
+
78
+ describe "environment signature" do
79
+ it "returns the git sha of HEAD" do
80
+ expect(subject.repo).to receive(:head).and_return 'f00b00'
81
+ expect(subject.signature).to eq 'f00b00'
82
+ end
83
+ end
84
+
85
+ describe "info hash" do
86
+ let(:info_hash) { subject.info }
87
+
88
+ before(:each) do
89
+ allow(subject.repo).to receive(:head).and_return 'f00b00'
90
+ end
91
+
92
+ it "includes name and signature" do
93
+ expect(info_hash.keys).to include :name, :signature
94
+ expect(info_hash).not_to have_value(nil)
95
+ end
96
+ end
77
97
  end