r10k 3.11.0 → 3.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.mkd +9 -0
  3. data/doc/dynamic-environments/configuration.mkd +7 -3
  4. data/doc/dynamic-environments/usage.mkd +26 -0
  5. data/doc/puppetfile.mkd +3 -4
  6. data/integration/tests/basic_functionality/basic_deployment.rb +176 -0
  7. data/lib/r10k/action/deploy/environment.rb +8 -1
  8. data/lib/r10k/action/deploy/module.rb +11 -6
  9. data/lib/r10k/action/puppetfile/check.rb +7 -5
  10. data/lib/r10k/action/puppetfile/install.rb +22 -16
  11. data/lib/r10k/action/puppetfile/purge.rb +12 -9
  12. data/lib/r10k/cli/deploy.rb +1 -0
  13. data/lib/r10k/cli/puppetfile.rb +0 -1
  14. data/lib/r10k/content_synchronizer.rb +16 -4
  15. data/lib/r10k/environment/base.rb +64 -11
  16. data/lib/r10k/environment/with_modules.rb +6 -10
  17. data/lib/r10k/git/stateful_repository.rb +7 -0
  18. data/lib/r10k/initializers.rb +1 -7
  19. data/lib/r10k/module/base.rb +5 -1
  20. data/lib/r10k/module/definition.rb +64 -0
  21. data/lib/r10k/module/forge.rb +10 -2
  22. data/lib/r10k/module/git.rb +22 -1
  23. data/lib/r10k/module/local.rb +2 -3
  24. data/lib/r10k/module/svn.rb +10 -0
  25. data/lib/r10k/module.rb +20 -2
  26. data/lib/r10k/module_loader/puppetfile/dsl.rb +8 -3
  27. data/lib/r10k/module_loader/puppetfile.rb +95 -29
  28. data/lib/r10k/puppetfile.rb +1 -2
  29. data/lib/r10k/settings.rb +11 -0
  30. data/lib/r10k/version.rb +1 -1
  31. data/locales/r10k.pot +75 -47
  32. data/spec/fixtures/unit/puppetfile/forge-override/Puppetfile +8 -0
  33. data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile +9 -0
  34. data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile.new +9 -0
  35. data/spec/r10k-mocks/mock_env.rb +3 -0
  36. data/spec/r10k-mocks/mock_source.rb +7 -3
  37. data/spec/unit/action/deploy/environment_spec.rb +80 -30
  38. data/spec/unit/action/deploy/module_spec.rb +50 -62
  39. data/spec/unit/action/puppetfile/check_spec.rb +17 -5
  40. data/spec/unit/action/puppetfile/install_spec.rb +42 -36
  41. data/spec/unit/action/puppetfile/purge_spec.rb +15 -17
  42. data/spec/unit/action/runner_spec.rb +0 -8
  43. data/spec/unit/environment/base_spec.rb +30 -17
  44. data/spec/unit/environment/git_spec.rb +2 -2
  45. data/spec/unit/environment/svn_spec.rb +4 -3
  46. data/spec/unit/environment/with_modules_spec.rb +2 -1
  47. data/spec/unit/module/base_spec.rb +8 -8
  48. data/spec/unit/module/forge_spec.rb +32 -4
  49. data/spec/unit/module/git_spec.rb +51 -10
  50. data/spec/unit/module/svn_spec.rb +18 -6
  51. data/spec/unit/module_loader/puppetfile_spec.rb +90 -30
  52. data/spec/unit/puppetfile_spec.rb +2 -2
  53. data/spec/unit/settings_spec.rb +25 -2
  54. metadata +7 -2
