module-concat/spec/acceptance/concat_spec.rb

216 lines
6.2 KiB
Ruby
Raw Normal View History

require 'spec_helper_acceptance'
2013-08-08 17:44:31 +02:00
case fact('osfamily')
when 'AIX'
username = 'root'
groupname = 'system'
scriptname = 'concatfragments.sh'
2014-09-11 21:41:41 +02:00
vardir = default['puppetvardir']
when 'Darwin'
username = 'root'
groupname = 'wheel'
scriptname = 'concatfragments.sh'
2014-09-11 21:41:41 +02:00
vardir = default['puppetvardir']
when 'windows'
username = 'Administrator'
groupname = 'Administrators'
scriptname = 'concatfragments.rb'
2014-09-11 21:41:41 +02:00
result = on default, "echo #{default['puppetvardir']}"
vardir = result.raw_output.chomp
when 'Solaris'
username = 'root'
groupname = 'root'
scriptname = 'concatfragments.rb'
2014-09-11 21:41:41 +02:00
vardir = default['puppetvardir']
else
username = 'root'
groupname = 'root'
scriptname = 'concatfragments.sh'
2014-09-11 21:41:41 +02:00
vardir = default['puppetvardir']
end
describe 'basic concat test' do
basedir = default.tmpdir('concat')
2014-09-11 21:41:41 +02:00
safe_basedir = basedir.gsub(/[\/:]/,'_')
2013-08-08 17:44:31 +02:00
shared_examples 'successfully_applied' do |pp|
it 'applies the manifest twice with no stderr' do
2014-09-08 21:01:30 +02:00
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
2013-08-08 17:44:31 +02:00
end
2014-09-11 21:41:41 +02:00
describe file("#{vardir}/concat") do
2013-08-08 17:44:31 +02:00
it { should be_directory }
it { should be_owned_by username }
2014-10-03 21:22:37 +02:00
it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
should be_mode 755
}
end
2014-09-11 21:41:41 +02:00
describe file("#{vardir}/concat/bin") do
it { should be_directory }
it { should be_owned_by username }
2014-10-03 21:22:37 +02:00
it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
should be_mode 755
}
end
2014-09-11 21:41:41 +02:00
describe file("#{vardir}/concat/bin/#{scriptname}") do
it { should be_file }
it { should be_owned_by username }
2014-10-03 21:22:37 +02:00
it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
should be_mode 755
}
2013-08-08 17:44:31 +02:00
end
2014-09-11 21:41:41 +02:00
describe file("#{vardir}/concat/#{safe_basedir}_file") do
2013-08-08 17:44:31 +02:00
it { should be_directory }
it { should be_owned_by username }
2014-10-03 21:22:37 +02:00
it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
should be_mode 750
}
2013-08-08 17:44:31 +02:00
end
2014-09-11 21:41:41 +02:00
describe file("#{vardir}/concat/#{safe_basedir}_file/fragments") do
2013-08-08 17:44:31 +02:00
it { should be_directory }
it { should be_owned_by username }
2014-10-03 21:22:37 +02:00
it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
should be_mode 750
}
2013-08-08 17:44:31 +02:00
end
2014-09-11 21:41:41 +02:00
describe file("#{vardir}/concat/#{safe_basedir}_file/fragments.concat") do
2013-08-08 17:44:31 +02:00
it { should be_file }
it { should be_owned_by username }
2014-10-03 21:22:37 +02:00
it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
should be_mode 640
}
end
2014-09-11 21:41:41 +02:00
describe file("#{vardir}/concat/#{safe_basedir}_file/fragments.concat.out") do
it { should be_file }
it { should be_owned_by username }
2014-10-03 21:22:37 +02:00
it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
should be_mode 640
}
2013-08-08 17:44:31 +02:00
end
end
context 'owner/group root' do
2014-09-11 01:06:17 +02:00
before(:all) do
pp = <<-EOS
file { '#{basedir}':
ensure => directory,
}
EOS
apply_manifest(pp)
end
2013-11-14 04:28:27 +01:00
pp = <<-EOS
concat { '#{basedir}/file':
owner => '#{username}',
group => '#{groupname}',
mode => '0644',
}
concat::fragment { '1':
target => '#{basedir}/file',
content => '1',
order => '01',
}
concat::fragment { '2':
target => '#{basedir}/file',
content => '2',
order => '02',
}
2013-11-14 04:28:27 +01:00
EOS
it_behaves_like 'successfully_applied', pp
2014-09-11 01:06:17 +02:00
describe file("#{basedir}/file") do
it { should be_file }
it { should be_owned_by username }
it("should be group", :unless => (fact('osfamily') == 'windows')) { should be_grouped_into groupname }
2014-10-03 21:22:37 +02:00
it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
should be_mode 644
}
it { should contain '1' }
it { should contain '2' }
end
2014-09-11 21:41:41 +02:00
describe file("#{vardir}/concat/#{safe_basedir}_file/fragments/01_1") do
it { should be_file }
it { should be_owned_by username }
2014-10-03 21:22:37 +02:00
it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
should be_mode 640
}
end
2014-09-11 21:41:41 +02:00
describe file("#{vardir}/concat/#{safe_basedir}_file/fragments/02_2") do
it { should be_file }
it { should be_owned_by username }
2014-10-03 21:22:37 +02:00
it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
should be_mode 640
}
end
2013-08-08 17:44:31 +02:00
end
context 'ensure' do
context 'works when set to present with path set' do
2014-09-11 01:06:17 +02:00
before(:all) do
pp = <<-EOS
file { '#{basedir}':
ensure => directory,
}
EOS
apply_manifest(pp)
end
pp="
concat { 'file':
ensure => present,
path => '#{basedir}/file',
mode => '0644',
}
concat::fragment { '1':
target => 'file',
content => '1',
order => '01',
}
"
it_behaves_like 'successfully_applied', pp
2014-09-11 01:06:17 +02:00
describe file("#{basedir}/file") do
it { should be_file }
2014-10-03 21:22:37 +02:00
it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
should be_mode 644
}
it { should contain '1' }
end
end
context 'works when set to absent with path set' do
2014-09-11 01:06:17 +02:00
before(:all) do
pp = <<-EOS
file { '#{basedir}':
ensure => directory,
}
EOS
apply_manifest(pp)
end
pp="
concat { 'file':
ensure => absent,
path => '#{basedir}/file',
mode => '0644',
}
concat::fragment { '1':
target => 'file',
content => '1',
order => '01',
}
"
it 'applies the manifest twice with no stderr' do
2014-09-08 21:01:30 +02:00
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
2014-09-11 01:06:17 +02:00
describe file("#{basedir}/file") do
it { should_not be_file }
end
end
end
2013-08-08 17:44:31 +02:00
end