r10k 3.6.0 → 3.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/docker.yml +4 -1
  3. data/.github/workflows/release.yml +3 -2
  4. data/.github/workflows/rspec_tests.yml +81 -0
  5. data/.github/workflows/stale.yml +19 -0
  6. data/.travis.yml +8 -1
  7. data/CHANGELOG.mkd +33 -0
  8. data/CODEOWNERS +2 -2
  9. data/README.mkd +2 -2
  10. data/doc/common-patterns.mkd +1 -0
  11. data/doc/dynamic-environments/configuration.mkd +123 -42
  12. data/doc/dynamic-environments/usage.mkd +12 -11
  13. data/doc/puppetfile.mkd +23 -3
  14. data/docker/Gemfile +1 -1
  15. data/docker/Makefile +4 -3
  16. data/docker/docker-compose.yml +18 -0
  17. data/docker/r10k/Dockerfile +1 -1
  18. data/docker/r10k/docker-entrypoint.sh +0 -1
  19. data/docker/r10k/release.Dockerfile +1 -1
  20. data/docker/spec/dockerfile_spec.rb +26 -32
  21. data/integration/tests/git_source/git_source_repeated_remote.rb +2 -2
  22. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module.rb +2 -1
  23. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module_static.rb +2 -1
  24. data/integration/tests/user_scenario/basic_workflow/multi_source_custom_forge_git_module.rb +1 -1
  25. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_git_module.rb +2 -1
  26. data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +1 -1
  27. data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +1 -1
  28. data/integration/tests/user_scenario/complex_workflow/multi_env_unamanaged.rb +1 -1
  29. data/lib/r10k/action/base.rb +10 -0
  30. data/lib/r10k/action/deploy/display.rb +49 -10
  31. data/lib/r10k/action/deploy/environment.rb +102 -51
  32. data/lib/r10k/action/deploy/module.rb +55 -30
  33. data/lib/r10k/action/puppetfile/check.rb +3 -1
  34. data/lib/r10k/action/puppetfile/install.rb +20 -23
  35. data/lib/r10k/action/puppetfile/purge.rb +8 -2
  36. data/lib/r10k/action/runner.rb +34 -0
  37. data/lib/r10k/cli/deploy.rb +14 -7
  38. data/lib/r10k/cli/puppetfile.rb +5 -5
  39. data/lib/r10k/content_synchronizer.rb +83 -0
  40. data/lib/r10k/deployment.rb +1 -1
  41. data/lib/r10k/environment/base.rb +30 -3
  42. data/lib/r10k/environment/git.rb +17 -5
  43. data/lib/r10k/environment/name.rb +22 -4
  44. data/lib/r10k/environment/svn.rb +11 -4
  45. data/lib/r10k/environment/with_modules.rb +46 -30
  46. data/lib/r10k/git.rb +1 -0
  47. data/lib/r10k/git/cache.rb +11 -1
  48. data/lib/r10k/git/rugged/credentials.rb +39 -2
  49. data/lib/r10k/initializers.rb +2 -0
  50. data/lib/r10k/module.rb +1 -1
  51. data/lib/r10k/module/base.rb +17 -1
  52. data/lib/r10k/module/forge.rb +29 -11
  53. data/lib/r10k/module/git.rb +50 -27
  54. data/lib/r10k/module/local.rb +2 -1
  55. data/lib/r10k/module/svn.rb +24 -18
  56. data/lib/r10k/puppetfile.rb +66 -83
  57. data/lib/r10k/settings.rb +29 -2
  58. data/lib/r10k/source/base.rb +9 -0
  59. data/lib/r10k/source/git.rb +18 -7
  60. data/lib/r10k/source/hash.rb +5 -5
  61. data/lib/r10k/source/svn.rb +5 -3
  62. data/lib/r10k/util/cleaner.rb +21 -0
  63. data/lib/r10k/util/setopts.rb +33 -12
  64. data/lib/r10k/version.rb +1 -1
  65. data/locales/r10k.pot +98 -82
  66. data/r10k.gemspec +1 -1
  67. data/spec/fixtures/unit/action/r10k_creds.yaml +9 -0
  68. data/spec/r10k-mocks/mock_source.rb +1 -1
  69. data/spec/shared-examples/puppetfile-action.rb +7 -7
  70. data/spec/shared-examples/subprocess-runner.rb +11 -5
  71. data/spec/unit/action/deploy/display_spec.rb +35 -5
  72. data/spec/unit/action/deploy/environment_spec.rb +207 -37
  73. data/spec/unit/action/deploy/module_spec.rb +173 -26
  74. data/spec/unit/action/puppetfile/check_spec.rb +2 -2
  75. data/spec/unit/action/puppetfile/install_spec.rb +31 -10
  76. data/spec/unit/action/puppetfile/purge_spec.rb +25 -5
  77. data/spec/unit/action/runner_spec.rb +48 -1
  78. data/spec/unit/environment/git_spec.rb +19 -2
  79. data/spec/unit/environment/name_spec.rb +28 -0
  80. data/spec/unit/environment/svn_spec.rb +12 -0
  81. data/spec/unit/environment/with_modules_spec.rb +74 -0
  82. data/spec/unit/git/cache_spec.rb +10 -0
  83. data/spec/unit/git/rugged/credentials_spec.rb +79 -2
  84. data/spec/unit/git_spec.rb +3 -3
  85. data/spec/unit/module/forge_spec.rb +21 -13
  86. data/spec/unit/module/git_spec.rb +64 -1
  87. data/spec/unit/module_spec.rb +60 -10
  88. data/spec/unit/puppetfile_spec.rb +63 -60
  89. data/spec/unit/settings_spec.rb +12 -0
  90. data/spec/unit/source/git_spec.rb +15 -3
  91. data/spec/unit/util/purgeable_spec.rb +2 -8
  92. data/spec/unit/util/setopts_spec.rb +25 -1
  93. metadata +11 -11
  94. data/azure-pipelines.yml +0 -87
