Skip to content

Commit

Permalink
Handle Float values
Browse files Browse the repository at this point in the history
Previously, the changes made only handled Integer values and didn't account for
Float values.  This commit accounts for Floats and adds a test for the same.
  • Loading branch information
Gary Larizza committed Apr 30, 2015
1 parent e771a8c commit 35187c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/puppet/type/hocon_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
# Puppet stringifies numerics in versions of Puppet < 4.0.0
# Account for this in the type
begin
numeric_as_string = Integer(value)
numeric_as_string = Float(value)
rescue ArgumentError
numeric_as_string = false
end
Expand All @@ -71,7 +71,7 @@

munge do |value|
if value.is_a?(String) and @resource[:type] == 'number'
value = Integer(value)
value = Float(value)
end
value
end
Expand Down
11 changes: 10 additions & 1 deletion spec/unit/puppet/provider/conf_setting/ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ def validate_file(expected_content,tmpfile = tmpfile)
expect(provider.value[0]).to eql(12)
end

it "should be able to handle a numerical string value with number type specified" do
it "should be able to handle an Integer string value with number type specified" do
resource = Puppet::Type::Hocon_setting.new(common_params.merge(
:setting => 'test_key_1.master', :value => '12', :type => 'number'))
provider = described_class.new(resource)
Expand All @@ -535,6 +535,15 @@ def validate_file(expected_content,tmpfile = tmpfile)
expect(provider.value[0]).to eql(12)
end

it "should be able to handle a Float string value with number type specified" do
resource = Puppet::Type::Hocon_setting.new(common_params.merge(
:setting => 'test_key_1.master', :value => '13.37', :type => 'number'))
provider = described_class.new(resource)
provider.create
expect(provider.exists?).to be true
expect(provider.value[0]).to eql(13.37)
end

it "should be able to handle string value with string type specified" do
resource = Puppet::Type::Hocon_setting.new(common_params.merge(
:setting => 'test_key_1.master', :value => "abc", :type => 'string'))
Expand Down

0 comments on commit 35187c2

Please sign in to comment.