File tree Expand file tree Collapse file tree
lib/puppet/provider/ini_setting
spec/unit/puppet/provider/ini_setting Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -70,7 +70,13 @@ def destroy
7070 end
7171
7272 def value
73- ini_file . get_value ( section , setting )
73+ result = ini_file . get_value ( section , setting )
74+ return result if result . nil?
75+
76+ value_property = resource . class . attrclass ( :value )
77+ return result if value_property && value_property . array_matching == :all
78+
79+ ( result . length == 1 ) ? result . first : result
7480 end
7581
7682 def value = ( _value )
Original file line number Diff line number Diff line change @@ -1731,4 +1731,49 @@ def self.file_path
17311731 validate_file ( expected_content_six , tmpfile )
17321732 end
17331733 end
1734+
1735+ context 'when used by a custom type whose value property is not array_matching' do
1736+ before ( :all ) do
1737+ Puppet ::Type . newtype ( :scalar_value_ini_setting ) do
1738+ newparam ( :name , namevar : true )
1739+ newparam ( :section )
1740+ newparam ( :setting )
1741+ newparam ( :path )
1742+ newparam ( :key_val_separator ) { defaultto ( '=' ) }
1743+ newparam ( :section_prefix ) { defaultto ( '[' ) }
1744+ newparam ( :section_suffix ) { defaultto ( ']' ) }
1745+ newparam ( :indent_char ) { defaultto ( ' ' ) }
1746+ newparam ( :indent_width )
1747+ newparam ( :force_new_section_creation ) { defaultto ( true ) }
1748+ ensurable
1749+ newproperty ( :value ) do
1750+ munge { |v | v . to_s }
1751+ end
1752+ end
1753+ Puppet ::Type . type ( :scalar_value_ini_setting ) . provide (
1754+ :ruby ,
1755+ parent : Puppet ::Type . type ( :ini_setting ) . provider ( :ruby ) ,
1756+ )
1757+ end
1758+
1759+ let ( :orig_content ) do
1760+ <<-INIFILE
1761+ [section1]
1762+ http_interface=127.0.0.1
1763+ INIFILE
1764+ end
1765+
1766+ it 'returns a scalar from #value so insync? matches a scalar should' do
1767+ resource = Puppet ::Type . type ( :scalar_value_ini_setting ) . new (
1768+ title : 'http_interface' ,
1769+ path : tmpfile ,
1770+ section : 'section1' ,
1771+ setting : 'http_interface' ,
1772+ value : '127.0.0.1' ,
1773+ )
1774+ provider = Puppet ::Type . type ( :scalar_value_ini_setting ) . provider ( :ruby ) . new ( resource )
1775+ expect ( provider . value ) . to eq ( '127.0.0.1' )
1776+ expect ( resource . property ( :value ) . insync? ( provider . value ) ) . to be true
1777+ end
1778+ end
17341779end
You can’t perform that action at this time.
0 commit comments