@@ -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')
@@ -128,23 +142,15 @@ describe R10K::Puppetfile do
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
130
144
 
131
- it "groups modules by vcs cache location" do
132
- module_opts = { install_path: File.join(subject.basedir, 'vendor') }
133
- opts1 = module_opts.merge(git: 'git@example.com:puppet/test_module.git')
134
- opts2 = module_opts.merge(git: 'git@example.com:puppet/test_module_c.git')
135
- sanitized_name1 = "git@example.com-puppet-test_module.git"
136
- sanitized_name2 = "git@example.com-puppet-test_module_c.git"
137
-
138
- subject.add_module('puppet/test_module_a', opts1)
139
- subject.add_module('puppet/test_module_b', opts1)
140
- subject.add_module('puppet/test_module_c', opts2)
141
- subject.add_module('puppet/test_module_d', '1.2.3')
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)
142
151
 
143
- mods_by_cachedir = subject.modules_by_vcs_cachedir
144
-
145
- expect(mods_by_cachedir[:none].length).to be 1
146
- expect(mods_by_cachedir[sanitized_name1].length).to be 2
147
- expect(mods_by_cachedir[sanitized_name2].length).to be 1
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 }
148
154
  end
149
155
  end
150
156
 
@@ -175,7 +181,7 @@ describe R10K::Puppetfile do
175
181
 
176
182
  describe '#managed_directories' do
177
183
  it 'returns an array of paths that can be purged' do
178
- allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.moduledir, '1.2.3', anything).and_call_original
184
+ allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.moduledir, hash_including(version: '1.2.3'), anything).and_call_original
179
185
 
180
186
  subject.add_module('puppet/test_module', '1.2.3')
181
187
  expect(subject.managed_directories).to match_array(["/some/nonexistent/basedir/modules"])
@@ -203,7 +209,7 @@ describe R10K::Puppetfile do
203
209
  it "wraps and re-raises syntax errors" do
204
210
  path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'invalid-syntax')
205
211
  pf_path = File.join(path, 'Puppetfile')
