r10k 3.5.2 → 3.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.github/pull_request_template.md +4 -1
  3. data/.github/workflows/docker.yml +4 -1
  4. data/.github/workflows/release.yml +3 -2
  5. data/.github/workflows/rspec_tests.yml +81 -0
  6. data/.github/workflows/stale.yml +19 -0
  7. data/.travis.yml +8 -1
  8. data/CHANGELOG.mkd +43 -1
  9. data/CODEOWNERS +2 -2
  10. data/README.mkd +13 -4
  11. data/doc/common-patterns.mkd +1 -0
  12. data/doc/dynamic-environments/configuration.mkd +149 -45
  13. data/doc/dynamic-environments/usage.mkd +12 -11
  14. data/doc/puppetfile.mkd +23 -3
  15. data/docker/Gemfile +1 -1
  16. data/docker/Makefile +7 -4
  17. data/docker/docker-compose.yml +18 -0
  18. data/docker/r10k/Dockerfile +4 -3
  19. data/docker/r10k/docker-entrypoint.sh +0 -1
  20. data/docker/r10k/release.Dockerfile +3 -2
  21. data/docker/spec/dockerfile_spec.rb +26 -32
  22. data/integration/tests/git_source/git_source_repeated_remote.rb +68 -0
  23. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module.rb +2 -1
  24. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module_static.rb +2 -1
  25. data/integration/tests/user_scenario/basic_workflow/multi_source_custom_forge_git_module.rb +1 -1
  26. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_git_module.rb +2 -1
  27. data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +1 -1
  28. data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +1 -1
  29. data/integration/tests/user_scenario/complex_workflow/multi_env_unamanaged.rb +1 -1
  30. data/lib/r10k/action/base.rb +8 -1
  31. data/lib/r10k/action/deploy/display.rb +46 -10
  32. data/lib/r10k/action/deploy/environment.rb +98 -50
  33. data/lib/r10k/action/deploy/module.rb +51 -29
  34. data/lib/r10k/action/puppetfile/check.rb +3 -1
  35. data/lib/r10k/action/puppetfile/install.rb +20 -23
  36. data/lib/r10k/action/puppetfile/purge.rb +8 -2
  37. data/lib/r10k/action/runner.rb +34 -0
  38. data/lib/r10k/cli/deploy.rb +14 -7
  39. data/lib/r10k/cli/puppetfile.rb +5 -5
  40. data/lib/r10k/content_synchronizer.rb +83 -0
  41. data/lib/r10k/deployment.rb +1 -1
  42. data/lib/r10k/environment/base.rb +30 -3
  43. data/lib/r10k/environment/git.rb +17 -5
  44. data/lib/r10k/environment/name.rb +22 -4
  45. data/lib/r10k/environment/svn.rb +11 -4
  46. data/lib/r10k/environment/with_modules.rb +46 -30
  47. data/lib/r10k/git.rb +1 -0
  48. data/lib/r10k/git/cache.rb +12 -4
  49. data/lib/r10k/git/rugged/credentials.rb +39 -2
  50. data/lib/r10k/git/stateful_repository.rb +4 -0
  51. data/lib/r10k/initializers.rb +2 -0
  52. data/lib/r10k/module.rb +1 -1
  53. data/lib/r10k/module/base.rb +25 -1
  54. data/lib/r10k/module/forge.rb +29 -11
  55. data/lib/r10k/module/git.rb +54 -27
  56. data/lib/r10k/module/local.rb +2 -1
  57. data/lib/r10k/module/svn.rb +24 -18
  58. data/lib/r10k/puppetfile.rb +75 -72
  59. data/lib/r10k/settings.rb +30 -3
  60. data/lib/r10k/source/base.rb +9 -0
  61. data/lib/r10k/source/git.rb +40 -9
  62. data/lib/r10k/source/hash.rb +5 -5
  63. data/lib/r10k/source/svn.rb +5 -3
  64. data/lib/r10k/util/cleaner.rb +21 -0
  65. data/lib/r10k/util/setopts.rb +33 -12
  66. data/lib/r10k/version.rb +1 -1
  67. data/locales/r10k.pot +103 -83
  68. data/r10k.gemspec +1 -1
  69. data/spec/fixtures/unit/action/r10k_creds.yaml +9 -0
  70. data/spec/r10k-mocks/mock_source.rb +1 -1
  71. data/spec/shared-examples/puppetfile-action.rb +7 -7
  72. data/spec/shared-examples/subprocess-runner.rb +11 -5
  73. data/spec/unit/action/deploy/display_spec.rb +35 -5
  74. data/spec/unit/action/deploy/environment_spec.rb +207 -37
  75. data/spec/unit/action/deploy/module_spec.rb +173 -26
  76. data/spec/unit/action/puppetfile/check_spec.rb +2 -2
  77. data/spec/unit/action/puppetfile/install_spec.rb +32 -10
  78. data/spec/unit/action/puppetfile/purge_spec.rb +25 -5
  79. data/spec/unit/action/runner_spec.rb +48 -1
  80. data/spec/unit/environment/git_spec.rb +19 -2
  81. data/spec/unit/environment/name_spec.rb +28 -0
  82. data/spec/unit/environment/svn_spec.rb +12 -0
  83. data/spec/unit/environment/with_modules_spec.rb +74 -0
  84. data/spec/unit/git/cache_spec.rb +10 -0
  85. data/spec/unit/git/rugged/credentials_spec.rb +79 -2
  86. data/spec/unit/git_spec.rb +3 -3
  87. data/spec/unit/module/forge_spec.rb +21 -13
  88. data/spec/unit/module/git_spec.rb +64 -1
  89. data/spec/unit/module_spec.rb +60 -10
  90. data/spec/unit/puppetfile_spec.rb +98 -30
  91. data/spec/unit/settings_spec.rb +12 -0
  92. data/spec/unit/source/git_spec.rb +49 -1
  93. data/spec/unit/util/purgeable_spec.rb +2 -8
  94. data/spec/unit/util/setopts_spec.rb +25 -1
  95. metadata +12 -11
  96. data/azure-pipelines.yml +0 -86
