File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,6 @@ DEPENDENCIES
66 path: test/cookbooks/ssh_test
77
88GRAPH
9- ssh (0.6.6 )
9+ ssh (0.10.0 )
1010 ssh_test (0.2.0)
1111 ssh (>= 0.0.0)
Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ def parse_file(path)
1717 return entries unless ::File . exist? ( path )
1818 name = nil?
1919 IO . foreach ( path ) do |line |
20+ next if line . match ( /^\s *(#|\r ?\n |\s *$)/ ) # skip lines with only comments or whitespace
21+
2022 matchdata = line . match ( /^\s *([h|H]ost)(.*$)/ )
2123 if matchdata
2224 name = matchdata . captures [ 1 ] . strip
@@ -25,6 +27,10 @@ def parse_file(path)
2527 end
2628
2729 matchdata = line . match ( /^\s *(\w +)(.*$)/ )
30+ unless matchdata
31+ Chef ::Log . error ( "Line |#{ line } | does not parse correctly" )
32+ next
33+ end
2834 entries [ name ] [ matchdata . captures [ 0 ] ] = matchdata . captures [ 1 ] . strip
2935 end
3036 entries
Original file line number Diff line number Diff line change 215215 )
216216 end
217217 end
218+
219+ it 'can handle files with comments in them' do
220+ content = [ ]
221+ content << '# this is a comment line'
222+ content += partial_start
223+ allow ( IO ) . to content . reduce ( receive ( :foreach ) . with ( default_config ) , :and_yield )
224+
225+ expect ( chef_run ) . to render_file ( default_config ) . with_content (
226+ ( common_end + github_and_partial_end ) . join ( "\n " )
227+ )
228+ end
229+
230+ it 'does not duplicate entries' do
231+ allow ( IO ) . to github_and_partial_end . reduce ( receive ( :foreach ) . with ( vagrant_config ) , :and_yield )
232+
233+ expect ( chef_run ) . to render_file ( default_config ) . with_content (
234+ ( common_end + github_and_partial_end ) . join ( "\n " )
235+ )
236+ end
218237end
You can’t perform that action at this time.
0 commit comments