@@ -23,6 +23,43 @@ def catalog_from_fixture(path)
2323 FileUtils . remove_entry_secure @tmpdir if File . directory? ( @tmpdir )
2424 end
2525
26+ it 'should use compilation directory if environments/production is unavailable' do
27+ FileUtils . rm_f File . join ( @tmpdir , 'environments' , 'production' )
28+
29+ # Set up test
30+ obj = catalog_from_fixture ( 'catalogs/catalog-test-file-v4.json' )
31+ obj . compilation_dir = @tmpdir
32+ resources_save = obj . resources . dup
33+
34+ # Perform test
35+ OctocatalogDiff ::CatalogUtil ::FileResources . convert_file_resources ( obj )
36+ expect ( obj . resources ) . to be_a_kind_of ( Array ) , obj . resources . to_json
37+ expect ( obj . resources . size ) . to eq ( 3 ) , obj . resources . to_json
38+ expect ( obj . resources [ 0 ] ) . to eq ( resources_save [ 0 ] ) , obj . resources . to_json
39+ expect ( obj . resources [ 1 ] ) . to eq ( resources_save [ 1 ] ) , obj . resources . to_json
40+ expect ( obj . resources [ 2 ] [ 'parameters' ] [ 'content' ] ) . to eq ( "foo\n " ) , obj . resources . to_json
41+ expect ( obj . resources [ 2 ] [ 'parameters' ] . key? ( 'source' ) ) . to eq ( false ) , obj . resources . to_json
42+
43+ # Make sure the symlink isn't there, i.e. that we actually tested this
44+ expect ( File . exist? ( File . join ( @tmpdir , 'environments' , 'production' ) ) ) . to eq ( false )
45+ end
46+
47+ it 'should not run at all if modules directory cannot be found' do
48+ module_dir = File . join ( @tmpdir , 'modules' )
49+ FileUtils . remove_entry_secure module_dir if File . directory? ( module_dir )
50+
51+ # Set up test
52+ obj = catalog_from_fixture ( 'catalogs/catalog-test-file-v4.json' )
53+ obj . compilation_dir = @tmpdir
54+
55+ # Perform test
56+ OctocatalogDiff ::CatalogUtil ::FileResources . convert_file_resources ( obj )
57+ expect ( obj . resources ) . to be_a_kind_of ( Array ) , obj . resources . to_json
58+ expect ( obj . resources . size ) . to eq ( 3 ) , obj . resources . to_json
59+ expect ( obj . resources [ 2 ] [ 'parameters' ] [ 'source' ] ) . to eq ( 'puppet:///modules/test/tmp/foo' )
60+ expect ( obj . resources [ 2 ] [ 'parameters' ] . key? ( 'content' ) ) . to eq ( false ) , obj . resources . to_json
61+ end
62+
2663 it 'should modify array with convertible resources' do
2764 # Set up test
2865 obj = catalog_from_fixture ( 'catalogs/catalog-test-file-v4.json' )
0 commit comments