206
- subject = described_class.new(path)
212
+ subject = described_class.new(path, {})
207
213
  expect {
208
214
  subject.load!
209
215
  }.to raise_error do |e|
@@ -214,7 +220,7 @@ describe R10K::Puppetfile do
214
220
  it "wraps and re-raises load errors" do
215
221
  path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'load-error')
216
222
  pf_path = File.join(path, 'Puppetfile')
217
- subject = described_class.new(path)
223
+ subject = described_class.new(path, {})
218
224
  expect {
219
225
  subject.load!
220
226
  }.to raise_error do |e|
@@ -225,7 +231,7 @@ describe R10K::Puppetfile do
225
231
  it "wraps and re-raises argument errors" do
226
232
  path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'argument-error')
227
233
  pf_path = File.join(path, 'Puppetfile')
228
- subject = described_class.new(path)
234
+ subject = described_class.new(path, {})
229
235
  expect {
230
236
  subject.load!
231
237
  }.to raise_error do |e|
@@ -236,7 +242,7 @@ describe R10K::Puppetfile do
236
242
  it "rejects Puppetfiles with duplicate module names" do
237
243
  path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'duplicate-module-error')
238
244
  pf_path = File.join(path, 'Puppetfile')
239
- subject = described_class.new(path)
245
+ subject = described_class.new(path, {})
240
246
  expect {
241
247
  subject.load!
242
248
  }.to raise_error(R10K::Error, /Puppetfiles cannot contain duplicate module names/i)
@@ -245,7 +251,7 @@ describe R10K::Puppetfile do
245
251
  it "wraps and re-raises name errors" do
246
252
  path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'name-error')
247
253
  pf_path = File.join(path, 'Puppetfile')
248
- subject = described_class.new(path)
254
+ subject = described_class.new(path, {})
249
255
  expect {
250
256
  subject.load!
251
257
  }.to raise_error do |e|
@@ -256,21 +262,21 @@ describe R10K::Puppetfile do
256
262
  it "accepts a forge module with a version" do
257
263
  path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-with-version')
258
264
  pf_path = File.join(path, 'Puppetfile')
259
- subject = described_class.new(path)
265
+ subject = described_class.new(path, {})
260
266
  expect { subject.load! }.not_to raise_error
261
267
  end
262
268
 
263
269
  it "accepts a forge module without a version" do
264
270
  path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-without-version')
265
271
  pf_path = File.join(path, 'Puppetfile')
266
- subject = described_class.new(path)
272
+ subject = described_class.new(path, {})
267
273
  expect { subject.load! }.not_to raise_error
268
274
  end
269
275
 
270
276
  it "creates a git module and applies the default branch sepcified in the Puppetfile" do
271
277
  path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'default-branch-override')
272
278
  pf_path = File.join(path, 'Puppetfile')
273
- subject = described_class.new(path)
279
+ subject = described_class.new(path, {})
274
280
  expect { subject.load! }.not_to raise_error
275
281
  git_module = subject.modules[0]
276
282
  expect(git_module.default_ref).to eq 'here_lies_the_default_branch'
@@ -279,11 +285,12 @@ describe R10K::Puppetfile do
279
285
  it "creates a git module and applies the provided default_branch_override" do
280
286
  path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'default-branch-override')
281
287
  pf_path = File.join(path, 'Puppetfile')
282
- subject = described_class.new(path)
288
+ subject = described_class.new(path, {})
283
289
  default_branch_override = 'default_branch_override_name'
284
290
  expect { subject.load!(default_branch_override) }.not_to raise_error
285
291
  git_module = subject.modules[0]
286
- 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"
287
294
  end
288
295
  end
289
296
 
@@ -294,7 +301,7 @@ describe R10K::Puppetfile do
294
301
  subject.accept(visitor)
295
302
  end
296
303
 
297
- it "passes the visitor to each module if the visitor yields" do
304
+ it "synchronizes each module if the visitor yields" do
298
305
  visitor = spy('visitor')
