r10k 3.11.0 → 3.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/docker.yml +1 -1
  3. data/.github/workflows/rspec_tests.yml +2 -2
  4. data/.travis.yml +1 -1
  5. data/CHANGELOG.mkd +34 -0
  6. data/doc/dynamic-environments/configuration.mkd +35 -7
  7. data/doc/dynamic-environments/usage.mkd +26 -0
  8. data/doc/puppetfile.mkd +16 -4
  9. data/integration/tests/basic_functionality/basic_deployment.rb +176 -0
  10. data/lib/r10k/action/base.rb +1 -1
  11. data/lib/r10k/action/deploy/deploy_helpers.rb +4 -0
  12. data/lib/r10k/action/deploy/display.rb +1 -1
  13. data/lib/r10k/action/deploy/environment.rb +13 -8
  14. data/lib/r10k/action/deploy/module.rb +14 -10
  15. data/lib/r10k/action/puppetfile/check.rb +7 -5
  16. data/lib/r10k/action/puppetfile/install.rb +22 -16
  17. data/lib/r10k/action/puppetfile/purge.rb +12 -9
  18. data/lib/r10k/action/runner.rb +6 -0
  19. data/lib/r10k/action/visitor.rb +3 -0
  20. data/lib/r10k/cli/deploy.rb +1 -0
  21. data/lib/r10k/cli/puppetfile.rb +0 -1
  22. data/lib/r10k/content_synchronizer.rb +16 -4
  23. data/lib/r10k/environment/bare.rb +4 -7
  24. data/lib/r10k/environment/base.rb +64 -11
  25. data/lib/r10k/environment/name.rb +14 -9
  26. data/lib/r10k/environment/plain.rb +16 -0
  27. data/lib/r10k/environment/tarball.rb +78 -0
  28. data/lib/r10k/environment/with_modules.rb +6 -10
  29. data/lib/r10k/environment.rb +2 -0
  30. data/lib/r10k/errors.rb +5 -0
  31. data/lib/r10k/forge/module_release.rb +2 -1
  32. data/lib/r10k/git/cache.rb +4 -13
  33. data/lib/r10k/git/rugged/base_repository.rb +12 -1
  34. data/lib/r10k/git/rugged/cache.rb +8 -0
  35. data/lib/r10k/git/stateful_repository.rb +9 -0
  36. data/lib/r10k/initializers.rb +21 -7
  37. data/lib/r10k/logging.rb +78 -1
  38. data/lib/r10k/module/base.rb +5 -1
  39. data/lib/r10k/module/definition.rb +64 -0
  40. data/lib/r10k/module/forge.rb +10 -2
  41. data/lib/r10k/module/git.rb +22 -1
  42. data/lib/r10k/module/local.rb +6 -3
  43. data/lib/r10k/module/svn.rb +10 -0
  44. data/lib/r10k/module/tarball.rb +101 -0
  45. data/lib/r10k/module.rb +21 -2
  46. data/lib/r10k/module_loader/puppetfile/dsl.rb +8 -3
  47. data/lib/r10k/module_loader/puppetfile.rb +109 -30
  48. data/lib/r10k/puppetfile.rb +1 -2
  49. data/lib/r10k/settings.rb +46 -0
  50. data/lib/r10k/source/git.rb +18 -18
  51. data/lib/r10k/source/yaml.rb +1 -1
  52. data/lib/r10k/tarball.rb +183 -0
  53. data/lib/r10k/util/cacheable.rb +31 -0
  54. data/lib/r10k/util/downloader.rb +134 -0
  55. data/lib/r10k/util/purgeable.rb +6 -2
  56. data/lib/r10k/util/setopts.rb +2 -0
  57. data/lib/r10k/util/subprocess.rb +1 -0
  58. data/lib/r10k/version.rb +1 -1
  59. data/locales/r10k.pot +119 -71
  60. data/r10k.gemspec +2 -2
  61. data/r10k.yaml.example +28 -0
  62. data/spec/fixtures/tarball/tarball.tar.gz +0 -0
  63. data/spec/fixtures/unit/action/r10k_logging.yaml +12 -0
  64. data/spec/fixtures/unit/puppetfile/forge-override/Puppetfile +8 -0
  65. data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile +10 -0
  66. data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile.new +10 -0
  67. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/managed_symlink_file +1 -0
  68. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/{managed_subdir_2 → subdir_allowlisted_2}/ignored_1 +0 -0
  69. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/unmanaged_symlink_dir +1 -0
  70. data/spec/fixtures/unit/util/purgeable/managed_one/managed_symlink_dir +1 -0
  71. data/spec/fixtures/unit/util/purgeable/managed_one/unmanaged_symlink_file +1 -0
  72. data/spec/integration/git/rugged/cache_spec.rb +33 -0
  73. data/spec/integration/util/purageable_spec.rb +41 -0
  74. data/spec/r10k-mocks/mock_env.rb +3 -0
  75. data/spec/r10k-mocks/mock_source.rb +7 -3
  76. data/spec/shared-contexts/tarball.rb +32 -0
  77. data/spec/spec_helper.rb +1 -0
  78. data/spec/unit/action/deploy/environment_spec.rb +80 -30
  79. data/spec/unit/action/deploy/module_spec.rb +52 -64
  80. data/spec/unit/action/puppetfile/check_spec.rb +17 -5
  81. data/spec/unit/action/puppetfile/install_spec.rb +42 -36
  82. data/spec/unit/action/puppetfile/purge_spec.rb +15 -17
  83. data/spec/unit/action/runner_spec.rb +52 -9
  84. data/spec/unit/environment/bare_spec.rb +13 -0
  85. data/spec/unit/environment/base_spec.rb +30 -17
  86. data/spec/unit/environment/git_spec.rb +2 -2
  87. data/spec/unit/environment/name_spec.rb +18 -0
  88. data/spec/unit/environment/plain_spec.rb +8 -0
  89. data/spec/unit/environment/svn_spec.rb +4 -3
  90. data/spec/unit/environment/tarball_spec.rb +45 -0
  91. data/spec/unit/environment/with_modules_spec.rb +3 -2
  92. data/spec/unit/git/cache_spec.rb +2 -15
  93. data/spec/unit/git/rugged/cache_spec.rb +19 -0
  94. data/spec/unit/module/base_spec.rb +8 -8
  95. data/spec/unit/module/forge_spec.rb +32 -4
  96. data/spec/unit/module/git_spec.rb +51 -10
  97. data/spec/unit/module/svn_spec.rb +18 -6
  98. data/spec/unit/module/tarball_spec.rb +70 -0
  99. data/spec/unit/module_loader/puppetfile_spec.rb +96 -31
  100. data/spec/unit/puppetfile_spec.rb +2 -2
  101. data/spec/unit/settings_spec.rb +25 -2
  102. data/spec/unit/tarball_spec.rb +57 -0
  103. data/spec/unit/util/cacheable_spec.rb +23 -0
  104. data/spec/unit/util/downloader_spec.rb +98 -0
  105. data/spec/unit/util/purgeable_spec.rb +22 -11
  106. metadata +44 -17
