Add validation for key_val_separator

For now, the key_val_separator is required to contain
exactly one '=' character.  This commit simply validates
that that is the case.
This commit is contained in:
Chris Price 2012-09-20 11:35:45 -07:00
parent 8d1fdc5c29
commit e527908b7c
2 changed files with 26 additions and 0 deletions

View file

@ -35,6 +35,12 @@ Puppet::Type.newtype(:ini_setting) do
'Defaults to " = ", but you could use this to override e.g. whether ' + 'Defaults to " = ", but you could use this to override e.g. whether ' +
'or not the separator should include whitespace.' 'or not the separator should include whitespace.'
defaultto(" = ") defaultto(" = ")
validate do |value|
unless value.scan('=').size == 1
raise Puppet::Error, ":key_val_separator must contain exactly one = character."
end
end
end end
end end

View file

@ -400,6 +400,26 @@ foo=bar
EOS 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 it "should modify an existing setting" do
resource = Puppet::Type::Ini_setting.new(common_params.merge( resource = Puppet::Type::Ini_setting.new(common_params.merge(
:section => 'section2', :section => 'section2',