From a45ab6593035cfbbd4cbcb535a8b8324b212ef4e Mon Sep 17 00:00:00 2001 From: Chris Price Date: Fri, 26 Oct 2012 17:24:37 -0700 Subject: Add detection for commented versions of settings This commit adds support for detecting commented versions of settings in an existing version of an inifile. If you are setting a value for a setting that isn't currently set in the file, but a commented version is found, then we add the new setting immediately following the commented version, rather than at the end of the section. --- spec/unit/puppet/provider/ini_setting/ruby_spec.rb | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'spec') diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb index 19db4c7..4f8bdc1 100644 --- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb @@ -731,4 +731,84 @@ subby=bar end + + context "when dealing settings that have a commented version present" do + let(:orig_content) { + <<-EOS + [section1] + # foo=foovalue + bar=barvalue + foo = foovalue2 + +[section2] +# foo = foovalue +;bar=barvalue +blah = blah + EOS + } + + it "should add a new setting below a commented version of that setting" do + resource = Puppet::Type::Ini_setting.new( + common_params.merge(:section => 'section2', :setting => 'foo', :value => 'foo3')) + provider = described_class.new(resource) + provider.exists?.should be_false + provider.create + validate_file(<<-EOS + [section1] + # foo=foovalue + bar=barvalue + foo = foovalue2 + +[section2] +# foo = foovalue +foo = foo3 +;bar=barvalue +blah = blah + EOS + ) + end + + it "should update an existing setting in place, even if there is a commented version of that setting" do + resource = Puppet::Type::Ini_setting.new( + common_params.merge(:section => 'section1', :setting => 'foo', :value => 'foo3')) + provider = described_class.new(resource) + provider.exists?.should be_true + provider.create + validate_file(<<-EOS + [section1] + # foo=foovalue + bar=barvalue + foo = foo3 + +[section2] +# foo = foovalue +;bar=barvalue +blah = blah + EOS + ) + end + + it "should add a new setting below a commented version of that setting, respecting semicolons as comments" do + resource = Puppet::Type::Ini_setting.new( + common_params.merge(:section => 'section2', :setting => 'bar', :value => 'bar3')) + provider = described_class.new(resource) + provider.exists?.should be_false + provider.create + validate_file(<<-EOS + [section1] + # foo=foovalue + bar=barvalue + foo = foovalue2 + +[section2] +# foo = foovalue +;bar=barvalue +bar=bar3 +blah = blah + EOS + ) + end + + end + end -- cgit v1.2.3