@@ -0,0 +1,8 @@
1
+ forge "my.custom.forge.com"
2
+
3
+ mod "puppetlabs/stdlib", '4.12.0'
4
+ mod "puppetlabs/concat", '2.1.0'
5
+
6
+ mod 'apache',
7
+ :git => 'https://github.com/puppetlabs/puppetlabs-apache',
8
+ :branch => 'docs_experiment'
@@ -0,0 +1,9 @@
1
+ mod 'puppetlabs/apt', '2.1.1'
2
+ mod 'puppetlabs/stdlib', :latest
3
+ mod 'puppetlabs/concat'
4
+ mod 'puppetlabs/rpm', '2.1.1-pre1'
5
+ mod 'foo', git: 'this/remote', branch: 'main'
6
+ mod 'bar', git: 'this/remote', tag: 'v1.2.3'
7
+ mod 'baz', git: 'this/remote', commit: '123abc456'
8
+ mod 'fizz', git: 'this/remote', ref: '1234567890abcdef1234567890abcdef12345678'
9
+ mod 'buzz', git: 'this/remote', ref: 'refs/heads/main'
@@ -0,0 +1,9 @@
1
+ mod 'puppetlabs/apt', '3.0.0'
2
+ mod 'puppetlabs/stdlib', :latest
3
+ mod 'puppetlabs/concat'
4
+ mod 'puppetlabs/rpm', '2.1.1-pre1'
5
+ mod 'foo', git: 'this/remote', branch: 'main'
6
+ mod 'bar', git: 'this/remote', tag: 'v1.2.3'
7
+ mod 'baz', git: 'this/remote', commit: '123abc456'
8
+ mod 'fizz', git: 'this/remote', ref: '1234567890abcdef1234567890abcdef12345678'
9
+ mod 'buzz', git: 'this/remote', ref: 'refs/heads/main'
@@ -1,6 +1,9 @@
1
1
  require 'r10k/environment'
2
+ require 'r10k/util/purgeable'
2
3
 
3
4
  class R10K::Environment::Mock < R10K::Environment::Base
5
+ include R10K::Util::Purgeable
6
+
4
7
  def sync
5
8
  "synced"
6
9
  end
@@ -5,9 +5,13 @@ class R10K::Source::Mock < R10K::Source::Base
5
5
  R10K::Source.register(:mock, self)
6
6
 
7
7
  def environments
8
- corrected_environment_names = @options[:environments].map do |env|
9
- R10K::Environment::Name.new(env, :prefix => @prefix, :invalid => 'correct_and_warn')
8
+ if @_environments.nil?
9
+ corrected_environment_names = @options[:environments].map do |env|
10
+ R10K::Environment::Name.new(env, :prefix => @prefix, :invalid => 'correct_and_warn')
11
+ end
12
+ @_environments = corrected_environment_names.map { |env| R10K::Environment::Mock.new(env.name, @basedir, env.dirname, { overrides: @options[:overrides] }) }
10
13
  end
11
- corrected_environment_names.map { |env| R10K::Environment::Mock.new(env.name, @basedir, env.dirname, { overrides: @options[:overrides] }) }
14
+
15
+ @_environments
12
16
  end
13
17
  end
@@ -63,6 +63,10 @@ describe R10K::Action::Deploy::Environment do
63
63
  described_class.new({ :'exclude-spec' => true }, [], {})
64
64
  end
65
65
 
66
+ it 'can accept an incremental option' do
67
+ described_class.new({ :incremental => true }, [], {})
68
+ end
69
+
66
70
  describe "initializing errors" do
