11# frozen_string_literal: true
22
3+ # Note: Puppet 5.0.0 and higher have reference checking built in and enabled, so the octocatalog-diff
4+ # reference checking functionality is disabled. In the gem's CI build, we test with different Puppet
5+ # versions, so there are conditionals here so that this test passes under all supported versions.
6+
37require_relative 'integration_helper'
48require 'json'
59
@@ -98,21 +102,32 @@ def self.catalog_contains_resource(result, type, title)
98102 expect ( @result . exitcode ) . to eq ( -1 ) , OctocatalogDiff ::Integration . format_exception ( @result )
99103 end
100104
101- it 'should raise ReferenceValidationError' do
102- expect ( @result . exception ) . to be_a_kind_of ( OctocatalogDiff ::Errors ::ReferenceValidationError )
103- end
104-
105- # Multiple line numbers given because Puppet 4.x and 3.8 correspond to first and last line of resource, respectively.
106- # rubocop:disable Metrics/LineLength
107- it 'should have formatted error messages' do
108- msg = @result . exception . message
109- expect ( msg ) . to match ( %r{exec\[ subscribe caller 1\] \( modules/test/manifests/subscribe_callers.pp:(2|5)\) -> subscribe\[ Exec\[ subscribe target\] \] } )
110- expect ( msg ) . to match ( %r{exec\[ subscribe caller 2\] \( modules/test/manifests/subscribe_callers.pp:(7|13)\) -> subscribe\[ Exec\[ subscribe target\] \] } )
111- expect ( msg ) . to match ( %r{exec\[ subscribe caller 2\] \( modules/test/manifests/subscribe_callers.pp:(7|13)\) -> subscribe\[ Exec\[ subscribe target 2\] \] } )
112- expect ( msg ) . to match ( %r{exec\[ subscribe caller 3\] \( modules/test/manifests/subscribe_callers.pp:(15|21)\) -> subscribe\[ Exec\[ subscribe target\] \] } )
113- expect ( msg ) . not_to match ( /exec\[ subscribe caller 3\] .+subscribe\[ Exec\[ subscribe caller 1\] \] / )
105+ if OctocatalogDiff ::Spec . is_puppet5?
106+ it 'should raise CatalogError' do
107+ expect ( @result . exception ) . to be_a_kind_of ( OctocatalogDiff ::Errors ::CatalogError )
108+ end
109+
110+ it 'should pass through the error messages from Puppet' do
111+ msg = @result . exception . message
112+ expect ( msg ) . to match ( /Error: Could not find resource 'Exec\[ subscribe target\] ' in parameter 'subscribe' at/ )
113+ end
114+ else
115+ it 'should raise ReferenceValidationError' do
116+ expect ( @result . exception ) . to be_a_kind_of ( OctocatalogDiff ::Errors ::ReferenceValidationError )
117+ end
118+
119+ # Multiple line numbers given because Puppet 4.x and 3.8 correspond to first and last line of resource, respectively.
120+ # rubocop:disable Metrics/LineLength
121+ it 'should have formatted error messages' do
122+ msg = @result . exception . message
123+ expect ( msg ) . to match ( %r{exec\[ subscribe caller 1\] \( modules/test/manifests/subscribe_callers.pp:(2|5)\) -> subscribe\[ Exec\[ subscribe target\] \] } )
124+ expect ( msg ) . to match ( %r{exec\[ subscribe caller 2\] \( modules/test/manifests/subscribe_callers.pp:(7|13)\) -> subscribe\[ Exec\[ subscribe target\] \] } )
125+ expect ( msg ) . to match ( %r{exec\[ subscribe caller 2\] \( modules/test/manifests/subscribe_callers.pp:(7|13)\) -> subscribe\[ Exec\[ subscribe target 2\] \] } )
126+ expect ( msg ) . to match ( %r{exec\[ subscribe caller 3\] \( modules/test/manifests/subscribe_callers.pp:(15|21)\) -> subscribe\[ Exec\[ subscribe target\] \] } )
127+ expect ( msg ) . not_to match ( /exec\[ subscribe caller 3\] .+subscribe\[ Exec\[ subscribe caller 1\] \] / )
128+ end
129+ # rubocop:enable Metrics/LineLength
114130 end
115- # rubocop:enable Metrics/LineLength
116131 end
117132
118133 context 'with broken before' do
@@ -124,16 +139,27 @@ def self.catalog_contains_resource(result, type, title)
124139 expect ( @result . exitcode ) . to eq ( -1 ) , OctocatalogDiff ::Integration . format_exception ( @result )
125140 end
126141
127- it 'should raise ReferenceValidationError' do
128- expect ( @result . exception ) . to be_a_kind_of ( OctocatalogDiff ::Errors ::ReferenceValidationError )
129- end
142+ if OctocatalogDiff ::Spec . is_puppet5?
143+ it 'should raise CatalogError' do
144+ expect ( @result . exception ) . to be_a_kind_of ( OctocatalogDiff ::Errors ::CatalogError )
145+ end
130146
131- # rubocop:disable Metrics/LineLength
132- it 'should have formatted error messages' do
133- msg = @result . exception . message
134- expect ( msg ) . to match ( %r{Catalog has broken reference: exec\[ before caller\] \( modules/test/manifests/before_callers.pp:(2|5)\) -> before\[ Exec\[ before target\] \] } )
147+ it 'should pass through the error messages from Puppet' do
148+ msg = @result . exception . message
149+ expect ( msg ) . to match ( /Error: Could not find resource 'Exec\[ before target\] ' in parameter 'before' at/ )
150+ end
151+ else
152+ it 'should raise ReferenceValidationError' do
153+ expect ( @result . exception ) . to be_a_kind_of ( OctocatalogDiff ::Errors ::ReferenceValidationError )
154+ end
155+
156+ # rubocop:disable Metrics/LineLength
157+ it 'should have formatted error messages' do
158+ msg = @result . exception . message
159+ expect ( msg ) . to match ( %r{Catalog has broken reference: exec\[ before caller\] \( modules/test/manifests/before_callers.pp:(2|5)\) -> before\[ Exec\[ before target\] \] } )
160+ end
161+ # rubocop:enable Metrics/LineLength
135162 end
136- # rubocop:enable Metrics/LineLength
137163 end
138164
139165 context 'with broken notify' do
@@ -145,16 +171,27 @@ def self.catalog_contains_resource(result, type, title)
145171 expect ( @result . exitcode ) . to eq ( -1 ) , OctocatalogDiff ::Integration . format_exception ( @result )
146172 end
147173
148- it 'should raise ReferenceValidationError' do
149- expect ( @result . exception ) . to be_a_kind_of ( OctocatalogDiff ::Errors ::ReferenceValidationError )
150- end
174+ if OctocatalogDiff ::Spec . is_puppet5?
175+ it 'should raise CatalogError' do
176+ expect ( @result . exception ) . to be_a_kind_of ( OctocatalogDiff ::Errors ::CatalogError )
177+ end
151178
152- # rubocop:disable Metrics/LineLength
153- it 'should have formatted error messages' do
154- msg = @result . exception . message
155- expect ( msg ) . to match ( %r{exec\[ notify caller\] \( modules/test/manifests/notify_callers.pp:(2|4)\) -> notify\[ Test::Foo::Bar\[ notify target\] \] } )
179+ it 'should pass through the error messages from Puppet' do
180+ msg = @result . exception . message
181+ expect ( msg ) . to match ( /Error: Could not find resource 'Test::Foo::Bar\[ notify target\] ' in parameter 'notify' at/ )
182+ end
183+ else
184+ it 'should raise ReferenceValidationError' do
185+ expect ( @result . exception ) . to be_a_kind_of ( OctocatalogDiff ::Errors ::ReferenceValidationError )
186+ end
187+
188+ # rubocop:disable Metrics/LineLength
189+ it 'should have formatted error messages' do
190+ msg = @result . exception . message
191+ expect ( msg ) . to match ( %r{exec\[ notify caller\] \( modules/test/manifests/notify_callers.pp:(2|4)\) -> notify\[ Test::Foo::Bar\[ notify target\] \] } )
192+ end
193+ # rubocop:enable Metrics/LineLength
156194 end
157- # rubocop:enable Metrics/LineLength
158195 end
159196
160197 context 'with broken require' do
@@ -166,33 +203,55 @@ def self.catalog_contains_resource(result, type, title)
166203 expect ( @result . exitcode ) . to eq ( -1 ) , OctocatalogDiff ::Integration . format_exception ( @result )
167204 end
168205
169- it 'should raise ReferenceValidationError' do
170- expect ( @result . exception ) . to be_a_kind_of ( OctocatalogDiff ::Errors ::ReferenceValidationError )
171- end
172-
173- # rubocop:disable Metrics/LineLength
174- it 'should have formatted error messages' do
175- msg = @result . exception . message
176- expect ( msg ) . to match ( %r{exec\[ require caller\] \( modules/test/manifests/require_callers.pp:(2|5)\) -> require\[ Exec\[ require target\] \] } )
177- expect ( msg ) . to match ( %r{exec\[ require caller 3\] \( modules/test/manifests/require_callers.pp:(12|18)\) -> require\[ Exec\[ require target\] \] } )
178- expect ( msg ) . to match ( %r{exec\[ require caller 4\] \( modules/test/manifests/require_callers.pp:(12|18)\) -> require\[ Exec\[ require target\] \] } )
179- expect ( msg ) . not_to match ( /exec\[ require caller 2\] / )
180- expect ( msg ) . not_to match ( /-> require\[ Exec\[ require caller\] \] / )
206+ if OctocatalogDiff ::Spec . is_puppet5?
207+ it 'should raise CatalogError' do
208+ expect ( @result . exception ) . to be_a_kind_of ( OctocatalogDiff ::Errors ::CatalogError )
209+ end
210+
211+ it 'should pass through the error messages from Puppet' do
212+ msg = @result . exception . message
213+ expect ( msg ) . to match ( /Error: Could not find resource 'Exec\[ require target\] ' in parameter 'require' at/ )
214+ end
215+ else
216+ it 'should raise ReferenceValidationError' do
217+ expect ( @result . exception ) . to be_a_kind_of ( OctocatalogDiff ::Errors ::ReferenceValidationError )
218+ end
219+
220+ # rubocop:disable Metrics/LineLength
221+ it 'should have formatted error messages' do
222+ msg = @result . exception . message
223+ expect ( msg ) . to match ( %r{exec\[ require caller\] \( modules/test/manifests/require_callers.pp:(2|5)\) -> require\[ Exec\[ require target\] \] } )
224+ expect ( msg ) . to match ( %r{exec\[ require caller 3\] \( modules/test/manifests/require_callers.pp:(12|18)\) -> require\[ Exec\[ require target\] \] } )
225+ expect ( msg ) . to match ( %r{exec\[ require caller 4\] \( modules/test/manifests/require_callers.pp:(12|18)\) -> require\[ Exec\[ require target\] \] } )
226+ expect ( msg ) . not_to match ( /exec\[ require caller 2\] / )
227+ expect ( msg ) . not_to match ( /-> require\[ Exec\[ require caller\] \] / )
228+ end
229+ # rubocop:enable Metrics/LineLength
181230 end
182- # rubocop:enable Metrics/LineLength
183231 end
184232
185233 context 'with broken subscribe but subscribe not checked' do
186234 before ( :all ) do
187235 @result = OctocatalogDiff ::Spec . reference_validation_catalog ( 'broken-subscribe' , %w( before notify require ) )
188236 end
189237
190- it 'should succeed' do
191- expect ( @result . exitcode ) . to eq ( 0 ) , OctocatalogDiff ::Integration . format_exception ( @result )
192- end
238+ if OctocatalogDiff ::Spec . is_puppet5?
239+ it 'should raise CatalogError' do
240+ expect ( @result . exception ) . to be_a_kind_of ( OctocatalogDiff ::Errors ::CatalogError )
241+ end
193242
194- it 'should not raise error' do
195- expect ( @result . exception ) . to be_nil
243+ it 'should pass through the error messages from Puppet' do
244+ msg = @result . exception . message
245+ expect ( msg ) . to match ( /Error: Could not find resource 'Exec\[ subscribe target\] ' in parameter 'subscribe' at/ )
246+ end
247+ else
248+ it 'should succeed' do
249+ expect ( @result . exitcode ) . to eq ( 0 ) , OctocatalogDiff ::Integration . format_exception ( @result )
250+ end
251+
252+ it 'should not raise error' do
253+ expect ( @result . exception ) . to be_nil
254+ end
196255 end
197256 end
198257end
@@ -228,22 +287,35 @@ def self.catalog_contains_resource(result, type, title)
228287 expect ( @result . exitcode ) . to eq ( -1 ) , OctocatalogDiff ::Integration . format_exception ( @result )
229288 end
230289
231- it 'should raise ReferenceValidationError' do
232- expect ( @result . exception ) . to be_a_kind_of ( OctocatalogDiff ::Errors ::ReferenceValidationError )
290+ if OctocatalogDiff ::Spec . is_puppet5?
291+ it 'should raise CatalogError' do
292+ expect ( @result . exception ) . to be_a_kind_of ( OctocatalogDiff ::Errors ::CatalogError )
293+ end
294+
295+ it 'should pass through the error messages from Puppet' do
296+ msg = @result . exception . message
297+ expect ( msg ) . to match ( /Error: Could not find resource 'Exec\[ before alias target\] ' in parameter 'before'/ )
298+ end
299+ else
300+ it 'should raise ReferenceValidationError' do
301+ expect ( @result . exception ) . to be_a_kind_of ( OctocatalogDiff ::Errors ::ReferenceValidationError )
302+ end
303+
304+ # rubocop:disable Metrics/LineLength
305+ it 'should have formatted error messages' do
306+ msg = @result . exception . message
307+ expect ( msg ) . to match ( %r{exec\[ before alias caller\] \( modules/test/manifests/alias_callers.pp:(2|5)\) -> before\[ Exec\[ before alias target\] \] } )
308+ expect ( msg ) . to match ( %r{exec\[ notify alias caller\] \( modules/test/manifests/alias_callers.pp:(7|10)\) -> before\[ Exec\[ notify alias target\] \] } )
309+ expect ( msg ) . to match ( %r{exec\[ require alias caller\] \( modules/test/manifests/alias_callers.pp:(12|15)\) -> before\[ Exec\[ require alias target\] \] } )
310+ expect ( msg ) . to match ( %r{exec\[ subscribe alias caller\] \( modules/test/manifests/alias_callers.pp:(17|20)\) -> before\[ Exec\[ subscribe alias target\] \] } )
311+ end
312+ # rubocop:enable Metrics/LineLength
233313 end
234-
235- # rubocop:disable Metrics/LineLength
236- it 'should have formatted error messages' do
237- msg = @result . exception . message
238- expect ( msg ) . to match ( %r{exec\[ before alias caller\] \( modules/test/manifests/alias_callers.pp:(2|5)\) -> before\[ Exec\[ before alias target\] \] } )
239- expect ( msg ) . to match ( %r{exec\[ notify alias caller\] \( modules/test/manifests/alias_callers.pp:(7|10)\) -> before\[ Exec\[ notify alias target\] \] } )
240- expect ( msg ) . to match ( %r{exec\[ require alias caller\] \( modules/test/manifests/alias_callers.pp:(12|15)\) -> before\[ Exec\[ require alias target\] \] } )
241- expect ( msg ) . to match ( %r{exec\[ subscribe alias caller\] \( modules/test/manifests/alias_callers.pp:(17|20)\) -> before\[ Exec\[ subscribe alias target\] \] } )
242- end
243- # rubocop:enable Metrics/LineLength
244314 end
245315end
246316
317+ # There are no conditionals for puppet 5 here, because all of these catalogs come from JSON
318+ # files and not from actual puppet compilations.
247319describe 'validation of references in catalog-diff' do
248320 context 'with valid catalog' do
249321 before ( :all ) do
0 commit comments