123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- require 'spec_helper_acceptance'
- 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
- concat { '#{basedir}/file':
- replace => false,
- }
- concat::fragment { '1':
- target => '#{basedir}/file',
- content => '1',
- }
- concat::fragment { '2':
- target => '#{basedir}/file',
- content => '2',
- }
- EOS
- it 'applies the manifest twice with no stderr' do
- apply_manifest(pp, :catch_failures => true)
- apply_manifest(pp, :catch_changes => true)
- end
- describe file("#{basedir}/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
- pp = <<-EOS
- file { '#{basedir}':
- ensure => directory,
- }
- file { '#{basedir}/file':
- content => "file exists\n"
- }
- EOS
- apply_manifest(pp)
- end
- pp = <<-EOS
- concat { '#{basedir}/file':
- replace => true,
- }
- concat::fragment { '1':
- target => '#{basedir}/file',
- content => '1',
- }
- concat::fragment { '2':
- target => '#{basedir}/file',
- content => '2',
- }
- EOS
- it 'applies the manifest twice with no stderr' do
- apply_manifest(pp, :catch_failures => true)
- apply_manifest(pp, :catch_changes => true)
- end
- describe file("#{basedir}/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', :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
- # 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
- concat { '#{basedir}/file':
- replace => false,
- }
- concat::fragment { '1':
- target => '#{basedir}/file',
- content => '1',
- }
- concat::fragment { '2':
- target => '#{basedir}/file',
- content => '2',
- }
- EOS
- it 'applies the manifest twice with no stderr' do
- apply_manifest(pp, :catch_failures => true)
- apply_manifest(pp, :catch_changes => true)
- end
- # XXX specinfra doesn't support be_linked_to on AIX
- describe file("#{basedir}/file"), :unless => (fact("osfamily") == "AIX" or fact("osfamily") == "windows") do
- it { should be_linked_to "#{basedir}/dangling" }
- end
- describe file("#{basedir}/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
- pp = <<-EOS
- file { '#{basedir}':
- ensure => directory,
- }
- file { '#{basedir}/file':
- ensure => link,
- target => '#{basedir}/dangling',
- }
- EOS
- apply_manifest(pp)
- end
- pp = <<-EOS
- concat { '#{basedir}/file':
- replace => true,
- }
- concat::fragment { '1':
- target => '#{basedir}/file',
- content => '1',
- }
- concat::fragment { '2':
- target => '#{basedir}/file',
- content => '2',
- }
- EOS
- it 'applies the manifest twice with no stderr' do
- apply_manifest(pp, :catch_failures => true)
- apply_manifest(pp, :catch_changes => true)
- end
- describe file("#{basedir}/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
- pp = <<-EOS
- file { '#{basedir}':
- ensure => directory,
- }
- file { '#{basedir}/file':
- ensure => directory,
- }
- EOS
- apply_manifest(pp)
- end
- pp = <<-EOS
- concat { '#{basedir}/file': }
- concat::fragment { '1':
- target => '#{basedir}/file',
- content => '1',
- }
- concat::fragment { '2':
- target => '#{basedir}/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("#{basedir}/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
- pp = <<-EOS
- concat { '#{basedir}/file':
- force => true,
- }
- concat::fragment { '1':
- target => '#{basedir}/file',
- content => '1',
- }
- concat::fragment { '2':
- target => '#{basedir}/file',
- content => '2',
- }
- EOS
- it 'applies the manifest twice with no stderr' do
- apply_manifest(pp, :catch_failures => true)
- apply_manifest(pp, :catch_changes => true)
- end
- describe file("#{basedir}/file") do
- it { should be_file }
- it { should contain '1' }
- end
- end
- end # directory
- end
|