Skip to content

Commit 28d3231

Browse files
author
Kevin Paulisse
committed
Update YAML integration to use diff_match? check
1 parent e569ea9 commit 28d3231

2 files changed

Lines changed: 35 additions & 24 deletions

File tree

spec/octocatalog-diff/integration/yaml_diff_spec.rb

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,23 @@
2121
end
2222

2323
it 'should contain the "similar JSON" static file as a diff' do
24-
arr = @result.diffs
25-
answer = ['~', "File\f/tmp/static/similar-yaml.json\fparameters\fcontent"]
26-
expect(OctocatalogDiff::Spec.array_contains_partial_array?(arr, answer)).to eq(true)
24+
resource = { diff_type: '~', type: 'File', title: '/tmp/static/similar-yaml.json', structure: %w(parameters content) }
25+
expect(OctocatalogDiff::Spec.diff_match?(@result.diffs, resource)).to eq(true)
2726
end
2827

2928
it 'should contain the "similar YAML" static file as a diff' do
30-
arr = @result.diffs
31-
answer = ['~', "File\f/tmp/static/similar-yaml.yaml\fparameters\fcontent"]
32-
expect(OctocatalogDiff::Spec.array_contains_partial_array?(arr, answer)).to eq(true)
29+
resource = { diff_type: '~', type: 'File', title: '/tmp/static/similar-yaml.yaml', structure: %w(parameters content) }
30+
expect(OctocatalogDiff::Spec.diff_match?(@result.diffs, resource)).to eq(true)
3331
end
3432

3533
it 'should contain the "similar JSON" template file as a diff' do
36-
arr = @result.diffs
37-
answer = ['~', "File\f/tmp/template/similar-yaml.json\fparameters\fcontent"]
38-
expect(OctocatalogDiff::Spec.array_contains_partial_array?(arr, answer)).to eq(true)
34+
resource = { diff_type: '~', type: 'File', title: '/tmp/template/similar-yaml.json', structure: %w(parameters content) }
35+
expect(OctocatalogDiff::Spec.diff_match?(@result.diffs, resource)).to eq(true)
3936
end
4037

4138
it 'should contain the "similar YAML" template file as a diff' do
42-
arr = @result.diffs
43-
answer = ['~', "File\f/tmp/template/similar-yaml.yaml\fparameters\fcontent"]
44-
expect(OctocatalogDiff::Spec.array_contains_partial_array?(arr, answer)).to eq(true)
39+
resource = { diff_type: '~', type: 'File', title: '/tmp/template/similar-yaml.yaml', structure: %w(parameters content) }
40+
expect(OctocatalogDiff::Spec.diff_match?(@result.diffs, resource)).to eq(true)
4541
end
4642
end
4743

@@ -62,27 +58,23 @@
6258
end
6359

6460
it 'should contain the "similar JSON" static file as a diff' do
65-
arr = @result.diffs
66-
answer = ['~', "File\f/tmp/static/similar-yaml.json\fparameters\fcontent"]
67-
expect(OctocatalogDiff::Spec.array_contains_partial_array?(arr, answer)).to eq(true)
61+
resource = { diff_type: '~', type: 'File', title: '/tmp/static/similar-yaml.json', structure: %w(parameters content) }
62+
expect(OctocatalogDiff::Spec.diff_match?(@result.diffs, resource)).to eq(true)
6863
end
6964

7065
it 'should not contain the "similar YAML" static file as a diff' do
71-
arr = @result.diffs
72-
answer = ['~', "File\f/tmp/static/similar-yaml.yaml\fparameters\fcontent"]
73-
expect(OctocatalogDiff::Spec.array_contains_partial_array?(arr, answer)).to eq(false)
66+
resource = { diff_type: '~', type: 'File', title: '/tmp/static/similar-yaml.yaml', structure: %w(parameters content) }
67+
expect(OctocatalogDiff::Spec.diff_match?(@result.diffs, resource)).to eq(false)
7468
end
7569

7670
it 'should contain the "similar JSON" template file as a diff' do
77-
arr = @result.diffs
78-
answer = ['~', "File\f/tmp/template/similar-yaml.json\fparameters\fcontent"]
79-
expect(OctocatalogDiff::Spec.array_contains_partial_array?(arr, answer)).to eq(true)
71+
resource = { diff_type: '~', type: 'File', title: '/tmp/template/similar-yaml.json', structure: %w(parameters content) }
72+
expect(OctocatalogDiff::Spec.diff_match?(@result.diffs, resource)).to eq(true)
8073
end
8174

8275
it 'should not contain the "similar YAML" template file as a diff' do
83-
arr = @result.diffs
84-
answer = ['~', "File\f/tmp/template/similar-yaml.yaml\fparameters\fcontent"]
85-
expect(OctocatalogDiff::Spec.array_contains_partial_array?(arr, answer)).to eq(false)
76+
resource = { diff_type: '~', type: 'File', title: '/tmp/template/similar-yaml.yaml', structure: %w(parameters content) }
77+
expect(OctocatalogDiff::Spec.diff_match?(@result.diffs, resource)).to eq(false)
8678
end
8779
end
8880
end

spec/octocatalog-diff/tests/spec_helper.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,25 @@ def self.array_contains_partial_array?(subject, lookup)
122122
false
123123
end
124124

125+
# Determine if a OctocatalogDiff::API::V1::Diff (or an array of those) matches a lookup hash. This
126+
# returns true if the object (or any object in the array) matches all keys given in the lookup hash.
127+
# @param diff_in [OctocatalogDiff::API::V1::Diff or Array<OctocatalogDiff::API::V1::Diff>] diff(s) to search
128+
# @param lookup [Hash] Lookup hash
129+
def self.diff_match?(diff_in, lookup)
130+
diffs = [diff_in].flatten
131+
diffs.each do |diff|
132+
flag = true
133+
lookup.to_h.each do |key, val|
134+
unless diff.send(key) == val
135+
flag = false
136+
break
137+
end
138+
end
139+
return true if flag
140+
end
141+
false
142+
end
143+
125144
# Mock out a small shell script that tests for environment variable setting.
126145
# This takes the LAST command line argument, gets the value of that variable,
127146
# and prints it to STDERR.

0 commit comments

Comments
 (0)