Skip to content

Commit 4169ee4

Browse files
committed
Add some test for corner cases.
1 parent 8ba3907 commit 4169ee4

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

Berksfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ DEPENDENCIES
66
path: test/cookbooks/ssh_test
77

88
GRAPH
9-
ssh (0.6.6)
9+
ssh (0.10.0)
1010
ssh_test (0.2.0)
1111
ssh (>= 0.0.0)

libraries/ssh_config_helpers.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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

spec/provider_tests/config_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,23 @@
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
218237
end

0 commit comments

Comments
 (0)