67
71
  let (:settings) { { deploy: { purge_levels: [:environment],
68
72
  purge_whitelist: ['coolfile', 'coolfile2'],
@@ -91,27 +95,70 @@ describe R10K::Action::Deploy::Environment do
91
95
 
92
96
  describe "with puppetfile or modules flag" do
93
97
  let(:deployment) { R10K::Deployment.new(mock_config) }
94
- let(:puppetfile) { instance_double("R10K::Puppetfile", modules: []).as_null_object }
98
+ let(:loader) do
99
+ instance_double("R10K::ModuleLoader::Puppetfile",
100
+ :load => {
101
+ :modules => ['foo'],
102
+ :purge_exclusions => [],
103
+ :managed_directories => [],
104
+ :desired_contents => []
105
+ }
106
+ ).as_null_object
107
+ end
95
108
 
96
109
  before do
97
110
  expect(R10K::Deployment).to receive(:new).and_return(deployment)
98
- expect(R10K::Puppetfile).to receive(:new).and_return(puppetfile).at_least(:once)
111
+ expect(R10K::ModuleLoader::Puppetfile).to receive(:new).
112
+ and_return(loader).at_least(:once)
99
113
  end
100
114
 
101
- it "syncs the puppetfile when given the puppetfile flag" do
102
- expect(puppetfile).to receive(:sync)
115
+ it "syncs the puppetfile content when given the puppetfile flag" do
116
+ expect(loader).to receive(:load).exactly(4).times
117
+ expect(R10K::ContentSynchronizer).to receive(:concurrent_sync).exactly(4).times
103
118
  action = described_class.new({config: "/some/nonexistent/path", puppetfile: true}, [], {})
104
119
  action.call
105
120
  end
106
121
 
107
122
  it "syncs the puppetfile when given the modules flag" do
108
- expect(puppetfile).to receive(:sync)
123
+ expect(loader).to receive(:load).exactly(4).times
124
+ expect(R10K::ContentSynchronizer).to receive(:concurrent_sync).exactly(4).times
109
125
  action = described_class.new({config: "/some/nonexistent/path", modules: true}, [], {})
110
126
  action.call
111
127
  end
128
+ end
129
+
130
+ describe "with incremental flag" do
131
+ let(:loader) do
132
+ instance_double("R10K::ModuleLoader::Puppetfile",
133
+ :load => {
134
+ :modules => ['foo'],
135
+ :purge_exclusions => [],
136
+ :managed_directories => [],
137
+ :desired_contents => []
138
+ }
139
+ ).as_null_object
140
+ end
141
+
142
+ before do
143
+ expect(R10K::Deployment).to receive(:new).and_wrap_original do |original, settings|
144
+ original.call(mock_config.merge(settings))
145
+ end
146
+ expect(R10K::ModuleLoader::Puppetfile).to receive(:new).
147
+ and_return(loader).at_least(:once)
148
+ end
112
149
 
150
+ it "incremental flag causes the module definitons to be preloaded by the loader" do
151
+ expect(loader).to receive(:load_metadata).exactly(4).times
152
+ action = described_class.new({:config => "/some/nonexistent/path",
153
+ :modules => true,
154
+ :incremental => true},
155
+ [],
156
+ {})
157
+ action.call
158
+ end
113
159
  end
114
160
 
161
+
115
162
  describe "with an environment that doesn't exist" do
116
163
  let(:deployment) do
117
164
  R10K::Deployment.new(mock_config)
@@ -224,19 +271,20 @@ describe R10K::Action::Deploy::Environment do
224
271
 
225
272
  describe "Purging white/allowlist" do
226
273
 
227
- let(:settings) { { deploy: { purge_levels: [:environment], purge_allowlist: ['coolfile', 'coolfile2'] } } }
228
- let(:overrides) { { environments: {}, modules: {}, purging: { purge_levels: [:environment], purge_allowlist: ['coolfile', 'coolfile2'] } } }
274
+ let(:settings) { { pool_size: 4, deploy: { purge_levels: [:environment], purge_allowlist: ['coolfile', 'coolfile2'] } } }
275
+ let(:overrides) { { environments: {}, modules: { pool_size: 4 }, purging: { purge_levels: [:environment], purge_allowlist: ['coolfile', 'coolfile2'] } } }
229
276
  let(:deployment) do
230
- R10K::Deployment.new(mock_config.merge(overrides))
277
+ R10K::Deployment.new(mock_config.merge({overrides: overrides}))
231
278
  end
232
279
  before do
233
280
  expect(R10K::Deployment).to receive(:new).and_return(deployment)
281
+ allow_any_instance_of(R10K::Environment::Base).to receive(:purge!)
234
282
  end
235
283
 
236
284
  subject { described_class.new({ config: "/some/nonexistent/path", modules: true }, %w[PREFIX_first], settings) }
237
285
 
238
286
  it "reads in the purge_allowlist setting and purges accordingly" do
239
- expect(subject.logger).to receive(:debug).with(/purging unmanaged content for environment/i)
287
+ expect(subject.logger).to receive(:debug).with(/Purging unmanaged content for environment/)
240
288
  expect(subject.settings[:overrides][:purging][:purge_allowlist]).to eq(['coolfile', 'coolfile2'])
241
289
  subject.call
242
290
  end
@@ -245,7 +293,7 @@ describe R10K::Action::Deploy::Environment do
245
293
  let (:settings) { { deploy: { purge_levels: [:environment], purge_whitelist: ['coolfile', 'coolfile2'] } } }
246
294
 
247
295
  it "reads in the purge_whitelist setting and still sets it to purge_allowlist and purges accordingly" do
248
- expect(subject.logger).to receive(:debug).with(/purging unmanaged content for environment/i)
296
+ expect(subject.logger).to receive(:debug).with(/Purging unmanaged content for environment/)
249
297
  expect(subject.settings[:overrides][:purging][:purge_allowlist]).to eq(['coolfile', 'coolfile2'])
250
298
  subject.call
251
299
  end
@@ -260,7 +308,8 @@ describe R10K::Action::Deploy::Environment do
260
308
  requested_environments: ['PREFIX_first']
261
309
  },
262
310
  modules: {
263
- deploy_modules: true
311
+ deploy_modules: true,
312
+ pool_size: 4
264
313
  },
265
314
  purging: {
266
315
  purge_levels: purge_levels
@@ -274,6 +323,7 @@ describe R10K::Action::Deploy::Environment do
274
323
 
275
324
  before do
276
325
  expect(R10K::Deployment).to receive(:new).and_return(deployment)
326
+ allow_any_instance_of(R10K::Environment::Base).to receive(:purge!)
277
327
  end
278
328
 
279
329
  subject { described_class.new({ config: "/some/nonexistent/path", modules: true }, %w[PREFIX_first], settings) }
@@ -292,12 +342,12 @@ describe R10K::Action::Deploy::Environment do
292
342
 
293
343
  it "only logs about purging deployment" do
294
344
  expect(subject).to receive(:visit_environment).and_wrap_original do |original, env, &block|
295
- expect(env.logger).to_not receive(:debug).with(/purging unmanaged puppetfile content/i)
345
+ expect(env.logger).to_not receive(:debug).with(/Purging unmanaged puppetfile content/)
296
346
  original.call(env)
297
347
  end.at_least(:once)
298
348
 
299
- expect(subject.logger).to receive(:debug).with(/purging unmanaged environments for deployment/i)
300
- expect(subject.logger).to_not receive(:debug).with(/purging unmanaged content for environment/i)
349
+ expect(subject.logger).to receive(:debug).with(/Purging unmanaged environments for deployment/)
350
+ expect(subject.logger).to_not receive(:debug).with(/Purging unmanaged content for environment/)
301
351
 
302
352
  subject.call
303
353
  end
@@ -308,11 +358,11 @@ describe R10K::Action::Deploy::Environment do
308
358
 
309
359
  it "only logs about purging environment" do
310
360
  expect(subject).to receive(:visit_environment).and_wrap_original do |original, env, &block|
311
- expect(env.logger).to_not receive(:debug).with(/purging unmanaged puppetfile content/i)
361
+ expect(env.logger).to_not receive(:debug).with(/Purging unmanaged puppetfile content/)
312
362
  original.call(env)
313
363
  end.at_least(:once)
314
- expect(subject.logger).to receive(:debug).with(/purging unmanaged content for environment/i)
315
- expect(subject.logger).to_not receive(:debug).with(/purging unmanaged environments for deployment/i)
364
+ expect(subject.logger).to receive(:debug).with(/Purging unmanaged content for environment/)
365
+ expect(subject.logger).to_not receive(:debug).with(/Purging unmanaged environments for deployment/)
316
366
 
317
367
  subject.call
318
368
  end
@@ -325,7 +375,7 @@ describe R10K::Action::Deploy::Environment do
325
375
  original.call(env)
326
376
  end.at_least(:once)
327
377
 
328
- expect(subject.logger).to receive(:debug).with(/not purging unmanaged content for environment/i)
378
+ expect(subject.logger).to receive(:debug).with(/Not purging unmanaged content for environment/)
329
379
 
330
380
  subject.call
331
381
  end
@@ -335,15 +385,16 @@ describe R10K::Action::Deploy::Environment do
335
385
  let(:purge_levels) { [:puppetfile] }
336
386
 
337
387
  it "only logs about purging puppetfile" do
388
+ allow(R10K::ContentSynchronizer).to receive(:concurrent_sync)
338
389
  expect(subject).to receive(:visit_environment).and_wrap_original do |original, env, &block|
339
390
  if env.name =~ /first/
340
- expect(env.logger).to receive(:debug).with(/purging unmanaged puppetfile content/i)
391
+ expect(env.logger).to receive(:debug).with(/Purging unmanaged Puppetfile content/)
341
392
  end
342
393
  original.call(env)
343
394
  end.at_least(:once)
344
395
 
345
- expect(subject.logger).to_not receive(:debug).with(/purging unmanaged environments for deployment/i)
346
- expect(subject.logger).to_not receive(:debug).with(/purging unmanaged content for environment/i)
396
+ expect(subject.logger).to_not receive(:debug).with(/Purging unmanaged environments for deployment/)
397
+ expect(subject.logger).to_not receive(:debug).with(/Purging unmanaged content for environment/)
347
398
 
348
399
  subject.call
349
400
  end
@@ -360,6 +411,11 @@ describe R10K::Action::Deploy::Environment do
360
411
  basedir: '/some/nonexistent/path/control',
361
412
  environments: %w[first second]
362
413
  }
414
+ },
415
+ overrides: {
416
+ modules: {
417
+ pool_size: 4
418
+ }
363
419
  }
364
420
  )