@@ -3,27 +3,77 @@ require 'r10k/module'
3
3
 
4
4
  describe R10K::Module do
5
5
  describe 'delegating to R10K::Module::Git' do
6
- it "accepts args {:git => 'git url}" do
7
- obj = R10K::Module.new('foo', '/modulepath', :git => 'git url')
8
- expect(obj).to be_a_kind_of(R10K::Module::Git)
6
+ [ {git: 'git url'},
7
+ {type: 'git', source: 'git url'},
8
+ ].each do |scenario|
9
+ it "accepts a name matching 'test' and args #{scenario.inspect}" do
10
+ obj = R10K::Module.new('test', '/modulepath', scenario)
11
+ expect(obj).to be_a_kind_of(R10K::Module::Git)
12
+ expect(obj.send(:instance_variable_get, :'@remote')).to eq('git url')
13
+ end
14
+ end
15
+ end
16
+
17
+ describe 'delegating to R10K::Module::Svn' do
18
+ [ {svn: 'svn url'},
19
+ {type: 'svn', source: 'svn url'},
20
+ ].each do |scenario|
21
+ it "accepts a name matching 'test' and args #{scenario.inspect}" do
22
+ obj = R10K::Module.new('test', '/modulepath', scenario)
23
+ expect(obj).to be_a_kind_of(R10K::Module::SVN)
24
+ expect(obj.send(:instance_variable_get, :'@url')).to eq('svn url')
25
+ end
9
26
  end
10
27
  end
11
28
 
12
29
  describe 'delegating to R10K::Module::Forge' do
