Merge pull request #229 from mhaskel/test

merge 1.1.x into master
This commit is contained in:
Colleen Murphy 2014-09-12 12:00:44 -07:00
commit fdbeb1bae4
7 changed files with 140 additions and 98 deletions

View file

@ -2,22 +2,36 @@ require 'spec_helper_acceptance'
case fact('osfamily')
when 'AIX'
username = 'root'
groupname = 'system'
username = 'root'
groupname = 'system'
scriptname = 'concatfragments.sh'
vardir = default['puppetvardir']
when 'Darwin'
username = 'root'
groupname = 'wheel'
username = 'root'
groupname = 'wheel'
scriptname = 'concatfragments.sh'
vardir = default['puppetvardir']
when 'windows'
username = 'Administrator'
groupname = 'Administrators'
username = 'Administrator'
groupname = 'Administrators'
scriptname = 'concatfragments.rb'
result = on default, "echo #{default['puppetvardir']}"
vardir = result.raw_output.chomp
when 'Solaris'
username = 'root'
groupname = 'root'
scriptname = 'concatfragments.rb'
vardir = default['puppetvardir']
else
username = 'root'
groupname = 'root'
username = 'root'
groupname = 'root'
scriptname = 'concatfragments.sh'
vardir = default['puppetvardir']
end
describe 'basic concat test' do
basedir = default.tmpdir('concat')
safe_basedir = basedir.gsub('/','_')
safe_basedir = basedir.gsub(/[\/:]/,'_')
shared_examples 'successfully_applied' do |pp|
it 'applies the manifest twice with no stderr' do
@ -25,58 +39,51 @@ describe 'basic concat test' do
apply_manifest(pp, :catch_changes => true)
end
describe file("#{default['puppetvardir']}/concat") do
describe file("#{vardir}/concat") do
it { should be_directory }
it { should be_owned_by username }
it { should be_grouped_into groupname }
it("should be mode", :unless => (fact('osfamily') == 'AIX')) {
should be_mode 755
}
end
describe file("#{default['puppetvardir']}/concat/bin") do
describe file("#{vardir}/concat/bin") do
it { should be_directory }
it { should be_owned_by username }
it { should be_grouped_into groupname }
it("should be mode", :unless => (fact('osfamily') == 'AIX')) {
should be_mode 755
}
end
describe file("#{default['puppetvardir']}/concat/bin/concatfragments.sh") do
describe file("#{vardir}/concat/bin/#{scriptname}") do
it { should be_file }
it { should be_owned_by username }
#it { should be_grouped_into groupname }
it("should be mode", :unless => (fact('osfamily') == 'AIX')) {
should be_mode 755
}
end
describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file") do
describe file("#{vardir}/concat/#{safe_basedir}_file") do
it { should be_directory }
it { should be_owned_by username }
it { should be_grouped_into groupname }
it("should be mode", :unless => (fact('osfamily') == 'AIX')) {
should be_mode 750
}
end
describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments") do
describe file("#{vardir}/concat/#{safe_basedir}_file/fragments") do
it { should be_directory }
it { should be_owned_by username }
it { should be_grouped_into groupname }
it("should be mode", :unless => (fact('osfamily') == 'AIX')) {
should be_mode 750
}
end
describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments.concat") do
describe file("#{vardir}/concat/#{safe_basedir}_file/fragments.concat") do
it { should be_file }
it { should be_owned_by username }
it { should be_grouped_into groupname }
it("should be mode", :unless => (fact('osfamily') == 'AIX')) {
should be_mode 640
}
end
describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments.concat.out") do
describe file("#{vardir}/concat/#{safe_basedir}_file/fragments.concat.out") do
it { should be_file }
it { should be_owned_by username }
it { should be_grouped_into groupname }
it("should be mode", :unless => (fact('osfamily') == 'AIX')) {
should be_mode 640
}
@ -124,18 +131,16 @@ describe 'basic concat test' do
it { should contain '1' }
it { should contain '2' }
end
describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments/01_1") do
describe file("#{vardir}/concat/#{safe_basedir}_file/fragments/01_1") do
it { should be_file }
it { should be_owned_by username }
it { should be_grouped_into groupname }
it("should be mode", :unless => (fact('osfamily') == 'AIX')) {
should be_mode 640
}
end
describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments/02_2") do
describe file("#{vardir}/concat/#{safe_basedir}_file/fragments/02_2") do
it { should be_file }
it { should be_owned_by username }
it { should be_grouped_into groupname }
it("should be mode", :unless => (fact('osfamily') == 'AIX')) {
should be_mode 640
}

