diff options
author | Chris Price <chris@puppetlabs.com> | 2012-09-04 10:27:39 -0700 |
---|---|---|
committer | Chris Price <chris@puppetlabs.com> | 2012-09-04 10:27:39 -0700 |
commit | 310a4b1575f7af903ac97108c6f1352d05f5f3fc (patch) | |
tree | f5df1b50be72705c7c24638a014555ced1d6979c | |
parent | 04e2c5ea3bb53af820d2ef24daac9ef1f1efd299 (diff) | |
parent | 4d3acd8faee57a38d08ae7d9c62154ff5806350a (diff) | |
download | puppet-inifile-310a4b1575f7af903ac97108c6f1352d05f5f3fc.tar.gz puppet-inifile-310a4b1575f7af903ac97108c6f1352d05f5f3fc.tar.bz2 |
Merge pull request #5 from jtopjian/jtopjian-colon
Added support for colons in section names
-rw-r--r-- | lib/puppet/util/ini_file.rb | 4 | ||||
-rw-r--r-- | spec/spec_helper.rb | 3 | ||||
-rw-r--r-- | spec/unit/puppet/provider/ini_setting/ruby_spec.rb | 107 |
3 files changed, 112 insertions, 2 deletions
diff --git a/lib/puppet/util/ini_file.rb b/lib/puppet/util/ini_file.rb index 8629db0..4fe4169 100644 --- a/lib/puppet/util/ini_file.rb +++ b/lib/puppet/util/ini_file.rb @@ -5,7 +5,7 @@ module Puppet module Util class IniFile - SECTION_REGEX = /^\s*\[([\w\d\.\\\/\-]+)\]\s*$/ + SECTION_REGEX = /^\s*\[([\w\d\.\\\/\-\:]+)\]\s*$/ SETTING_REGEX = /^\s*([\w\d\.\\\/\-]+)\s*=\s*([\S]+)\s*$/ def initialize(path) @@ -133,4 +133,4 @@ module Util end end -end
\ No newline at end of file +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ddbcd6e..7ca9fac 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,3 +6,6 @@ require 'puppetlabs_spec_helper/puppetlabs_spec_helper' require 'puppetlabs_spec_helper/puppetlabs_spec/files' +RSpec.configure do |config| + config.mock_with :rspec +end diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb index d26c78d..2dbbf55 100644 --- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb @@ -43,6 +43,8 @@ master = true foo= foovalue2 baz=bazvalue url = http://192.168.1.1:8080 +[section:sub] +subby=bar #another comment ; yet another comment EOS @@ -67,6 +69,36 @@ master = true foo= foovalue2 baz=bazvalue url = http://192.168.1.1:8080 +yahoo = yippee +[section:sub] +subby=bar + #another comment + ; yet another comment + EOS +) + end + + it "should add a missing setting to the correct section with colon" 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 == false + 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 ; yet another comment yahoo = yippee @@ -93,6 +125,35 @@ master = true foo= foovalue2 baz = bazvalue2 url = http://192.168.1.1:8080 +[section:sub] +subby=bar + #another comment + ; yet another comment + EOS + ) + end + + it "should modify an existing setting with a different value - with colon in section" do + resource = Puppet::Type::Ini_setting.new(common_params.merge( + :section => 'section:sub', :setting => 'subby', :value => 'foo')) + provider = described_class.new(resource) + provider.exists?.should == false + 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 = foo #another comment ; yet another comment EOS @@ -119,6 +180,8 @@ master = true foo= foovalue2 baz=bazvalue url = http://192.168.0.1:8080 +[section:sub] +subby=bar #another comment ; yet another comment EOS @@ -151,6 +214,8 @@ master = true foo= foovalue2 baz=bazvalue url = http://192.168.1.1:8080 +[section:sub] +subby=bar #another comment ; yet another comment @@ -160,6 +225,36 @@ huzzah = shazaam ) end + it "should add a new section if the section does not exist - with colon" do + resource = Puppet::Type::Ini_setting.new(common_params.merge( + :section => "section:subsection", :setting => 'huzzah', :value => 'shazaam')) + provider = described_class.new(resource) + provider.exists?.should == false + 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 + ; yet another comment + +[section:subsection] +huzzah = shazaam + EOS + ) + end + it "should add a new section if no sections exists" do resource = Puppet::Type::Ini_setting.new(common_params.merge( :section => "section1", :setting => 'setting1', :value => 'hellowworld', :path => emptyfile)) @@ -172,6 +267,18 @@ setting1 = hellowworld ", emptyfile) end + it "should add a new section with colon if no sections exists" do + resource = Puppet::Type::Ini_setting.new(common_params.merge( + :section => "section:subsection", :setting => 'setting1', :value => 'hellowworld', :path => emptyfile)) + provider = described_class.new(resource) + provider.exists?.should == false + provider.create + validate_file(" +[section:subsection] +setting1 = hellowworld +", emptyfile) + end + it "should be able to handle variables of any type" do resource = Puppet::Type::Ini_setting.new(common_params.merge( :section => "section1", :setting => 'master', :value => true)) |