13
- [
14
- ['bar/quux', nil],
15
- ['bar-quux', nil],
16
- ['bar/quux', '8.0.0'],
30
+ [ 'bar/quux',
31
+ 'bar-quux',
17
32
  ].each do |scenario|
18
- it "accepts a name matching #{scenario[0]} and args #{scenario[1].inspect}" do
19
- expect(R10K::Module.new(scenario[0], '/modulepath', scenario[1])).to be_a_kind_of(R10K::Module::Forge)
33
+ it "accepts a name matching #{scenario} and version nil" do
34
+ obj = R10K::Module.new(scenario, '/modulepath', { version: nil })
35
+ expect(obj).to be_a_kind_of(R10K::Module::Forge)
36
+ end
37
+ end
38
+ [ {version: '8.0.0'},
39
+ {type: 'forge', version: '8.0.0'},
40
+ ].each do |scenario|
41
+ it "accepts a name matching bar-quux and args #{scenario.inspect}" do
42
+ obj = R10K::Module.new('bar-quux', '/modulepath', scenario)
43
+ expect(obj).to be_a_kind_of(R10K::Module::Forge)
44
+ expect(obj.send(:instance_variable_get, :'@expected_version')).to eq('8.0.0')
45
+ end
46
+ end
47
+
48
+ describe 'when the module is ostensibly on disk' do
49
+ before do
50
+ owner = 'theowner'
51
+ module_name = 'themodulename'
52
+ @title = "#{owner}-#{module_name}"
53
+ metadata = <<~METADATA
54
+ {
55
+ "name": "#{@title}",
56
+ "version": "1.2.0"
57
+ }
58
+ METADATA
59
+ @dirname = Dir.mktmpdir
60
+ module_path = File.join(@dirname, module_name)
61
+ FileUtils.mkdir(module_path)
62
+ File.open("#{module_path}/metadata.json", 'w') do |file|
63
+ file.write(metadata)
64
+ end
65
+ end
66
+
67
+ it 'sets the expected version to what is found in the metadata' do
68
+ obj = R10K::Module.new(@title, @dirname, {version: nil})
69
+ expect(obj.send(:instance_variable_get, :'@expected_version')).to eq('1.2.0')
20
70
  end
21
71
  end
22
72
  end
23
73
 
24
74
  it "raises an error if delegation fails" do
25
75
  expect {
26
- R10K::Module.new('bar!quux', '/modulepath', ["NOPE NOPE NOPE NOPE!"])
76
+ R10K::Module.new('bar!quux', '/modulepath', {version: ["NOPE NOPE NOPE NOPE!"]})
27
77
  }.to raise_error RuntimeError, /doesn't have an implementation/
28
78
  end
29
79
  end
@@ -6,9 +6,7 @@ describe R10K::Puppetfile do
6
6
  subject do
7
7
  described_class.new(
8
8
  '/some/nonexistent/basedir',
9
- nil,
10
- nil,
11
- 'Puppetfile.r10k'
9
+ {puppetfile_name: 'Puppetfile.r10k'}
12
10
  )
13
11
  end
14
12
 
@@ -23,9 +21,25 @@ end
23
21
  describe R10K::Puppetfile do
24
22
 
25
23
  subject do
26
- described_class.new(
27
- '/some/nonexistent/basedir'
28
- )
24
+ described_class.new( '/some/nonexistent/basedir', {})
25
+ end
26
+
27
+ describe "backwards compatibility with older calling conventions" do
28
+ it "honors all arguments correctly" do
29
+ puppetfile = described_class.new('/some/nonexistant/basedir', '/some/nonexistant/basedir/site-modules', nil, 'Pupupupetfile', true)
30
+ expect(puppetfile.force).to eq(true)
31
+ expect(puppetfile.moduledir).to eq('/some/nonexistant/basedir/site-modules')
32
+ expect(puppetfile.puppetfile_path).to eq('/some/nonexistant/basedir/Pupupupetfile')
33
+ expect(puppetfile.overrides).to eq({})
34
+ end
35
+
36
+ it "handles defaults correctly" do
37
+ puppetfile = described_class.new('/some/nonexistant/basedir', nil, nil, nil)
38
+ expect(puppetfile.force).to eq(false)
39
+ expect(puppetfile.moduledir).to eq('/some/nonexistant/basedir/modules')
40
+ expect(puppetfile.puppetfile_path).to eq('/some/nonexistant/basedir/Puppetfile')
41
+ expect(puppetfile.overrides).to eq({})
42
+ end
29
43
  end
30
44
 
31
45
  describe "the default moduledir" do
@@ -54,15 +68,15 @@ describe R10K::Puppetfile do
54
68
  end
55
69
 
56
70
  describe "adding modules" do
57
- it "should accept Forge modules with a string arg" do
58
- allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.moduledir, '1.2.3', anything).and_call_original
71
+ it "should transform Forge modules with a string arg to have a version key" do
72
+ allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.moduledir, hash_including(version: '1.2.3'), anything).and_call_original
59
73
 
