spec/unit/action/deploy/module_spec.rb in r10k-3.11.0 vs spec/unit/action/deploy/module_spec.rb in r10k-3.12.0
- old
+ new
@@ -75,10 +75,15 @@
control: {
type: :mock,
basedir: '/some/nonexistent/path/control',
environments: %w[first second]
}
+ },
+ overrides: {
+ modules: {
+ pool_size: 4
+ }
}
)
end
before do
@@ -95,32 +100,26 @@
%w[first],
{}
)
end
- before do
- @modules = []
+ it 'generate_types is true' do
+ expect(subject.settings[:overrides][:environments][:generate_types]).to eq(true)
+ end
+
+ it 'only calls puppet generate types on environments where the specified module was updated' do
allow(subject).to receive(:visit_environment).and_wrap_original do |original, environment, &block|
- mod = R10K::Module::Local.new(environment.name, '/fakedir', {}, environment)
- if mod.name == 'first'
+ if environment.name == 'first'
+ expect(environment).to receive(:deploy).and_return(['first'])
expect(environment).to receive(:generate_types!)
else
+ expect(environment).to receive(:deploy).and_return([])
expect(environment).not_to receive(:generate_types!)
end
- @modules << mod
- expect(environment.puppetfile).to receive(:modules).and_return([mod]).twice
original.call(environment, &block)
end
- end
-
- it 'generate_types is true' do
- expect(subject.settings[:overrides][:environments][:generate_types]).to eq(true)
- end
-
- it 'only calls puppet generate types on environments with specified module' do
subject.call
- expect(@modules.length).to be(2)
end
end
context 'with generate-types disabled' do
subject do
@@ -246,33 +245,31 @@
expect(subject).to receive(:visit_environment).and_wrap_original do |original, environment, &block|
# For this test we want to have realistic Modules and access to
# their internal Repos to validate the sync. Unfortunately, to
# do so we do some invasive mocking, effectively implementing
- # our own R10K::Puppetfile#load. We directly update the Puppetfile's
- # internal ModuleLoader and then call `load` on it so it will create
- # the correct loaded_content.
- puppetfile = environment.puppetfile
- loader = puppetfile.loader
- expect(puppetfile).to receive(:load) do
+ # our own R10K::ModuleLoader::Puppetfile#load. We directly update
+ # the Environment's internal ModuleLoader and then call `load` on
+ # it so it will create the correct loaded_content.
+ loader = environment.loader
+ allow(loader).to receive(:puppetfile_content).and_return('')
+ expect(loader).to receive(:load) do
loader.add_module('mod1', { git: 'git://remote' })
loader.add_module('mod2', { git: 'git://remote' })
loader.add_module('mod3', { git: 'git://remote' })
- allow(loader).to receive(:puppetfile_content).and_return('')
- loaded_content = loader.load
- puppetfile.instance_variable_set(:@loaded_content, loaded_content)
- puppetfile.instance_variable_set(:@loaded, true)
- end
-
- puppetfile.modules.each do |mod|
- if ['mod1', 'mod2'].include?(mod.name)
- expect(mod.should_sync?).to be(true)
- else
- expect(mod.should_sync?).to be(false)
+ loaded_content = loader.load!
+ loaded_content[:modules].each do |mod|
+ if ['mod1', 'mod2'].include?(mod.name)
+ expect(mod.should_sync?).to be(true)
+ else
+ expect(mod.should_sync?).to be(false)
+ end
+ expect(mod).to receive(:sync).and_call_original
end
- expect(mod).to receive(:sync).and_call_original
+
+ loaded_content
end
original.call(environment, &block)
end
@@ -305,40 +302,39 @@
allow(R10K::Git).to receive_message_chain(:cache, :generate).and_return(cache)
allow_any_instance_of(R10K::Source::Git).to receive(:branch_names).and_return([R10K::Environment::Name.new('first', {}),
R10K::Environment::Name.new('second', {})])
expect(subject).to receive(:visit_environment).and_wrap_original do |original, environment, &block|
- puppetfile = environment.puppetfile
+ loader = environment.loader
if environment.name == 'first'
# For this test we want to have realistic Modules and access to
# their internal Repos to validate the sync. Unfortunately, to
# do so we do some invasive mocking, effectively implementing
- # our own R10K::Puppetfile#load. We directly update the Puppetfile's
- # internal ModuleLoader and then call `load` on it so it will create
- # the correct loaded_content.
- loader = puppetfile.loader
- expect(puppetfile).to receive(:load) do
+ # our own R10K::ModuleLoader::Puppetfile#load. We directly update
+ # the Environment's internal ModuleLoader and then call `load` on
+ # it so it will create the correct loaded_content.
+ allow(loader).to receive(:puppetfile_content).and_return('')
+ expect(loader).to receive(:load) do
loader.add_module('mod1', { git: 'git://remote' })
loader.add_module('mod2', { git: 'git://remote' })
- allow(loader).to receive(:puppetfile_content).and_return('')
- loaded_content = loader.load
- puppetfile.instance_variable_set(:@loaded_content, loaded_content)
- puppetfile.instance_variable_set(:@loaded, true)
- end
-
- puppetfile.modules.each do |mod|
- if mod.name == 'mod1'
- expect(mod.should_sync?).to be(true)
- else
- expect(mod.should_sync?).to be(false)
+ loaded_content = loader.load!
+ loaded_content[:modules].each do |mod|
+ if mod.name == 'mod1'
+ expect(mod.should_sync?).to be(true)
+ else
+ expect(mod.should_sync?).to be(false)
+ end
+ expect(mod).to receive(:sync).and_call_original
end
- expect(mod).to receive(:sync).and_call_original
+
+ loaded_content
end
+
else
- expect(puppetfile).not_to receive(:load)
+ expect(loader).not_to receive(:load)
end
original.call(environment, &block)
end.twice
@@ -413,20 +409,17 @@
it "properly substitutes the environment" do
mock_subprocess = double
allow(mock_subprocess).to receive(:logger=)
expect(mock_subprocess).to receive(:execute)
- mock_mod = double('mock_mod', name: 'mod1')
-
expect(R10K::Util::Subprocess).to receive(:new).
with(["/generate/types/wrapper", "first"]).
and_return(mock_subprocess)
expect(subject).to receive(:visit_environment).and_wrap_original do |original, environment, &block|
if environment.name == 'first'
- expect(environment).to receive(:deploy).and_return(true)
- expect(environment).to receive(:modules).and_return([mock_mod])
+ expect(environment).to receive(:deploy).and_return(['first'])
end
original.call(environment, &block)
end.exactly(3).times
subject.call
@@ -453,16 +446,13 @@
expect(R10K::Util::Subprocess).to receive(:new).
with(["/generate/types/wrapper", "first third"]).
and_return(mock_subprocess)
- mock_mod = double('mock_mod', name: 'mod1')
-
expect(subject).to receive(:visit_environment).and_wrap_original do |original, environment, &block|
- expect(environment).to receive(:deploy).and_return(true)
if ['first', 'third'].include?(environment.name)
- expect(environment).to receive(:modules).and_return([mock_mod])
+ expect(environment).to receive(:deploy).and_return(['mod1'])
end
original.call(environment, &block)
end.exactly(3).times
subject.call
@@ -471,12 +461,10 @@
it "does not execute the command if no envs had the module" do
expect(R10K::Util::Subprocess).not_to receive(:new)
mock_mod2 = double('mock_mod', name: 'mod2')
expect(subject).to receive(:visit_environment).and_wrap_original do |original, environment, &block|
- expect(environment).to receive(:deploy).and_return(true)
- # Envs have a different module than the one we asked to deploy
- expect(environment).to receive(:modules).and_return([mock_mod2])
+ expect(environment).to receive(:deploy).and_return([])
original.call(environment, &block)
end.exactly(3).times
subject.call
end