299
306
  expect(visitor).to receive(:visit) do |type, other, &block|
300
307
  expect(type).to eq :puppetfile
@@ -302,12 +309,12 @@ describe R10K::Puppetfile do
302
309
  block.call
303
310
  end
304
311
 
305
- mod1 = spy('module')
306
- expect(mod1).to receive(:accept).with(visitor)
307
- mod2 = spy('module')
308
- expect(mod2).to receive(:accept).with(visitor)
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)
316
+ expect(subject).to receive(:modules).and_return([mod1, mod2])
309
317
 
310
- expect(subject).to receive(:modules_by_vcs_cachedir).and_return({none: [mod1, mod2]})
311
318
  subject.accept(visitor)
312
319
  end
313
320
 
@@ -323,12 +330,11 @@ describe R10K::Puppetfile do
323
330
  block.call
324
331
  end
325
332
 
326
- mod1 = spy('module')
327
- expect(mod1).to receive(:accept).with(visitor)
328
- mod2 = spy('module')
329
- expect(mod2).to receive(:accept).with(visitor)
330
-
331
- expect(subject).to receive(:modules_by_vcs_cachedir).and_return({none: [mod1, mod2]})
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)
337
+ expect(subject).to receive(:modules).and_return([mod1, mod2])
332
338
 
333
339
  expect(Thread).to receive(:new).exactly(pool_size).and_call_original
334
340
  expect(Queue).to receive(:new).and_call_original
@@ -344,22 +350,19 @@ describe R10K::Puppetfile do
344
350
  block.call
345
351
  end
346
352
 
347
- mod1 = spy('module1')
348
- mod2 = spy('module2')
349
- mod3 = spy('module3')
350
- mod4 = spy('module4')
351
- mod5 = spy('module5')
352
- mod6 = spy('module6')
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')
353
359
 
354
- expect(subject).to receive(:modules_by_vcs_cachedir)
355
- .and_return({:none => [mod1, mod2],
356
- "foo-cachedir" => [mod3, mod4],
357
- "bar-cachedir" => [mod5, mod6]})
360
+ modules = [m1, m2, m3, m4, m5, m6]
358
361
 
359
- queue = subject.modules_queue(visitor)
362
+ queue = R10K::ContentSynchronizer.modules_visit_queue(modules, visitor, subject)
360
363
  expect(queue.length).to be 4
361
364
  queue_array = 4.times.map { queue.pop }
362
- expect(queue_array).to match_array([[mod1], [mod2], [mod3, mod4], [mod5, mod6]])
365
+ expect(queue_array).to match_array([[m1], [m2], [m3, m4], [m5, m6]])
363
366
  end
364
367
  end
365
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
@@ -99,7 +99,11 @@ describe R10K::Source::Git do
99
99
 
100
100
  describe "filtering branches with command" do
101
101
  let(:branches) { ['master', 'development', 'production'] }
102
- let(:filter_command) { 'sh -c "[ $R10K_BRANCH != development ]"' }
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
103
107
 
104
108
  it "filters branches" do
105
109
  expect(subject.filter_branches_by_command(branches, filter_command)).to eq(['master', 'production'])
@@ -109,7 +113,11 @@ describe R10K::Source::Git do
109
113
  describe "generate_environments respects filter_command setting" do
110
114
  before do
111
115
  allow(subject.cache).to receive(:branches).and_return ['master', 'development', 'production']
112
- subject.instance_variable_set(:@filter_command, '[ $R10K_BRANCH != master ]')
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
113
121
  end
114
122
 
115
123
  let(:environments) { subject.generate_environments }
@@ -122,7 +130,11 @@ describe R10K::Source::Git do
122
130
  describe "generate_environments respects filter_command setting and name" do
123
131
  before do
124
132
  allow(subject.cache).to receive(:branches).and_return ['master', 'development', 'production']
125
- subject.instance_variable_set(:@filter_command, '[ $R10K_NAME = mysource ]')
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
126
138
  end
127
139
 
128
140
  let(:environments) { subject.generate_environments }
@@ -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