60
74
  expect { subject.add_module('puppet/test_module', '1.2.3') }.to change { subject.modules }
61
75
  expect(subject.modules.collect(&:name)).to include('test_module')
62
76
  end
63
77
 
64
78
  it "should not accept Forge modules with a version comparison" do
65
- allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.moduledir, '< 1.2.0', anything).and_call_original
79
+ allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.moduledir, hash_including(version: '< 1.2.0'), anything).and_call_original
66
80
 
67
81
  expect {
68
82
  subject.add_module('puppet/test_module', '< 1.2.0')
@@ -127,6 +141,17 @@ describe R10K::Puppetfile do
127
141
 
128
142
  expect { subject.add_module('puppet/test_module', module_opts) }.to raise_error(R10K::Error, /cannot manage content.*is not within/i).and not_change { subject.modules }
129
143
  end
144
+
145
+ it "should disable and not add modules that conflict with the environment" do
146
+ env = instance_double('R10K::Environment::Base')
147
+ mod = instance_double('R10K::Module::Base', name: 'conflict', origin: :puppetfile)
148
+ allow(mod).to receive(:origin=).and_return(nil)
149
+ allow(subject).to receive(:environment).and_return(env)
150
+ allow(env).to receive(:'module_conflicts?').with(mod).and_return(true)
151
+
152
+ allow(R10K::Module).to receive(:new).with('test', anything, anything, anything).and_return(mod)
153
+ expect { subject.add_module('test', {}) }.not_to change { subject.modules }
154
+ end
130
155
  end
131
156
 
132
157
  describe "#purge_exclusions" do
@@ -154,6 +179,26 @@ describe R10K::Puppetfile do
154
179
  end
155
180
  end
156
181
 
182
+ describe '#managed_directories' do
183
+ it 'returns an array of paths that can be purged' do
184
+ allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.moduledir, hash_including(version: '1.2.3'), anything).and_call_original
185
+
186
+ subject.add_module('puppet/test_module', '1.2.3')
187
+ expect(subject.managed_directories).to match_array(["/some/nonexistent/basedir/modules"])
188
+ end
189
+
190
+ context 'with a module with install_path == \'\'' do
191
+ it 'basedir isn\'t in the list of paths to purge' do
192
+ module_opts = { install_path: '', git: 'git@example.com:puppet/test_module.git' }
193
+
194
+ allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.basedir, module_opts, anything).and_call_original
195
+
196
+ subject.add_module('puppet/test_module', module_opts)
197
+ expect(subject.managed_directories).to be_empty
198
+ end
199
+ end
200
+ end
201
+
157
202
  describe "evaluating a Puppetfile" do
158
203
  def expect_wrapped_error(orig, pf_path, wrapped_error)
159
204
  expect(orig).to be_a_kind_of(R10K::Error)
@@ -164,7 +209,7 @@ describe R10K::Puppetfile do
164
209
  it "wraps and re-raises syntax errors" do
165
210
  path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'invalid-syntax')
166
211
  pf_path = File.join(path, 'Puppetfile')
167
- subject = described_class.new(path)
212
+ subject = described_class.new(path, {})
168
213
  expect {
169
214
  subject.load!
170
215
  }.to raise_error do |e|
@@ -175,7 +220,7 @@ describe R10K::Puppetfile do
175
220
  it "wraps and re-raises load errors" do
176
221
  path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'load-error')
177
222
  pf_path = File.join(path, 'Puppetfile')
178
- subject = described_class.new(path)
223
+ subject = described_class.new(path, {})
179
224
  expect {
180
225
  subject.load!
181
226
  }.to raise_error do |e|
@@ -186,7 +231,7 @@ describe R10K::Puppetfile do
186
231
  it "wraps and re-raises argument errors" do
187
232
  path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'argument-error')
188
233
  pf_path = File.join(path, 'Puppetfile')