@@ -6,21 +6,29 @@ describe R10K::Environment::Name do
6
6
  it "does not modify the given name when no strip_component is given" do
7
7
  bn = described_class.new('myenv', source: 'source', prefix: false)
8
8
  expect(bn.dirname).to eq 'myenv'
9
+ expect(bn.name).to eq 'myenv'
10
+ expect(bn.original_name).to eq 'myenv'
9
11
  end
10
12
 
11
13
  it "removes the first occurance of a regex match when a regex is given" do
12
14
  bn = described_class.new('myenv', source: 'source', prefix: false, strip_component: '/env/')
13
15
  expect(bn.dirname).to eq 'my'
16
+ expect(bn.name).to eq 'my'
17
+ expect(bn.original_name).to eq 'myenv'
14
18
  end
15
19
 
16
20
  it "does not modify the given name when there is no regex match" do
17
21
  bn = described_class.new('myenv', source: 'source', prefix: false, strip_component: '/bar/')
18
22
  expect(bn.dirname).to eq 'myenv'
23
+ expect(bn.name).to eq 'myenv'
24
+ expect(bn.original_name).to eq 'myenv'
19
25
  end
20
26
 
21
27
  it "removes the given name's prefix when it matches strip_component" do
22
28
  bn = described_class.new('env/prod', source: 'source', prefix: false, strip_component: 'env/')
