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

(GH-154) Fix canonicalization in get method for DSC Base Provider #157

Merged
merged 1 commit into from
Jun 21, 2021
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
9 changes: 6 additions & 3 deletions lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def canonicalize(context, resources)
# During RSAPI refresh runs mandatory parameters are stripped and not available;
# Instead of checking again and failing, search the cache for a namevar match.
namevarized_r = r.select { |k, _v| namevar_attributes(context).include?(k) }
cached_result = fetch_cached_hashes(@@cached_canonicalized_resource, [namevarized_r])
if cached_result.empty?
cached_result = fetch_cached_hashes(@@cached_canonicalized_resource, [namevarized_r]).first
if cached_result.nil?
# If the resource is meant to be absent, skip canonicalization and rely on the manifest
# value; there's no reason to compare system state to desired state for casing if the
# resource is being removed.
Expand Down Expand Up @@ -88,7 +88,10 @@ def canonicalize(context, resources)
# rubocop:enable Metrics/BlockNesting
end
else
canonicalized = cached_result
# The resource has already been canonicalized for the set values and is not being canonicalized for get
# In this case, we do *not* want to process anything, just return the resource. We only call canonicalize
# so we can get case insensitive but preserving values for _setting_ state.
canonicalized = r
end
canonicalized_resources << canonicalized
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
let(:expected_resource) { base_resource.merge({ dsc_property: 'foobar' }) }
let(:cached_canonicalized_resource) { expected_resource.dup }

it 'returns the cached resource' do
expect(canonicalized_resource).to eq([expected_resource])
it 'returns the manifest resource' do
expect(canonicalized_resource).to eq([manifest_resource])
end
end

Expand Down