189
- subject = described_class.new(path)
234
+ subject = described_class.new(path, {})
190
235
  expect {
191
236
  subject.load!
192
237
  }.to raise_error do |e|
@@ -197,7 +242,7 @@ describe R10K::Puppetfile do
197
242
  it "rejects Puppetfiles with duplicate module names" do
198
243
  path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'duplicate-module-error')
199
244
  pf_path = File.join(path, 'Puppetfile')
200
- subject = described_class.new(path)
245
+ subject = described_class.new(path, {})
201
246
  expect {
202
247
  subject.load!
203
248
  }.to raise_error(R10K::Error, /Puppetfiles cannot contain duplicate module names/i)
@@ -206,7 +251,7 @@ describe R10K::Puppetfile do
206
251
  it "wraps and re-raises name errors" do
207
252
  path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'name-error')
208
253
  pf_path = File.join(path, 'Puppetfile')
209
- subject = described_class.new(path)
254
+ subject = described_class.new(path, {})
210
255
  expect {
211
256
  subject.load!
212
257
  }.to raise_error do |e|
@@ -217,21 +262,21 @@ describe R10K::Puppetfile do
217
262
  it "accepts a forge module with a version" do
218
263
  path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-with-version')
219
264
  pf_path = File.join(path, 'Puppetfile')
220
- subject = described_class.new(path)
265
+ subject = described_class.new(path, {})
221
266
  expect { subject.load! }.not_to raise_error
222
267
  end
223
268
 
224
269
  it "accepts a forge module without a version" do
225
270
  path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-without-version')
226
271
  pf_path = File.join(path, 'Puppetfile')
227
- subject = described_class.new(path)
272
+ subject = described_class.new(path, {})
228
273
  expect { subject.load! }.not_to raise_error
229
274
  end
230
275
 
231
276
  it "creates a git module and applies the default branch sepcified in the Puppetfile" do
232
277
  path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'default-branch-override')
233
278
  pf_path = File.join(path, 'Puppetfile')
234
- subject = described_class.new(path)
279
+ subject = described_class.new(path, {})
235
280
  expect { subject.load! }.not_to raise_error
236
281
  git_module = subject.modules[0]
237
282
  expect(git_module.default_ref).to eq 'here_lies_the_default_branch'
@@ -240,11 +285,12 @@ describe R10K::Puppetfile do
240
285
  it "creates a git module and applies the provided default_branch_override" do
241
286
  path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'default-branch-override')
242
287
  pf_path = File.join(path, 'Puppetfile')
243
- subject = described_class.new(path)
288
+ subject = described_class.new(path, {})
244
289
  default_branch_override = 'default_branch_override_name'
245
290
  expect { subject.load!(default_branch_override) }.not_to raise_error
246
291
  git_module = subject.modules[0]
247
- expect(git_module.default_ref).to eq default_branch_override
292
+ expect(git_module.default_override_ref).to eq default_branch_override
293
+ expect(git_module.default_ref).to eq "here_lies_the_default_branch"
248
294
  end
249
295
  end
250
296
 
@@ -255,7 +301,7 @@ describe R10K::Puppetfile do
255
301
  subject.accept(visitor)
256
302
  end
257
303
 
258
- it "passes the visitor to each module if the visitor yields" do
304
+ it "synchronizes each module if the visitor yields" do
259
305
  visitor = spy('visitor')
260
306
  expect(visitor).to receive(:visit) do |type, other, &block|
261
307
  expect(type).to eq :puppetfile
@@ -263,12 +309,12 @@ describe R10K::Puppetfile do
263
309
  block.call
264
310
  end
265
311
 
266
- mod1 = spy('module')
267
- expect(mod1).to receive(:accept).with(visitor)
268
- mod2 = spy('module')
269
- expect(mod2).to receive(:accept).with(visitor)
270
-
312
+ mod1 = instance_double('R10K::Module::Base', :cachedir => :none)
313
+ mod2 = instance_double('R10K::Module::Base', :cachedir => :none)
314
+ expect(mod1).to receive(:sync)
315
+ expect(mod2).to receive(:sync)
271
316
  expect(subject).to receive(:modules).and_return([mod1, mod2])
317
+
272
318
  subject.accept(visitor)
