File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,6 @@ DEPENDENCIES
6
6
path: test/cookbooks/ssh_test
7
7
8
8
GRAPH
9
- ssh (0.6.6 )
9
+ ssh (0.10.0 )
10
10
ssh_test (0.2.0)
11
11
ssh (>= 0.0.0)
Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ def parse_file(path)
17
17
return entries unless ::File . exist? ( path )
18
18
name = nil?
19
19
IO . foreach ( path ) do |line |
20
+ next if line . match ( /^\s *(#|\r ?\n |\s *$)/ ) # skip lines with only comments or whitespace
21
+
20
22
matchdata = line . match ( /^\s *([h|H]ost)(.*$)/ )
21
23
if matchdata
22
24
name = matchdata . captures [ 1 ] . strip
@@ -25,6 +27,10 @@ def parse_file(path)
25
27
end
26
28
27
29
matchdata = line . match ( /^\s *(\w +)(.*$)/ )
30
+ unless matchdata
31
+ Chef ::Log . error ( "Line |#{ line } | does not parse correctly" )
32
+ next
33
+ end
28
34
entries [ name ] [ matchdata . captures [ 0 ] ] = matchdata . captures [ 1 ] . strip
29
35
end
30
36
entries
Original file line number Diff line number Diff line change 215
215
)
216
216
end
217
217
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
218
237
end
You can’t perform that action at this time.
0 commit comments