View file

@ -1,6 +1,7 @@
require 'spec_helper_acceptance'
describe 'deprecation warnings' do
basedir = default.tmpdir('concat')
shared_examples 'has_warning'do |pp, w|
it 'applies the manifest twice with a stderr regex' do
@ -11,11 +12,11 @@ describe 'deprecation warnings' do
context 'concat gnu parameter' do
pp = <<-EOS
concat { '/tmp/concat/file':
concat { '#{basedir}/file':
gnu => 'foo',
}
concat::fragment { 'foo':
target => '/tmp/concat/file',
target => '#{basedir}/file',
content => 'bar',
}
EOS
@ -28,11 +29,11 @@ describe 'deprecation warnings' do
['true', 'yes', 'on'].each do |warn|
context warn do
pp = <<-EOS
concat { '/tmp/concat/file':
concat { '#{basedir}/file':
warn => '#{warn}',
}
concat::fragment { 'foo':
target => '/tmp/concat/file',
target => '#{basedir}/file',
content => 'bar',
}
EOS
@ -40,7 +41,7 @@ describe 'deprecation warnings' do
it_behaves_like 'has_warning', pp, w
describe file('/tmp/concat/file') do
describe file("#{basedir}/file") do
it { should be_file }
it { should contain '# This file is managed by Puppet. DO NOT EDIT.' }
it { should contain 'bar' }
@ -51,11 +52,11 @@ describe 'deprecation warnings' do
['false', 'no', 'off'].each do |warn|
context warn do
pp = <<-EOS
concat { '/tmp/concat/file':
concat { '#{basedir}/file':
warn => '#{warn}',
}
concat::fragment { 'foo':
target => '/tmp/concat/file',
target => '#{basedir}/file',
content => 'bar',
}
EOS
@ -63,7 +64,7 @@ describe 'deprecation warnings' do
it_behaves_like 'has_warning', pp, w
describe file('/tmp/concat/file') do
describe file("#{basedir}/file") do
it { should be_file }
it { should_not contain '# This file is managed by Puppet. DO NOT EDIT.' }
it { should contain 'bar' }
@ -75,37 +76,39 @@ describe 'deprecation warnings' do
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')
shell("/bin/echo 'file1 contents' > #{basedir}/file1")
pp = <<-EOS
file { '#{basedir}':
ensure => directory,
}
file { '#{basedir}/file1':
content => "file1 contents\n",
}
EOS
apply_manifest(pp)
end
pp = <<-EOS
concat { '/tmp/concat/file': }
concat { '#{basedir}/file': }
concat::fragment { 'foo':
target => '/tmp/concat/file',
ensure => '/tmp/concat/file1',
target => '#{basedir}/file',
ensure => '#{basedir}/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
describe file("#{basedir}/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
describe 'the fragment can be changed from a symlink to a plain file', :unless => (fact("osfamily") == "windows") do
pp = <<-EOS
concat { '/tmp/concat/file': }
concat { '#{basedir}/file': }
concat::fragment { 'foo':
target => '/tmp/concat/file',
target => '#{basedir}/file',
content => 'new content',
}
EOS
@ -115,7 +118,7 @@ describe 'deprecation warnings' do
apply_manifest(pp, :catch_changes => true)
end
describe file('/tmp/concat/file') do
describe file("#{basedir}/file") do
it { should be_file }
it { should contain 'new content' }
it { should_not contain 'file1 contents' }
@ -125,25 +128,25 @@ describe 'deprecation warnings' do
context 'target does not exist' do
pp = <<-EOS
concat { '/tmp/concat/file': }
concat { '#{basedir}/file': }
concat::fragment { 'foo':
target => '/tmp/concat/file',
ensure => '/tmp/concat/file1',
target => '#{basedir}/file',
ensure => '#{basedir}/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
describe file("#{basedir}/file") do
it { should be_file }
end
describe 'the fragment can be changed from a symlink to a plain file' do
describe 'the fragment can be changed from a symlink to a plain file', :unless => (fact('osfamily') == 'windows') do
pp = <<-EOS
concat { '/tmp/concat/file': }
concat { '#{basedir}/file': }
concat::fragment { 'foo':
target => '/tmp/concat/file',
target => '#{basedir}/file',
content => 'new content',
}
EOS
@ -153,7 +156,7 @@ describe 'deprecation warnings' do
apply_manifest(pp, :catch_changes => true)
end
describe file('/tmp/concat/file') do
describe file("#{basedir}/file") do
it { should be_file }
it { should contain 'new content' }
end
@ -164,9 +167,9 @@ describe 'deprecation warnings' do
context 'concat::fragment mode parameter' do
pp = <<-EOS
concat { '/tmp/concat/file': }
concat { '#{basedir}/file': }
concat::fragment { 'foo':
target => '/tmp/concat/file',
target => '#{basedir}/file',
content => 'bar',
mode => 'bar',
}
@ -178,9 +181,9 @@ describe 'deprecation warnings' do
context 'concat::fragment owner parameter' do
pp = <<-EOS
concat { '/tmp/concat/file': }
concat { '#{basedir}/file': }
concat::fragment { 'foo':
target => '/tmp/concat/file',
target => '#{basedir}/file',
content => 'bar',
owner => 'bar',
}
@ -192,9 +195,9 @@ describe 'deprecation warnings' do
context 'concat::fragment group parameter' do
pp = <<-EOS
concat { '/tmp/concat/file': }
concat { '#{basedir}/file': }
concat::fragment { 'foo':
target => '/tmp/concat/file',
target => '#{basedir}/file',
content => 'bar',
group => 'bar',
}
@ -206,9 +209,9 @@ describe 'deprecation warnings' do
context 'concat::fragment backup parameter' do
pp = <<-EOS
concat { '/tmp/concat/file': }
concat { '#{basedir}/file': }
concat::fragment { 'foo':
target => '/tmp/concat/file',
target => '#{basedir}/file',
content => 'bar',
backup => 'bar',
}

View file

@ -1,25 +1,31 @@
require 'spec_helper_acceptance'
describe 'concat::fragment replace' do
basedir = default.tmpdir('concat')
context 'should create fragment files' do
before(:all) do
shell('rm -rf /tmp/concat /var/lib/puppet/concat')
shell('mkdir /tmp/concat')
pp = <<-EOS
file { '#{basedir}':
ensure => directory,
}
EOS
apply_manifest(pp)
end
pp1 = <<-EOS
concat { '/tmp/concat/foo': }
concat { '#{basedir}/foo': }
concat::fragment { '1':
target => '/tmp/concat/foo',
target => '#{basedir}/foo',
content => 'caller has replace unset run 1',
}
EOS
pp2 = <<-EOS
concat { '/tmp/concat/foo': }
concat { '#{basedir}/foo': }
concat::fragment { '1':
target => '/tmp/concat/foo',
target => '#{basedir}/foo',
content => 'caller has replace unset run 2',
}
EOS
@ -31,7 +37,7 @@ describe 'concat::fragment replace' do
apply_manifest(pp2, :catch_changes => true)
end
describe file('/tmp/concat/foo') do
describe file("#{basedir}/foo") do
it { should be_file }
it { should_not contain 'caller has replace unset run 1' }
it { should contain 'caller has replace unset run 2' }
@ -40,25 +46,29 @@ describe 'concat::fragment replace' do
context 'should replace its own fragment files when caller has File { replace=>true } set' do
before(:all) do
shell('rm -rf /tmp/concat /var/lib/puppet/concat')
shell('mkdir /tmp/concat')
pp = <<-EOS
file { '#{basedir}':
ensure => directory,
}
EOS
apply_manifest(pp)
end
pp1 = <<-EOS
File { replace=>true }
concat { '/tmp/concat/foo': }
concat { '#{basedir}/foo': }
concat::fragment { '1':
target => '/tmp/concat/foo',
target => '#{basedir}/foo',
content => 'caller has replace true set run 1',
}
EOS
pp2 = <<-EOS
File { replace=>true }
concat { '/tmp/concat/foo': }
concat { '#{basedir}/foo': }
concat::fragment { '1':
target => '/tmp/concat/foo',
target => '#{basedir}/foo',
content => 'caller has replace true set run 2',
}
EOS
@ -70,7 +80,7 @@ describe 'concat::fragment replace' do
apply_manifest(pp2, :catch_changes => true)
end
describe file('/tmp/concat/foo') do
describe file("#{basedir}/foo") do
it { should be_file }
it { should_not contain 'caller has replace true set run 1' }
it { should contain 'caller has replace true set run 2' }
@ -79,25 +89,29 @@ describe 'concat::fragment replace' do
context 'should replace its own fragment files even when caller has File { replace=>false } set' do
before(:all) do
shell('rm -rf /tmp/concat /var/lib/puppet/concat')
shell('mkdir /tmp/concat')
pp = <<-EOS
file { '#{basedir}':
ensure => directory,
}
EOS
apply_manifest(pp)
end
pp1 = <<-EOS
File { replace=>false }
concat { '/tmp/concat/foo': }
concat { '#{basedir}/foo': }
concat::fragment { '1':
target => '/tmp/concat/foo',
target => '#{basedir}/foo',
content => 'caller has replace false set run 1',
}
EOS
pp2 = <<-EOS
File { replace=>false }
concat { '/tmp/concat/foo': }
concat { '#{basedir}/foo': }
concat::fragment { '1':
target => '/tmp/concat/foo',
target => '#{basedir}/foo',
content => 'caller has replace false set run 2',
}
EOS
@ -109,7 +123,7 @@ describe 'concat::fragment replace' do
apply_manifest(pp2, :catch_changes => true)
end
describe file('/tmp/concat/foo') do
describe file("#{basedir}/foo") do
it { should be_file }
it { should_not contain 'caller has replace false set run 1' }
it { should contain 'caller has replace false set run 2' }

View file

@ -59,7 +59,9 @@ describe 'concat ensure_newline parameter' do
describe file("#{basedir}/file") do
it { should be_file }
it { should contain "1\n2\n" }
it("should contain 1\n2\n", :unless => (fact('osfamily') == 'Solaris')) {
should contain "1\n2\n"
}
end
end
end

View file

@ -1,21 +1,30 @@
require 'spec_helper_acceptance'
describe 'quoted paths' do
basedir = default.tmpdir('concat')
before(:all) do
shell('rm -rf "/tmp/concat test" /var/lib/puppet/concat')
shell('mkdir -p "/tmp/concat test"')
pp = <<-EOS
file { '#{basedir}':
ensure => directory,
}
file { '#{basedir}/concat test':
ensure => directory,
}
EOS
apply_manifest(pp)
end
context 'path with blanks' do
pp = <<-EOS
concat { '/tmp/concat test/foo':
concat { '#{basedir}/concat test/foo':
}
concat::fragment { '1':
target => '/tmp/concat test/foo',
target => '#{basedir}/concat test/foo',
content => 'string1',
}
concat::fragment { '2':
target => '/tmp/concat test/foo',
target => '#{basedir}/concat test/foo',
content => 'string2',
}
EOS
@ -25,9 +34,11 @@ describe 'quoted paths' do
apply_manifest(pp, :catch_changes => true)
end
describe file('/tmp/concat test/foo') do
describe file("#{basedir}/concat test/foo") do
it { should be_file }
it { should contain "string1\nsring2" }
it("should contain string1\nstring2", :unless => (fact('osfamily') == 'Solaris')) {
should contain "string1\nstring2"
}
end
end
end

View file

@ -86,7 +86,7 @@ describe 'replacement of' do
end
end # file
context 'symlink' do
context 'symlink', :unless => (fact("osfamily") == "windows") 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

View file

@ -23,8 +23,15 @@ RSpec.configure do |c|
# 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, "mkdir -p #{host['distmoduledir']}/concat"
result = on host, "echo #{host['distmoduledir']}/concat"
target = result.raw_output.chomp
%w(files lib manifests metadata.json).each do |file|
scp_to host, "#{proj_root}/#{file}", target
end
#copy_module_to(host, :source => proj_root, :module_name => 'concat')
on host, puppet('module','install','puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] }
end
end