Skip to content

Commit c42b8af

Browse files
authored
Merge pull request #105 from github/kpaulisse-fix-ignore-tags
Remove legacy exclusion of tags
2 parents 4babf7f + d3ef92a commit c42b8af

File tree

5 files changed

+233
-5
lines changed

5 files changed

+233
-5
lines changed

doc/advanced-dynamic-ignores.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Using the `--ignore-tags` command line option, it is possible to ignore all resources with particular Puppet tags. This allows dynamic ignoring of wrappers or other resources that are not of interest.
44

5+
NOTE: This option is separate and distinct from `--include-tags`, which controls whether differences in tags themselves will appear as a difference. For more on `--include-tags`, consult the [options reference](/doc/optionsref.md).
6+
57
## Getting Started
68

79
To use ignored tags, you first need to decide what the name of your tag will be. The standard is `ignored_octocatalog_diff`.

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,8 @@ def filter_and_cleanup(catalog_resources)
266266
hsh[k] = cleansed_param unless cleansed_param.nil? || cleansed_param.empty?
267267
elsif k == 'tags'
268268
# The order of tags is unimportant. Sort this array to avoid false diffs if order changes.
269-
# Also if tags is empty, don't add. Most uses of catalog diff will want to ignore tags,
270-
# and if you're ignoring tags you won't get here anyway. Also, don't add empty array of tags.
271-
unless @opts[:ignore_tags]
272-
hsh[k] = v.sort if v.is_a?(Array) && v.any?
273-
end
269+
# Also if tags is empty, don't add.
270+
hsh[k] = v.sort if v.is_a?(Array) && v.any?
274271
elsif k == 'file' || k == 'line'
275272
# We don't care, for the purposes of catalog-diff, from which manifest and line this resource originated.
276273
# However, we may report this to the user, so we will keep it in here for now.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"document_type": "Catalog",
3+
"data": {
4+
"tags": ["settings"],
5+
"name": "my.rspec.node",
6+
"version": "production",
7+
"environment": "production",
8+
"resources": [
9+
{
10+
"type": "Stage",
11+
"title": "main",
12+
"tags": ["stage"],
13+
"exported": false,
14+
"parameters": {
15+
"name": "main"
16+
}
17+
},
18+
{
19+
"type": "Class",
20+
"title": "Settings",
21+
"tags": ["class","settings"],
22+
"exported": false
23+
},
24+
{
25+
"type": "File",
26+
"title": "/tmp/foo",
27+
"tags": ["tag-one-new","tag-too","ignore-tag__file"],
28+
"parameters": {
29+
"content": "foofoo",
30+
"owner": "root"
31+
}
32+
}
33+
],
34+
"classes": [
35+
"settings"
36+
]
37+
},
38+
"metadata": {
39+
"api_version": 1
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"document_type": "Catalog",
3+
"data": {
4+
"tags": ["settings"],
5+
"name": "my.rspec.node",
6+
"version": "production",
7+
"environment": "production",
8+
"resources": [
9+
{
10+
"type": "Stage",
11+
"title": "main",
12+
"tags": ["stage"],
13+
"exported": false,
14+
"parameters": {
15+
"name": "main"
16+
}
17+
},
18+
{
19+
"type": "Class",
20+
"title": "Settings",
21+
"tags": ["class","settings"],
22+
"exported": false
23+
},
24+
{
25+
"type": "File",
26+
"title": "/tmp/foo",
27+
"tags": ["tag-one","tag-two"],
28+
"parameters": {
29+
"content": "foofoo",
30+
"owner": "root"
31+
}
32+
}
33+
],
34+
"classes": [
35+
"settings"
36+
]
37+
},
38+
"metadata": {
39+
"api_version": 1
40+
}
41+
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# frozen_string_literal: true
2+
3+
require_relative 'integration_helper'
4+
require 'json'
5+
6+
describe 'include-tags integration' do
7+
let(:default_argv) do
8+
[
9+
'--from-catalog', OctocatalogDiff::Spec.fixture_path('catalogs/include-tags-old.json'),
10+
'--to-catalog', OctocatalogDiff::Spec.fixture_path('catalogs/include-tags-new.json')
11+
]
12+
end
13+
14+
context 'with --include-tags specified' do
15+
let(:argv) do
16+
default_argv.concat ['--include-tags']
17+
end
18+
19+
let(:result) do
20+
OctocatalogDiff::Integration.integration(
21+
argv: argv
22+
)
23+
end
24+
25+
it 'should exit indicating success with differences' do
26+
expect(result.exitcode).to eq(2)
27+
end
28+
29+
it 'should contain representative tag differences' do
30+
diffs = result.diffs
31+
expect(diffs.size).to eq(1)
32+
expect(diffs.first.change?).to eq(true)
33+
expect(diffs.first.structure).to eq(['tags'])
34+
expect(diffs.first.old_value).to eq(['tag-one', 'tag-two'])
35+
expect(diffs.first.new_value).to eq(['ignore-tag__file', 'tag-one-new', 'tag-too'])
36+
end
37+
end
38+
39+
context 'with --no-include-tags specified' do
40+
let(:argv) do
41+
default_argv.concat ['--no-include-tags']
42+
end
43+
44+
let(:result) do
45+
OctocatalogDiff::Integration.integration(
46+
argv: argv
47+
)
48+
end
49+
50+
it 'should exit indicating success with no differences' do
51+
expect(result.exitcode).to eq(0)
52+
end
53+
54+
it 'should contain representative tag differences' do
55+
diffs = result.diffs
56+
expect(diffs.size).to eq(0)
57+
end
58+
end
59+
60+
context 'with --include-tags not specified' do
61+
let(:argv) do
62+
default_argv
63+
end
64+
65+
let(:result) do
66+
OctocatalogDiff::Integration.integration(
67+
argv: argv
68+
)
69+
end
70+
71+
it 'should exit indicating success with no differences' do
72+
expect(result.exitcode).to eq(0)
73+
end
74+
75+
it 'should contain representative tag differences' do
76+
diffs = result.diffs
77+
expect(diffs.size).to eq(0)
78+
end
79+
end
80+
81+
context 'with --ignore-tags and --include-tags specified' do
82+
let(:argv) do
83+
default_argv.concat ['--include-tags', '--ignore-tags', 'foo']
84+
end
85+
86+
let(:result) do
87+
OctocatalogDiff::Integration.integration(
88+
argv: argv
89+
)
90+
end
91+
92+
it 'should exit indicating success with differences' do
93+
expect(result.exitcode).to eq(2)
94+
end
95+
96+
it 'should contain representative tag differences' do
97+
diffs = result.diffs
98+
expect(diffs.size).to eq(1)
99+
expect(diffs.first.change?).to eq(true)
100+
expect(diffs.first.structure).to eq(['tags'])
101+
expect(diffs.first.old_value).to eq(['tag-one', 'tag-two'])
102+
expect(diffs.first.new_value).to eq(['ignore-tag__file', 'tag-one-new', 'tag-too'])
103+
end
104+
end
105+
106+
context 'with --ignore-tags and --no-include-tags specified' do
107+
let(:argv) do
108+
default_argv.concat ['--no-include-tags', '--ignore-tags', 'foo']
109+
end
110+
111+
let(:result) do
112+
OctocatalogDiff::Integration.integration(
113+
argv: argv
114+
)
115+
end
116+
117+
it 'should exit indicating success with no differences' do
118+
expect(result.exitcode).to eq(0)
119+
end
120+
121+
it 'should contain representative tag differences' do
122+
diffs = result.diffs
123+
expect(diffs.size).to eq(0)
124+
end
125+
end
126+
127+
context 'with matching --ignore-tags and --include-tags specified' do
128+
let(:argv) do
129+
default_argv.concat ['--include-tags', '--ignore-tags', 'ignore-tag']
130+
end
131+
132+
let(:result) do
133+
OctocatalogDiff::Integration.integration(
134+
argv: argv
135+
)
136+
end
137+
138+
it 'should exit indicating success with no differences' do
139+
expect(result.exitcode).to eq(0)
140+
end
141+
142+
it 'should contain representative tag differences' do
143+
diffs = result.diffs
144+
expect(diffs.size).to eq(0)
145+
end
146+
end
147+
end

0 commit comments

Comments
 (0)