@@ -22,16 +22,59 @@ def catalog_from_fixture(path)
22
22
end
23
23
24
24
it 'should return path if file is found' do
25
+ allow ( File ) . to receive ( :exist? ) . and_call_original
25
26
allow ( File ) . to receive ( :exist? ) . with ( '/a/foo/files/bar' ) . and_return ( true )
26
27
result = OctocatalogDiff ::CatalogUtil ::FileResources . file_path ( 'puppet:///modules/foo/bar' , [ '/a' ] )
27
28
expect ( result ) . to eq ( '/a/foo/files/bar' )
28
29
end
29
30
30
31
it 'should return nil if file is not found' do
32
+ allow ( File ) . to receive ( :exist? ) . and_call_original
31
33
allow ( File ) . to receive ( :exist? ) . with ( '/a/foo/files/bar' ) . and_return ( false )
32
34
result = OctocatalogDiff ::CatalogUtil ::FileResources . file_path ( 'puppet:///modules/foo/bar' , [ '/a' ] )
33
35
expect ( result ) . to eq ( nil )
34
36
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
35
78
end
36
79
37
80
describe '#module_path' do
0 commit comments