spec/unit/puppetfile_spec.rb in r10k-3.5.2 vs spec/unit/puppetfile_spec.rb in r10k-3.6.0

- old
+ new

@@ -125,10 +125,29 @@ allow(R10K::Module).to receive(:new).with('puppet/test_module', File.join(subject.basedir, 'vendor'), module_opts, anything).and_call_original 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 } end + + it "groups modules by vcs cache location" do + module_opts = { install_path: File.join(subject.basedir, 'vendor') } + opts1 = module_opts.merge(git: 'git@example.com:puppet/test_module.git') + opts2 = module_opts.merge(git: 'git@example.com:puppet/test_module_c.git') + sanitized_name1 = "git@example.com-puppet-test_module.git" + sanitized_name2 = "git@example.com-puppet-test_module_c.git" + + subject.add_module('puppet/test_module_a', opts1) + subject.add_module('puppet/test_module_b', opts1) + subject.add_module('puppet/test_module_c', opts2) + subject.add_module('puppet/test_module_d', '1.2.3') + + mods_by_cachedir = subject.modules_by_vcs_cachedir + + expect(mods_by_cachedir[:none].length).to be 1 + expect(mods_by_cachedir[sanitized_name1].length).to be 2 + expect(mods_by_cachedir[sanitized_name2].length).to be 1 + end end describe "#purge_exclusions" do let(:managed_dirs) { ['dir1', 'dir2'] } @@ -152,10 +171,30 @@ expect(subject.purge_exclusions).to match_array(managed_dirs + env_contents) end end end + describe '#managed_directories' do + it 'returns an array of paths that can be purged' do + allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.moduledir, '1.2.3', anything).and_call_original + + subject.add_module('puppet/test_module', '1.2.3') + expect(subject.managed_directories).to match_array(["/some/nonexistent/basedir/modules"]) + end + + context 'with a module with install_path == \'\'' do + it 'basedir isn\'t in the list of paths to purge' do + module_opts = { install_path: '', git: 'git@example.com:puppet/test_module.git' } + + allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.basedir, module_opts, anything).and_call_original + + subject.add_module('puppet/test_module', module_opts) + expect(subject.managed_directories).to be_empty + end + end + end + describe "evaluating a Puppetfile" do def expect_wrapped_error(orig, pf_path, wrapped_error) expect(orig).to be_a_kind_of(R10K::Error) expect(orig.message).to eq("Failed to evaluate #{pf_path}") expect(orig.original).to be_a_kind_of(wrapped_error) @@ -266,11 +305,11 @@ mod1 = spy('module') expect(mod1).to receive(:accept).with(visitor) mod2 = spy('module') expect(mod2).to receive(:accept).with(visitor) - expect(subject).to receive(:modules).and_return([mod1, mod2]) + expect(subject).to receive(:modules_by_vcs_cachedir).and_return({none: [mod1, mod2]}) subject.accept(visitor) end it "creates a thread pool to visit concurrently if pool_size setting is greater than one" do pool_size = 3 @@ -287,14 +326,40 @@ mod1 = spy('module') expect(mod1).to receive(:accept).with(visitor) mod2 = spy('module') expect(mod2).to receive(:accept).with(visitor) - expect(subject).to receive(:modules).and_return([mod1, mod2]) + expect(subject).to receive(:modules_by_vcs_cachedir).and_return({none: [mod1, mod2]}) expect(Thread).to receive(:new).exactly(pool_size).and_call_original expect(Queue).to receive(:new).and_call_original subject.accept(visitor) + end + + it "Creates queues of modules grouped by cachedir" do + visitor = spy('visitor') + expect(visitor).to receive(:visit) do |type, other, &block| + expect(type).to eq :puppetfile + expect(other).to eq subject + block.call + end + + mod1 = spy('module1') + mod2 = spy('module2') + mod3 = spy('module3') + mod4 = spy('module4') + mod5 = spy('module5') + mod6 = spy('module6') + + expect(subject).to receive(:modules_by_vcs_cachedir) + .and_return({:none => [mod1, mod2], + "foo-cachedir" => [mod3, mod4], + "bar-cachedir" => [mod5, mod6]}) + + queue = subject.modules_queue(visitor) + expect(queue.length).to be 4 + queue_array = 4.times.map { queue.pop } + expect(queue_array).to match_array([[mod1], [mod2], [mod3, mod4], [mod5, mod6]]) end end end