diff options
-rw-r--r-- | lib/puppet/type/ini_setting.rb | 6 | ||||
-rw-r--r-- | spec/unit/puppet/provider/ini_setting/ruby_spec.rb | 20 |
2 files changed, 26 insertions, 0 deletions
diff --git a/lib/puppet/type/ini_setting.rb b/lib/puppet/type/ini_setting.rb index f1ab490..50b6b38 100644 --- a/lib/puppet/type/ini_setting.rb +++ b/lib/puppet/type/ini_setting.rb @@ -35,6 +35,12 @@ Puppet::Type.newtype(:ini_setting) do 'Defaults to " = ", but you could use this to override e.g. whether ' + 'or not the separator should include whitespace.' defaultto(" = ") + + validate do |value| + unless value.scan('=').size == 1 + raise Puppet::Error, ":key_val_separator must contain exactly one = character." + end + end end end diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb index ac9bb91..20882fd 100644 --- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb @@ -400,6 +400,26 @@ foo=bar EOS } + it "should fail if the separator doesn't include an equals sign" do + expect { + Puppet::Type::Ini_setting.new(common_params.merge( + :section => 'section2', + :setting => 'foo', + :value => 'yippee', + :key_val_separator => '+')) + }.to raise_error Puppet::Error, /must contain exactly one/ + end + + it "should fail if the separator includes more than one equals sign" do + expect { + Puppet::Type::Ini_setting.new(common_params.merge( + :section => 'section2', + :setting => 'foo', + :value => 'yippee', + :key_val_separator => ' = foo = ')) + }.to raise_error Puppet::Error, /must contain exactly one/ + end + it "should modify an existing setting" do resource = Puppet::Type::Ini_setting.new(common_params.merge( :section => 'section2', |