Fixing up tests

This commit is contained in:
Morgan Haskel 2014-09-10 19:06:17 -04:00
parent 5f17a26256
commit f81ef495e3
6 changed files with 138 additions and 63 deletions

View file

@ -3,18 +3,24 @@ require 'spec_helper_acceptance'
describe 'concat backup parameter' do
basedir = default.tmpdir('concat')
context '=> puppet' do
before(:all) do
pp = <<-EOS
file { '#{basedir}':
ensure => directory,
}
file { '#{basedir}/file':
content => "old contents\n",
}
EOS
apply_manifest(pp)
end
pp = <<-EOS
file { '#{basedir}/file':
content => "old contents\n",
}
concat { '#{basedir}/file':
backup => 'puppet',
require => File['#{basedir}/file'],
backup => 'puppet',
}
concat::fragment { 'new file':
target => '#{basedir}/file',
content => 'new contents',
require => File['#{basedir}/file'],
}
EOS
@ -32,18 +38,24 @@ describe 'concat backup parameter' do
end
context '=> .backup' do
before(:all) do
pp = <<-EOS
file { '#{basedir}':
ensure => directory,
}
file { '#{basedir}/file':
content => "old contents\n",
}
EOS
apply_manifest(pp)
end
pp = <<-EOS
file { '#{basedir}/file':
content => "old contents\n",
}
concat { '#{basedir}/file':
backup => '.backup',
require => File['#{basedir}/file'],
backup => '.backup',
}
concat::fragment { 'new file':
target => '#{basedir}/file',
content => 'new contents',
require => File['#{basedir}/file'],
}
EOS
@ -67,18 +79,24 @@ describe 'concat backup parameter' do
# 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
pp = <<-EOS
file { '#{basedir}':
ensure => directory,
}
file { '#{basedir}/file':
content => "old contents\n",
}
EOS
apply_manifest(pp)
end
pp = <<-EOS
file { '#{basedir}/file':
content => "old contents\n",
}
concat { '#{basedir}/file':
backup => '.backup',
require => File['#{basedir}/file'],
}
concat::fragment { 'new file':
target => '#{basedir}/file',
content => 'new contents',
require => File['#{basedir}/file'],
}
EOS

View file

