Skip to content

Commit db95215

Browse files
committed
Add integration test for filtering single-item arrays
1 parent 4cb164a commit db95215

File tree

3 files changed

+210
-0
lines changed

3 files changed

+210
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"document_type": "Catalog",
3+
"data": {
4+
"tags": [
5+
"settings"
6+
],
7+
"name": "my.rspec.node",
8+
"version": "production",
9+
"environment": "production",
10+
"resources": [
11+
{
12+
"type": "File",
13+
"title": "/tmp/amazing",
14+
"file": "/environments/production/modules/foo/manifests/init.pp",
15+
"line": 10,
16+
"exported": false,
17+
"parameters": {
18+
"content": "This is my file.\nMy file is amazing.\n",
19+
"group": "root",
20+
"mode": "0755",
21+
"notify": "Service[foo]",
22+
"owner": "root"
23+
}
24+
},
25+
{
26+
"type": "File",
27+
"title": "/tmp/awesome",
28+
"file": "/environments/production/modules/foo/manifests/init.pp",
29+
"line": 20,
30+
"exported": false,
31+
"parameters": {
32+
"content": "This is my file.\nMy file is awesome.\n",
33+
"group": "root",
34+
"mode": "0755",
35+
"notify": [
36+
"Service[foo]",
37+
"Service[bar]"
38+
],
39+
"owner": "root"
40+
}
41+
},
42+
{
43+
"type": "File",
44+
"title": "/tmp/fizzbuzz",
45+
"file": "/environments/production/modules/foo/manifests/init.pp",
46+
"line": 30,
47+
"exported": false,
48+
"parameters": {
49+
"content": "1\n2\nfizz\n4\nbuzz\nfizz\n7\n8\nfizz\nbuzz\n",
50+
"group": "root",
51+
"mode": "0755",
52+
"owner": "root"
53+
}
54+
},
55+
{
56+
"type": "File",
57+
"title": "/tmp/foobar",
58+
"file": "/environments/production/modules/foo/manifests/init.pp",
59+
"line": 40,
60+
"exported": false,
61+
"parameters": {
62+
"content": "foo\nbar\n",
63+
"group": "root",
64+
"mode": "0755",
65+
"owner": "root",
66+
"notify": "Service[foobar]"
67+
}
68+
}
69+
],
70+
"classes": [
71+
"settings"
72+
]
73+
},
74+
"metadata": {
75+
"api_version": 1
76+
}
77+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"document_type": "Catalog",
3+
"data": {
4+
"tags": [
5+
"settings"
6+
],
7+
"name": "my.rspec.node",
8+
"version": "production",
9+
"environment": "production",
10+
"resources": [
11+
{
12+
"type": "File",
13+
"title": "/tmp/amazing",
14+
"file": "/environments/production/modules/foo/manifests/init.pp",
15+
"line": 10,
16+
"exported": false,
17+
"parameters": {
18+
"content": "This is my file.\nMy file is amazing.\n",
19+
"group": "root",
20+
"mode": "0755",
21+
"notify": [
22+
"Service[foo]"
23+
],
24+
"owner": "root"
25+
}
26+
},
27+
{
28+
"type": "File",
29+
"title": "/tmp/awesome",
30+
"file": "/environments/production/modules/foo/manifests/init.pp",
31+
"line": 20,
32+
"exported": false,
33+
"parameters": {
34+
"content": "This is my file.\nMy file is awesome.\n",
35+
"group": "root",
36+
"mode": "0755",
37+
"notify": [
38+
"Service[foo]",
39+
"Service[baz]"
40+
],
41+
"owner": "root"
42+
}
43+
},
44+
{
45+
"type": "File",
46+
"title": "/tmp/fizzbuzz",
47+
"file": "/environments/production/modules/foo/manifests/init.pp",
48+
"line": 30,
49+
"exported": false,
50+
"parameters": {
51+
"content": "1\n2\nfizz\n4\nbuzz\nfizz\n7\n8\nfizz\nbuzz\n",
52+
"group": "root",
53+
"mode": "0755",
54+
"owner": "root",
55+
"notify": [
56+
"Service[fizzbuzz]"
57+
]
58+
}
59+
},
60+
{
61+
"type": "File",
62+
"title": "/tmp/foobar",
63+
"file": "/environments/production/modules/foo/manifests/init.pp",
64+
"line": 40,
65+
"exported": false,
66+
"parameters": {
67+
"content": "foo\nbar\n",
68+
"group": "root",
69+
"mode": "0755",
70+
"owner": "root",
71+
"notify": [
72+
"Service[fizzbuzz]",
73+
"Service[foobar]"
74+
]
75+
}
76+
}
77+
],
78+
"classes": [
79+
"settings"
80+
]
81+
},
82+
"metadata": {
83+
"api_version": 1
84+
}
85+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# frozen_string_literal: true
2+
3+
require_relative 'integration_helper'
4+
5+
describe 'filter single-item arrays' do
6+
context 'with default behavior' do
7+
before(:all) do
8+
@result = OctocatalogDiff::Integration.integration(
9+
spec_catalog_old: 'filter-single-item-array-1.json',
10+
spec_catalog_new: 'filter-single-item-array-2.json'
11+
)
12+
@diffs = OctocatalogDiff::Spec.remove_file_and_line(@result[:diffs])
13+
end
14+
15+
it 'should succeed' do
16+
expect(@result[:exitcode]).not_to eq(-1), "Internal error: #{@result[:exception]}\n#{@result[:logs]}"
17+
expect(@result[:exitcode]).to eq(2), "Runtime error: #{@result[:logs]}"
18+
end
19+
20+
it 'should contain the correct number of diffs' do
21+
expect(@diffs.size).to eq(4), @diffs.inspect
22+
end
23+
24+
it 'should contain a diff of a string to a single-item array' do
25+
expect(@diffs).to include(
26+
['~', "File\f/tmp/amazing\fparameters\fnotify", 'Service[foo]', ['Service[foo]']]
27+
)
28+
end
29+
30+
it 'should contain a diff of an array whose size has changed' do
31+
expect(@diffs).to include(
32+
['~', "File\f/tmp/foobar\fparameters\fnotify", 'Service[foobar]', ['Service[fizzbuzz]', 'Service[foobar]']]
33+
)
34+
end
35+
36+
it 'should contain a diff of an array whose elements have changed' do
37+
expect(@diffs).to include(
38+
['!', "File\f/tmp/awesome\fparameters\fnotify", ['Service[bar]', 'Service[foo]'], ['Service[baz]', 'Service[foo]']]
39+
)
40+
end
41+
42+
it 'should contain a diff of an array that has been added' do
43+
expect(@diffs).to include(
44+
['!', "File\f/tmp/fizzbuzz\fparameters\fnotify", nil, ['Service[fizzbuzz]']]
45+
)
46+
end
47+
end
48+
end

0 commit comments

Comments
 (0)