273
319
  end
274
320
 
@@ -284,11 +330,10 @@ describe R10K::Puppetfile do
284
330
  block.call
285
331
  end
286
332
 
287
- mod1 = spy('module')
288
- expect(mod1).to receive(:accept).with(visitor)
289
- mod2 = spy('module')
290
- expect(mod2).to receive(:accept).with(visitor)
291
-
333
+ mod1 = instance_double('R10K::Module::Base', :cachedir => :none)
334
+ mod2 = instance_double('R10K::Module::Base', :cachedir => :none)
335
+ expect(mod1).to receive(:sync)
336
+ expect(mod2).to receive(:sync)
292
337
  expect(subject).to receive(:modules).and_return([mod1, mod2])
293
338
 
294
339
  expect(Thread).to receive(:new).exactly(pool_size).and_call_original
@@ -296,5 +341,28 @@ describe R10K::Puppetfile do
296
341
 
297
342
  subject.accept(visitor)
298
343
  end
344
+
345
+ it "Creates queues of modules grouped by cachedir" do
346
+ visitor = spy('visitor')
347
+ expect(visitor).to receive(:visit) do |type, other, &block|
348
+ expect(type).to eq :puppetfile
349
+ expect(other).to eq subject
350
+ block.call
351
+ end
352
+
353
+ m1 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/A')
354
+ m2 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/B')
355
+ m3 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/C')
356
+ m4 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/C')
357
+ m5 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/D')
358
+ m6 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/D')
359
+
360
+ modules = [m1, m2, m3, m4, m5, m6]
361
+
362
+ queue = R10K::ContentSynchronizer.modules_visit_queue(modules, visitor, subject)
363
+ expect(queue.length).to be 4
364
+ queue_array = 4.times.map { queue.pop }
365
+ expect(queue_array).to match_array([[m1], [m2], [m3, m4], [m5, m6]])
366
+ end
299
367
  end
300
368
  end
@@ -129,6 +129,18 @@ describe R10K::Settings do
129
129
  expect { subject.evaluate('puppet_path' => '/nonexistent') }.to raise_error(R10K::Settings::Collection::ValidationError)
130
130
  end
131
131
  end
132
+
133
+ describe 'puppet_conf' do
134
+ it 'when file raises no error' do
135
+ allow(File).to receive(:readable?).with('/nonexistent').and_return(true)
136
+ expect { subject.evaluate('puppet_conf' => '/nonexistent') }.not_to raise_error
137
+ end
138
+
139
+ it 'when not file raises error' do
140
+ allow(File).to receive(:readable?).with('/nonexistent').and_return(false)
141
+ expect { subject.evaluate('puppet_conf' => '/nonexistent') }.to raise_error(R10K::Settings::Collection::ValidationError)
142
+ end
143
+ end
132
144
  end
133
145
 
134
146
  describe "global settings" do
@@ -93,9 +93,57 @@ describe R10K::Source::Git do
93
93
  let(:ignore_prefixes) { ['dev', 'test'] }
94
94
 
95
95
  it "filters branches" do
96
- expect(subject.filter_branches(branches, ignore_prefixes)).to eq(['master', 'production', 'not_dev_test_me'])
96
+ expect(subject.filter_branches_by_regexp(branches, ignore_prefixes)).to eq(['master', 'production', 'not_dev_test_me'])
97
97
  end
98
98
  end
