Skip to content

Commit afd4d9c

Browse files
author
Kevin Paulisse
committed
Convert more integration tests to .diff_match?
1 parent f47c864 commit afd4d9c

3 files changed

Lines changed: 113 additions & 73 deletions

File tree

spec/octocatalog-diff/integration/convert_file_resources_spec.rb

Lines changed: 72 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,39 @@
2727
end
2828

2929
it 'should contain /tmp/foo1' do
30-
answer = ['~', "File\f/tmp/foo1\fparameters\fcontent", "content of foo-old\n", "content of foo-new\n"]
31-
expect(OctocatalogDiff::Spec.array_contains_partial_array?(@result[:diffs], answer)).to eq(true)
30+
resource = {
31+
diff_type: '~',
32+
type: 'File',
33+
title: '/tmp/foo1',
34+
structure: %w(parameters content),
35+
old_value: "content of foo-old\n",
36+
new_value: "content of foo-new\n"
37+
}
38+
expect(OctocatalogDiff::Spec.diff_match?(@result[:diffs], resource)).to eq(true)
3239
end
3340

3441
it 'should contain /tmp/binary1' do
35-
answer = [
36-
'~',
37-
"File\f/tmp/binary1\fparameters\fcontent",
38-
'{md5}e0897d525d5d600a037622b62fc99a4c',
39-
'{md5}97918b387001eb04ae7cb20b13e07f43'
40-
]
41-
expect(OctocatalogDiff::Spec.array_contains_partial_array?(@result[:diffs], answer)).to eq(true)
42+
resource = {
43+
diff_type: '~',
44+
type: 'File',
45+
title: '/tmp/binary1',
46+
structure: %w(parameters content),
47+
old_value: '{md5}e0897d525d5d600a037622b62fc99a4c',
48+
new_value: '{md5}97918b387001eb04ae7cb20b13e07f43'
49+
}
50+
expect(OctocatalogDiff::Spec.diff_match?(@result[:diffs], resource)).to eq(true)
4251
end
4352

4453
it 'should contain /tmp/bar2' do
45-
answer = ['~', "File\f/tmp/bar2\fparameters\fcontent", "content of bar\n", "content of new-bar\n"]
46-
expect(OctocatalogDiff::Spec.array_contains_partial_array?(@result[:diffs], answer)).to eq(true)
54+
resource = {
55+
diff_type: '~',
56+
type: 'File',
57+
title: '/tmp/bar2',
58+
structure: %w(parameters content),
59+
old_value: "content of bar\n",
60+
new_value: "content of new-bar\n"
61+
}
62+
expect(OctocatalogDiff::Spec.diff_match?(@result[:diffs], resource)).to eq(true)
4763
end
4864
end
4965

@@ -71,38 +87,63 @@
7187
end
7288

7389
it 'should contain /tmp/binary1' do
74-
answer = [
75-
'~',
76-
"File\f/tmp/binary1\fparameters\fsource",
77-
'puppet:///modules/test/binary-old',
78-
'puppet:///modules/test/binary-new'
79-
]
80-
expect(OctocatalogDiff::Spec.array_contains_partial_array?(@result[:diffs], answer)).to eq(true)
90+
resource = {
91+
diff_type: '~',
92+
type: 'File',
93+
title: '/tmp/binary1',
94+
structure: %w(parameters source),
95+
old_value: 'puppet:///modules/test/binary-old',
96+
new_value: 'puppet:///modules/test/binary-new'
97+
}
98+
expect(OctocatalogDiff::Spec.diff_match?(@result[:diffs], resource)).to eq(true)
8199
end
82100

83101
it 'should contain /tmp/binary3' do
84-
answer = [
85-
'~',
86-
"File\f/tmp/binary3\fparameters\fsource",
87-
'puppet:///modules/test/binary-old',
88-
'puppet:///modules/test/binary-old2'
89-
]
90-
expect(OctocatalogDiff::Spec.array_contains_partial_array?(@result[:diffs], answer)).to eq(true)
102+
resource = {
103+
diff_type: '~',
104+
type: 'File',
105+
title: '/tmp/binary3',
106+
structure: %w(parameters source),
107+
old_value: 'puppet:///modules/test/binary-old',
108+
new_value: 'puppet:///modules/test/binary-old2'
109+
}
110+
expect(OctocatalogDiff::Spec.diff_match?(@result[:diffs], resource)).to eq(true)
91111
end
92112

93113
it 'should contain /tmp/foo1' do
94-
answer = ['~', "File\f/tmp/foo1\fparameters\fsource", 'puppet:///modules/test/foo-old', 'puppet:///modules/test/foo-new']
95-
expect(OctocatalogDiff::Spec.array_contains_partial_array?(@result[:diffs], answer)).to eq(true)
114+
resource = {
115+
diff_type: '~',
116+
type: 'File',
117+
title: '/tmp/foo1',
118+
structure: %w(parameters source),
119+
old_value: 'puppet:///modules/test/foo-old',
120+
new_value: 'puppet:///modules/test/foo-new'
121+
}
122+
expect(OctocatalogDiff::Spec.diff_match?(@result[:diffs], resource)).to eq(true)
96123
end
97124

