From 5e37dea3899cc6dd34d52a463c87bf36c57ea871 Mon Sep 17 00:00:00 2001 From: Mark Vanderwiel Date: Wed, 15 Apr 2015 16:22:52 -0500 Subject: [PATCH] Fix render_config_file with_section_content to handle dup sections Since duplicate sections are allowed within openstack conf files, need to be able to handle them in some cases. The first case of this is in network where the ml2 conf is including the openvswitch conf within it and there are a couple dup sections. This allows the spec tests to handle those cases. Change-Id: I8d2733a248a6a13ab87c286ff620c71955726f86 Closes-Bug: #1444696 --- libraries/matchers.rb | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/libraries/matchers.rb b/libraries/matchers.rb index 05342e8d..21676a52 100644 --- a/libraries/matchers.rb +++ b/libraries/matchers.rb @@ -11,10 +11,20 @@ if defined?(ChefSpec) # option1 = value1 # option2 = value2 # [section2] - # option1 = value2 + # option3 = value3 + # + # Example file content with dup sections: + # + # [section1] + # option1 = value1 + # option2 = value2 + # [section2] + # option3 = value3 + # [section1] + # option4 = value4 # # Example custom matcher that can be called in other - # dependends cookbooks. + # cookbooks. # # render_config_file(path).with_section_content( # 'section1', 'option1 = value1') @@ -47,17 +57,17 @@ if defined?(ChefSpec) end def get_section_content(content, section) - match = false + within_section = false section_content = '' content.split("\n").each do |line| if section?(line, section) - match = true + within_section = true next end - section_content << "#{line}\n" if match == true && !section?(line) - - break if match == true && section?(line) + start_of_new_section = section?(line) + section_content << "#{line}\n" if within_section && !start_of_new_section + within_section = false if start_of_new_section end section_content end