summaryrefslogtreecommitdiff
path: root/spec/unit/puppet/provider/ini_setting
diff options
context:
space:
mode:
authorDan Bode <dan@puppetlabs.com>2013-03-11 17:31:00 -0700
committerDan Bode <dan@puppetlabs.com>2013-03-11 17:42:08 -0700
commit5f71d7f0bd78bbcc587210c9d251b92e1a1dea0f (patch)
treef0727439eb02070077c999d435ee765396a88802 /spec/unit/puppet/provider/ini_setting
parent2008179ebea70d296f65a1809c961951884a7b11 (diff)
downloadpuppet-inifile-5f71d7f0bd78bbcc587210c9d251b92e1a1dea0f.tar.gz
puppet-inifile-5f71d7f0bd78bbcc587210c9d251b92e1a1dea0f.tar.bz2
guard against nil indentation values
This commit is intended to resolves an issue where the indentation value can be nil (which leads to a run time exception) This occurrs in cases where a section is following by only one of more comments. The proposed fix is to guard against potential nil values where the error occurs. This fix is idential to code used at line 125 of the same file.
Diffstat (limited to 'spec/unit/puppet/provider/ini_setting')
-rw-r--r--spec/unit/puppet/provider/ini_setting/ruby_spec.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb
index 4f8bdc1..ed2f24a 100644
--- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb
+++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb
@@ -809,6 +809,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