@ -17,6 +17,7 @@ end
describe 'basic concat test' do
basedir = default.tmpdir('concat')
safe_basedir = basedir.gsub('/','_')
shared_examples 'successfully_applied' do |pp|
it 'applies the manifest twice with no stderr' do
@ -32,7 +33,7 @@ describe 'basic concat test' do
should be_mode 755
}
end
describe file("#{default['puppetvardir']}/concat/bin") do
describe file("#{default['puppetvardir']}/concat/bin") do
it { should be_directory }
it { should be_owned_by username }
it { should be_grouped_into groupname }
@ -48,7 +49,7 @@ describe 'basic concat test' do
should be_mode 755
}
end
describe file("#{default['puppetvardir']}/concat/_tmp_concat_file") do
describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file") do
it { should be_directory }
it { should be_owned_by username }
it { should be_grouped_into groupname }
@ -56,7 +57,7 @@ describe 'basic concat test' do
should be_mode 750
}
end
describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments") do
describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments") do
it { should be_directory }
it { should be_owned_by username }
it { should be_grouped_into groupname }
@ -64,7 +65,7 @@ describe 'basic concat test' do
should be_mode 750
}
end
describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments.concat") do
describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments.concat") do
it { should be_file }
it { should be_owned_by username }
it { should be_grouped_into groupname }
@ -72,7 +73,7 @@ describe 'basic concat test' do
should be_mode 640
}
end
describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments.concat.out") do
describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments.concat.out") do
it { should be_file }
it { should be_owned_by username }
it { should be_grouped_into groupname }
@ -83,6 +84,14 @@ describe 'basic concat test' do
end
context 'owner/group root' do
before(:all) do
pp = <<-EOS
file { '#{basedir}':
ensure => directory,
}
EOS
apply_manifest(pp)
end
pp = <<-EOS
concat { '#{basedir}/file':
owner => '#{username}',
@ -105,7 +114,7 @@ describe 'basic concat test' do
it_behaves_like 'successfully_applied', pp
describe file('#{basedir}/file') do
describe file("#{basedir}/file") do
it { should be_file }
it { should be_owned_by username }
it { should be_grouped_into groupname }
@ -115,7 +124,7 @@ describe 'basic concat test' do
it { should contain '1' }
it { should contain '2' }
end
describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments/01_1") do
describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments/01_1") do
it { should be_file }
it { should be_owned_by username }
it { should be_grouped_into groupname }
@ -123,7 +132,7 @@ describe 'basic concat test' do
should be_mode 640
}
end
describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments/02_2") do
describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments/02_2") do
it { should be_file }
it { should be_owned_by username }
it { should be_grouped_into groupname }
@ -135,6 +144,14 @@ describe 'basic concat test' do
context 'ensure' do
context 'works when set to present with path set' do
before(:all) do
pp = <<-EOS
file { '#{basedir}':
ensure => directory,
}
EOS
apply_manifest(pp)
end
pp="
concat { 'file':
ensure => present,
@ -150,7 +167,7 @@ describe 'basic concat test' do
it_behaves_like 'successfully_applied', pp
describe file('#{basedir}/file') do
describe file("#{basedir}/file") do
it { should be_file }
it("should be mode", :unless => (fact('osfamily') == 'AIX')) {
should be_mode 644
@ -159,6 +176,14 @@ describe 'basic concat test' do
end
end
context 'works when set to absent with path set' do
before(:all) do
pp = <<-EOS
file { '#{basedir}':
ensure => directory,
}
EOS
apply_manifest(pp)
end
pp="
concat { 'file':
ensure => absent,
@ -177,7 +202,7 @@ describe 'basic concat test' do
apply_manifest(pp, :catch_changes => true)
end
describe file('#{basedir}/file') do
describe file("#{basedir}/file") do
it { should_not be_file }
end
end

View file

@ -4,7 +4,6 @@ describe 'concat force empty parameter' do
basedir = default.tmpdir('concat')
context 'should run successfully' do
pp = <<-EOS
include concat::setup
concat { '#{basedir}/file':
mode => '0644',
force => true,

View file

@ -3,8 +3,16 @@ require 'spec_helper_acceptance'
describe 'concat ensure_newline parameter' do
basedir = default.tmpdir('concat')
context '=> false' do
before(:all) do
pp = <<-EOS
file { '#{basedir}':
ensure => directory
}
EOS
apply_manifest(pp)
end
pp = <<-EOS
include concat::setup
concat { '#{basedir}/file':
ensure_newline => false,
}
@ -49,7 +57,7 @@ describe 'concat ensure_newline parameter' do
apply_manifest(pp, :catch_changes => true)
end
describe file('#{basedir}/file') do
describe file("#{basedir}/file") do
it { should be_file }
it { should contain "1\n2\n" }
end

View file

@ -5,7 +5,6 @@ describe 'concat order' do
context '=> alpha' do
pp = <<-EOS
include concat::setup
concat { '#{basedir}/foo':
order => 'alpha'
}

View file

@ -4,25 +4,30 @@ describe 'replacement of' do
basedir = default.tmpdir('concat')
context 'file' do
context 'should not succeed' do
before(:all) do
pp = <<-EOS
file { '#{basedir}':
ensure => directory,
}
file { '#{basedir}/file':
content => "file exists\n"
}
EOS
apply_manifest(pp)
end
pp = <<-EOS
file { '#{basedir}/file':
content => "file exists\n"
}
concat { '#{basedir}/file':
replace => false,
require => File['#{basedir}/file'],
}
concat::fragment { '1':
target => '#{basedir}/file',
content => '1',
require => File['#{basedir}/file'],
}
concat::fragment { '2':
target => '#{basedir}/file',
content => '2',
require => File['#{basedir}/file'],
}
EOS
@ -40,25 +45,30 @@ describe 'replacement of' do
end
context 'should succeed' do
before(:all) do
pp = <<-EOS
file { '#{basedir}':
ensure => directory,
}
file { '#{basedir}/file':
content => "file exists\n"
}
EOS
apply_manifest(pp)
end
pp = <<-EOS
file { '#{basedir}/file':
content => "file exists\n"
}
concat { '#{basedir}/file':
replace => true,
require => File['#{basedir}/file'],
}
concat::fragment { '1':
target => '#{basedir}/file',
content => '1',
require => File['#{basedir}/file'],
}
concat::fragment { '2':
target => '#{basedir}/file',
content => '2',
require => File['#{basedir}/file'],
}
EOS
@ -81,30 +91,32 @@ describe 'replacement of' 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
pp = <<-EOS
file { '#{basedir}':
ensure => directory,
}
file { '#{basedir}/file':
ensure => link,
target => '#{basedir}/dangling',
}
EOS
apply_manifest(pp)
end
pp = <<-EOS
file { '#{basedir}/file':
content => "file exists\n"
}
file { '{basedir}/dangling':
ensure => link,
target => File['#{basedir}/file'],
}
concat { '#{basedir}/file':
replace => false,
require => File['{basedir}/dangling'],
}
concat::fragment { '1':
target => '#{basedir}/file',
content => '1',
require => File['{basedir}/dangling'],
}
concat::fragment { '2':
target => '#{basedir}/file',
content => '2',
require => File['{basedir}/dangling'],
}
EOS
@ -129,29 +141,32 @@ describe 'replacement of' 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
pp = <<-EOS
file { '#{basedir}':
ensure => directory,
}
file { '#{basedir}/file':
ensure => link,
target => '#{basedir}/dangling',
}
EOS
apply_manifest(pp)
end
pp = <<-EOS
file { '#{basedir}/file':
content => "file exists\n"
}
file { '{basedir}/dangling':
ensure => link,
target => File['#{basedir}/file'],
}
concat { '#{basedir}/file':
replace => true,
require => File['{basedir}/dangling'],
}
concat::fragment { '1':
target => '#{basedir}/file',
content => '1',
require => File['{basedir}/dangling'],
}
concat::fragment { '2':
target => '#{basedir}/file',
content => '2',
require => File['{basedir}/dangling'],
}
EOS
@ -170,6 +185,17 @@ describe 'replacement of' do
context 'directory' do
context 'should not succeed' do
before(:all) do
pp = <<-EOS
file { '#{basedir}':
ensure => directory,
}
file { '#{basedir}/file':
ensure => directory,
}
EOS
apply_manifest(pp)
end
pp = <<-EOS
concat { '#{basedir}/file': }