2014-01-22 02:52:37 +01:00
|
|
|
require 'spec_helper_acceptance'
|
|
|
|
|
2014-02-27 23:57:12 +01:00
|
|
|
tmpdir = default.tmpdir('tmp')
|
|
|
|
|
2014-01-22 02:52:37 +01:00
|
|
|
describe 'ini_setting resource' do
|
|
|
|
after :all do
|
2015-02-09 20:50:05 +01:00
|
|
|
shell("rm #{tmpdir}/*.ini", :acceptable_exit_codes => [0, 1, 2])
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
|
2015-02-09 20:50:05 +01:00
|
|
|
shared_examples 'has_content' do |path, pp, content|
|
2014-01-22 02:52:37 +01:00
|
|
|
before :all do
|
2015-02-09 20:50:05 +01:00
|
|
|
shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
after :all do
|
2015-02-09 20:50:05 +01:00
|
|
|
shell("cat #{path}", :acceptable_exit_codes => [0, 1, 2])
|
|
|
|
shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
|
2014-05-29 18:56:09 +02:00
|
|
|
it 'applies the manifest twice' do
|
|
|
|
apply_manifest(pp, :catch_failures => true)
|
|
|
|
apply_manifest(pp, :catch_changes => true)
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe file(path) do
|
|
|
|
it { should be_file }
|
2015-02-09 20:50:05 +01:00
|
|
|
its(:content) { should match content }
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-09 20:50:05 +01:00
|
|
|
shared_examples 'has_error' do |path, pp, error|
|
2014-01-22 02:52:37 +01:00
|
|
|
before :all do
|
2015-02-09 20:50:05 +01:00
|
|
|
shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
after :all do
|
2015-02-09 20:50:05 +01:00
|
|
|
shell("cat #{path}", :acceptable_exit_codes => [0, 1, 2])
|
|
|
|
shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'applies the manifest and gets a failure message' do
|
|
|
|
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(error)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe file(path) do
|
|
|
|
it { should_not be_file }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'ensure parameter' do
|
|
|
|
context '=> present for global and section' do
|
|
|
|
pp = <<-EOS
|
|
|
|
ini_setting { 'ensure => present for section':
|
2015-06-18 23:06:44 +02:00
|
|
|
ensure => present,
|
|
|
|
path => "#{tmpdir}/ini_setting.ini",
|
|
|
|
section => 'one',
|
|
|
|
setting => 'two',
|
|
|
|
value => 'three',
|
|
|
|
}
|
|
|
|
ini_setting { 'ensure => present for global':
|
|
|
|
ensure => present,
|
|
|
|
path => "#{tmpdir}/ini_setting.ini",
|
|
|
|
section => '',
|
|
|
|
setting => 'four',
|
|
|
|
value => 'five',
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
|
|
|
it 'applies the manifest twice' do
|
|
|
|
apply_manifest(pp, :catch_failures => true)
|
|
|
|
apply_manifest(pp, :catch_changes => true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'has_content', "#{tmpdir}/ini_setting.ini", pp, /four = five\n\n\[one\]\ntwo = three/
|
|
|
|
end
|
|
|
|
|
|
|
|
context '=> present for global and section (from previous blank value)' do
|
|
|
|
before :all do
|
|
|
|
if fact('osfamily') == 'Darwin'
|
|
|
|
shell("echo \"four =[one]\ntwo =\" > #{tmpdir}/ini_setting.ini")
|
|
|
|
else
|
|
|
|
shell("echo -e \"four =\n[one]\ntwo =\" > #{tmpdir}/ini_setting.ini")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
pp = <<-EOS
|
|
|
|
ini_setting { 'ensure => present for section':
|
2014-01-22 02:52:37 +01:00
|
|
|
ensure => present,
|
2014-02-27 23:57:12 +01:00
|
|
|
path => "#{tmpdir}/ini_setting.ini",
|
2014-01-22 02:52:37 +01:00
|
|
|
section => 'one',
|
|
|
|
setting => 'two',
|
|
|
|
value => 'three',
|
|
|
|
}
|
|
|
|
ini_setting { 'ensure => present for global':
|
|
|
|
ensure => present,
|
2014-02-27 23:57:12 +01:00
|
|
|
path => "#{tmpdir}/ini_setting.ini",
|
2014-01-22 02:52:37 +01:00
|
|
|
section => '',
|
|
|
|
setting => 'four',
|
|
|
|
value => 'five',
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
2014-05-29 18:56:09 +02:00
|
|
|
it 'applies the manifest twice' do
|
|
|
|
apply_manifest(pp, :catch_failures => true)
|
|
|
|
apply_manifest(pp, :catch_changes => true)
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
|
2015-02-09 20:50:05 +01:00
|
|
|
it_behaves_like 'has_content', "#{tmpdir}/ini_setting.ini", pp, /four = five\n\n\[one\]\ntwo = three/
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context '=> absent for key/value' do
|
|
|
|
before :all do
|
2014-06-12 17:01:58 +02:00
|
|
|
if fact('osfamily') == 'Darwin'
|
2015-02-09 20:50:05 +01:00
|
|
|
shell("echo \"four = five[one]\ntwo = three\" > #{tmpdir}/ini_setting.ini")
|
2014-06-12 17:01:58 +02:00
|
|
|
else
|
|
|
|
shell("echo -e \"four = five\n[one]\ntwo = three\" > #{tmpdir}/ini_setting.ini")
|
|
|
|
end
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
pp = <<-EOS
|
|
|
|
ini_setting { 'ensure => absent for key/value':
|
|
|
|
ensure => absent,
|
2014-02-27 23:57:12 +01:00
|
|
|
path => "#{tmpdir}/ini_setting.ini",
|
2014-01-22 02:52:37 +01:00
|
|
|
section => 'one',
|
|
|
|
setting => 'two',
|
|
|
|
value => 'three',
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
2014-05-29 18:56:09 +02:00
|
|
|
it 'applies the manifest twice' do
|
|
|
|
apply_manifest(pp, :catch_failures => true)
|
2015-02-09 20:50:05 +01:00
|
|
|
apply_manifest(pp, :catch_changes => true)
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
|
2014-02-27 23:57:12 +01:00
|
|
|
describe file("#{tmpdir}/ini_setting.ini") do
|
2014-01-22 02:52:37 +01:00
|
|
|
it { should be_file }
|
2015-02-09 20:50:05 +01:00
|
|
|
its(:content) {
|
|
|
|
should match /four = five/
|
|
|
|
should match /\[one\]/
|
|
|
|
should_not match /two = three/
|
|
|
|
}
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context '=> absent for global' do
|
|
|
|
before :all do
|
2014-06-12 17:01:58 +02:00
|
|
|
if fact('osfamily') == 'Darwin'
|
|
|
|
shell("echo \"four = five\n[one]\ntwo = three\" > #{tmpdir}/ini_setting.ini")
|
|
|
|
else
|
|
|
|
shell("echo -e \"four = five\n[one]\ntwo = three\" > #{tmpdir}/ini_setting.ini")
|
|
|
|
end
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
after :all do
|
2015-02-09 20:50:05 +01:00
|
|
|
shell("cat #{tmpdir}/ini_setting.ini", :acceptable_exit_codes => [0, 1, 2])
|
|
|
|
shell("rm #{tmpdir}/ini_setting.ini", :acceptable_exit_codes => [0, 1, 2])
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
pp = <<-EOS
|
|
|
|
ini_setting { 'ensure => absent for global':
|
|
|
|
ensure => absent,
|
2014-02-27 23:57:12 +01:00
|
|
|
path => "#{tmpdir}/ini_setting.ini",
|
2014-01-22 02:52:37 +01:00
|
|
|
section => '',
|
|
|
|
setting => 'four',
|
|
|
|
value => 'five',
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
2014-05-29 18:56:09 +02:00
|
|
|
it 'applies the manifest twice' do
|
|
|
|
apply_manifest(pp, :catch_failures => true)
|
2015-02-09 20:50:05 +01:00
|
|
|
apply_manifest(pp, :catch_changes => true)
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
|
2014-02-27 23:57:12 +01:00
|
|
|
describe file("#{tmpdir}/ini_setting.ini") do
|
2014-01-22 02:52:37 +01:00
|
|
|
it { should be_file }
|
2015-02-09 20:50:05 +01:00
|
|
|
its(:content) {
|
|
|
|
should_not match /four = five/
|
|
|
|
should match /\[one\]/
|
|
|
|
should match /two = three/
|
|
|
|
}
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'section, setting, value parameters' do
|
|
|
|
{
|
2015-03-31 23:26:11 +02:00
|
|
|
"section => 'test', setting => 'foo', value => 'bar'," => /\[test\]\nfoo = bar/,
|
|
|
|
"section => 'more', setting => 'baz', value => 'quux'," => /\[more\]\nbaz = quux/,
|
|
|
|
"section => '', setting => 'top', value => 'level'," => /top = level/,
|
|
|
|
"section => 'z', setting => 'sp aces', value => 'foo bar'," => /\[z\]\nsp aces = foo bar/,
|
2014-01-22 02:52:37 +01:00
|
|
|
}.each do |parameter_list, content|
|
|
|
|
context parameter_list do
|
|
|
|
pp = <<-EOS
|
|
|
|
ini_setting { "#{parameter_list}":
|
|
|
|
ensure => present,
|
2014-02-27 23:57:12 +01:00
|
|
|
path => "#{tmpdir}/ini_setting.ini",
|
2014-01-22 02:52:37 +01:00
|
|
|
#{parameter_list}
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
2014-02-27 23:57:12 +01:00
|
|
|
it_behaves_like 'has_content', "#{tmpdir}/ini_setting.ini", pp, content
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
{
|
2015-02-09 20:50:05 +01:00
|
|
|
"section => 'test'," => /setting is a required.+value is a required/,
|
|
|
|
"setting => 'foo', value => 'bar'," => /section is a required/,
|
|
|
|
"section => 'test', setting => 'foo'," => /value is a required/,
|
|
|
|
"section => 'test', value => 'bar'," => /setting is a required/,
|
|
|
|
"value => 'bar'," => /section is a required.+setting is a required/,
|
|
|
|
"setting => 'foo'," => /section is a required.+value is a required/,
|
2014-01-22 02:52:37 +01:00
|
|
|
}.each do |parameter_list, error|
|
|
|
|
context parameter_list, :pending => 'no error checking yet' do
|
|
|
|
pp = <<-EOS
|
|
|
|
ini_setting { "#{parameter_list}":
|
|
|
|
ensure => present,
|
2014-02-27 23:57:12 +01:00
|
|
|
path => "#{tmpdir}/ini_setting.ini",
|
2014-01-22 02:52:37 +01:00
|
|
|
#{parameter_list}
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
2014-02-27 23:57:12 +01:00
|
|
|
it_behaves_like 'has_error', "#{tmpdir}/ini_setting.ini", pp, error
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'path parameter' do
|
|
|
|
[
|
2015-02-09 20:50:05 +01:00
|
|
|
"#{tmpdir}/one.ini",
|
|
|
|
"#{tmpdir}/two.ini",
|
|
|
|
"#{tmpdir}/three.ini",
|
2014-01-22 02:52:37 +01:00
|
|
|
].each do |path|
|
|
|
|
context "path => #{path}" do
|
|
|
|
pp = <<-EOS
|
|
|
|
ini_setting { 'path => #{path}':
|
|
|
|
ensure => present,
|
|
|
|
section => 'one',
|
|
|
|
setting => 'two',
|
|
|
|
value => 'three',
|
|
|
|
path => '#{path}',
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
2015-02-09 20:50:05 +01:00
|
|
|
it_behaves_like 'has_content', path, pp, /\[one\]\ntwo = three/
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "path => foo" do
|
|
|
|
pp = <<-EOS
|
|
|
|
ini_setting { 'path => foo':
|
|
|
|
ensure => present,
|
|
|
|
section => 'one',
|
|
|
|
setting => 'two',
|
|
|
|
value => 'three',
|
|
|
|
path => 'foo',
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
|
|
|
it_behaves_like 'has_error', 'foo', pp, /must be fully qualified/
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'key_val_separator parameter' do
|
|
|
|
{
|
2015-02-09 20:50:05 +01:00
|
|
|
"" => /two = three/,
|
|
|
|
"key_val_separator => '='," => /two=three/,
|
|
|
|
"key_val_separator => ' = '," => /two = three/,
|
2014-01-22 02:52:37 +01:00
|
|
|
}.each do |parameter, content|
|
|
|
|
context "with \"#{parameter}\" makes \"#{content}\"" do
|
|
|
|
pp = <<-EOS
|
|
|
|
ini_setting { "with #{parameter} makes #{content}":
|
|
|
|
ensure => present,
|
|
|
|
section => 'one',
|
|
|
|
setting => 'two',
|
|
|
|
value => 'three',
|
2014-02-27 23:57:12 +01:00
|
|
|
path => "#{tmpdir}/key_val_separator.ini",
|
2014-01-22 02:52:37 +01:00
|
|
|
#{parameter}
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
2014-02-27 23:57:12 +01:00
|
|
|
it_behaves_like 'has_content', "#{tmpdir}/key_val_separator.ini", pp, content
|
2014-01-22 02:52:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|