@@ -20,13 +20,13 @@ def catalog_from_fixture(path)
2020 end
2121
2222 it 'should return path if file is found' do
23- allow ( File ) . to receive ( :file ? ) . with ( '/a/foo/files/bar' ) . and_return ( true )
23+ allow ( File ) . to receive ( :exist ? ) . with ( '/a/foo/files/bar' ) . and_return ( true )
2424 result = OctocatalogDiff ::CatalogUtil ::FileResources . file_path ( 'puppet:///modules/foo/bar' , [ '/a' ] )
2525 expect ( result ) . to eq ( '/a/foo/files/bar' )
2626 end
2727
2828 it 'should return nil if file is not found' do
29- allow ( File ) . to receive ( :file ? ) . with ( '/a/foo/files/bar' ) . and_return ( false )
29+ allow ( File ) . to receive ( :exist ? ) . with ( '/a/foo/files/bar' ) . and_return ( false )
3030 result = OctocatalogDiff ::CatalogUtil ::FileResources . file_path ( 'puppet:///modules/foo/bar' , [ '/a' ] )
3131 expect ( result ) . to eq ( nil )
3232 end
@@ -54,6 +54,46 @@ def catalog_from_fixture(path)
5454 end
5555 end
5656
57+ context 'with mixed files and directories' do
58+ describe '#convert_file_resources' do
59+ before ( :each ) do
60+ @tmpdir = Dir . mktmpdir
61+ FileUtils . cp_r OctocatalogDiff ::Spec . fixture_path ( 'repos/modulepath/manifests' ) , @tmpdir
62+ FileUtils . cp_r OctocatalogDiff ::Spec . fixture_path ( 'repos/modulepath/modules' ) , @tmpdir
63+ Dir . mkdir File . join ( @tmpdir , 'environments' )
64+ File . symlink @tmpdir , File . join ( @tmpdir , 'environments' , 'production' )
65+ File . open ( File . join ( @tmpdir , 'manifests' , 'site.pp' ) , 'w' ) { |f | f . write "include modulestest\n " }
66+
67+ @obj = catalog_from_fixture ( 'catalogs/catalog-modules-test.json' )
68+ @obj . compilation_dir = @tmpdir
69+ @resources_save = @obj . resources . dup
70+ OctocatalogDiff ::CatalogUtil ::FileResources . convert_file_resources ( @obj )
71+ end
72+
73+ after ( :each ) do
74+ FileUtils . remove_entry_secure @tmpdir if File . directory? ( @tmpdir )
75+ end
76+
77+ it 'should populate content of a file' do
78+ r = @obj . resources . select { |x | x [ 'type' ] == 'File' && x [ 'title' ] == '/tmp/foo' }
79+ expect ( r ) . to be_a_kind_of ( Array )
80+ expect ( r . size ) . to eq ( 1 )
81+ expect ( r . first ) . to be_a_kind_of ( Hash )
82+ expect ( r . first [ 'parameters' ] . key? ( 'source' ) ) . to eq ( false )
83+ expect ( r . first [ 'parameters' ] [ 'content' ] ) . to eq ( "Modules Test\n " )
84+ end
85+
86+ it 'should leave a directory unmodified' do
87+ r = @obj . resources . select { |x | x [ 'type' ] == 'File' && x [ 'title' ] == '/tmp/foobaz' }
88+ expect ( r ) . to be_a_kind_of ( Array )
89+ expect ( r . size ) . to eq ( 1 )
90+ expect ( r . first ) . to be_a_kind_of ( Hash )
91+ expect ( r . first [ 'parameters' ] . key? ( 'content' ) ) . to eq ( false )
92+ expect ( r . first [ 'parameters' ] [ 'source' ] ) . to eq ( 'puppet:///modules/modulestest/foo' )
93+ end
94+ end
95+ end
96+
5797 describe '#convert_file_resources' do
5898 before ( :each ) do
5999 @tmpdir = Dir . mktmpdir
0 commit comments