Skip to content

Commit

Permalink
Cleaned up output text from development to make the code cleaner.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnEricson committed Oct 7, 2020
1 parent 095335e commit ab62f19
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
9 changes: 1 addition & 8 deletions lib/puppet/catalog-diff/comparer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def compare_resources(old, new, options)

if options[:show_resource_diff]
Puppet.debug("Resource diff: #{resource[:resource_id]}")
puts 'show_resource_diff'

diff_array = str_diff(
Puppet::CatalogDiff::Formater.new.resource_to_string(resource),
Puppet::CatalogDiff::Formater.new.resource_to_string(new_resource),
Expand Down Expand Up @@ -138,20 +138,13 @@ def str_diff(cont1, cont2)
sum2 = Digest::MD5.hexdigest(str2)
end

puts "str_diff: str1: #{str1} str1.encoding: #{str1.encoding}"
puts "str_diff: str2: #{str2} str2.encoding: #{str2.encoding}"
unless str1.valid_encoding?
Puppet::debug("content parameter in old resource has invalid #{str1.encoding} encoding.")
str1.encode!('UTF-8', 'UTF-8', :invalid => :replace)
puts "str_diff: str1 fixed str1: #{str1} str1.encoding: #{str1.encoding}"
unless str1.valid_encoding?
puts "str1 STILL WRONG!"
end
end
unless str2.valid_encoding?
Puppet::debug("content parameter in new resource has invalid #{str2.encoding} encoding.")
str2.encode!('UTF-8', 'UTF-8', :invalid => :replace)
puts "str2 fixed str2: #{str2} str2.encoding: #{str2.encoding}"
end

return nil unless str1 && str2
Expand Down
8 changes: 1 addition & 7 deletions spec/unit/puppet/catalog_diff/comparer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,12 @@
Encoding.default_internal = 'UTF-8'
Encoding.default_external = 'UTF-8' # Needed because diff uses tempfile.

puts "Encoding.default_internal: #{Encoding.default_internal}"
latin1_string = [246].pack('C*').force_encoding('UTF-8')
res1[0][:parameters][:content] = latin1_string
puts "latin1_string.encoding: #{latin1_string.encoding}"
#puts "latin1_string: #{latin1_string}"
#puts "latin1_string.bytes: #{latin1_string.bytes}"
expect{compare_resources(res1, res2, show_resource_diff: true)}.not_to raise_error(ArgumentError)
diffs = compare_resources(res1, res2, show_resource_diff: true)
#puts "diffs: #{diffs}"
puts "diffs: #{diffs[:string_diffs]['file.foo'][3].bytes}"

ruby_default_replacement_string_for_invalid_characters = '�'

expect(diffs[:string_diffs]['file.foo'][3]).to \
eq("-\t content => \"" + ruby_default_replacement_string_for_invalid_characters + "\"")
end
Expand Down

0 comments on commit ab62f19

Please sign in to comment.