99
+
100
+ describe "filtering branches with command" do
101
+ let(:branches) { ['master', 'development', 'production'] }
102
+ if R10K::Util::Platform.windows?
103
+ let(:filter_command) { 'powershell.exe if ($env:R10K_BRANCH.equals(\"development\")) {exit 1} else {exit 0}' }
104
+ else
105
+ let(:filter_command) { 'sh -c "[ $R10K_BRANCH != development ]"' }
106
+ end
107
+
108
+ it "filters branches" do
109
+ expect(subject.filter_branches_by_command(branches, filter_command)).to eq(['master', 'production'])
110
+ end
111
+ end
112
+
113
+ describe "generate_environments respects filter_command setting" do
114
+ before do
115
+ allow(subject.cache).to receive(:branches).and_return ['master', 'development', 'production']
116
+ if R10K::Util::Platform.windows?
117
+ subject.instance_variable_set(:@filter_command, 'powershell.exe if ($env:R10K_BRANCH.equals(\"master\")) {exit 1} else {exit 0}')
118
+ else
119
+ subject.instance_variable_set(:@filter_command, '[ $R10K_BRANCH != master ]')
120
+ end
121
+ end
122
+
123
+ let(:environments) { subject.generate_environments }
124
+
125
+ it "creates an environment for each branch not filtered by filter_command" do
126
+ expect(subject.generate_environments.size).to eq(2)
127
+ end
128
+ end
129
+
130
+ describe "generate_environments respects filter_command setting and name" do
131
+ before do
132
+ allow(subject.cache).to receive(:branches).and_return ['master', 'development', 'production']
133
+ if R10K::Util::Platform.windows?
134
+ subject.instance_variable_set(:@filter_command, 'powershell.exe if ($env:R10K_NAME.equals(\"mysource\")) {exit 0} else {exit 1}')
135
+ else
136
+ subject.instance_variable_set(:@filter_command, '[ $R10K_NAME = mysource ]')
137
+ end
138
+ end
139
+
140
+ let(:environments) { subject.generate_environments }
141
+
142
+ it "creates an environment for each branch not filtered by filter_command" do
143
+ expect(subject.generate_environments.size).to eq(3)
144
+ end
145
+ end
146
+
99
147
  end
100
148
 
101
149
  describe R10K::Source::Git, "handling invalid branch names" do
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'r10k/util/purgeable'
3
+ require 'r10k/util/cleaner'
3
4
 
4
5
  RSpec.describe R10K::Util::Purgeable do
5
6
  let(:managed_directories) do
@@ -21,14 +22,7 @@ RSpec.describe R10K::Util::Purgeable do
21
22
  ]
22
23
  end
23
24
 
24
- let(:test_class) do
25
- Struct.new(:managed_directories, :desired_contents) do
26
- include R10K::Util::Purgeable
27
- include R10K::Logging
28
- end
29
- end
30
-
31
- subject { test_class.new(managed_directories, desired_contents) }
25
+ subject { R10K::Util::Cleaner.new(managed_directories, desired_contents) }
32
26
 
33
27
  context 'without recurse option' do
34
28
  let(:recurse) { false }
@@ -10,7 +10,10 @@ describe R10K::Util::Setopts do
10
10
 
11
11
  def initialize(opts = {})
12
12
  setopts(opts, {
13
- :valid => :self, :alsovalid => :self, :truthyvalid => true,
13
+ :valid => :self,
14
+ :duplicate => :valid,
15
+ :alsovalid => :self,
16
+ :truthyvalid => true,
14
17
  :validalias => :valid,
15
18
  :ignoreme => nil
16
19
  })
@@ -53,7 +56,28 @@ describe R10K::Util::Setopts do
53
56
  }.to raise_error(ArgumentError, /cannot handle option 'notvalid'/)
54
57
  end
55
58
 
59
+ it "warns when given an unhandled option and raise_on_unhandled=false" do
60
+ test = Class.new { include R10K::Util::Setopts }.new
61
+ allow(test).to receive(:logger).and_return(spy)
62
+
63
+ test.send(:setopts, {valid: :value, invalid: :value},
64
+ {valid: :self},
65
+ raise_on_unhandled: false)
66
+
67
+ expect(test.logger).to have_received(:warn).with(%r{cannot handle option 'invalid'})
68
+ end
69
+
56
70
  it "ignores values that are marked as unhandled" do
57
71
  klass.new(:ignoreme => "IGNORE ME!")
58
72
  end
73
+
74
+ it "warns when given conflicting options" do
75
+ test = Class.new { include R10K::Util::Setopts }.new
76
+ allow(test).to receive(:logger).and_return(spy)
77
+
78
+ test.send(:setopts, {valid: :one, duplicate: :two},
79
+ {valid: :arg, duplicate: :arg})
80
+
81
+ expect(test.logger).to have_received(:warn).with(%r{valid.*duplicate.*conflict.*not both})
82
+ end
59
83
  end