Added modules

This commit is contained in:
Ciaby 2014-07-11 13:30:23 -05:00
parent c53c931217
commit 59ec520742
646 changed files with 35182 additions and 0 deletions

View file

@ -0,0 +1,101 @@
require 'spec_helper_acceptance'
describe 'concat backup parameter' do
context '=> puppet' do
before :all do
shell('rm -rf /tmp/concat')
shell('mkdir -p /tmp/concat')
shell("/bin/echo 'old contents' > /tmp/concat/file")
end
pp = <<-EOS
concat { '/tmp/concat/file':
backup => 'puppet',
}
concat::fragment { 'new file':
target => '/tmp/concat/file',
content => 'new contents',
}
EOS
it 'applies the manifest twice with "Filebucketed" stdout and no stderr' do
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stderr).to eq("")
expect(r.stdout).to match(/Filebucketed \/tmp\/concat\/file to puppet with sum 0140c31db86293a1a1e080ce9b91305f/) # sum is for file contents of 'old contents'
end
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/file') do
it { should be_file }
it { should contain 'new contents' }
end
end
context '=> .backup' do
before :all do
shell('rm -rf /tmp/concat')
shell('mkdir -p /tmp/concat')
shell("/bin/echo 'old contents' > /tmp/concat/file")
end
pp = <<-EOS
concat { '/tmp/concat/file':
backup => '.backup',
}
concat::fragment { 'new file':
target => '/tmp/concat/file',
content => 'new contents',
}
EOS
# XXX Puppet doesn't mention anything about filebucketing with a given
# extension like .backup
it 'applies the manifest twice no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/file') do
it { should be_file }
it { should contain 'new contents' }
end
describe file('/tmp/concat/file.backup') do
it { should be_file }
it { should contain 'old contents' }
end
end
# XXX The backup parameter uses validate_string() and thus can't be the
# boolean false value, but the string 'false' has the same effect in Puppet 3
context "=> 'false'" do
before :all do
shell('rm -rf /tmp/concat')
shell('mkdir -p /tmp/concat')
shell("/bin/echo 'old contents' > /tmp/concat/file")
end
pp = <<-EOS
concat { '/tmp/concat/file':
backup => '.backup',
}
concat::fragment { 'new file':
target => '/tmp/concat/file',
content => 'new contents',
}
EOS
it 'applies the manifest twice with no "Filebucketed" stdout and no stderr' do
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stderr).to eq("")
expect(r.stdout).to_not match(/Filebucketed/)
end
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/file') do
it { should be_file }
it { should contain 'new contents' }
end
end
end

View file

@ -0,0 +1,204 @@
require 'spec_helper_acceptance'
describe 'basic concat test' do
shared_examples 'successfully_applied' do |pp|
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file("#{default['puppetvardir']}/concat") do
it { should be_directory }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should be_mode 755 }
end
describe file("#{default['puppetvardir']}/concat/bin") do
it { should be_directory }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should be_mode 755 }
end
describe file("#{default['puppetvardir']}/concat/bin/concatfragments.sh") do
it { should be_file }
it { should be_owned_by 'root' }
#it { should be_grouped_into 'root' }
it { should be_mode 755 }
end
describe file("#{default['puppetvardir']}/concat/_tmp_concat_file") do
it { should be_directory }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should be_mode 750 }
end
describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments") do
it { should be_directory }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should be_mode 750 }
end
describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments.concat") do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should be_mode 640 }
end
describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments.concat.out") do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should be_mode 640 }
end
end
context 'owner/group root' do
pp = <<-EOS
concat { '/tmp/concat/file':
owner => 'root',
group => 'root',
mode => '0644',
}
concat::fragment { '1':
target => '/tmp/concat/file',
content => '1',
order => '01',
}
concat::fragment { '2':
target => '/tmp/concat/file',
content => '2',
order => '02',
}
EOS
it_behaves_like 'successfully_applied', pp
describe file('/tmp/concat/file') do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should be_mode 644 }
it { should contain '1' }
it { should contain '2' }
end
describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments/01_1") do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should be_mode 640 }
end
describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments/02_2") do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should be_mode 640 }
end
end
context 'owner/group non-root' do
before(:all) do
shell "groupadd -g 64444 bob"
shell "useradd -u 42 -g 64444 bob"
end
after(:all) do
shell "userdel bob"
end
pp="
concat { '/tmp/concat/file':
owner => 'bob',
group => 'bob',
mode => '0644',
}
concat::fragment { '1':
target => '/tmp/concat/file',
content => '1',
order => '01',
}
concat::fragment { '2':
target => '/tmp/concat/file',
content => '2',
order => '02',
}
"
it_behaves_like 'successfully_applied', pp
describe file('/tmp/concat/file') do
it { should be_file }
it { should be_owned_by 'bob' }
it { should be_grouped_into 'bob' }
it { should be_mode 644 }
it { should contain '1' }
it { should contain '2' }
end
describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments/01_1") do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should be_mode 640 }
it { should contain '1' }
end
describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments/02_2") do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should be_mode 640 }
it { should contain '2' }
end
end
context 'ensure' do
context 'works when set to present with path set' do
pp="
concat { 'file':
ensure => present,
path => '/tmp/concat/file',
mode => '0644',
}
concat::fragment { '1':
target => 'file',
content => '1',
order => '01',
}
"
it_behaves_like 'successfully_applied', pp
describe file('/tmp/concat/file') do
it { should be_file }
it { should be_mode 644 }
it { should contain '1' }
end
end
context 'works when set to absent with path set' do
pp="
concat { 'file':
ensure => absent,
path => '/tmp/concat/file',
mode => '0644',
}
concat::fragment { '1':
target => 'file',
content => '1',
order => '01',
}
"
# Can't used shared examples as this will always trigger the exec when
# absent is set.
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
end
describe file('/tmp/concat/file') do
it { should_not be_file }
end
end
end
end

