Fix parsing of boolean values in flagfiles

Previously, settings in flagfiles without a value were considered false.
This change makes them true and also parses values with a "no" prefix as
false.

Unit tests included.
This commit is contained in:
Soren Hansen 2012-06-07 16:42:25 +02:00
parent 10f8b3f9ca
commit ac6287e492
2 changed files with 16 additions and 1 deletions

View File

@ -23,9 +23,12 @@ Puppet::Type.type(:nova_config).provide(
if hash[:line] =~ /^\s*(\S+?)\s*=\s*([\S ]+)\s*$/
hash[:name]=$1
hash[:value]=$2
elsif hash[:line] =~ /^\s*(\S+)\s*$/
elsif hash[:line] =~ /^\s*no(\S+)\s*$/
hash[:name]=$1
hash[:value]=false
elsif hash[:line] =~ /^\s*(\S+)\s*$/
hash[:name]=$1
hash[:value]=true
else
raise Puppet::Error, "Invalid line: #{hash[:line]}"
end

View File

@ -19,6 +19,18 @@ describe provider_class do
record[:value].should == 'bar'
record[:record_type].should == :parsed
end
it 'should be able to parse settings without values' do
record = @provider.class.parse('--foo').first
record[:name].should == 'foo'
record[:value].should == true
record[:record_type].should == :parsed
end
it 'should be able to parse negated settings without values' do
record = @provider.class.parse('--nofoo').first
record[:name].should == 'foo'
record[:value].should == false
record[:record_type].should == :parsed
end
it 'should be able to parse values that have spaces' do
record = @provider.class.parse('--foo = bar or baz').first
record[:name].should == 'foo'