98125
it 'should contain /tmp/bar content' do
99-
answer = ['!', "File\f/tmp/bar\fparameters\fcontent", nil, "content of bar\n"]
100-
expect(OctocatalogDiff::Spec.array_contains_partial_array?(@result[:diffs], answer)).to eq(true)
126+
resource = {
127+
diff_type: '!',
128+
type: 'File',
129+
title: '/tmp/bar',
130+
structure: %w(parameters content),
131+
old_value: nil,
132+
new_value: "content of bar\n"
133+
}
134+
expect(OctocatalogDiff::Spec.diff_match?(@result[:diffs], resource)).to eq(true)
101135
end
102136

103137
it 'should contain /tmp/bar source' do
104-
answer = ['!', "File\f/tmp/bar\fparameters\fsource", 'puppet:///modules/test/bar-old', nil]
105-
expect(OctocatalogDiff::Spec.array_contains_partial_array?(@result[:diffs], answer)).to eq(true)
138+
resource = {
139+
diff_type: '!',
140+
type: 'File',
141+
title: '/tmp/bar',
142+
structure: %w(parameters source),
143+
old_value: 'puppet:///modules/test/bar-old',
144+
new_value: nil
145+
}
146+
expect(OctocatalogDiff::Spec.diff_match?(@result[:diffs], resource)).to eq(true)
106147
end
107148
end
108149

spec/octocatalog-diff/integration/preserve_environments_spec.rb

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -151,35 +151,45 @@
151151
end
152152

153153
it 'should display proper diffs' do
154-
diffs = @result.diffs
155-
156-
expect(
157-
OctocatalogDiff::Spec.array_contains_partial_array?(
158-
diffs,
159-
['~', "File\f/tmp/bar\fparameters\fcontent", 'one', 'two']
160-
)
161-
).to eq(true)
162-
163-
expect(
164-
OctocatalogDiff::Spec.array_contains_partial_array?(
165-
diffs,
166-
['~', "File\f/tmp/bar\fparameters\fowner", 'one', 'two']
167-
)
168-
).to eq(true)
169-
170-
expect(
171-
OctocatalogDiff::Spec.array_contains_partial_array?(
172-
diffs,
173-
['~', "File\f/tmp/foo\fparameters\fcontent", 'one', 'two']
174-
)
175-
).to eq(true)
176-
177-
expect(
178-
OctocatalogDiff::Spec.array_contains_partial_array?(
179-
diffs,
180-
['~', "File\f/tmp/sitetest\fparameters\fcontent", 'one', 'two']
181-
)
182-
).to eq(true)
154+
resource = {
155+
diff_type: '~',
156+
type: 'File',
157+
title: '/tmp/bar',
158+
structure: %w(parameters content),
159+
old_value: 'one',
160+
new_value: 'two'
161+
}
162+
expect(OctocatalogDiff::Spec.diff_match?(@result[:diffs], resource)).to eq(true)
163+
164+
resource = {
165+
diff_type: '~',
166+
type: 'File',
167+
title: '/tmp/bar',
168+
structure: %w(parameters owner),
169+
old_value: 'one',
170+
new_value: 'two'
171+
}
172+
expect(OctocatalogDiff::Spec.diff_match?(@result[:diffs], resource)).to eq(true)
173+
174+
resource = {
175+
diff_type: '~',
176+
type: 'File',
177+
title: '/tmp/foo',
178+
structure: %w(parameters content),
179+
old_value: 'one',
180+
new_value: 'two'
181+
}
182+
expect(OctocatalogDiff::Spec.diff_match?(@result[:diffs], resource)).to eq(true)
183+
184+
resource = {
185+
diff_type: '~',
186+
type: 'File',
187+
title: '/tmp/sitetest',
188+
structure: %w(parameters content),
189+
old_value: 'one',
190+
new_value: 'two'
191+
}
192+
expect(OctocatalogDiff::Spec.diff_match?(@result[:diffs], resource)).to eq(true)
183193
end
184194

185195
it 'should handle hieradata properly' do

spec/octocatalog-diff/integration/reference_validation_spec.rb

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -255,19 +255,8 @@ def self.catalog_contains_resource(result, type, title)
255255
diffs = @result.diffs
256256
expect(diffs).to be_a_kind_of(Array)
257257
expect(diffs.size).to eq(1)
258-
259-
answer = [
260-
'-',
261-
"Exec\fbefore caller",
262-
{
263-
'type' => 'Exec',
264-
'title' => 'before caller',
265-
'tags' => ['before_callers', 'class', 'default', 'exec', 'node', 'test', 'test::before_callers'],
266-
'exported' => false,
267-
'parameters' => { 'command' => '/bin/true' }
268-
}
269-
]
270-
expect(OctocatalogDiff::Spec.array_contains_partial_array?(diffs, answer)).to eq(true)
258+
resource = { diff_type: '-', type: 'Exec', title: 'before caller' }
259+
expect(OctocatalogDiff::Spec.diff_match?(@result[:diffs], resource)).to eq(true)
271260
end
272261
end
273262

0 commit comments

Comments
 (0)