diff options
author | Chris Price <chris@puppetlabs.com> | 2012-10-22 11:05:39 -0700 |
---|---|---|
committer | Chris Price <chris@puppetlabs.com> | 2012-10-22 11:05:39 -0700 |
commit | 8a0d1fa1f289a5f1fc3f72cd0ebb3c52e923d024 (patch) | |
tree | 610b78ab10ae9cf0f495f71f743433ab9f11ea57 /spec/unit/puppet/provider | |
parent | a5eebcfca0c1c8e8fb8130205a6ec623c8691326 (diff) | |
parent | f0d443fed02d870965613dd174793cc1816137a2 (diff) | |
download | puppet-inifile-8a0d1fa1f289a5f1fc3f72cd0ebb3c52e923d024.tar.gz puppet-inifile-8a0d1fa1f289a5f1fc3f72cd0ebb3c52e923d024.tar.bz2 |
Merge pull request #19 from cprice-puppet/feature/master/use-existing-indentation
Feature/master/use existing indentation
Diffstat (limited to 'spec/unit/puppet/provider')
-rw-r--r-- | spec/unit/puppet/provider/ini_setting/ruby_spec.rb | 204 |
1 files changed, 201 insertions, 3 deletions
diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb index 8b2f8e5..19db4c7 100644 --- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb @@ -123,7 +123,7 @@ master = true [section2] foo= foovalue2 -baz = bazvalue2 +baz=bazvalue2 url = http://192.168.1.1:8080 [section:sub] subby=bar @@ -154,7 +154,7 @@ foo= foovalue2 baz=bazvalue url = http://192.168.1.1:8080 [section:sub] -subby = foo +subby=foo #another comment ; yet another comment EOS @@ -329,7 +329,7 @@ foo = http://192.168.1.1:8080 provider.value=('yippee') validate_file(<<-EOS # This is a comment -foo = yippee +foo=yippee [section2] foo = http://192.168.1.1:8080 ; yet another comment @@ -361,6 +361,7 @@ foo = http://192.168.1.1:8080 provider.create validate_file(<<-EOS foo = yippee + [section2] foo = http://192.168.1.1:8080 EOS @@ -533,4 +534,201 @@ subby=bar end end + + context "when dealing with indentation in sections" do + let(:orig_content) { + <<-EOS +# This is a comment + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + master = true + +[section2] + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 +[section:sub] + subby=bar + #another comment + fleezy = flam + ; yet another comment + EOS + } + + it "should add a missing setting at the correct indentation when the header is aligned" do + resource = Puppet::Type::Ini_setting.new(common_params.merge( + :section => 'section1', :setting => 'yahoo', :value => 'yippee')) + provider = described_class.new(resource) + provider.exists?.should be_nil + provider.create + validate_file(<<-EOS +# This is a comment + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + master = true + yahoo = yippee + +[section2] + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 +[section:sub] + subby=bar + #another comment + fleezy = flam + ; yet another comment + EOS + ) + end + + it "should update an existing setting at the correct indentation when the header is aligned" 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_true + provider.create + validate_file(<<-EOS +# This is a comment + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue2 + master = true + +[section2] + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 +[section:sub] + subby=bar + #another comment + fleezy = flam + ; yet another comment + EOS + ) + end + + it "should add a missing setting at the correct indentation when the header is not aligned" do + resource = Puppet::Type::Ini_setting.new(common_params.merge( + :section => 'section2', :setting => 'yahoo', :value => 'yippee')) + provider = described_class.new(resource) + provider.exists?.should be_nil + provider.create + validate_file(<<-EOS +# This is a comment + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + master = true + +[section2] + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + yahoo = yippee +[section:sub] + subby=bar + #another comment + fleezy = flam + ; yet another comment + EOS + ) + end + + it "should update an existing setting at the correct indentation when the header is not aligned" do + resource = Puppet::Type::Ini_setting.new( + common_params.merge(:section => 'section2', :setting => 'baz', :value => 'bazvalue2')) + provider = described_class.new(resource) + provider.exists?.should be_true + provider.create + validate_file(<<-EOS +# This is a comment + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + master = true + +[section2] + foo= foovalue2 + baz=bazvalue2 + url = http://192.168.1.1:8080 +[section:sub] + subby=bar + #another comment + fleezy = flam + ; yet another comment + EOS + ) + end + + it "should add a missing setting at the min indentation when the section is not aligned" do + resource = Puppet::Type::Ini_setting.new( + common_params.merge(:section => 'section:sub', :setting => 'yahoo', :value => 'yippee')) + provider = described_class.new(resource) + provider.exists?.should be_nil + provider.create + validate_file(<<-EOS +# This is a comment + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + master = true + +[section2] + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 +[section:sub] + subby=bar + #another comment + fleezy = flam + ; yet another comment + yahoo = yippee + EOS + ) + end + + it "should update an existing setting at the previous indentation when the section is not aligned" do + resource = Puppet::Type::Ini_setting.new( + common_params.merge(:section => 'section:sub', :setting => 'fleezy', :value => 'flam2')) + provider = described_class.new(resource) + provider.exists?.should be_true + provider.create + validate_file(<<-EOS +# This is a comment + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + master = true + +[section2] + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 +[section:sub] + subby=bar + #another comment + fleezy = flam2 + ; yet another comment + EOS + ) + end + + end + end |