@@ -360,4 +360,60 @@ def validate_file(expected_content, tmpfile)
360360 expect ( validate_file ( expected_content_two , tmpfile ) ) . to be_truthy
361361 end
362362 end
363+
364+ context 'when the parent setting has multiple values (same key repeated)' do
365+ let ( :common_params ) do
366+ {
367+ title : 'ini_subsetting_multivalue_test' ,
368+ path : tmpfile ,
369+ section : 'main' ,
370+ key_val_separator : '=' ,
371+ }
372+ end
373+
374+ let ( :orig_content ) do
375+ <<-INIFILE
376+ [main]
377+ setting="value1 value2"
378+ setting="value3 value4"
379+ other=data
380+ INIFILE
381+ end
382+
383+ it 'reads subsetting from the first occurrence of a multi-value key' do
384+ resource = Puppet ::Type ::Ini_subsetting . new ( common_params . merge ( setting : 'setting' , subsetting : 'value1' , quote_char : '"' ) )
385+ provider = described_class . new ( resource )
386+ expect ( provider . exists? ) . to eq ''
387+ end
388+
389+ # NOTE: When ini_subsetting modifies a key that has multiple values,
390+ # it collapses them to a single value (the first one, modified).
391+ # This is expected behavior per the multi-value PR design.
392+ expected_content_one = <<-INIFILE
393+ [main]
394+ setting="value1 value2 newval"
395+ other=data
396+ INIFILE
397+
398+ it 'modifies the first occurrence and collapses multi-value keys when adding a subsetting' do
399+ resource = Puppet ::Type ::Ini_subsetting . new ( common_params . merge ( setting : 'setting' , subsetting : 'newval' , value : '' , quote_char : '"' ) )
400+ provider = described_class . new ( resource )
401+ expect ( provider . exists? ) . to be_nil
402+ provider . create
403+ validate_file ( expected_content_one , tmpfile )
404+ end
405+
406+ expected_content_two = <<-INIFILE
407+ [main]
408+ setting="value2"
409+ other=data
410+ INIFILE
411+
412+ it 'removes a subsetting and collapses multi-value keys' do
413+ resource = Puppet ::Type ::Ini_subsetting . new ( common_params . merge ( setting : 'setting' , subsetting : 'value1' , quote_char : '"' ) )
414+ provider = described_class . new ( resource )
415+ provider . destroy
416+ validate_file ( expected_content_two , tmpfile )
417+ end
418+ end
363419end
0 commit comments