23
29
  expect(bn.dirname).to eq 'prod'
30
+ expect(bn.name).to eq 'prod'
31
+ expect(bn.original_name).to eq 'env/prod'
24
32
  end
25
33
 
26
34
  it "raises an error when given an integer" do
@@ -34,21 +42,29 @@ describe R10K::Environment::Name do
34
42
  it "uses the branch name as the dirname when prefixing is off" do
35
43
  bn = described_class.new('mybranch', :source => 'source', :prefix => false)
36
44
  expect(bn.dirname).to eq 'mybranch'
45
+ expect(bn.name).to eq 'mybranch'
46
+ expect(bn.original_name).to eq 'mybranch'
37
47
  end
38
48
 
39
49
  it "prepends the source name when prefixing is on" do
40
50
  bn = described_class.new('mybranch', :source => 'source', :prefix => true)
41
51
  expect(bn.dirname).to eq 'source_mybranch'
52
+ expect(bn.name).to eq 'mybranch'
53
+ expect(bn.original_name).to eq 'mybranch'
42
54
  end
43
55
 
44
56
  it "prepends the prefix name when prefixing is overridden" do
45
57
  bn = described_class.new('mybranch', {:prefix => "bar", :sourcename => 'foo'})
46
58
  expect(bn.dirname).to eq 'bar_mybranch'
59
+ expect(bn.name).to eq 'mybranch'
60
+ expect(bn.original_name).to eq 'mybranch'
47
61
  end
48
62
 
49
63
  it "uses the branch name as the dirname when prefixing is nil" do
50
64
  bn = described_class.new('mybranch', {:prefix => nil, :sourcename => 'foo'})
51
65
  expect(bn.dirname).to eq 'mybranch'
66
+ expect(bn.name).to eq 'mybranch'
67
+ expect(bn.original_name).to eq 'mybranch'
52
68
  end
53
69
  end
54
70
 
@@ -149,6 +165,8 @@ describe R10K::Environment::Name do
149
165
  it "replaces invalid characters in #{branch} with underscores" do
150
166
  bn = described_class.new(branch.dup, {:correct => true})
151
167
  expect(bn.dirname).to eq branch.gsub(/\W/, '_')
168
+ expect(bn.name).to eq branch
169
+ expect(bn.original_name).to eq branch
152
170
  end
153
171
  end
154
172
 
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'r10k/environment'
3
+
4
+ describe R10K::Environment::Plain do
5
+ it "initializes successfully" do
6
+ expect(described_class.new('envname', '/basedir', 'dirname', {})).to be_a_kind_of(described_class)
7
+ end
8
+ end
@@ -78,9 +78,10 @@ describe R10K::Environment::SVN do
78
78
 
79
79
  describe "enumerating modules" do
80
80
  it "loads the Puppetfile and returns modules in that puppetfile" do
81
- expect(subject.puppetfile).to receive(:load)
82
- expect(subject.puppetfile).to receive(:modules).and_return [:modules]
83
- expect(subject.modules).to eq([:modules])
81
+ loaded = { managed_directories: [], desired_contents: [], purge_exclusions: [] }
82
+ mod = double('A module', :name => 'dbl')
83
+ expect(subject.loader).to receive(:load).and_return(loaded.merge(modules: [mod]))
84
+ expect(subject.modules).to eq([mod])
84
85
  end
85
86
  end