View file

@ -0,0 +1,230 @@
require 'spec_helper_acceptance'
describe 'deprecation warnings' do
shared_examples 'has_warning'do |pp, w|
it 'applies the manifest twice with a stderr regex' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to match(/#{Regexp.escape(w)}/m)
expect(apply_manifest(pp, :catch_changes => true).stderr).to match(/#{Regexp.escape(w)}/m)
end
end
context 'concat gnu parameter' do
pp = <<-EOS
concat { '/tmp/concat/file':
gnu => 'foo',
}
concat::fragment { 'foo':
target => '/tmp/concat/file',
content => 'bar',
}
EOS
w = 'The $gnu parameter to concat is deprecated and has no effect'
it_behaves_like 'has_warning', pp, w
end
context 'concat warn parameter =>' do
['true', 'yes', 'on'].each do |warn|
context warn do
pp = <<-EOS
concat { '/tmp/concat/file':
warn => '#{warn}',
}
concat::fragment { 'foo':
target => '/tmp/concat/file',
content => 'bar',
}
EOS
w = 'Using stringified boolean values (\'true\', \'yes\', \'on\', \'false\', \'no\', \'off\') to represent boolean true/false as the $warn parameter to concat is deprecated and will be treated as the warning message in a future release'
it_behaves_like 'has_warning', pp, w
describe file('/tmp/concat/file') do
it { should be_file }
it { should contain '# This file is managed by Puppet. DO NOT EDIT.' }
it { should contain 'bar' }
end
end
end
['false', 'no', 'off'].each do |warn|
context warn do
pp = <<-EOS
concat { '/tmp/concat/file':
warn => '#{warn}',
}
concat::fragment { 'foo':
target => '/tmp/concat/file',
content => 'bar',
}
EOS
w = 'Using stringified boolean values (\'true\', \'yes\', \'on\', \'false\', \'no\', \'off\') to represent boolean true/false as the $warn parameter to concat is deprecated and will be treated as the warning message in a future release'
it_behaves_like 'has_warning', pp, w
describe file('/tmp/concat/file') do
it { should be_file }
it { should_not contain '# This file is managed by Puppet. DO NOT EDIT.' }
it { should contain 'bar' }
end
end
end
end
context 'concat::fragment ensure parameter' do
context 'target file exists' do
before(:all) do
shell("/bin/echo 'file1 contents' > /tmp/concat/file1")
end
after(:all) do
# XXX this test may leave behind a symlink in the fragment directory
# which could cause warnings and/or breakage from the subsequent tests
# unless we clean it up.
shell('rm -rf /tmp/concat /var/lib/puppet/concat')
shell('mkdir -p /tmp/concat')
end
pp = <<-EOS
concat { '/tmp/concat/file': }
concat::fragment { 'foo':
target => '/tmp/concat/file',
ensure => '/tmp/concat/file1',
}
EOS
w = 'Passing a value other than \'present\' or \'absent\' as the $ensure parameter to concat::fragment is deprecated. If you want to use the content of a file as a fragment please use the $source parameter.'
it_behaves_like 'has_warning', pp, w
describe file('/tmp/concat/file') do
it { should be_file }
it { should contain 'file1 contents' }
end
describe 'the fragment can be changed from a symlink to a plain file' do
pp = <<-EOS
concat { '/tmp/concat/file': }
concat::fragment { 'foo':
target => '/tmp/concat/file',
content => 'new content',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/file') do
it { should be_file }
it { should contain 'new content' }
it { should_not contain 'file1 contents' }
end
end
end # target file exists
context 'target does not exist' do
pp = <<-EOS
concat { '/tmp/concat/file': }
concat::fragment { 'foo':
target => '/tmp/concat/file',
ensure => '/tmp/concat/file1',
}
EOS
w = 'Passing a value other than \'present\' or \'absent\' as the $ensure parameter to concat::fragment is deprecated. If you want to use the content of a file as a fragment please use the $source parameter.'
it_behaves_like 'has_warning', pp, w
describe file('/tmp/concat/file') do
it { should be_file }
end
describe 'the fragment can be changed from a symlink to a plain file' do
pp = <<-EOS
concat { '/tmp/concat/file': }
concat::fragment { 'foo':
target => '/tmp/concat/file',
content => 'new content',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/file') do
it { should be_file }
it { should contain 'new content' }
end
end
end # target file exists
end # concat::fragment ensure parameter
context 'concat::fragment mode parameter' do
pp = <<-EOS
concat { '/tmp/concat/file': }
concat::fragment { 'foo':
target => '/tmp/concat/file',
content => 'bar',
mode => 'bar',
}
EOS
w = 'The $mode parameter to concat::fragment is deprecated and has no effect'
it_behaves_like 'has_warning', pp, w
end
context 'concat::fragment owner parameter' do
pp = <<-EOS
concat { '/tmp/concat/file': }
concat::fragment { 'foo':
target => '/tmp/concat/file',
content => 'bar',
owner => 'bar',
}
EOS
w = 'The $owner parameter to concat::fragment is deprecated and has no effect'
it_behaves_like 'has_warning', pp, w
end
context 'concat::fragment group parameter' do
pp = <<-EOS
concat { '/tmp/concat/file': }
concat::fragment { 'foo':
target => '/tmp/concat/file',
content => 'bar',
group => 'bar',
}
EOS
w = 'The $group parameter to concat::fragment is deprecated and has no effect'
it_behaves_like 'has_warning', pp, w
end
context 'concat::fragment backup parameter' do
pp = <<-EOS
concat { '/tmp/concat/file': }
concat::fragment { 'foo':
target => '/tmp/concat/file',
content => 'bar',
backup => 'bar',
}
EOS
w = 'The $backup parameter to concat::fragment is deprecated and has no effect'
it_behaves_like 'has_warning', pp, w
end
context 'include concat::setup' do
pp = <<-EOS
include concat::setup
EOS
w = 'concat::setup is deprecated as a public API of the concat module and should no longer be directly included in the manifest.'
it_behaves_like 'has_warning', pp, w
end
end

View file

@ -0,0 +1,24 @@
require 'spec_helper_acceptance'
describe 'concat force empty parameter' do
context 'should run successfully' do
pp = <<-EOS
concat { '/tmp/concat/file':
owner => root,
group => root,
mode => '0644',
force => true,
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/file') do
it { should be_file }
it { should_not contain '1\n2' }
end
end
end

View file

@ -0,0 +1,134 @@
require 'spec_helper_acceptance'
describe 'concat::fragment source' do
context 'should read file fragments from local system' do
before(:all) do
shell("/bin/echo 'file1 contents' > /tmp/concat/file1")
shell("/bin/echo 'file2 contents' > /tmp/concat/file2")
end
pp = <<-EOS
concat { '/tmp/concat/foo': }
concat::fragment { '1':
target => '/tmp/concat/foo',
source => '/tmp/concat/file1',
}
concat::fragment { '2':
target => '/tmp/concat/foo',
content => 'string1 contents',
}
concat::fragment { '3':
target => '/tmp/concat/foo',
source => '/tmp/concat/file2',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/foo') do
it { should be_file }
it { should contain 'file1 contents' }
it { should contain 'string1 contents' }
it { should contain 'file2 contents' }
end
end # should read file fragments from local system
context 'should create files containing first match only.' do
before(:all) do
shell('rm -rf /tmp/concat /var/lib/puppet/concat')
shell('mkdir -p /tmp/concat')
shell("/bin/echo 'file1 contents' > /tmp/concat/file1")
shell("/bin/echo 'file2 contents' > /tmp/concat/file2")
end
pp = <<-EOS
concat { '/tmp/concat/result_file1':
owner => root,
group => root,
mode => '0644',
}
concat { '/tmp/concat/result_file2':
owner => root,
group => root,
mode => '0644',
}
concat { '/tmp/concat/result_file3':
owner => root,
group => root,
mode => '0644',
}
concat::fragment { '1':
target => '/tmp/concat/result_file1',
source => [ '/tmp/concat/file1', '/tmp/concat/file2' ],
order => '01',
}
concat::fragment { '2':
target => '/tmp/concat/result_file2',
source => [ '/tmp/concat/file2', '/tmp/concat/file1' ],
order => '01',
}
concat::fragment { '3':
target => '/tmp/concat/result_file3',
source => [ '/tmp/concat/file1', '/tmp/concat/file2' ],
order => '01',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/result_file1') do
it { should be_file }
it { should contain 'file1 contents' }
it { should_not contain 'file2 contents' }
end
describe file('/tmp/concat/result_file2') do
it { should be_file }
it { should contain 'file2 contents' }
it { should_not contain 'file1 contents' }
end
describe file('/tmp/concat/result_file3') do
it { should be_file }
it { should contain 'file1 contents' }
it { should_not contain 'file2 contents' }
end
end
context 'should fail if no match on source.' do
before(:all) do
shell('rm -rf /tmp/concat /var/lib/puppet/concat')
shell('mkdir -p /tmp/concat')
shell('/bin/rm -rf /tmp/concat/fail_no_source /tmp/concat/nofilehere /tmp/concat/nothereeither')
end
pp = <<-EOS
concat { '/tmp/concat/fail_no_source':
owner => root,
group => root,
mode => '0644',
}
concat::fragment { '1':
target => '/tmp/concat/fail_no_source',
source => [ '/tmp/concat/nofilehere', '/tmp/concat/nothereeither' ],
order => '01',
}
EOS
it 'applies the manifest with resource failures' do
apply_manifest(pp, :expect_failures => true)
end
describe file('/tmp/concat/fail_no_source') do
#FIXME: Serverspec::Type::File doesn't support exists? for some reason. so... hack.
it { should_not be_file }
it { should_not be_directory }
end
end
end

View file

@ -0,0 +1,57 @@
require 'spec_helper_acceptance'
describe 'concat ensure_newline parameter' do
context '=> false' do
pp = <<-EOS
concat { '/tmp/concat/file':
ensure_newline => false,
}
concat::fragment { '1':
target => '/tmp/concat/file',
content => '1',
}
concat::fragment { '2':
target => '/tmp/concat/file',
content => '2',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/file') do
it { should be_file }
it { should contain '12' }
end
end
context '=> true' do
pp = <<-EOS
concat { '/tmp/concat/file':
ensure_newline => true,
}
concat::fragment { '1':
target => '/tmp/concat/file',
content => '1',
}
concat::fragment { '2':
target => '/tmp/concat/file',
content => '2',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
#XXX ensure_newline => true causes changes on every run because the files
#are modified in place.
end
describe file('/tmp/concat/file') do
it { should be_file }
it { should contain "1\n2\n" }
end
end
end

View file

@ -0,0 +1,19 @@
HOSTS:
pe-aix-71-acceptance:
roles:
- master
- dashboard
- database
- agent
- default
platform: aix-7.1-power
hypervisor: aix
ip: pe-aix-71-acceptance.delivery.puppetlabs.net
CONFIG:
type: pe
nfs_server: NONE
consoleport: 443
datastore: instance0
folder: Delivery/Quality Assurance/Enterprise/Dynamic
resourcepool: delivery/Quality Assurance/Enterprise/Dynamic
pooling_api: http://vcloud.delivery.puppetlabs.net/

View file

@ -0,0 +1,10 @@
HOSTS:
centos-59-x64:
roles:
- master
platform: el-5-x86_64
box : centos-59-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-59-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: git

View file

@ -0,0 +1,12 @@
HOSTS:
centos-64-x64:
roles:
- master
- database
- dashboard
platform: el-6-x86_64
box : centos-64-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: pe

View file

@ -0,0 +1,10 @@
HOSTS:
centos-64-x64:
roles:
- master
platform: el-6-x86_64
box : centos-64-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: foss

View file

@ -0,0 +1,10 @@
HOSTS:
debian-607-x64:
roles:
- master
platform: debian-6-amd64
box : debian-607-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-607-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: git

View file

@ -0,0 +1,10 @@
HOSTS:
debian-70rc1-x64:
roles:
- master
platform: debian-7-amd64
box : debian-70rc1-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-70rc1-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: git

View file

@ -0,0 +1,11 @@
HOSTS:
debian-73-x64.localhost:
roles:
- master
platform: debian-7-amd64
box : debian-73-x64-virtualbox-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-73-x64-virtualbox-nocm.box
hypervisor : vagrant
CONFIG:
log_level: debug
type: foss

View file

@ -0,0 +1,10 @@
HOSTS:
centos-64-x64.localdomain:
roles:
- master
platform: el-6-x86_64
box : centos-65-x64-virtualbox-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box
hypervisor : vagrant
CONFIG:
type: foss

View file

@ -0,0 +1,10 @@
HOSTS:
fedora-18-x64:
roles:
- master
platform: fedora-18-x86_64
box : fedora-18-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/fedora-18-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: foss

View file

@ -0,0 +1,15 @@
HOSTS:
'redhat-7-vcloud':
roles:
- master
platform: el-7-x86_64
hypervisor: vcloud
template: redhat-7-x86_64
CONFIG:
type: foss
ssh:
keys: "~/.ssh/id_rsa-acceptance"
datastore: instance0
folder: Delivery/Quality Assurance/Enterprise/Dynamic
resourcepool: delivery/Quality Assurance/Enterprise/Dynamic
pooling_api: http://vcloud.delivery.puppetlabs.net/

View file

@ -0,0 +1,10 @@
HOSTS:
sles-11-x64.local:
roles:
- master
platform: sles-11-x64
box : sles-11sp1-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/sles-11sp1-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: foss

View file

@ -0,0 +1,10 @@
HOSTS:
sles-11sp1-x64:
roles:
- master
platform: sles-11-x86_64
box : sles-11sp1-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/sles-11sp1-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: git

View file

@ -0,0 +1,10 @@
HOSTS:
ubuntu-server-10044-x64:
roles:
- master
platform: ubuntu-10.04-amd64
box : ubuntu-server-10044-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-10044-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: foss

View file

@ -0,0 +1,10 @@
HOSTS:
ubuntu-server-12042-x64:
roles:
- master
platform: ubuntu-12.04-amd64
box : ubuntu-server-12042-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: foss

View file

@ -0,0 +1,11 @@
HOSTS:
ubuntu-server-1404-x64:
roles:
- master
platform: ubuntu-14.04-amd64
box : puppetlabs/ubuntu-14.04-64-nocm
box_url : https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-nocm
hypervisor : vagrant
CONFIG:
log_level : debug
type: git

View file

@ -0,0 +1,137 @@
require 'spec_helper_acceptance'
describe 'concat order' do
before(:all) do
shell('rm -rf /tmp/concat /var/lib/puppet/concat')
shell('mkdir -p /tmp/concat')
end
context '=> alpha' do
pp = <<-EOS
concat { '/tmp/concat/foo':
order => 'alpha'
}
concat::fragment { '1':
target => '/tmp/concat/foo',
content => 'string1',
}
concat::fragment { '2':
target => '/tmp/concat/foo',
content => 'string2',
}
concat::fragment { '10':
target => '/tmp/concat/foo',
content => 'string10',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/foo') do
it { should be_file }
it { should contain "string10\nstring1\nsring2" }
end
end
context '=> numeric' do
pp = <<-EOS
concat { '/tmp/concat/foo':
order => 'numeric'
}
concat::fragment { '1':
target => '/tmp/concat/foo',
content => 'string1',
}
concat::fragment { '2':
target => '/tmp/concat/foo',
content => 'string2',
}
concat::fragment { '10':
target => '/tmp/concat/foo',
content => 'string10',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/foo') do
it { should be_file }
it { should contain "string1\nstring2\nsring10" }
end
end
end # concat order
describe 'concat::fragment order' do
before(:all) do
shell('rm -rf /tmp/concat /var/lib/puppet/concat')
shell('mkdir -p /tmp/concat')
end
context '=> reverse order' do
pp = <<-EOS
concat { '/tmp/concat/foo': }
concat::fragment { '1':
target => '/tmp/concat/foo',
content => 'string1',
order => '15',
}
concat::fragment { '2':
target => '/tmp/concat/foo',
content => 'string2',
# default order 10
}
concat::fragment { '3':
target => '/tmp/concat/foo',
content => 'string3',
order => '1',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/foo') do
it { should be_file }
it { should contain "string3\nstring2\nsring1" }
end
end
context '=> normal order' do
pp = <<-EOS
concat { '/tmp/concat/foo': }
concat::fragment { '1':
target => '/tmp/concat/foo',
content => 'string1',
order => '01',
}
concat::fragment { '2':
target => '/tmp/concat/foo',
content => 'string2',
order => '02'
}
concat::fragment { '3':
target => '/tmp/concat/foo',
content => 'string3',
order => '03',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/foo') do
it { should be_file }
it { should contain "string1\nstring2\nsring3" }
end
end
end # concat::fragment order

View file

@ -0,0 +1,33 @@
require 'spec_helper_acceptance'
describe 'quoted paths' do
before(:all) do
shell('rm -rf "/tmp/concat test" /var/lib/puppet/concat')
shell('mkdir -p "/tmp/concat test"')
end
context 'path with blanks' do
pp = <<-EOS
concat { '/tmp/concat test/foo':
}
concat::fragment { '1':
target => '/tmp/concat test/foo',
content => 'string1',
}
concat::fragment { '2':
target => '/tmp/concat test/foo',
content => 'string2',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat test/foo') do
it { should be_file }
it { should contain "string1\nsring2" }
end
end
end

View file

@ -0,0 +1,241 @@
require 'spec_helper_acceptance'
describe 'replacement of' do
context 'file' do
context 'should not succeed' do
before(:all) do
shell('mkdir -p /tmp/concat')
shell('echo "file exists" > /tmp/concat/file')
end
after(:all) do
shell('rm -rf /tmp/concat /var/lib/puppet/concat')
end
pp = <<-EOS
concat { '/tmp/concat/file':
replace => false,
}
concat::fragment { '1':
target => '/tmp/concat/file',
content => '1',
}
concat::fragment { '2':
target => '/tmp/concat/file',
content => '2',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/file') do
it { should be_file }
it { should contain 'file exists' }
it { should_not contain '1' }
it { should_not contain '2' }
end
end
context 'should succeed' do
before(:all) do
shell('mkdir -p /tmp/concat')
shell('echo "file exists" > /tmp/concat/file')
end
after(:all) do
shell('rm -rf /tmp/concat /var/lib/puppet/concat')
end
pp = <<-EOS
concat { '/tmp/concat/file':
replace => true,
}
concat::fragment { '1':
target => '/tmp/concat/file',
content => '1',
}
concat::fragment { '2':
target => '/tmp/concat/file',
content => '2',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/file') do
it { should be_file }
it { should_not contain 'file exists' }
it { should contain '1' }
it { should contain '2' }
end
end
end # file
context 'symlink' do
context 'should not succeed' do
# XXX the core puppet file type will replace a symlink with a plain file
# when using ensure => present and source => ... but it will not when using
# ensure => present and content => ...; this is somewhat confusing behavior
before(:all) do
shell('mkdir -p /tmp/concat')
shell('ln -s /tmp/concat/dangling /tmp/concat/file')
end
after(:all) do
shell('rm -rf /tmp/concat /var/lib/puppet/concat')
end
pp = <<-EOS
concat { '/tmp/concat/file':
replace => false,
}
concat::fragment { '1':
target => '/tmp/concat/file',
content => '1',
}
concat::fragment { '2':
target => '/tmp/concat/file',
content => '2',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/file') do
it { should be_linked_to '/tmp/concat/dangling' }
end
describe file('/tmp/concat/dangling') do
# XXX serverspec does not have a matcher for 'exists'
it { should_not be_file }
it { should_not be_directory }
end
end
context 'should succeed' do
# XXX the core puppet file type will replace a symlink with a plain file
# when using ensure => present and source => ... but it will not when using
# ensure => present and content => ...; this is somewhat confusing behavior
before(:all) do
shell('mkdir -p /tmp/concat')
shell('ln -s /tmp/concat/dangling /tmp/concat/file')
end
after(:all) do
shell('rm -rf /tmp/concat /var/lib/puppet/concat')
end
pp = <<-EOS
concat { '/tmp/concat/file':
replace => true,
}
concat::fragment { '1':
target => '/tmp/concat/file',
content => '1',
}
concat::fragment { '2':
target => '/tmp/concat/file',
content => '2',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/file') do
it { should be_file }
it { should contain '1' }
it { should contain '2' }
end
end
end # symlink
context 'directory' do
context 'should not succeed' do
before(:all) do
shell('mkdir -p /tmp/concat/file')
end
after(:all) do
shell('rm -rf /tmp/concat /var/lib/puppet/concat')
end
pp = <<-EOS
concat { '/tmp/concat/file': }
concat::fragment { '1':
target => '/tmp/concat/file',
content => '1',
}
concat::fragment { '2':
target => '/tmp/concat/file',
content => '2',
}
EOS
it 'applies the manifest twice with stderr for changing to file' do
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/change from directory to file failed/)
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/change from directory to file failed/)
end
describe file('/tmp/concat/file') do
it { should be_directory }
end
end
# XXX concat's force param currently enables the creation of empty files
# when there are no fragments, and the replace param will only replace
# files and symlinks, not directories. The semantics either need to be
# changed, extended, or a new param introduced to control directory
# replacement.
context 'should succeed', :pending => 'not yet implemented' do
before(:all) do
shell('mkdir -p /tmp/concat/file')
end
after(:all) do
shell('rm -rf /tmp/concat /var/lib/puppet/concat')
end
pp = <<-EOS
concat { '/tmp/concat/file':
force => true,
}
concat::fragment { '1':
target => '/tmp/concat/file',
content => '1',
}
concat::fragment { '2':
target => '/tmp/concat/file',
content => '2',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/file') do
it { should be_file }
it { should contain '1' }
end
end
end # directory
end

View file

@ -0,0 +1,32 @@
require 'spec_helper_acceptance'
describe 'symbolic name' do
pp = <<-EOS
concat { 'not_abs_path':
path => '/tmp/concat/file',
}
concat::fragment { '1':
target => 'not_abs_path',
content => '1',
order => '01',
}
concat::fragment { '2':
target => 'not_abs_path',
content => '2',
order => '02',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/file') do
it { should be_file }
it { should contain '1' }
it { should contain '2' }
end
end

View file

@ -0,0 +1,97 @@
require 'spec_helper_acceptance'
describe 'concat warn =>' do
context 'true should enable default warning message' do
pp = <<-EOS
concat { '/tmp/concat/file':
warn => true,
}
concat::fragment { '1':
target => '/tmp/concat/file',
content => '1',
order => '01',
}
concat::fragment { '2':
target => '/tmp/concat/file',
content => '2',
order => '02',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/file') do
it { should be_file }
it { should contain '# This file is managed by Puppet. DO NOT EDIT.' }
it { should contain '1' }
it { should contain '2' }
end
end
context 'false should not enable default warning message' do
pp = <<-EOS
concat { '/tmp/concat/file':
warn => false,
}
concat::fragment { '1':
target => '/tmp/concat/file',
content => '1',
order => '01',
}
concat::fragment { '2':
target => '/tmp/concat/file',
content => '2',
order => '02',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/file') do
it { should be_file }
it { should_not contain '# This file is managed by Puppet. DO NOT EDIT.' }
it { should contain '1' }
it { should contain '2' }
end
end
context '# foo should overide default warning message' do
pp = <<-EOS
concat { '/tmp/concat/file':
warn => '# foo',
}
concat::fragment { '1':
target => '/tmp/concat/file',
content => '1',
order => '01',
}
concat::fragment { '2':
target => '/tmp/concat/file',
content => '2',
order => '02',
}
EOS
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
end
describe file('/tmp/concat/file') do
it { should be_file }
it { should contain '# foo' }
it { should contain '1' }
it { should contain '2' }
end
end
end

View file

@ -0,0 +1 @@
require 'puppetlabs_spec_helper/module_spec_helper'

View file

@ -0,0 +1,39 @@
require 'beaker-rspec/spec_helper'
require 'beaker-rspec/helpers/serverspec'
unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no'
if hosts.first.is_pe?
install_pe
else
install_puppet
end
hosts.each do |host|
on hosts, "mkdir -p #{host['distmoduledir']}"
end
end
RSpec.configure do |c|
# Project root
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
# Readable test descriptions
c.formatter = :documentation
# Configure all nodes in nodeset
c.before :suite do
# Install module and dependencies
puppet_module_install(:source => proj_root, :module_name => 'concat')
hosts.each do |host|
on host, puppet('module','install','puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] }
end
end
c.before(:all) do
shell('mkdir -p /tmp/concat')
end
c.after(:all) do
shell('rm -rf /tmp/concat /var/lib/puppet/concat')
end
c.treat_symbols_as_metadata_keys_with_true_values = true
end

View file

@ -0,0 +1,42 @@
require 'spec_helper'
describe 'concat::setup', :type => :class do
shared_examples 'setup' do |concatdir|
concatdir = '/foo' if concatdir.nil?
let(:facts) {{ :concat_basedir => concatdir }}
it do
should contain_file("#{concatdir}/bin/concatfragments.sh").with({
:mode => '0755',
:source => 'puppet:///modules/concat/concatfragments.sh',
:backup => false,
})
end
[concatdir, "#{concatdir}/bin"].each do |file|
it do
should contain_file(file).with({
:ensure => 'directory',
:mode => '0755',
:backup => false,
})
end
end
end
context 'facts' do
context 'concat_basedir =>' do
context '/foo' do
it_behaves_like 'setup', '/foo'
end
end
end # facts
context 'deprecated as a public class' do
it 'should create a warning' do
pending('rspec-puppet support for testing warning()')
end
end
end

View file

@ -0,0 +1,267 @@
require 'spec_helper'
describe 'concat::fragment', :type => :define do
shared_examples 'fragment' do |title, params|
params = {} if params.nil?
p = {
:content => nil,
:source => nil,
:order => 10,
:ensure => 'present',
}.merge(params)
safe_name = title.gsub(/[\/\n]/, '_')
safe_target_name = p[:target].gsub(/[\/\n]/, '_')
concatdir = '/var/lib/puppet/concat'
fragdir = "#{concatdir}/#{safe_target_name}"
id = 'root'
if p[:ensure] == 'absent'
safe_ensure = p[:ensure]
else
safe_ensure = 'file'
end
let(:title) { title }
let(:facts) {{ :concat_basedir => concatdir, :id => id }}
let(:params) { params }
let(:pre_condition) do
"concat{ '#{p[:target]}': }"
end
it do
should contain_class('concat::setup')
should contain_concat(p[:target])
should contain_file("#{fragdir}/fragments/#{p[:order]}_#{safe_name}").with({
:ensure => safe_ensure,
:owner => id,
:mode => '0640',
:source => p[:source],
:content => p[:content],
:alias => "concat_fragment_#{title}",
:backup => false,
})
end
end
context 'title' do
['0', '1', 'a', 'z'].each do |title|
it_behaves_like 'fragment', title, {
:target => '/etc/motd',
}
end
end # title
context 'target =>' do
['./etc/motd', 'etc/motd', 'motd_header'].each do |target|
context target do
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 }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a string/)
end
end
end # target =>
context 'ensure =>' do
['present', 'absent'].each do |ens|
context ens do
it_behaves_like 'fragment', 'motd_header', {
:ensure => ens,
:target => '/etc/motd',
}
end
end
context 'any value other than \'present\' or \'absent\'' do
let(:title) { 'motd_header' }
let(:facts) {{ :concat_basedir => '/tmp' }}
let(:params) {{ :ensure => 'invalid', :target => '/etc/motd' }}
it 'should create a warning' do
pending('rspec-puppet support for testing warning()')
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' }
let(:facts) {{ :concat_basedir => '/tmp' }}
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', ['/foo/bar', '/foo/baz']].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' }
let(:facts) {{ :concat_basedir => '/tmp' }}
let(:params) {{ :source => false, :target => '/etc/motd' }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a string or an Array/)
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' }
let(:facts) {{ :concat_basedir => '/tmp' }}
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 'more than one content source' do
error_msg = 'You cannot specify more than one of $content, $source, $ensure => /target'
context 'ensure => target and source' do
let(:title) { 'motd_header' }
let(:facts) {{ :concat_basedir => '/tmp' }}
let(:params) do
{
:target => '/etc/motd',
:ensure => '/foo',
:source => '/bar',
}
end
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m)
end
end
context 'ensure => target and content' do
let(:title) { 'motd_header' }
let(:facts) {{ :concat_basedir => '/tmp' }}
let(:params) do
{
:target => '/etc/motd',
:ensure => '/foo',
:content => 'bar',
}
end
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m)
end
end
context 'source and content' do
let(:title) { 'motd_header' }
let(:facts) {{ :concat_basedir => '/tmp' }}
let(:params) do
{
:target => '/etc/motd',
:source => '/foo',
:content => 'bar',
}
end
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m)
end
end
end # more than one content source
describe 'deprecated parameter' do
context 'mode =>' do
context '1755' do
it_behaves_like 'fragment', 'motd_header', {
:mode => '1755',
:target => '/etc/motd',
}
it 'should create a warning' do
pending('rspec-puppet support for testing warning()')
end
end
end # mode =>
context 'owner =>' do
context 'apenny' do
it_behaves_like 'fragment', 'motd_header', {
:owner => 'apenny',
:target => '/etc/motd',
}
it 'should create a warning' do
pending('rspec-puppet support for testing warning()')
end
end
end # owner =>
context 'group =>' do
context 'apenny' do
it_behaves_like 'fragment', 'motd_header', {
:group => 'apenny',
:target => '/etc/motd',
}
it 'should create a warning' do
pending('rspec-puppet support for testing warning()')
end
end
end # group =>
context 'backup =>' do
context 'foo' do
it_behaves_like 'fragment', 'motd_header', {
:backup => 'foo',
:target => '/etc/motd',
}
it 'should create a warning' do
pending('rspec-puppet support for testing warning()')
end
end
end # backup =>
end # deprecated params
end

View file

@ -0,0 +1,380 @@
require 'spec_helper'
describe 'concat', :type => :define do
shared_examples 'concat' do |title, params, id|
params = {} if params.nil?
id = 'root' if id.nil?
# default param values
p = {
:ensure => 'present',
:path => title,
:owner => nil,
:group => nil,
:mode => '0644',
:warn => false,
:force => false,
:backup => 'puppet',
:replace => true,
:order => 'alpha',
:ensure_newline => false,
}.merge(params)
safe_name = title.gsub('/', '_')
concatdir = '/var/lib/puppet/concat'
fragdir = "#{concatdir}/#{safe_name}"
concat_name = 'fragments.concat.out'
default_warn_message = '# This file is managed by Puppet. DO NOT EDIT.'
file_defaults = {
:backup => false,
}
let(:title) { title }
let(:params) { params }
let(:facts) {{ :concat_basedir => concatdir, :id => id }}
if p[:ensure] == 'present'
it do
should contain_file(fragdir).with(file_defaults.merge({
:ensure => 'directory',
:mode => '0750',
}))
end
it do
should contain_file("#{fragdir}/fragments").with(file_defaults.merge({
:ensure => 'directory',
:mode => '0750',
:force => true,
:ignore => ['.svn', '.git', '.gitignore'],
:purge => true,
:recurse => true,
}))
end
[
"#{fragdir}/fragments.concat",
"#{fragdir}/#{concat_name}",
].each do |file|
it do
should contain_file(file).with(file_defaults.merge({
:ensure => 'present',
:mode => '0640',
}))
end
end
it do
should contain_file(title).with(file_defaults.merge({
:ensure => 'present',
:owner => p[:owner],
:group => p[:group],
:mode => p[:mode],
:replace => p[:replace],
:path => p[:path],
:alias => "concat_#{title}",
:source => "#{fragdir}/#{concat_name}",
:backup => p[:backup],
}))
end
cmd = "#{concatdir}/bin/concatfragments.sh " +
"-o \"#{concatdir}/#{safe_name}/fragments.concat.out\" " +
"-d \"#{concatdir}/#{safe_name}\""
# flag order: fragdir, warnflag, forceflag, orderflag, newlineflag
if p.has_key?(:warn)
case p[:warn]
when TrueClass
message = default_warn_message
when 'true', 'yes', 'on'
# should generate a stringified boolean warning
message = default_warn_message
when FalseClass
message = nil
when 'false', 'no', 'off'
# should generate a stringified boolean warning
message = nil
else
message = p[:warn]
end
unless message.nil?
cmd += " -w \'#{message}\'"
end
end
cmd += " -f" if p[:force]
cmd += " -n" if p[:order] == 'numeric'
cmd += " -l" if p[:ensure_newline] == true
it do
should contain_exec("concat_#{title}").with({
:alias => "concat_#{fragdir}",
:command => cmd,
:unless => "#{cmd} -t",
})
end
else
[
fragdir,
"#{fragdir}/fragments",
"#{fragdir}/fragments.concat",
"#{fragdir}/#{concat_name}",
].each do |file|
it do
should contain_file(file).with(file_defaults.merge({
:ensure => 'absent',
:backup => false,
:force => true,
}))
end
end
it do
should contain_file(title).with(file_defaults.merge({
:ensure => 'absent',
:backup => p[:backup],
}))
end
it do
should contain_exec("concat_#{title}").with({
:alias => "concat_#{fragdir}",
:command => 'true',
:path => '/bin:/usr/bin',
})
end
end
end
context 'title' do
context 'without path param' do
# title/name is the default value for the path param. therefore, the
# title must be an absolute path unless path is specified
['/foo', '/foo/bar', '/foo/bar/baz'].each do |title|
context title do
it_behaves_like 'concat', '/etc/foo.bar'
end
end
['./foo', 'foo', 'foo/bar'].each do |title|
context title do
let(:title) { title }
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not an absolute path/)
end
end
end
end
context 'with path param' do
['./foo', 'foo', 'foo/bar'].each do |title|
context title do
it_behaves_like 'concat', title, { :path => '/etc/foo.bar' }
end
end
end
end # title =>
context 'as non-root user' do
it_behaves_like 'concat', '/etc/foo.bar', {}, 'bob'
end
context 'ensure =>' do
['present', 'absent'].each do |ens|
context ens do
it_behaves_like 'concat', '/etc/foo.bar', { :ensure => ens }
end
end
context 'invalid' do
let(:title) { '/etc/foo.bar' }
let(:params) {{ :ensure => 'invalid' }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^present$|^absent$"')}/)
end
end
end # ensure =>
context 'path =>' do
context '/foo' do
it_behaves_like 'concat', '/etc/foo.bar', { :path => '/foo' }
end
['./foo', 'foo', 'foo/bar', false].each do |path|
context path do
let(:title) { '/etc/foo.bar' }
let(:params) {{ :path => path }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not an absolute path/)
end
end
end
end # path =>
context 'owner =>' do
context 'apenney' do
it_behaves_like 'concat', '/etc/foo.bar', { :owner => 'apenny' }
end
context 'false' do
let(:title) { '/etc/foo.bar' }
let(:params) {{ :owner => false }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a string/)
end
end
end # owner =>
context 'group =>' do
context 'apenney' do
it_behaves_like 'concat', '/etc/foo.bar', { :group => 'apenny' }
end
context 'false' do
let(:title) { '/etc/foo.bar' }
let(:params) {{ :group => false }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a string/)
end
end
end # group =>
context 'mode =>' do
context '1755' do
it_behaves_like 'concat', '/etc/foo.bar', { :mode => '1755' }
end
context 'false' do
let(:title) { '/etc/foo.bar' }
let(:params) {{ :mode => false }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a string/)
end
end
end # mode =>
context 'warn =>' do
[true, false, '# foo'].each do |warn|
context warn do
it_behaves_like 'concat', '/etc/foo.bar', { :warn => warn }
end
end
context '(stringified boolean)' do
['true', 'yes', 'on', 'false', 'no', 'off'].each do |warn|
context warn do
it_behaves_like 'concat', '/etc/foo.bar', { :warn => warn }
it 'should create a warning' do
pending('rspec-puppet support for testing warning()')
end
end
end
end
context '123' do
let(:title) { '/etc/foo.bar' }
let(:params) {{ :warn => 123 }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a string or boolean/)
end
end
end # warn =>
context 'force =>' do
[true, false].each do |force|
context force do
it_behaves_like 'concat', '/etc/foo.bar', { :force => force }
end
end
context '123' do
let(:title) { '/etc/foo.bar' }
let(:params) {{ :force => 123 }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a boolean/)
end
end
end # force =>
context 'backup =>' do
context 'reverse' do
it_behaves_like 'concat', '/etc/foo.bar', { :backup => 'reverse' }
end
context 'false' do
let(:title) { '/etc/foo.bar' }
let(:params) {{ :backup => false }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a string/)
end
end
end # backup =>
context 'replace =>' do
[true, false].each do |replace|
context replace do
it_behaves_like 'concat', '/etc/foo.bar', { :replace => replace }
end
end
context '123' do
let(:title) { '/etc/foo.bar' }
let(:params) {{ :replace => 123 }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a boolean/)
end
end
end # replace =>
context 'order =>' do
['alpha', 'numeric'].each do |order|
context order do
it_behaves_like 'concat', '/etc/foo.bar', { :order => order }
end
end
context 'invalid' do
let(:title) { '/etc/foo.bar' }
let(:params) {{ :order => 'invalid' }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^alpha$|^numeric$"')}/)
end
end
end # order =>
context 'ensure_newline =>' do
[true, false].each do |ensure_newline|
context 'true' do
it_behaves_like 'concat', '/etc/foo.bar', { :ensure_newline => ensure_newline}
end
end
context '123' do
let(:title) { '/etc/foo.bar' }
let(:params) {{ :ensure_newline => 123 }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a boolean/)
end
end
end # ensure_newline =>
describe 'deprecated parameter' do
context 'gnu =>' do
context 'foo' do
it_behaves_like 'concat', '/etc/foo.bar', { :gnu => 'foo'}
it 'should create a warning' do
pending('rspec-puppet support for testing warning()')
end
end
end
end
end
# vim:sw=2:ts=2:expandtab:textwidth=79

View file

@ -0,0 +1,18 @@
require 'spec_helper'
describe 'concat_basedir', :type => :fact do
before(:each) { Facter.clear }
context 'Puppet[:vardir] ==' do
it '/var/lib/puppet' do
Puppet.stubs(:[]).with(:vardir).returns('/var/lib/puppet')
Facter.fact(:concat_basedir).value.should == '/var/lib/puppet/concat'
end
it '/home/apenny/.puppet/var' do
Puppet.stubs(:[]).with(:vardir).returns('/home/apenny/.puppet/var')
Facter.fact(:concat_basedir).value.should == '/home/apenny/.puppet/var/concat'
end
end
end