Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#775 - Explicitly resolve deferred values #789

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading