diff options
author | Chris Price <chris@puppetlabs.com> | 2012-10-26 17:24:37 -0700 |
---|---|---|
committer | Chris Price <chris@puppetlabs.com> | 2012-10-26 17:24:37 -0700 |
commit | a45ab6593035cfbbd4cbcb535a8b8324b212ef4e (patch) | |
tree | 8fec4645f400965c3402df673c7276d2ed012e6f /spec/unit/puppet/provider/ini_setting | |
parent | 8a0d1fa1f289a5f1fc3f72cd0ebb3c52e923d024 (diff) | |
download | puppet-inifile-a45ab6593035cfbbd4cbcb535a8b8324b212ef4e.tar.gz puppet-inifile-a45ab6593035cfbbd4cbcb535a8b8324b212ef4e.tar.bz2 |
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.
Diffstat (limited to 'spec/unit/puppet/provider/ini_setting')
-rw-r--r-- | spec/unit/puppet/provider/ini_setting/ruby_spec.rb | 80 |
1 files changed, 80 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 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 |