365
421
  )
@@ -367,9 +423,8 @@ describe R10K::Action::Deploy::Environment do
367
423
 
368
424
  before do
369
425
  allow(R10K::Deployment).to receive(:new).and_return(deployment)
370
- end
426
+ allow_any_instance_of(R10K::Environment::Base).to receive(:purge!)
371
427
 
372
- before(:each) do
373
428
  allow(subject).to receive(:write_environment_info!)
374
429
  expect(subject.logger).not_to receive(:error)
375
430
  end
@@ -531,7 +586,6 @@ describe R10K::Action::Deploy::Environment do
531
586
  })
532
587
  end
533
588
  let(:mock_forge_module_1) { double(:name => "their_shiny_module", :properties => { :expected => "2.0.0" }) }
534
- let(:mock_puppetfile) { instance_double("R10K::Puppetfile", :modules => [mock_git_module_1, mock_git_module_2, mock_forge_module_1]) }
535
589
 
536
590
  before(:all) do
537
591
  @tmp_path = "./tmp-r10k-test-dir/"
@@ -544,10 +598,8 @@ describe R10K::Action::Deploy::Environment do
544
598
  end
545
599
 
546
600
  it "writes the .r10k-deploy file correctly if all goes well" do
547
- allow(R10K::Puppetfile).to receive(:new).and_return(mock_puppetfile)
548
-
549
601
  fake_env = Fake_Environment.new(@tmp_path, {:name => "my_cool_environment", :signature => "pablo picasso"})
