Skip to content

Commit

Permalink
Merge pull request #789 from fetzerms/handle_deferred_values
Browse files Browse the repository at this point in the history
#775 - Explicitly resolve deferred values
  • Loading branch information
bastelfreak authored Nov 28, 2023
2 parents f3ac73c + 5ae15cd commit b355f42
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/puppet/type/concat_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ def nested_merge(hash1, hash2)

def fragment_content(r)
if r[:content].nil? == false
fragment_content = r[:content]
# Explicitly resolve deferred values.
fragment_content = r[:content].instance_of?(Puppet::Pops::Evaluator::DeferredValue) ? r[:content].resolve : r[:content]
elsif r[:source].nil? == false
@source = nil
Array(r[:source]).each do |source|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

# For testing the deferred function call
require 'digest/md5'

describe 'deferred function call' do
attr_reader :basedir

before(:all) do
@basedir = setup_test_directory
end

describe 'file' do
let(:pp) do
<<-MANIFEST
concat { '#{basedir}/deferred_file': }
concat::fragment { '1':
target => '#{basedir}/deferred_file',
content => Deferred('md5', ['test']),
}
MANIFEST
end

it 'idempotent, file matches' do
idempotent_apply(pp)
expect(file("#{basedir}/deferred_file")).to be_file
expect(file("#{basedir}/deferred_file").content).to match Digest::MD5.hexdigest('test')
end
end
end

0 comments on commit b355f42

Please sign in to comment.