86
87
 
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'r10k/environment'
3
+
4
+ describe R10K::Environment::Tarball do
5
+ let(:tgz_path) do
6
+ File.expand_path('spec/fixtures/tarball/tarball.tar.gz', PROJECT_ROOT)
7
+ end
8
+
9
+ let(:checksum) { '36afcfc2378b8235902d6e647fce7479da6898354d620388646c595a1155ed67' }
10
+ let(:base_params) { { source: tgz_path, version: checksum, modules: { } } }
11
+
12
+ subject { described_class.new('envname', '/some/imaginary/path', 'dirname', base_params) }
13
+
14
+ describe "initializing" do
15
+ it "accepts valid base class initialization arguments" do
16
+ expect(subject.name).to eq 'envname'
17
+ end
18
+ end
19
+
20
+ describe "storing attributes" do
21
+ it "can return the environment name" do
22
+ expect(subject.name).to eq 'envname'
23
+ end
24
+
25
+ it "can return the environment basedir" do
26
+ expect(subject.basedir).to eq '/some/imaginary/path'
27
+ end
28
+
29
+ it "can return the environment dirname" do
30
+ expect(subject.dirname).to eq 'dirname'
31
+ end
32
+
33
+ it "can return the environment path" do
34
+ expect(subject.path.to_s).to eq '/some/imaginary/path/dirname'
35
+ end
36
+
37
+ it "can return the environment source" do
38
+ expect(subject.tarball.source).to eq tgz_path
39
+ end
40
+
41
+ it "can return the environment version" do
42
+ expect(subject.tarball.checksum).to eq checksum
43
+ end
44
+ end
45
+ end
@@ -8,7 +8,7 @@ describe R10K::Environment::WithModules do
8
8
  '/some/nonexistent/environmentdir',
9
9
  'prefix_release42',
