Skip to content

Commit aa4d306

Browse files
author
Kevin Paulisse
committed
Write --to-enc-override and --from-enc-override
1 parent 6fc6d52 commit aa4d306

2 files changed

Lines changed: 119 additions & 0 deletions

File tree

spec/octocatalog-diff/integration/enc_override_spec.rb

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,124 @@
8787
end
8888

8989
describe 'ENC override integration with --to-enc-override' do
90+
before(:all) do
91+
@result = OctocatalogDiff::Integration.integration(
92+
spec_repo: 'enc-overrides',
93+
spec_fact_file: 'valid-facts.yaml',
94+
hiera_config: 'hiera.yaml',
95+
hiera_path: 'hieradata',
96+
argv: [
97+
'--no-parallel',
98+
'--enc',
99+
OctocatalogDiff::Spec.fixture_path('repos/enc-overrides/enc.sh'),
100+
'--to-enc-override', 'role=two'
101+
]
102+
)
103+
end
104+
105+
it 'should succeed' do
106+
expect(@result.exitcode).not_to eq(-1), OctocatalogDiff::Integration.format_exception(@result)
107+
expect(@result.exitcode).to eq(2), "Runtime error: #{@result.logs}"
108+
end
109+
110+
it 'should show expected changes' do
111+
diffs = @result.diffs.map { |x| OctocatalogDiff::Spec.remove_file_and_line(x) }
112+
expect(diffs).to include(
113+
diff_type: '~',
114+
type: 'File',
115+
title: '/tmp/one',
116+
structure: %w(parameters content),
117+
old_value: 'one',
118+
new_value: 'two'
119+
)
120+
expect(diffs).to include(
121+
diff_type: '~',
122+
type: 'File',
123+
title: '/tmp/two',
124+
structure: %w(parameters content),
125+
old_value: 'one',
126+
new_value: 'two'
127+
)
128+
end
129+
130+
it 'should log proper messages' do
131+
expect(@result.log_messages).to include('DEBUG - ENC override: role = "two"')
132+
end
90133
end
91134

92135
describe 'ENC override integration with --from-enc-override' do
136+
before(:all) do
137+
@result = OctocatalogDiff::Integration.integration(
138+
spec_repo: 'enc-overrides',
139+
spec_fact_file: 'valid-facts.yaml',
140+
hiera_config: 'hiera.yaml',
141+
hiera_path: 'hieradata',
142+
argv: [
143+
'--no-parallel',
144+
'--enc',
145+
OctocatalogDiff::Spec.fixture_path('repos/enc-overrides/enc.sh'),
146+
'--from-enc-override', 'role=two'
147+
]
148+
)
149+
end
150+
151+
it 'should succeed' do
152+
expect(@result.exitcode).not_to eq(-1), OctocatalogDiff::Integration.format_exception(@result)
153+
expect(@result.exitcode).to eq(2), "Runtime error: #{@result.logs}"
154+
end
155+
156+
it 'should show expected changes' do
157+
diffs = @result.diffs.map { |x| OctocatalogDiff::Spec.remove_file_and_line(x) }
158+
expect(diffs).to include(
159+
diff_type: '~',
160+
type: 'File',
161+
title: '/tmp/one',
162+
structure: %w(parameters content),
163+
old_value: 'two',
164+
new_value: 'one'
165+
)
166+
expect(diffs).to include(
167+
diff_type: '~',
168+
type: 'File',
169+
title: '/tmp/two',
170+
structure: %w(parameters content),
171+
old_value: 'two',
172+
new_value: 'one'
173+
)
174+
end
175+
176+
it 'should log proper messages' do
177+
expect(@result.log_messages).to include('DEBUG - ENC override: role = "two"')
178+
end
93179
end
94180

95181
describe 'ENC override integration with catalog compilation only' do
182+
before(:all) do
183+
@result = OctocatalogDiff::Integration.integration(
184+
spec_repo: 'enc-overrides',
185+
spec_fact_file: 'valid-facts.yaml',
186+
hiera_config: 'hiera.yaml',
187+
hiera_path: 'hieradata',
188+
argv: [
189+
'--no-parallel',
190+
'--enc',
191+
OctocatalogDiff::Spec.fixture_path('repos/enc-overrides/enc.sh'),
192+
'--enc-override', 'role=two',
193+
'--catalog-only'
194+
]
195+
)
196+
end
197+
198+
it 'should succeed' do
199+
expect(@result.exitcode).not_to eq(-1), OctocatalogDiff::Integration.format_exception(@result)
200+
expect(@result.exitcode).to eq(0), "Runtime error: #{@result.logs}"
201+
end
202+
203+
it 'should show no changes' do
204+
expect(@result.to).to eq([])
205+
end
206+
207+
it 'should log proper messages' do
208+
expect(@result.log_messages).to include('DEBUG - ENC override: role = "two"')
209+
end
96210
end

spec/octocatalog-diff/tests/spec_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ def self.setup_logger
217217
# remove the file and line locations. This takes the JSON result from catalog-diff and returns
218218
# a cleaned-up array of diffs.
219219
def self.remove_file_and_line(diff)
220+
if diff.is_a?(OctocatalogDiff::API::V1::Diff)
221+
result = diff.to_h.dup
222+
%w(new_location old_location new_line old_line new_file old_file).each { |x| result.delete(x.to_sym) }
223+
return result
224+
end
220225
if diff.is_a?(Hash)
221226
result = diff.dup
222227
%w(new_location old_location new_line old_line new_file old_file).each { |x| result.delete(x) }

0 commit comments

Comments
 (0)