550
- allow(fake_env).to receive(:modules).and_return(mock_puppetfile.modules)
602
+ allow(fake_env).to receive(:modules).and_return([mock_git_module_1, mock_git_module_2, mock_forge_module_1])
551
603
  subject.send(:write_environment_info!, fake_env, "2019-01-01 23:23:22 +0000", true)
552
604
 
553
605
  file_contents = File.read("#{@tmp_path}/.r10k-deploy.json")
@@ -570,10 +622,8 @@ describe R10K::Action::Deploy::Environment do
570
622
  end
571
623
 
572
624
  it "writes the .r10k-deploy file correctly if there's a failure" do
573
- allow(R10K::Puppetfile).to receive(:new).and_return(mock_puppetfile)
574
-
575
625
  fake_env = Fake_Environment.new(@tmp_path, {:name => "my_cool_environment", :signature => "pablo picasso"})
576
- allow(fake_env).to receive(:modules).and_return(mock_puppetfile.modules)
626
+ allow(fake_env).to receive(:modules).and_return([mock_git_module_1, mock_git_module_2, mock_forge_module_1])
577
627
  allow(mock_forge_module_1).to receive(:properties).and_raise(StandardError)
578
628
  subject.send(:write_environment_info!, fake_env, "2019-01-01 23:23:22 +0000", true)
579
629
 
@@ -77,6 +77,11 @@ describe R10K::Action::Deploy::Module do
77
77
  basedir: '/some/nonexistent/path/control',
78
78
  environments: %w[first second]
79
79
  }
80
+ },
81
+ overrides: {
82
+ modules: {
83
+ pool_size: 4
84
+ }
80
85
  }
81
86
  )
82
87
  end
