2013-10-15 23:07:51 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2013-10-23 16:41:38 +02:00
|
|
|
describe 'concat::fragment', :type => :define do
|
2013-10-15 23:07:51 +02:00
|
|
|
|
2013-10-23 21:18:09 +02:00
|
|
|
shared_examples 'fragment' do |title, params|
|
|
|
|
params = {} if params.nil?
|
|
|
|
|
2013-10-23 16:41:38 +02:00
|
|
|
p = {
|
|
|
|
:content => nil,
|
|
|
|
:source => nil,
|
|
|
|
:order => 10,
|
|
|
|
:ensure => 'present',
|
2013-11-02 02:20:41 +01:00
|
|
|
:mode => '0640',
|
2013-10-24 17:48:37 +02:00
|
|
|
:owner => nil,
|
2013-10-23 16:41:38 +02:00
|
|
|
:group => nil,
|
|
|
|
:backup => 'puppet',
|
|
|
|
}.merge(params)
|
|
|
|
|
|
|
|
safe_name = title.gsub(/[\/\n]/, '_')
|
|
|
|
safe_target_name = p[:target].gsub(/[\/\n]/, '_')
|
|
|
|
concatdir = '/var/lib/puppet/concat'
|
|
|
|
fragdir = "#{concatdir}/#{safe_target_name}"
|
|
|
|
|
|
|
|
let(:title) { title }
|
2013-10-24 17:48:37 +02:00
|
|
|
let(:facts) {{ :concat_basedir => concatdir }}
|
2013-10-23 16:41:38 +02:00
|
|
|
let(:params) { params }
|
|
|
|
let(:pre_condition) do
|
|
|
|
"concat{ '#{p[:target]}': }"
|
|
|
|
end
|
2013-10-15 23:07:51 +02:00
|
|
|
|
|
|
|
it do
|
|
|
|
should contain_class('concat::setup')
|
2013-10-23 16:41:38 +02:00
|
|
|
should contain_concat(p[:target])
|
|
|
|
should contain_file("#{fragdir}/fragments/#{p[:order]}_#{safe_name}").with({
|
|
|
|
:ensure => p[:ensure],
|
|
|
|
:mode => p[:mode],
|
|
|
|
:owner => p[:owner],
|
2013-10-24 17:48:37 +02:00
|
|
|
:group => p[:group],
|
2013-10-23 16:41:38 +02:00
|
|
|
:source => p[:source],
|
|
|
|
:content => p[:content],
|
|
|
|
:alias => "concat_fragment_#{title}",
|
2013-10-24 00:42:44 +02:00
|
|
|
:backup => false,
|
2013-10-15 23:07:51 +02:00
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
2013-10-23 16:41:38 +02:00
|
|
|
|
2013-11-02 17:33:41 +01:00
|
|
|
context 'title' do
|
|
|
|
['0', '1', 'a', 'z'].each do |title|
|
|
|
|
it_behaves_like 'fragment', title, {
|
2013-10-23 16:41:38 +02:00
|
|
|
:target => '/etc/motd',
|
|
|
|
}
|
|
|
|
end
|
2013-11-02 17:33:41 +01:00
|
|
|
end # title
|
2013-10-23 16:41:38 +02:00
|
|
|
|
2013-11-02 17:33:41 +01:00
|
|
|
context 'target =>' do
|
|
|
|
['./etc/motd', 'etc/motd', 'motd_header'].each do |target|
|
2013-10-23 16:41:38 +02:00
|
|
|
context target do
|
2013-11-02 17:33:41 +01:00
|
|
|
it_behaves_like 'fragment', target, {
|
|
|
|
:target => '/etc/motd',
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'false' do
|
|
|
|
let(:title) { 'motd_header' }
|
|
|
|
let(:facts) {{ :concat_basedir => '/tmp' }}
|
|
|
|
let(:params) {{ :target => false }}
|
2013-10-23 16:41:38 +02:00
|
|
|
|
2013-11-02 17:33:41 +01:00
|
|
|
it 'should fail' do
|
|
|
|
expect { should }.to raise_error(Puppet::Error, /is not a string/)
|
2013-10-23 16:41:38 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end # target =>
|
|
|
|
|
|
|
|
context 'ensure =>' do
|
|
|
|
['', 'present', 'absent', 'file', 'directory'].each do |ens|
|
|
|
|
context ens do
|
|
|
|
it_behaves_like 'fragment', 'motd_header', {
|
|
|
|
:ensure => ens,
|
|
|
|
:target => '/etc/motd',
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'invalid' do
|
|
|
|
let(:title) { 'motd_header' }
|
2013-10-24 17:48:37 +02:00
|
|
|
let(:facts) {{ :concat_basedir => '/tmp' }}
|
2013-10-23 16:41:38 +02:00
|
|
|
let(:params) {{ :ensure => 'invalid', :target => '/etc/motd' }}
|
|
|
|
|
|
|
|
it 'should fail' do
|
|
|
|
expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^$|^present$|^absent$|^file$|^directory$"')}/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end # ensure =>
|
|
|
|
|
|
|
|
context 'content =>' do
|
|
|
|
['', 'ashp is our hero'].each do |content|
|
|
|
|
context content do
|
|
|
|
it_behaves_like 'fragment', 'motd_header', {
|
|
|
|
:content => content,
|
|
|
|
:target => '/etc/motd',
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'false' do
|
|
|
|
let(:title) { 'motd_header' }
|
2013-10-24 17:48:37 +02:00
|
|
|
let(:facts) {{ :concat_basedir => '/tmp' }}
|
2013-10-23 16:41:38 +02:00
|
|
|
let(:params) {{ :content => false, :target => '/etc/motd' }}
|
|
|
|
|
|
|
|
it 'should fail' do
|
|
|
|
expect { should }.to raise_error(Puppet::Error, /is not a string/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end # content =>
|
|
|
|
|
|
|
|
context 'source =>' do
|
|
|
|
['', '/foo/bar'].each do |source|
|
|
|
|
context source do
|
|
|
|
it_behaves_like 'fragment', 'motd_header', {
|
|
|
|
:source => source,
|
|
|
|
:target => '/etc/motd',
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'false' do
|
|
|
|
let(:title) { 'motd_header' }
|
2013-10-24 17:48:37 +02:00
|
|
|
let(:facts) {{ :concat_basedir => '/tmp' }}
|
2013-10-23 16:41:38 +02:00
|
|
|
let(:params) {{ :source => false, :target => '/etc/motd' }}
|
|
|
|
|
|
|
|
it 'should fail' do
|
|
|
|
expect { should }.to raise_error(Puppet::Error, /is not a string/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end # source =>
|
|
|
|
|
|
|
|
context 'order =>' do
|
|
|
|
['', '42', 'a', 'z'].each do |order|
|
|
|
|
context '\'\'' do
|
|
|
|
it_behaves_like 'fragment', 'motd_header', {
|
|
|
|
:order => order,
|
|
|
|
:target => '/etc/motd',
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'false' do
|
|
|
|
let(:title) { 'motd_header' }
|
2013-10-24 17:48:37 +02:00
|
|
|
let(:facts) {{ :concat_basedir => '/tmp' }}
|
2013-10-23 16:41:38 +02:00
|
|
|
let(:params) {{ :order => false, :target => '/etc/motd' }}
|
|
|
|
|
|
|
|
it 'should fail' do
|
|
|
|
expect { should }.to raise_error(Puppet::Error, /is not a string/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end # order =>
|
|
|
|
|
|
|
|
context 'mode =>' do
|
|
|
|
context '1755' do
|
|
|
|
it_behaves_like 'fragment', 'motd_header', {
|
|
|
|
:mode => '1755',
|
|
|
|
:target => '/etc/motd',
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'false' do
|
|
|
|
let(:title) { 'motd_header' }
|
2013-10-24 17:48:37 +02:00
|
|
|
let(:facts) {{ :concat_basedir => '/tmp' }}
|
2013-10-23 16:41:38 +02:00
|
|
|
let(:params) {{ :mode => false, :target => '/etc/motd' }}
|
|
|
|
|
|
|
|
it 'should fail' do
|
|
|
|
expect { should }.to raise_error(Puppet::Error, /is not a string/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end # mode =>
|
|
|
|
|
|
|
|
context 'owner =>' do
|
|
|
|
context 'apenny' do
|
|
|
|
it_behaves_like 'fragment', 'motd_header', {
|
|
|
|
:owner => 'apenny',
|
|
|
|
:target => '/etc/motd',
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'false' do
|
|
|
|
let(:title) { 'motd_header' }
|
2013-10-24 17:48:37 +02:00
|
|
|
let(:facts) {{ :concat_basedir => '/tmp' }}
|
2013-10-23 16:41:38 +02:00
|
|
|
let(:params) {{ :owner => false, :target => '/etc/motd' }}
|
|
|
|
|
|
|
|
it 'should fail' do
|
|
|
|
expect { should }.to raise_error(Puppet::Error, /is not a string/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end # owner =>
|
|
|
|
|
|
|
|
context 'group =>' do
|
|
|
|
context 'apenny' do
|
|
|
|
it_behaves_like 'fragment', 'motd_header', {
|
|
|
|
:group => 'apenny',
|
|
|
|
:target => '/etc/motd',
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'false' do
|
|
|
|
let(:title) { 'motd_header' }
|
2013-10-24 17:48:37 +02:00
|
|
|
let(:facts) {{ :concat_basedir => '/tmp' }}
|
2013-10-23 16:41:38 +02:00
|
|
|
let(:params) {{ :group => false, :target => '/etc/motd' }}
|
|
|
|
|
|
|
|
it 'should fail' do
|
|
|
|
expect { should }.to raise_error(Puppet::Error, /is not a string/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end # group =>
|
|
|
|
|
2013-10-29 23:39:54 +01:00
|
|
|
# should raise a warning but rspec-puppet can't presently test for warning()
|
|
|
|
# we can only test for the existence of the parameter
|
|
|
|
context 'backup =>' do
|
|
|
|
context 'foo' do
|
|
|
|
it_behaves_like 'fragment', 'motd_header', {
|
|
|
|
:backup => 'foo',
|
|
|
|
:target => '/etc/motd',
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end # backup =>
|
|
|
|
|
2013-10-15 23:07:51 +02:00
|
|
|
end
|