2014-02-12 22:41:41 +01:00
|
|
|
require 'spec_helper_acceptance'
|
|
|
|
|
|
|
|
describe 'replacement of' do
|
2014-02-28 00:50:18 +01:00
|
|
|
basedir = default.tmpdir('concat')
|
2014-02-12 22:41:41 +01:00
|
|
|
context 'file' do
|
|
|
|
context 'should not succeed' do
|
|
|
|
before(:all) do
|
2014-02-27 23:52:53 +01:00
|
|
|
shell("mkdir -p #{basedir}")
|
|
|
|
shell('echo "file exists" > #{basedir}/file')
|
2014-02-12 22:41:41 +01:00
|
|
|
end
|
|
|
|
after(:all) do
|
2014-02-27 23:52:53 +01:00
|
|
|
shell("rm -rf #{basedir} #{default.puppet['vardir']}/concat")
|
2014-02-12 22:41:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
pp = <<-EOS
|
|
|
|
include concat::setup
|
2014-02-27 23:52:53 +01:00
|
|
|
concat { '#{basedir}/file':
|
2014-02-12 22:41:41 +01:00
|
|
|
replace => false,
|
|
|
|
}
|
|
|
|
|
|
|
|
concat::fragment { '1':
|
2014-02-27 23:52:53 +01:00
|
|
|
target => '#{basedir}/file',
|
2014-02-12 22:41:41 +01:00
|
|
|
content => '1',
|
|
|
|
}
|
|
|
|
|
|
|
|
concat::fragment { '2':
|
2014-02-27 23:52:53 +01:00
|
|
|
target => '#{basedir}/file',
|
2014-02-12 22:41:41 +01:00
|
|
|
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
|
|
|
|
|
2014-02-27 23:52:53 +01:00
|
|
|
describe file("#{basedir}/file") do
|
2014-02-12 22:41:41 +01:00
|
|
|
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
|
2014-02-27 23:52:53 +01:00
|
|
|
shell("mkdir -p #{basedir}")
|
|
|
|
shell("echo "file exists" > #{basedir}/file")
|
2014-02-12 22:41:41 +01:00
|
|
|
end
|
|
|
|
after(:all) do
|
2014-02-27 23:52:53 +01:00
|
|
|
shell("rm -rf #{basedir} #{default.puppet['vardir']}/concat")
|
2014-02-12 22:41:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
pp = <<-EOS
|
|
|
|
include concat::setup
|
2014-02-27 23:52:53 +01:00
|
|
|
concat { '#{basedir}/file':
|
2014-02-12 22:41:41 +01:00
|
|
|
replace => true,
|
|
|
|
}
|
|
|
|
|
|
|
|
concat::fragment { '1':
|
2014-02-27 23:52:53 +01:00
|
|
|
target => '#{basedir}/file',
|
2014-02-12 22:41:41 +01:00
|
|
|
content => '1',
|
|
|
|
}
|
|
|
|
|
|
|
|
concat::fragment { '2':
|
2014-02-27 23:52:53 +01:00
|
|
|
target => '#{basedir}/file',
|
2014-02-12 22:41:41 +01:00
|
|
|
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
|
|
|
|
|
2014-02-27 23:52:53 +01:00
|
|
|
describe file("#{basedir}/file") do
|
2014-02-12 22:41:41 +01:00
|
|
|
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
|
2014-02-27 23:52:53 +01:00
|
|
|
shell("mkdir -p #{basedir}")
|
|
|
|
shell("ln -s #{basedir}/dangling #{basedir}/file")
|
2014-02-12 22:41:41 +01:00
|
|
|
end
|
|
|
|
after(:all) do
|
2014-02-27 23:52:53 +01:00
|
|
|
shell("rm -rf #{basedir} #{default.puppet['vardir']}/concat")
|
2014-02-12 22:41:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
pp = <<-EOS
|
|
|
|
include concat::setup
|
2014-02-27 23:52:53 +01:00
|
|
|
concat { '#{basedir}/file':
|
2014-02-12 22:41:41 +01:00
|
|
|
replace => false,
|
|
|
|
}
|
|
|
|
|
|
|
|
concat::fragment { '1':
|
2014-02-27 23:52:53 +01:00
|
|
|
target => '#{basedir}/file',
|
2014-02-12 22:41:41 +01:00
|
|
|
content => '1',
|
|
|
|
}
|
|
|
|
|
|
|
|
concat::fragment { '2':
|
2014-02-27 23:52:53 +01:00
|
|
|
target => '#{basedir}/file',
|
2014-02-12 22:41:41 +01:00
|
|
|
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
|
|
|
|
|
2014-02-26 23:17:59 +01:00
|
|
|
# XXX specinfra doesn't support be_linked_to on AIX
|
2014-02-27 23:52:53 +01:00
|
|
|
describe file("#{basedir}/file"), :unless => fact("osfamily") == "AIX" do
|
|
|
|
it { should be_linked_to "#{basedir}/dangling" }
|
2014-02-12 22:41:41 +01:00
|
|
|
end
|
|
|
|
|
2014-02-27 23:52:53 +01:00
|
|
|
describe file("#{basedir}/dangling") do
|
2014-02-12 22:41:41 +01:00
|
|
|
# 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
|
2014-02-27 23:52:53 +01:00
|
|
|
shell("mkdir -p #{basedir}")
|
|
|
|
shell("ln -s #{basedir}/dangling #{basedir}/file")
|
2014-02-12 22:41:41 +01:00
|
|
|
end
|
|
|
|
after(:all) do
|
2014-02-27 23:52:53 +01:00
|
|
|
shell("rm -rf #{basedir} #{default.puppet['vardir']}/concat")
|
2014-02-12 22:41:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
pp = <<-EOS
|
|
|
|
include concat::setup
|
2014-02-27 23:52:53 +01:00
|
|
|
concat { '#{basedir}/file':
|
2014-02-12 22:41:41 +01:00
|
|
|
replace => true,
|
|
|
|
}
|
|
|
|
|
|
|
|
concat::fragment { '1':
|
2014-02-27 23:52:53 +01:00
|
|
|
target => '#{basedir}/file',
|
2014-02-12 22:41:41 +01:00
|
|
|
content => '1',
|
|
|
|
}
|
|
|
|
|
|
|
|
concat::fragment { '2':
|
2014-02-27 23:52:53 +01:00
|
|
|
target => '#{basedir}/file',
|
2014-02-12 22:41:41 +01:00
|
|
|
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
|
|
|
|
|
2014-02-27 23:52:53 +01:00
|
|
|
describe file("#{basedir}/file") do
|
2014-02-12 22:41:41 +01:00
|
|
|
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
|
2014-02-27 23:52:53 +01:00
|
|
|
shell("mkdir -p #{basedir}/file")
|
2014-02-12 22:41:41 +01:00
|
|
|
end
|
|
|
|
after(:all) do
|
2014-02-27 23:52:53 +01:00
|
|
|
shell("rm -rf #{basedir} #{default.puppet['vardir']}/concat")
|
2014-02-12 22:41:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
pp = <<-EOS
|
|
|
|
include concat::setup
|
2014-02-27 23:52:53 +01:00
|
|
|
concat { '#{basedir}/file': }
|
2014-02-12 22:41:41 +01:00
|
|
|
|
|
|
|
concat::fragment { '1':
|
2014-02-27 23:52:53 +01:00
|
|
|
target => '#{basedir}/file',
|
2014-02-12 22:41:41 +01:00
|
|
|
content => '1',
|
|
|
|
}
|
|
|
|
|
|
|
|
concat::fragment { '2':
|
2014-02-27 23:52:53 +01:00
|
|
|
target => '#{basedir}/file',
|
2014-02-12 22:41:41 +01:00
|
|
|
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
|
|
|
|
|
2014-02-27 23:52:53 +01:00
|
|
|
describe file("#{basedir}/file") do
|
2014-02-12 22:41:41 +01:00
|
|
|
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
|
2014-02-27 23:52:53 +01:00
|
|
|
shell("mkdir -p #{basedir}/file")
|
2014-02-12 22:41:41 +01:00
|
|
|
end
|
|
|
|
after(:all) do
|
2014-02-27 23:52:53 +01:00
|
|
|
shell("rm -rf #{basedir} #{default.puppet['vardir']}/concat")
|
2014-02-12 22:41:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
pp = <<-EOS
|
|
|
|
include concat::setup
|
2014-02-27 23:52:53 +01:00
|
|
|
concat { '#{basedir}/file':
|
2014-02-12 22:41:41 +01:00
|
|
|
force => true,
|
|
|
|
}
|
|
|
|
|
|
|
|
concat::fragment { '1':
|
2014-02-27 23:52:53 +01:00
|
|
|
target => '#{basedir}/file',
|
2014-02-12 22:41:41 +01:00
|
|
|
content => '1',
|
|
|
|
}
|
|
|
|
|
|
|
|
concat::fragment { '2':
|
2014-02-27 23:52:53 +01:00
|
|
|
target => '#{basedir}/file',
|
2014-02-12 22:41:41 +01:00
|
|
|
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
|
|
|
|
|
2014-02-27 23:52:53 +01:00
|
|
|
describe file("#{basedir}/file") do
|
2014-02-12 22:41:41 +01:00
|
|
|
it { should be_file }
|
|
|
|
it { should contain '1' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end # directory
|
|
|
|
end
|