@@ -97,28 +102,22 @@ describe R10K::Action::Deploy::Module do
97
102
  )
98
103
  end
99
104
 
100
- before do
101
- @modules = []
105
+ it 'generate_types is true' do
106
+ expect(subject.settings[:overrides][:environments][:generate_types]).to eq(true)
107
+ end
108
+
109
+ it 'only calls puppet generate types on environments where the specified module was updated' do
102
110
  allow(subject).to receive(:visit_environment).and_wrap_original do |original, environment, &block|
103
- mod = R10K::Module::Local.new(environment.name, '/fakedir', {}, environment)
104
- if mod.name == 'first'
111
+ if environment.name == 'first'
112
+ expect(environment).to receive(:deploy).and_return(['first'])
105
113
  expect(environment).to receive(:generate_types!)
106
114
  else
115
+ expect(environment).to receive(:deploy).and_return([])
107
116
  expect(environment).not_to receive(:generate_types!)
108
117
  end
109
- @modules << mod
110
- expect(environment.puppetfile).to receive(:modules).and_return([mod]).twice
111
118
  original.call(environment, &block)
112
119
  end
113
- end
114
-
115
- it 'generate_types is true' do
116
- expect(subject.settings[:overrides][:environments][:generate_types]).to eq(true)
117
- end
118
-
119
- it 'only calls puppet generate types on environments with specified module' do
120
120
  subject.call
121
- expect(@modules.length).to be(2)
122
121
  end
123
122
  end
124
123
 
@@ -248,29 +247,27 @@ describe R10K::Action::Deploy::Module do
248
247
  # For this test we want to have realistic Modules and access to
249
248
  # their internal Repos to validate the sync. Unfortunately, to
250
249
  # do so we do some invasive mocking, effectively implementing
251
- # our own R10K::Puppetfile#load. We directly update the Puppetfile's
252
- # internal ModuleLoader and then call `load` on it so it will create
253
- # the correct loaded_content.
254
- puppetfile = environment.puppetfile
255
- loader = puppetfile.loader
256
- expect(puppetfile).to receive(:load) do
250
+ # our own R10K::ModuleLoader::Puppetfile#load. We directly update
251
+ # the Environment's internal ModuleLoader and then call `load` on
252
+ # it so it will create the correct loaded_content.
253
+ loader = environment.loader
254
+ allow(loader).to receive(:puppetfile_content).and_return('')
255
+ expect(loader).to receive(:load) do
257
256
  loader.add_module('mod1', { git: 'git://remote' })
258
257
  loader.add_module('mod2', { git: 'git://remote' })
259
258
  loader.add_module('mod3', { git: 'git://remote' })
260
259
 
261
- allow(loader).to receive(:puppetfile_content).and_return('')
262
- loaded_content = loader.load
263
- puppetfile.instance_variable_set(:@loaded_content, loaded_content)
264
- puppetfile.instance_variable_set(:@loaded, true)
265
- end
266
-
267
- puppetfile.modules.each do |mod|
268
- if ['mod1', 'mod2'].include?(mod.name)
269
- expect(mod.should_sync?).to be(true)
270
- else
271
- expect(mod.should_sync?).to be(false)
260
+ loaded_content = loader.load!
261
+ loaded_content[:modules].each do |mod|
262
+ if ['mod1', 'mod2'].include?(mod.name)
263
+ expect(mod.should_sync?).to be(true)
264
+ else
265
+ expect(mod.should_sync?).to be(false)
266
+ end
267
+ expect(mod).to receive(:sync).and_call_original
272
268
  end
273
- expect(mod).to receive(:sync).and_call_original
269
+
270
+ loaded_content
274
271
  end
275
272
 
276
273
  original.call(environment, &block)
@@ -307,36 +304,35 @@ describe R10K::Action::Deploy::Module do
307
304
  R10K::Environment::Name.new('second', {})])
308
305
 
309
306
  expect(subject).to receive(:visit_environment).and_wrap_original do |original, environment, &block|
310
- puppetfile = environment.puppetfile
307
+ loader = environment.loader
311
308
 
312
309
  if environment.name == 'first'
313
310
  # For this test we want to have realistic Modules and access to
314
311
  # their internal Repos to validate the sync. Unfortunately, to
315
312
  # do so we do some invasive mocking, effectively implementing
