spec/unit/puppetfile_spec.rb in r10k-3.9.0 vs spec/unit/puppetfile_spec.rb in r10k-3.9.1
- old
+ new
@@ -4,13 +4,11 @@
describe R10K::Puppetfile do
subject do
described_class.new(
'/some/nonexistent/basedir',
- nil,
- nil,
- 'Puppetfile.r10k'
+ {puppetfile_name: 'Puppetfile.r10k'}
)
end
describe "a custom puppetfile Puppetfile.r10k" do
it "is the basedir joined with '/Puppetfile.r10k' path" do
@@ -21,15 +19,31 @@
end
describe R10K::Puppetfile do
subject do
- described_class.new(
- '/some/nonexistent/basedir'
- )
+ described_class.new( '/some/nonexistent/basedir', {})
end
+ describe "backwards compatibility with older calling conventions" do
+ it "honors all arguments correctly" do
+ puppetfile = described_class.new('/some/nonexistant/basedir', '/some/nonexistant/basedir/site-modules', nil, 'Pupupupetfile', true)
+ expect(puppetfile.force).to eq(true)
+ expect(puppetfile.moduledir).to eq('/some/nonexistant/basedir/site-modules')
+ expect(puppetfile.puppetfile_path).to eq('/some/nonexistant/basedir/Pupupupetfile')
+ expect(puppetfile.overrides).to eq({})
+ end
+
+ it "handles defaults correctly" do
+ puppetfile = described_class.new('/some/nonexistant/basedir', nil, nil, nil)
+ expect(puppetfile.force).to eq(false)
+ expect(puppetfile.moduledir).to eq('/some/nonexistant/basedir/modules')
+ expect(puppetfile.puppetfile_path).to eq('/some/nonexistant/basedir/Puppetfile')
+ expect(puppetfile.overrides).to eq({})
+ end
+ end
+
describe "the default moduledir" do
it "is the basedir joined with '/modules' path" do
expect(subject.moduledir).to eq '/some/nonexistent/basedir/modules'
end
end
@@ -52,19 +66,19 @@
expect(subject.moduledir).to eq '/some/nonexistent/basedir/relative/moduledir'
end
end
describe "adding modules" do
- it "should accept Forge modules with a string arg" do
- allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.moduledir, '1.2.3', anything).and_call_original
+ it "should transform Forge modules with a string arg to have a version key" do
+ allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.moduledir, hash_including(version: '1.2.3'), anything).and_call_original
expect { subject.add_module('puppet/test_module', '1.2.3') }.to change { subject.modules }
expect(subject.modules.collect(&:name)).to include('test_module')
end
it "should not accept Forge modules with a version comparison" do
- allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.moduledir, '< 1.2.0', anything).and_call_original
+ allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.moduledir, hash_including(version: '< 1.2.0'), anything).and_call_original
expect {
subject.add_module('puppet/test_module', '< 1.2.0')
}.to raise_error(RuntimeError, /module puppet\/test_module.*doesn't have an implementation/i)
@@ -165,11 +179,11 @@
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
+ allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.moduledir, hash_including(version: '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
@@ -193,87 +207,87 @@
end
it "wraps and re-raises syntax errors" do
path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'invalid-syntax')
pf_path = File.join(path, 'Puppetfile')
- subject = described_class.new(path)
+ subject = described_class.new(path, {})
expect {
subject.load!
}.to raise_error do |e|
expect_wrapped_error(e, pf_path, SyntaxError)
end
end
it "wraps and re-raises load errors" do
path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'load-error')
pf_path = File.join(path, 'Puppetfile')
- subject = described_class.new(path)
+ subject = described_class.new(path, {})
expect {
subject.load!
}.to raise_error do |e|
expect_wrapped_error(e, pf_path, LoadError)
end
end
it "wraps and re-raises argument errors" do
path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'argument-error')
pf_path = File.join(path, 'Puppetfile')
- subject = described_class.new(path)
+ subject = described_class.new(path, {})
expect {
subject.load!
}.to raise_error do |e|
expect_wrapped_error(e, pf_path, ArgumentError)
end
end
it "rejects Puppetfiles with duplicate module names" do
path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'duplicate-module-error')
pf_path = File.join(path, 'Puppetfile')
- subject = described_class.new(path)
+ subject = described_class.new(path, {})
expect {
subject.load!
}.to raise_error(R10K::Error, /Puppetfiles cannot contain duplicate module names/i)
end
it "wraps and re-raises name errors" do
path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'name-error')
pf_path = File.join(path, 'Puppetfile')
- subject = described_class.new(path)
+ subject = described_class.new(path, {})
expect {
subject.load!
}.to raise_error do |e|
expect_wrapped_error(e, pf_path, NameError)
end
end
it "accepts a forge module with a version" do
path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-with-version')
pf_path = File.join(path, 'Puppetfile')
- subject = described_class.new(path)
+ subject = described_class.new(path, {})
expect { subject.load! }.not_to raise_error
end
it "accepts a forge module without a version" do
path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-without-version')
pf_path = File.join(path, 'Puppetfile')
- subject = described_class.new(path)
+ subject = described_class.new(path, {})
expect { subject.load! }.not_to raise_error
end
it "creates a git module and applies the default branch sepcified in the Puppetfile" do
path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'default-branch-override')
pf_path = File.join(path, 'Puppetfile')
- subject = described_class.new(path)
+ subject = described_class.new(path, {})
expect { subject.load! }.not_to raise_error
git_module = subject.modules[0]
expect(git_module.default_ref).to eq 'here_lies_the_default_branch'
end
it "creates a git module and applies the provided default_branch_override" do
path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'default-branch-override')
pf_path = File.join(path, 'Puppetfile')
- subject = described_class.new(path)
+ subject = described_class.new(path, {})
default_branch_override = 'default_branch_override_name'
expect { subject.load!(default_branch_override) }.not_to raise_error
git_module = subject.modules[0]
expect(git_module.default_override_ref).to eq default_branch_override
expect(git_module.default_ref).to eq "here_lies_the_default_branch"
@@ -285,22 +299,22 @@
visitor = spy('visitor')
expect(visitor).to receive(:visit).with(:puppetfile, subject)
subject.accept(visitor)
end
- it "passes the visitor to each module if the visitor yields" do
+ it "synchronizes each module if the visitor yields" 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 = instance_double('R10K::Module::Base', :cachedir => :none)
mod2 = instance_double('R10K::Module::Base', :cachedir => :none)
- expect(mod1).to receive(:accept).with(visitor)
- expect(mod2).to receive(:accept).with(visitor)
+ expect(mod1).to receive(:sync)
+ expect(mod2).to receive(:sync)
expect(subject).to receive(:modules).and_return([mod1, mod2])
subject.accept(visitor)
end
@@ -316,12 +330,12 @@
block.call
end
mod1 = instance_double('R10K::Module::Base', :cachedir => :none)
mod2 = instance_double('R10K::Module::Base', :cachedir => :none)
- expect(mod1).to receive(:accept).with(visitor)
- expect(mod2).to receive(:accept).with(visitor)
+ expect(mod1).to receive(:sync)
+ expect(mod2).to receive(:sync)
expect(subject).to receive(:modules).and_return([mod1, mod2])
expect(Thread).to receive(:new).exactly(pool_size).and_call_original
expect(Queue).to receive(:new).and_call_original
@@ -341,12 +355,12 @@
m3 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/C')
m4 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/C')
m5 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/D')
m6 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/D')
- expect(subject).to receive(:modules).and_return([m1, m2, m3, m4, m5, m6])
+ modules = [m1, m2, m3, m4, m5, m6]
- queue = subject.modules_queue(visitor)
+ queue = R10K::ContentSynchronizer.modules_visit_queue(modules, visitor, subject)
expect(queue.length).to be 4
queue_array = 4.times.map { queue.pop }
expect(queue_array).to match_array([[m1], [m2], [m3, m4], [m5, m6]])
end
end