10
10
  {
11
- :type => 'bare',
11
+ :type => 'plain',
12
12
  :modules => {
13
13
  'puppetlabs-stdlib' => { local: true },
14
14
  'puppetlabs-concat' => { local: true },
@@ -65,8 +65,9 @@ describe R10K::Environment::WithModules do
65
65
 
66
66
  describe "modules method" do
67
67
  it "returns the configured modules, and Puppetfile modules" do
68
+ loaded = { managed_directories: [], desired_contents: [], purge_exclusions: [] }
68
69
  puppetfile_mod = instance_double('R10K::Module::Base', name: 'zebra')
69
- expect(subject.puppetfile).to receive(:modules).and_return [puppetfile_mod]
70
+ expect(subject.loader).to receive(:load).and_return(loaded.merge(modules: [puppetfile_mod]))
70
71
  returned_modules = subject.modules
71
72
  expect(returned_modules.map(&:name).sort).to eq(%w[concat exec stdlib zebra])
72
73
  end
@@ -21,7 +21,8 @@ describe R10K::Git::Cache do
21
21
  end
22
22
  end
23
23
 
24
- subject { subclass.new('git://some/git/remote') }
24
+ let(:remote) { 'git://some/git/remote' }
25
+ subject { subclass.new(remote) }
25
26
 
26
27
  describe "updating the cache" do
27
28
  it "only updates the cache once" do
@@ -62,18 +63,4 @@ describe R10K::Git::Cache do
62
63
  subject.cached?
63
64
  end
64
65
  end
65
-
66
- describe "dirname sanitization" do
67
- it 'sanitizes cache directory name' do
68
- expect(subject.sanitized_dirname).to eq('git---some-git-remote')
69
- end
70
-
71
- context 'with username and password' do
72
- subject { subclass.new('https://"user:pa$$w0rd:@some/git/remote') }
73
-
74
- it 'sanitizes cache directory name' do
75
- expect(subject.sanitized_dirname).to eq('https---some-git-remote')
76
- end
77
- end
78
- end
79
66
  end
@@ -26,4 +26,23 @@ describe R10K::Git::Rugged::Cache, :unless => R10K::Util::Platform.jruby? do
26
26
  expect(described_class.settings[:cache_root]).to eq '/some/path'
27
27
  end
28
28
  end
29
+
30
+ describe "remote url updates" do
31
+ before do
32
+ allow(subject.repo).to receive(:exist?).and_return true
33
+ allow(subject.repo).to receive(:fetch)
34
+ allow(subject.repo).to receive(:remotes).and_return({ 'origin' => 'git://some/git/remote' })
35
+ end
36
+
37
+ it "does not update the URLs if they match" do
38
+ expect(subject.repo).to_not receive(:update_remote)
39
+ subject.sync!
40
+ end
41
+
42
+ it "updates the remote URL if they do not match" do
43
+ allow(subject.repo).to receive(:remotes).and_return({ 'origin' => 'foo'})
44
+ expect(subject.repo).to receive(:update_remote)
45
+ subject.sync!
46
+ end
47
+ end
29
48
  end
@@ -4,26 +4,26 @@ require 'r10k/module/base'
4
4
  describe R10K::Module::Base do
5
5
  describe "parsing the title" do
6
6
  it "parses titles with no owner" do
7
- m = described_class.new('eight_hundred', '/moduledir', [])
7
+ m = described_class.new('eight_hundred', '/moduledir', {})
8
8
  expect(m.name).to eq 'eight_hundred'
9
9
  expect(m.owner).to be_nil
10
10
  end
11
11
 
12
12
  it "parses forward slash separated titles" do
13
- m = described_class.new('branan/eight_hundred', '/moduledir', [])
13
+ m = described_class.new('branan/eight_hundred', '/moduledir', {})
14
14
  expect(m.name).to eq 'eight_hundred'
15
15
  expect(m.owner).to eq 'branan'
16
16
  end
17
17
 
18
18
  it "parses hyphen separated titles" do
19
- m = described_class.new('branan-eight_hundred', '/moduledir', [])
19
+ m = described_class.new('branan-eight_hundred', '/moduledir', {})
20
20
  expect(m.name).to eq 'eight_hundred'
21
21
  expect(m.owner).to eq 'branan'
22
22
  end
23
23
 
24
24
  it "raises an error when the title is not correctly formatted" do
25
25
  expect {
26
- described_class.new('branan!eight_hundred', '/moduledir', [])
26
+ described_class.new('branan!eight_hundred', '/moduledir', {})
27
27
  }.to raise_error(ArgumentError, "Module name (branan!eight_hundred) must match either 'modulename' or 'owner/modulename'")
28
28
  end
29
29
  end
@@ -76,13 +76,13 @@ describe R10K::Module::Base do
76
76
 
77
77
  describe "path variables" do
78
78
  it "uses the module name as the name" do
79
- m = described_class.new('eight_hundred', '/moduledir', [])
79
+ m = described_class.new('eight_hundred', '/moduledir', {})
80
80
  expect(m.dirname).to eq '/moduledir'
81
81
  expect(m.path).to eq(Pathname.new('/moduledir/eight_hundred'))
82
82
  end
83
83
 
84
84
  it "does not include the owner in the path" do
85
- m = described_class.new('branan/eight_hundred', '/moduledir', [])
85
+ m = described_class.new('branan/eight_hundred', '/moduledir', {})
86
86
  expect(m.dirname).to eq '/moduledir'
87
87
  expect(m.path).to eq(Pathname.new('/moduledir/eight_hundred'))
88
88
  end
@@ -90,7 +90,7 @@ describe R10K::Module::Base do
90
90
 
91
91
  describe "with alternate variable names" do
92
92
  subject do
93
- described_class.new('branan/eight_hundred', '/moduledir', [])
93
+ described_class.new('branan/eight_hundred', '/moduledir', {})
94
94
  end
95
95
 
96
96
  it "aliases full_name to title" do
@@ -107,7 +107,7 @@ describe R10K::Module::Base do
107
107
  end
108
108
 
109
109
  describe "accepting a visitor" do
110
- subject { described_class.new('branan-eight_hundred', '/moduledir', []) }
110
+ subject { described_class.new('branan-eight_hundred', '/moduledir', {}) }
111
111
 
112
112
  it "passes itself to the visitor" do
113
113
  visitor = spy('visitor')
@@ -9,6 +9,28 @@ describe R10K::Module::Forge do
9
9
  let(:fixture_modulepath) { File.expand_path('spec/fixtures/module/forge', PROJECT_ROOT) }
10
10
  let(:empty_modulepath) { File.expand_path('spec/fixtures/empty', PROJECT_ROOT) }
11
11
 
12
+ describe "statically determined version support" do
13
+ it 'returns explicitly released forge versions' do
14
+ static_version = described_class.statically_defined_version('branan/eight_hundred', { version: '8.0.0' })
15
+ expect(static_version).to eq('8.0.0')
16
+ end
17
+
18
+ it 'returns explicit pre-released forge versions' do
19
+ static_version = described_class.statically_defined_version('branan/eight_hundred', { version: '8.0.0-pre1' })
20
+ expect(static_version).to eq('8.0.0-pre1')
21
+ end
22
+
23
+ it 'retuns nil for latest versions' do
24
+ static_version = described_class.statically_defined_version('branan/eight_hundred', { version: :latest })
25
+ expect(static_version).to eq(nil)
26
+ end
27
+
28
+ it 'retuns nil for undefined versions' do
29
+ static_version = described_class.statically_defined_version('branan/eight_hundred', { version: nil })
30
+ expect(static_version).to eq(nil)
31
+ end
32
+ end
33
+
12
34
  describe "implementing the Puppetfile spec" do
13
35
  it "should implement 'branan/eight_hundred', '8.0.0'" do
14
36
  expect(described_class).to be_implement('branan/eight_hundred', { version: '8.0.0' })
@@ -190,25 +212,31 @@ describe R10K::Module::Forge do
190
212
  expect(subject).to receive(:install).never
191
213
  expect(subject).to receive(:upgrade).never
192
214
  expect(subject).to receive(:reinstall).never
193
- subject.sync
215
+ expect(subject.sync).to be false
194
216
  end
195
217
 
196
218
  it 'reinstalls the module when it is mismatched' do
197
219
  allow(subject).to receive(:status).and_return :mismatched
198
220
  expect(subject).to receive(:reinstall)
199
- subject.sync
221
+ expect(subject.sync).to be true
200
222
  end
201
223
 
202
224
  it 'upgrades the module when it is outdated' do
203
225
  allow(subject).to receive(:status).and_return :outdated
204
226
  expect(subject).to receive(:upgrade)
205
- subject.sync
227
+ expect(subject.sync).to be true
206
228
  end
207
229
 
208
230
  it 'installs the module when it is absent' do
209
231
  allow(subject).to receive(:status).and_return :absent
210
232
  expect(subject).to receive(:install)
211
- subject.sync
233
+ expect(subject.sync).to be true
234
+ end
235
+
236
+ it 'returns false if `should_sync?` is false' do
237
+ # modules do not sync if they are not requested
238
+ mod = described_class.new('my_org/my_mod', '/path/to/mod', { overrides: { modules: { requested_modules: ['other_mod'] } } })
239
+ expect(mod.sync).to be false
212
240
  end
213
241
  end
214
242
 
@@ -10,15 +10,41 @@ describe R10K::Module::Git do
10
10
  allow(R10K::Git::StatefulRepository).to receive(:new).and_return(mock_repo)
11
11
  end
12
12
 
13
+
14
+ describe "statically determined version support" do
15
+ it 'returns a given commit' do
16
+ static_version = described_class.statically_defined_version('branan/eight_hundred', { git: 'my/remote', commit: '123adf' })
17
+ expect(static_version).to eq('123adf')
18
+ end
19
+
20
+ it 'returns a given tag' do
21
+ static_version = described_class.statically_defined_version('branan/eight_hundred', { git: 'my/remote', tag: 'v1.2.3' })
22
+ expect(static_version).to eq('v1.2.3')
23
+ end
24
+
25
+ it 'returns a ref if it looks like a full commit sha' do
26
+ static_version = described_class.statically_defined_version('branan/eight_hundred', { git: 'my/remote', ref: '1234567890abcdef1234567890abcdef12345678' })
27
+ expect(static_version).to eq('1234567890abcdef1234567890abcdef12345678')
28
+ end
29
+
30
+ it 'returns nil for any non-sha-like ref' do
31
+ static_version = described_class.statically_defined_version('branan/eight_hundred', { git: 'my/remote', ref: 'refs/heads/main' })
32
+ expect(static_version).to eq(nil)
33
+ end
34
+
35
+ it 'returns nil for branches' do
36
+ static_version = described_class.statically_defined_version('branan/eight_hundred', { git: 'my/remote', branch: 'main' })
37
+ expect(static_version).to eq(nil)
38
+ end
39
+ end
40
+
13
41
  describe "setting the owner and name" do
14
42
  describe "with a title of 'branan/eight_hundred'" do
15
43
  subject do
16
44
  described_class.new(
17
45
  'branan/eight_hundred',
18
46
  '/moduledir',
19
- {
20
- :git => 'git://git-server.site/branan/puppet-eight_hundred',
21
- }
47
+ { :git => 'git://git-server.site/branan/puppet-eight_hundred' }
22
48
  )
23
49
  end
24
50
 
@@ -40,9 +66,7 @@ describe R10K::Module::Git do
40
66
  described_class.new(
41
67
  'eight_hundred',
42
68
  '/moduledir',
43
- {
44
- :git => 'git://git-server.site/branan/puppet-eight_hundred',
45
- }
69
+ { :git => 'git://git-server.site/branan/puppet-eight_hundred' }
46
70
  )
47
71
  end
48
72
 
@@ -97,13 +121,32 @@ describe R10K::Module::Git do
97
121
  let(:spec_path) { dirname + module_name + 'spec' }
98
122
  subject { described_class.new(title, dirname, {}) }
99
123
 
124
+ before(:each) do
125
+ allow(mock_repo).to receive(:resolve).with('master').and_return('abc123')
126
+ end
127
+
100
128
  it 'defaults to keeping the spec dir' do
101
129
  FileUtils.mkdir_p(spec_path)
102
- allow(mock_repo).to receive(:resolve).with('master').and_return('abc123')
103
130
  allow(mock_repo).to receive(:sync)
104
131
  subject.sync
105
132
  expect(Dir.exist?(spec_path)).to eq true
106
133
  end
134
+
135
+ it 'returns true if repo was updated' do
136
+ expect(mock_repo).to receive(:sync).and_return(true)
137
+ expect(subject.sync).to be true
138
+ end
139
+
140
+ it 'returns false if repo was not updated (in-sync)' do
141
+ expect(mock_repo).to receive(:sync).and_return(false)
142
+ expect(subject.sync).to be false
143
+ end
144
+
145
+ it 'returns false if `should_sync?` is false' do
146
+ # modules do not sync if they are not requested
147
+ mod = described_class.new(title, dirname, { overrides: { modules: { requested_modules: ['other_mod'] } } })
148
+ expect(mod.sync).to be false
149
+ end
107
150
  end
108
151
 
109
152
  describe "determining the status" do
@@ -111,9 +154,7 @@ describe R10K::Module::Git do
111
154
  described_class.new(
112
155
  'boolean',
113
156
  '/moduledir',
114
- {
115
- :git => 'git://git.example.com/adrienthebo/puppet-boolean'
116
- }
157
+ { :git => 'git://git.example.com/adrienthebo/puppet-boolean' }
117
158
  )
118
159
  end
119
160
 
@@ -6,6 +6,13 @@ describe R10K::Module::SVN do
6
6
 
7
7
  include_context 'fail on execution'
8
8
 
9
+ describe "statically determined version support" do
10
+ it 'is unsupported by svn backed modules' do
11
+ static_version = described_class.statically_defined_version('branan/eight_hundred', { svn: 'my/remote', revision: '123adf' })
12
+ expect(static_version).to eq(nil)
13
+ end
14
+ end
15
+
9
16
  describe "determining it implements a Puppetfile mod" do
10
17
  it "implements mods with the :svn hash key" do
11
18
  implements = described_class.implement?('r10k-fixture-repo', :svn => 'https://github.com/adrienthebo/r10k-fixture-repo')
@@ -128,7 +135,6 @@ describe R10K::Module::SVN do
128
135
  subject { described_class.new(title, dirname, {}) }
129
136
 
130
137
  it 'is kept by default' do
131
-
132
138
  FileUtils.mkdir_p(spec_path)
133
139
  expect(subject).to receive(:status).and_return(:absent)
134
140
  expect(subject).to receive(:install).and_return(nil)
@@ -150,7 +156,7 @@ describe R10K::Module::SVN do
150
156
 
151
157
  it "installs the SVN module" do
152
158
  expect(subject).to receive(:install)
153
- subject.sync
159
+ expect(subject.sync).to be true
154
160
  end
155
161
  end
156
162
 
@@ -160,14 +166,14 @@ describe R10K::Module::SVN do
160
166
  it "reinstalls the module" do
161
167
  expect(subject).to receive(:reinstall)
162
168
 
163
- subject.sync
169
+ expect(subject.sync).to be true
164
170
  end
165
171
 
166
172
  it "removes the existing directory" do
167
173
  expect(subject.path).to receive(:rmtree)
168
174
  allow(subject).to receive(:install)
169
175
 
170
- subject.sync
176
+ expect(subject.sync).to be true
171
177
  end
172
178
  end
173
179
 
@@ -177,7 +183,7 @@ describe R10K::Module::SVN do
177
183
  it "upgrades the repository" do
178
184
  expect(subject).to receive(:update)
179
185
 
180
- subject.sync
186
+ expect(subject.sync).to be true
181
187
  end
182
188
  end
183
189
 
@@ -189,8 +195,14 @@ describe R10K::Module::SVN do
189
195
  expect(subject).to receive(:reinstall).never
190
196
  expect(subject).to receive(:update).never
191
197
 
192
- subject.sync
198
+ expect(subject.sync).to be false
193
199
  end
194
200
  end
201
+
202
+ it 'and `should_sync?` is false' do
203
+ # modules do not sync if they are not requested
204
+ mod = described_class.new('my_mod', '/path/to/mod', { overrides: { modules: { requested_modules: ['other_mod'] } } })
205
+ expect(mod.sync).to be false
206
+ end
195
207
  end
196
208
  end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+ require 'r10k/module'
3
+ require 'fileutils'
4
+
5
+ describe R10K::Module::Tarball do
6
+ include_context 'Tarball'
7
+
8
+ let(:base_params) { { type: 'tarball', source: fixture_tarball, version: fixture_checksum } }
9
+
10
+ subject do
11
+ described_class.new(
12
+ 'fixture-tarball',
13
+ moduledir,
14
+ base_params,
15
+ )
16
+ end
17
+
18
+ describe "setting the owner and name" do
19
+ describe "with a title of 'fixture-tarball'" do
20
+ it "sets the owner to 'fixture'" do
21
+ expect(subject.owner).to eq 'fixture'
22
+ end
23
+
24
+ it "sets the name to 'tarball'" do
25
+ expect(subject.name).to eq 'tarball'
26
+ end
27
+
28
+ it "sets the path to the given moduledir + modname" do
29
+ expect(subject.path.to_s).to eq(File.join(moduledir, 'tarball'))
30
+ end
31
+ end
32
+ end
33
+
34
+ describe "properties" do
35
+ it "sets the module type to :tarball" do
36
+ expect(subject.properties).to include(type: :tarball)
37
+ end
38
+
39
+ it "sets the version" do
40
+ expect(subject.properties).to include(expected: fixture_checksum)
41
+ end
42
+ end
43
+
44
+ describe 'syncing the module' do
45
+ it 'defaults to keeping the spec dir' do
46
+ subject.sync
47
+ expect(Dir.exist?(File.join(moduledir, 'tarball', 'spec'))).to be(true)
48
+ end
49
+ end
50
+
51
+ describe "determining the status" do
52
+ it "delegates to R10K::Tarball" do
53
+ expect(subject).to receive(:tarball).twice.and_return instance_double('R10K::Tarball', cache_valid?: true, insync?: true)
54
+ expect(subject).to receive(:path).twice.and_return instance_double('Pathname', exist?: true)
55
+
56
+ expect(subject.status).to eq(:insync)
57
+ end
58
+ end
59
+
60
+ describe "option parsing" do
61
+ describe "version" do
62
+ context "when no version is given" do
63
+ subject { described_class.new('fixture-tarball', moduledir, base_params.reject { |k| k.eql?(:version) }) }
64
+ it "does not require a version" do
65
+ expect(subject).to be_kind_of(described_class)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end