Skip to content
Open
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
14 changes: 11 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 @@ -550,9 +550,14 @@ def insync_resource_mode(context, name, property_name, should_hash)

return true if in_sync

# DSC Test says out of sync. Suppress non-dsc_ and nil/empty properties.
# DSC Test says out of sync. Suppress non-DSC, nil and empty collection
# properties. An empty String is an explicit valid DSC value and must be
# compared.
return true unless property_name.to_s.start_with?('dsc_')
return true if should_value.nil? || (should_value.respond_to?(:empty?) && should_value.empty?)
return true if should_value.nil?
return true if !should_value.is_a?(String) &&
should_value.respond_to?(:empty?) &&
should_value.empty?

# Fresh Get comparison for dsc_ properties with values
compare_fresh_value(context, name, property_name, should_hash, report_on_failure: true)
Expand All @@ -563,7 +568,10 @@ def insync_property_mode(context, name, property_name, should_hash)
return nil unless property_name.to_s.start_with?('dsc_')

should_value = should_hash.is_a?(Hash) ? should_hash[property_name] : nil
return nil if should_value.nil? || (should_value.respond_to?(:empty?) && should_value.empty?)
return nil if should_value.nil?
return nil if !should_value.is_a?(String) &&
should_value.respond_to?(:empty?) &&
should_value.empty?

compare_fresh_value(context, name, property_name, should_hash, report_on_failure: false)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,25 @@
end

context 'when should_value is empty string' do
it 'returns nil' do
it 'compares the value' do
should_hash_empty = should_hash.merge(dsc_setting: '')
allow(provider).to receive(:compare_fresh_value).and_return(true)
result = provider.send(:insync?, context, name, :dsc_setting, is_hash, should_hash_empty)
expect(result).to be(true)
end
end

context 'when should_value is empty array' do
it 'returns nil' do
should_hash_empty = should_hash.merge(dsc_setting: [])
result = provider.send(:insync?, context, name, :dsc_setting, is_hash, should_hash_empty)
expect(result).to be_nil
end
end

context 'when should_value is empty hash' do
it 'returns nil' do
should_hash_empty = should_hash.merge(dsc_setting: {})
result = provider.send(:insync?, context, name, :dsc_setting, is_hash, should_hash_empty)
expect(result).to be_nil
end
Expand Down
Loading