@@ -22,16 +22,59 @@ def catalog_from_fixture(path)
2222 end
2323
2424 it 'should return path if file is found' do
25+ allow ( File ) . to receive ( :exist? ) . and_call_original
2526 allow ( File ) . to receive ( :exist? ) . with ( '/a/foo/files/bar' ) . and_return ( true )
2627 result = OctocatalogDiff ::CatalogUtil ::FileResources . file_path ( 'puppet:///modules/foo/bar' , [ '/a' ] )
2728 expect ( result ) . to eq ( '/a/foo/files/bar' )
2829 end
2930
3031 it 'should return nil if file is not found' do
32+ allow ( File ) . to receive ( :exist? ) . and_call_original
3133 allow ( File ) . to receive ( :exist? ) . with ( '/a/foo/files/bar' ) . and_return ( false )
3234 result = OctocatalogDiff ::CatalogUtil ::FileResources . file_path ( 'puppet:///modules/foo/bar' , [ '/a' ] )
3335 expect ( result ) . to eq ( nil )
3436 end
37+
38+ it 'should return the first entry from an array if found' do
39+ allow ( File ) . to receive ( :exist? ) . and_call_original
40+ allow ( File ) . to receive ( :exist? ) . with ( '/a/foo/files/bar' ) . and_return ( true )
41+ expect ( File ) . not_to receive ( :exist? ) . with ( '/a/foo/files/baz' )
42+ tries = [ 'puppet:///modules/foo/bar' , 'puppet:///modules/foo/baz' ]
43+ result = OctocatalogDiff ::CatalogUtil ::FileResources . file_path ( tries , [ '/a' ] )
44+ expect ( result ) . to eq ( '/a/foo/files/bar' )
45+ end
46+
47+ it 'should return the first actually found entry from an array' do
48+ allow ( File ) . to receive ( :exist? ) . and_call_original
49+ allow ( File ) . to receive ( :exist? ) . with ( '/a/foo/files/bar' ) . and_return ( false )
50+ allow ( File ) . to receive ( :exist? ) . with ( '/a/foo/files/baz' ) . and_return ( true )
51+ tries = [ 'sdfasdf' , 'puppet:///modules/foo/bar' , 'puppet:///modules/foo/baz' ]
52+ result = OctocatalogDiff ::CatalogUtil ::FileResources . file_path ( tries , [ '/a' ] )
53+ expect ( result ) . to eq ( '/a/foo/files/baz' )
54+ end
55+
56+ it 'should return nil if no entries from an array are found' do
57+ allow ( File ) . to receive ( :exist? ) . and_call_original
58+ allow ( File ) . to receive ( :exist? ) . with ( '/a/foo/files/bar' ) . and_return ( false )
59+ allow ( File ) . to receive ( :exist? ) . with ( '/a/foo/files/baz' ) . and_return ( false )
60+ tries = [ 'puppet:///modules/foo/bar' , 'puppet:///modules/foo/baz' ]
61+ result = OctocatalogDiff ::CatalogUtil ::FileResources . file_path ( tries , [ '/a' ] )
62+ expect ( result ) . to be_nil
63+ end
64+
65+ it 'should raise an error if the only entry is malformed' do
66+ tries = 'sddfsdfsdf'
67+ expect do
68+ OctocatalogDiff ::CatalogUtil ::FileResources . file_path ( tries , [ '/a' ] )
69+ end . to raise_error ( ArgumentError , /Bad parameter source/ )
70+ end
71+
72+ it 'should raise an error if the all entries are malformed' do
73+ tries = %w[ sddfsdfsdf asdfasfdasdf ]
74+ expect do
75+ OctocatalogDiff ::CatalogUtil ::FileResources . file_path ( tries , [ '/a' ] )
76+ end . to raise_error ( ArgumentError , /Bad parameter source/ )
77+ end
3578 end
3679
3780 describe '#module_path' do
0 commit comments