Skip to content

Commit

Permalink
(maint) Resolve config object before manipulating it
Browse files Browse the repository at this point in the history
The ConfigDocument API that preserves comments and formatting in HOCON
files does not automatically resolve substitutions. This makes it
impossible to manipulate settings that involve substitutions. This
commit adds a `resolve` call to the config object that is parsed and
provided for manipulation.
  • Loading branch information
Magisus committed Oct 23, 2018
1 parent d9de8af commit 663ca88
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/puppet/provider/hocon_setting/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def conf_object
if @conf_file.nil? && !File.exist?(file_path)
File.new(file_path, 'w')
end
Hocon::ConfigFactory.parse_file(file_path)
Hocon::ConfigFactory.parse_file(file_path).resolve
end

def remove_value(value_to_remove)
Expand Down
29 changes: 29 additions & 0 deletions spec/unit/puppet/provider/conf_setting/ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -839,4 +839,33 @@ def validate_file(expected_content, tmp = tmpfile)
expect(provider.value[0]).to eql('a' => 'b')
end
end

context 'substitutions' do
let(:orig_content) do
<<-EOS
test_key_1:
{
bar: barvalue
}
sub_key: ${test_key_1.bar}
EOS
end

it 'can change the value of a setting with a substitution' do
resource = Puppet::Type::Hocon_setting.new(common_params.merge(
setting: 'sub_key', ensure: 'present', value: 'newvalue', type: 'string'
))
provider = described_class.new(resource)
expect(provider.exists?).to be true
provider.value = 'newvalue'
validate_file(<<-EOS
test_key_1:
{
bar: barvalue
}
sub_key: "newvalue"
EOS
)
end
end
end

0 comments on commit 663ca88

Please sign in to comment.