Skip to content

Commit de45163

Browse files
committed
Merge pull request #184 from glarizza/MODULES_2369_key_val_separator
[MODULES-2369] Support a space as a key_val_separator
2 parents f1e4313 + d452e6c commit de45163

3 files changed

Lines changed: 46 additions & 1 deletion

File tree

lib/puppet/util/ini_file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class IniFile
77

88
def initialize(path, key_val_separator = ' = ', section_prefix = '[', section_suffix = ']')
99

10-
k_v_s = key_val_separator.strip
10+
k_v_s = key_val_separator =~ /^\s+$/ ? ' ' : key_val_separator.strip
1111

1212
@section_prefix = section_prefix
1313
@section_suffix = section_suffix

spec/acceptance/ini_setting_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@
262262
"" => /two = three/,
263263
"key_val_separator => '='," => /two=three/,
264264
"key_val_separator => ' = '," => /two = three/,
265+
"key_val_separator => ' '," => /two three/,
266+
"key_val_separator => ' '," => /two three/,
265267
}.each do |parameter, content|
266268
context "with \"#{parameter}\" makes \"#{content}\"" do
267269
pp = <<-EOS

spec/unit/puppet/provider/ini_setting/ruby_spec.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,49 @@ def self.file_path
783783

784784
end
785785

786+
context "when overriding the separator to a space" do
787+
let(:orig_content) {
788+
<<-EOS
789+
[section2]
790+
foo bar
791+
EOS
792+
}
793+
794+
it "should modify an existing setting" do
795+
resource = Puppet::Type::Ini_setting.new(common_params.merge(
796+
:section => 'section2',
797+
:setting => 'foo',
798+
:value => 'yippee',
799+
:key_val_separator => ' '))
800+
provider = described_class.new(resource)
801+
provider.exists?.should be true
802+
provider.value.should == 'bar'
803+
provider.value=('yippee')
804+
validate_file(<<-EOS
805+
[section2]
806+
foo yippee
807+
EOS
808+
)
809+
end
810+
811+
it "should add a new setting" do
812+
resource = Puppet::Type::Ini_setting.new(common_params.merge(
813+
:section => 'section2',
814+
:setting => 'bar',
815+
:value => 'baz',
816+
:key_val_separator => ' '))
817+
provider = described_class.new(resource)
818+
provider.exists?.should be false
819+
provider.create
820+
validate_file(<<-EOS
821+
[section2]
822+
foo bar
823+
bar baz
824+
EOS
825+
)
826+
end
827+
end
828+
786829
context "when ensuring that a setting is absent" do
787830
let(:orig_content) {
788831
<<-EOS

0 commit comments

Comments
 (0)