316
- # our own R10K::Puppetfile#load. We directly update the Puppetfile's
317
- # internal ModuleLoader and then call `load` on it so it will create
318
- # the correct loaded_content.
319
- loader = puppetfile.loader
320
- expect(puppetfile).to receive(:load) do
313
+ # our own R10K::ModuleLoader::Puppetfile#load. We directly update
314
+ # the Environment's internal ModuleLoader and then call `load` on
315
+ # it so it will create the correct loaded_content.
316
+ allow(loader).to receive(:puppetfile_content).and_return('')
317
+ expect(loader).to receive(:load) do
321
318
  loader.add_module('mod1', { git: 'git://remote' })
322
319
  loader.add_module('mod2', { git: 'git://remote' })
323
320
 
324
- allow(loader).to receive(:puppetfile_content).and_return('')
325
- loaded_content = loader.load
326
- puppetfile.instance_variable_set(:@loaded_content, loaded_content)
327
- puppetfile.instance_variable_set(:@loaded, true)
328
- end
329
-
330
- puppetfile.modules.each do |mod|
331
- if mod.name == 'mod1'
332
- expect(mod.should_sync?).to be(true)
333
- else
334
- expect(mod.should_sync?).to be(false)
321
+ loaded_content = loader.load!
322
+ loaded_content[:modules].each do |mod|
323
+ if mod.name == 'mod1'
324
+ expect(mod.should_sync?).to be(true)
325
+ else
326
+ expect(mod.should_sync?).to be(false)
327
+ end
328
+ expect(mod).to receive(:sync).and_call_original
335
329
  end
336
- expect(mod).to receive(:sync).and_call_original
330
+
331
+ loaded_content
337
332
  end
333
+
338
334
  else
339
- expect(puppetfile).not_to receive(:load)
335
+ expect(loader).not_to receive(:load)
340
336
  end
341
337
 
342
338
  original.call(environment, &block)
@@ -415,16 +411,13 @@ describe R10K::Action::Deploy::Module do
415
411
  allow(mock_subprocess).to receive(:logger=)
416
412
  expect(mock_subprocess).to receive(:execute)
417
413
 
418
- mock_mod = double('mock_mod', name: 'mod1')
419
-
420
414
  expect(R10K::Util::Subprocess).to receive(:new).
421
415
  with(["/generate/types/wrapper", "first"]).
422
416
  and_return(mock_subprocess)
423
417
 
424
418
  expect(subject).to receive(:visit_environment).and_wrap_original do |original, environment, &block|
425
419
  if environment.name == 'first'
426
- expect(environment).to receive(:deploy).and_return(true)
427
- expect(environment).to receive(:modules).and_return([mock_mod])
420
+ expect(environment).to receive(:deploy).and_return(['first'])
428
421
  end
429
422
  original.call(environment, &block)
430
423
  end.exactly(3).times
@@ -455,12 +448,9 @@ describe R10K::Action::Deploy::Module do
455
448
  with(["/generate/types/wrapper", "first third"]).
456
449
  and_return(mock_subprocess)
457
450
 
458
- mock_mod = double('mock_mod', name: 'mod1')
459
-
460
451
  expect(subject).to receive(:visit_environment).and_wrap_original do |original, environment, &block|
461
- expect(environment).to receive(:deploy).and_return(true)
462
452
  if ['first', 'third'].include?(environment.name)
463
- expect(environment).to receive(:modules).and_return([mock_mod])
453
+ expect(environment).to receive(:deploy).and_return(['mod1'])
464
454
  end
465
455
  original.call(environment, &block)
466
456
  end.exactly(3).times
@@ -473,9 +463,7 @@ describe R10K::Action::Deploy::Module do
473
463
 
474
464
  mock_mod2 = double('mock_mod', name: 'mod2')
475
465
  expect(subject).to receive(:visit_environment).and_wrap_original do |original, environment, &block|
476
- expect(environment).to receive(:deploy).and_return(true)
477
- # Envs have a different module than the one we asked to deploy
478
- expect(environment).to receive(:modules).and_return([mock_mod2])
466
+ expect(environment).to receive(:deploy).and_return([])
479
467
  original.call(environment, &block)
480
468
  end.exactly(3).times
481
469