Skip to content

Commit eb1c2c5

Browse files
committed
Add integration test for array of sources
1 parent 38d824f commit eb1c2c5

File tree

9 files changed

+155
-2
lines changed

9 files changed

+155
-2
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
node default {
2-
include test
2+
if $::test_class {
3+
include "test::${::test_class}"
4+
} else {
5+
include test
6+
}
37
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class test::array1 {
2+
file { '/tmp/foo':
3+
source => [
4+
'puppet:///modules/test/foo-new',
5+
'puppet:///modules/test/foo-old',
6+
]
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class test::array2 {
2+
file { '/tmp/foo':
3+
source => [
4+
'puppet:///modules/test/foo-bar',
5+
'puppet:///modules/test/foo-new',
6+
]
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class test::array3 {
2+
file { '/tmp/foo':
3+
source => [
4+
'puppet:///modules/test/foo-bar',
5+
'puppet:///modules/test/foo-baz',
6+
]
7+
}
8+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
node default {
2-
include test
2+
if $::test_class {
3+
include "test::${::test_class}"
4+
} else {
5+
include test
6+
}
37
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class test::array1 {
2+
file { '/tmp/foo':
3+
source => [
4+
'puppet:///modules/test/foo-new',
5+
'puppet:///modules/test/foo-old',
6+
]
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class test::array2 {
2+
file { '/tmp/foo':
3+
source => [
4+
'puppet:///modules/test/foo-bar',
5+
'puppet:///modules/test/foo-old',
6+
]
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class test::array3 {
2+
file { '/tmp/foo':
3+
source => [
4+
'puppet:///modules/test/foo-bar',
5+
'puppet:///modules/test/foo-baz',
6+
]
7+
}
8+
}

spec/octocatalog-diff/integration/convert_file_resources_spec.rb

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,101 @@
164164
expect(result[:exception].message).to match(%r{Unable to resolve 'puppet:///modules/test/foo-new'})
165165
end
166166
end
167+
168+
context 'when an array is used as the source and the first file is found' do
169+
before(:all) do
170+
@result = OctocatalogDiff::Integration.integration(
171+
spec_fact_file: 'facts.yaml',
172+
spec_repo_old: 'convert-resources/old',
173+
spec_repo_new: 'convert-resources/new',
174+
argv: [
175+
'-n', 'rspec-node.github.net',
176+
'--compare-file-text',
177+
'--fact-override', 'test_class=array1'
178+
]
179+
)
180+
end
181+
182+
it 'should compile the catalog' do
183+
expect(@result[:exitcode]).not_to eq(-1), OctocatalogDiff::Integration.format_exception(@result)
184+
expect(@result[:exitcode]).to eq(2), "Runtime error: #{@result[:logs]}"
185+
expect(@result[:diffs]).to be_a_kind_of(Array)
186+
end
187+
188+
it 'should contain the correct number of diffs' do
189+
expect(@result[:diffs].size).to eq(1)
190+
end
191+
192+
it 'should contain a change to the file' do
193+
resource = {
194+
diff_type: '~',
195+
type: 'File',
196+
title: '/tmp/foo',
197+
structure: %w(parameters content),
198+
old_value: "content of foo-old\n",
199+
new_value: "content of foo-new\n"
200+
}
201+
expect(OctocatalogDiff::Spec.diff_match?(@result[:diffs], resource)).to eq(true)
202+
end
203+
end
204+
205+
context 'when an array is used as the source and a later file is found' do
206+
before(:all) do
207+
@result = OctocatalogDiff::Integration.integration(
208+
spec_fact_file: 'facts.yaml',
209+
spec_repo_old: 'convert-resources/old',
210+
spec_repo_new: 'convert-resources/new',
211+
argv: [
212+
'-n', 'rspec-node.github.net',
213+
'--compare-file-text',
214+
'--fact-override', 'test_class=array2'
215+
]
216+
)
217+
end
218+
219+
it 'should compile the catalog' do
220+
expect(@result[:exitcode]).not_to eq(-1), OctocatalogDiff::Integration.format_exception(@result)
221+
expect(@result[:exitcode]).to eq(2), "Runtime error: #{@result[:logs]}"
222+
expect(@result[:diffs]).to be_a_kind_of(Array)
223+
end
224+
225+
it 'should contain the correct number of diffs' do
226+
expect(@result[:diffs].size).to eq(1)
227+
end
228+
229+
it 'should contain a change to the file' do
230+
resource = {
231+
diff_type: '~',
232+
type: 'File',
233+
title: '/tmp/foo',
234+
structure: %w(parameters content),
235+
old_value: "content of foo-old\n",
236+
new_value: "content of foo-new\n"
237+
}
238+
expect(OctocatalogDiff::Spec.diff_match?(@result[:diffs], resource)).to eq(true)
239+
end
240+
end
241+
242+
context 'when an array is used as the source and no file is found' do
243+
before(:all) do
244+
@result = OctocatalogDiff::Integration.integration(
245+
spec_fact_file: 'facts.yaml',
246+
spec_repo_old: 'convert-resources/old',
247+
spec_repo_new: 'convert-resources/new',
248+
argv: [
249+
'-n', 'rspec-node.github.net',
250+
'--compare-file-text',
251+
'--fact-override', 'test_class=array3'
252+
]
253+
)
254+
end
255+
256+
it 'should fail' do
257+
expect(@result[:exitcode]).to eq(-1)
258+
expect(@result[:exception]).to be_a_kind_of(OctocatalogDiff::Errors::CatalogError)
259+
expect(@result[:exception].message).to match(/Errno::ENOENT/)
260+
rexp = Regexp.new(Regexp.escape("Unable to resolve '[\"puppet:///modules/test/foo-bar\""))
261+
expect(@result[:exception].message).to match(rexp)
262+
end
263+
end
167264
end

0 commit comments

Comments
 (0)