MetaData changes
- bump metadata versions to 11
Gemfile changes
- bump robocop to 0.29.1
- bump chef to 11.18.6 close to 12 but not quite (need infra changes for 12)
- bump berks to 3.2.1 to get fix for running twice (destination already exists)
Rubocop changes
- add .robucop_todo.yml for future cleanup
- rubocop --auto-gen-config and add an inherit_from: .rubocop_todo.yml in your .rubocop.yml
- add .bundle/**/* to .rubocop.yml
- add .cookbooks/**/* to robocop.yml
- fixup berks-cookbooks/** with /**/*
Changelog changes
- delete Changelog.rb
Other codes changes
- change juno to kilo where appropriate
- cleanup any obvious old deprecated code
Change-Id: I146aa7f7ba4024115c1297103e176a72336fbe5d
Partial-Bug: #1426424
93 lines
2.3 KiB
Ruby
93 lines
2.3 KiB
Ruby
# encoding: UTF-8
|
|
|
|
if defined?(ChefSpec)
|
|
|
|
#
|
|
# Test method for ini format file
|
|
#
|
|
# Example file content:
|
|
#
|
|
# [section1]
|
|
# option1 = value1
|
|
# option2 = value2
|
|
# [section2]
|
|
# option1 = value2
|
|
#
|
|
# Example custom matcher that can be called in other
|
|
# dependends cookbooks.
|
|
#
|
|
# render_config_file(path).with_section_content(
|
|
# 'section1', 'option1 = value1')
|
|
# render_config_file(path).with_section_content(
|
|
# 'section1', /^option2 = value2$/)
|
|
#
|
|
def render_config_file(path)
|
|
RenderConfigFileMatcher.new(path)
|
|
end
|
|
|
|
#
|
|
# Extend the RenderFileMatcher as RenderConfigFileMatcher,
|
|
# add a new method with_section_content for ini format file.
|
|
#
|
|
class RenderConfigFileMatcher < ChefSpec::Matchers::RenderFileMatcher
|
|
def with_section_content(section, expected_content)
|
|
@section = section
|
|
@expected_content = expected_content
|
|
self
|
|
end
|
|
|
|
# rubocop:disable MethodLength, CyclomaticComplexity
|
|
def matches_content?
|
|
def section?(line, section = '.*')
|
|
if line =~ /^[ \t]*\[#{section}\]/
|
|
return true
|
|
else
|
|
return false
|
|
end
|
|
end
|
|
|
|
def get_section_content(content, section)
|
|
match = false
|
|
section_content = ''
|
|
content.split("\n").each do |line|
|
|
if section?(line, section)
|
|
match = true
|
|
next
|
|
end
|
|
|
|
section_content << "#{line}\n" if match == true && !section?(line)
|
|
|
|
break if match == true && section?(line)
|
|
end
|
|
section_content
|
|
end
|
|
|
|
return true if @expected_content.nil?
|
|
|
|
@actual_content = ChefSpec::Renderer.new(@runner, resource).content
|
|
|
|
unless @actual_content.nil?
|
|
unless @section.nil?
|
|
@actual_content = get_section_content(@actual_content, @section)
|
|
end
|
|
end
|
|
|
|
return false if @actual_content.nil?
|
|
|
|
if @expected_content.is_a?(Regexp)
|
|
|
|
# MRV Hack to allow windows env to work with rspec
|
|
# when regex end with $
|
|
@actual_content = @actual_content.gsub(/\r/, '')
|
|
|
|
@actual_content =~ @expected_content
|
|
elsif RSpec::Matchers.is_a_matcher?(@expected_content)
|
|
@expected_content.matches?(@actual_content)
|
|
else
|
|
@actual_content.include?(@expected_content)
|
|
end
|
|
end
|
|
# rubocop:enable MethodLength, CyclomaticComplexity
|
|
end
|
|
end
|