Merge pull request #30 from bodepd/fix_nil_indentation

guard against nil indentation values
This commit is contained in:
Chris Price 2013-03-12 11:11:09 -07:00
commit 8064df6d00
2 changed files with 41 additions and 1 deletions

View file

@ -264,7 +264,7 @@ module Util
def insert_inline_setting_line(result, section, setting, value)
line_num = result[:line_num]
match = result[:match]
lines.insert(line_num + 1, "#{' ' * section.indentation}#{setting}#{match[4]}#{value}")
lines.insert(line_num + 1, "#{' ' * (section.indentation || 0 )}#{setting}#{match[4]}#{value}")
end
# Utility method; given a section index (index into the @section_names

View file

@ -887,6 +887,46 @@ blah = blah
)
end
context 'when a section only contains comments' do
let(:orig_content) {
<<-EOS
[section1]
# foo=foovalue
# bar=bar2
EOS
}
it 'should be able to add a new setting when a section contains only comments' do
resource = Puppet::Type::Ini_setting.new(
common_params.merge(:section => 'section1', :setting => 'foo', :value => 'foovalue2')
)
provider = described_class.new(resource)
provider.exists?.should be_false
provider.create
validate_file(<<-EOS
[section1]
# foo=foovalue
foo=foovalue2
# bar=bar2
EOS
)
end
it 'should be able to add a new setting when it matches a commented out line other than the first one' do
resource = Puppet::Type::Ini_setting.new(
common_params.merge(:section => 'section1', :setting => 'bar', :value => 'barvalue2')
)
provider = described_class.new(resource)
provider.exists?.should be_false
provider.create
validate_file(<<-EOS
[section1]
# foo=foovalue
# bar=bar2
bar=barvalue2
EOS
)
end
end
end
end