Skip to content

Commit 3f3c654

Browse files
authored
Merge pull request #125 from github/kpaulisse-datatype-regression
Fix datatype regression for fixnums vs. integers
2 parents d1f8b62 + 88a3c91 commit 3f3c654

File tree

5 files changed

+76
-14
lines changed

5 files changed

+76
-14
lines changed

lib/octocatalog-diff/catalog-diff/differ.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
require_relative '../catalog'
1010
require_relative '../errors'
11+
require_relative '../util/util'
1112
require_relative 'filter'
1213

1314
module OctocatalogDiff
@@ -530,7 +531,8 @@ def hashdiff_initial(catalog1_in, catalog2_in)
530531

531532
# Added a new key that points to some kind of data structure that we know how
532533
# to handle.
533-
if obj[1] =~ /^(.+)\f([^\f]+)$/ && [String, Integer, Float, TrueClass, FalseClass, Array, Hash].include?(obj[2].class)
534+
classes = [String, Integer, Float, TrueClass, FalseClass, Array, Hash]
535+
if obj[1] =~ /^(.+)\f([^\f]+)$/ && OctocatalogDiff::Util::Util.object_is_any_of?(obj[2], classes)
534536
hashdiff_add_remove.add(obj[1])
535537
next
536538
end

lib/octocatalog-diff/catalog-diff/display/text.rb

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# frozen_string_literal: true
22

33
require_relative '../display'
4-
require_relative '../../util/colored.rb'
4+
require_relative '../../util/colored'
5+
require_relative '../../util/util'
56

67
require 'diffy'
78
require 'json'
@@ -447,26 +448,16 @@ def self.class_name_for_diffy(class_name)
447448
class_name
448449
end
449450

450-
# Utility Method!
451-
# `is_a?(class)` only allows one method, but this uses an array
452-
# @param object [?] Object to consider
453-
# @param classes [Array] Classes to determine if object is a member of
454-
# @return [Boolean] True if object is_a any of the classes, false otherwise
455-
def self.object_is_any_of?(object, classes)
456-
classes.each { |clazz| return true if object.is_a? clazz }
457-
false
458-
end
459-
460451
# Utility Method!
461452
# Given an arbitrary object, convert it into a string for use by 'diffy'.
462453
# This basically exists so we can do something prettier than just calling .inspect or .to_s
463454
# on object types we anticipate seeing, while not failing entirely on other object types.
464455
# @param obj [?] Object to be stringified
465456
# @return [String] String representation of object for diffy
466457
def self.stringify_for_diffy(obj)
467-
return JSON.pretty_generate(obj) if object_is_any_of?(obj, [Hash, Array])
458+
return JSON.pretty_generate(obj) if OctocatalogDiff::Util::Util.object_is_any_of?(obj, [Hash, Array])
468459
return '""' if obj.is_a?(String) && obj == ''
469-
return obj if object_is_any_of?(obj, [String, Fixnum, Integer, Float])
460+
return obj if OctocatalogDiff::Util::Util.object_is_any_of?(obj, [String, Fixnum, Integer, Float])
470461
"#{class_name_for_diffy(obj.class)}: #{obj.inspect}"
471462
end
472463

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"document_type": "Catalog",
3+
"data": {
4+
"name": "octoawesome-fe-00decaf.example.com",
5+
"version": "",
6+
"environment": "production",
7+
"resources": [
8+
{
9+
"type": "Special",
10+
"title": "My::Silly::Class",
11+
"tags": [
12+
"class",
13+
"my::silly::class",
14+
"my",
15+
"silly",
16+
"class"
17+
],
18+
"exported": false,
19+
"parameters": {
20+
"number_one": 7199,
21+
"number_two": 2181
22+
}
23+
}
24+
]
25+
}
26+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"document_type": "Catalog",
3+
"data": {
4+
"name": "octoawesome-fe-00decaf.example.com",
5+
"version": "",
6+
"environment": "production",
7+
"resources": [
8+
{
9+
"type": "Special",
10+
"title": "My::Silly::Class",
11+
"tags": [
12+
"class",
13+
"my::silly::class",
14+
"my",
15+
"silly",
16+
"class"
17+
],
18+
"exported": false,
19+
"parameters": {
20+
"number_one": 7199,
21+
"number_two": 2181,
22+
"number_three": 1234,
23+
"string": "boom"
24+
}
25+
}
26+
]
27+
}
28+
}

spec/octocatalog-diff/integration/regressions_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,18 @@
2525
expect(@result[:diffs].size).to eq(0), @result[:diffs].map(&:inspect).join("\n")
2626
end
2727
end
28+
29+
describe 'resource with Fixnum parameters added' do
30+
before(:all) do
31+
@result = OctocatalogDiff::Integration.integration(
32+
from_catalog: OctocatalogDiff::Spec.fixture_path('catalogs/regression-fixnum-1.json'),
33+
to_catalog: OctocatalogDiff::Spec.fixture_path('catalogs/regression-fixnum-2.json')
34+
)
35+
end
36+
37+
it 'should run without an error' do
38+
expect(@result[:exitcode]).not_to eq(-1), "Internal error: #{OctocatalogDiff::Integration.format_exception(@result)}"
39+
expect(@result[:exitcode]).to eq(2), "Runtime error: #{@result[:logs]}"
40+
expect(@result[:diffs].size).to eq(2), @result[:diffs].map(&:inspect).join("\n")
41+
end
42+
end

0 commit comments

Comments
 (0)