summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Ilyin <dilyin@mirantis.com>2016-03-30 15:24:26 +0300
committerDmitry Ilyin <dilyin@mirantis.com>2016-03-31 20:06:55 +0300
commitd54efb1c7b1235cdb86f761fe282442918bb6a1b (patch)
treef007b0899f8c8c5681585f194a87e876e5dc0c19
parent6d343f2038cdba97f2b2cb27b409f72d55fbfc9c (diff)
Add coverage support
Notes
Notes (review): Verified+1: Fuel CI <fuel-ci-bot@mirantis.com> Code-Review+2: Dmitry Ilyin <dilyin@mirantis.com> Workflow+1: Dmitry Ilyin <dilyin@mirantis.com> Code-Review+1: Sergii Golovatiuk <sgolovatiuk@mirantis.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Mon, 04 Apr 2016 16:03:16 +0000 Reviewed-on: https://review.openstack.org/299355 Project: openstack/fuel-noop-fixtures Branch: refs/heads/master
-rw-r--r--Gemfile1
-rw-r--r--lib/noop/manager/options.rb6
-rw-r--r--lib/noop/task/overrides.rb30
-rw-r--r--lib/noop/task/report.rb15
-rw-r--r--reports/coverage/.gitignore3
-rw-r--r--spec/shared-examples.rb20
6 files changed, 71 insertions, 4 deletions
diff --git a/Gemfile b/Gemfile
index e010dad..d886be3 100644
--- a/Gemfile
+++ b/Gemfile
@@ -7,7 +7,6 @@ group :development, :test do
7 gem 'rspec-puppet-utils', '~> 2.0.0' 7 gem 'rspec-puppet-utils', '~> 2.0.0'
8 gem 'deep_merge' 8 gem 'deep_merge'
9 gem 'pry' 9 gem 'pry'
10 gem 'simplecov'
11 gem 'puppet-spec' 10 gem 'puppet-spec'
12 gem 'colorize' 11 gem 'colorize'
13 gem 'parallel' 12 gem 'parallel'
diff --git a/lib/noop/manager/options.rb b/lib/noop/manager/options.rb
index 9497b58..4765662 100644
--- a/lib/noop/manager/options.rb
+++ b/lib/noop/manager/options.rb
@@ -137,9 +137,9 @@ module Noop
137 opts.on('-a', '--spec_status', 'Show spec status blocks') do 137 opts.on('-a', '--spec_status', 'Show spec status blocks') do
138 ENV['SPEC_SHOW_STATUS'] = 'YES' 138 ENV['SPEC_SHOW_STATUS'] = 'YES'
139 end 139 end
140 # opts.on('--spec_coverage', 'Show spec coverage statistics') do 140 opts.on('--spec_coverage', 'Show spec coverage statistics') do
141 # ENV['SPEC_COVERAGE'] = 'YES' 141 ENV['SPEC_COVERAGE'] = 'YES'
142 # end 142 end
143 opts.on('--puppet_binary_files', 'Check if Puppet installs binary files') do 143 opts.on('--puppet_binary_files', 'Check if Puppet installs binary files') do
144 ENV['SPEC_PUPPET_BINARY_FILES'] = 'YES' 144 ENV['SPEC_PUPPET_BINARY_FILES'] = 'YES'
145 end 145 end
diff --git a/lib/noop/task/overrides.rb b/lib/noop/task/overrides.rb
index d07e8fc..cd8a354 100644
--- a/lib/noop/task/overrides.rb
+++ b/lib/noop/task/overrides.rb
@@ -5,6 +5,7 @@ module Noop
5 puppet_default_settings 5 puppet_default_settings
6 puppet_debug_override if ENV['SPEC_PUPPET_DEBUG'] 6 puppet_debug_override if ENV['SPEC_PUPPET_DEBUG']
7 puppet_resource_scope_override 7 puppet_resource_scope_override
8 rspec_coverage_add_override
8 return unless file_name_spec_set? 9 return unless file_name_spec_set?
9 hiera_config_override 10 hiera_config_override
10 setup_manifest 11 setup_manifest
@@ -92,5 +93,34 @@ module Noop
92 ) 93 )
93 end 94 end
94 95
96 def rspec_coverage_add_override
97 RSpec::Puppet::Coverage.class_eval do
98 def add_from_catalog(catalog, test_module)
99 catalog.to_a.each do |resource|
100 next if @filters.include?(resource.to_s)
101 if resource.file == Puppet[:manifest]
102 add(resource)
103 else
104 @excluded = [] unless @excluded
105 @excluded << resource.to_s
106 end
107 end
108 end
109
110 def report!
111 report = {}
112 report[:total] = @collection.size
113 report[:touched] = @collection.count { |_, resource| resource.touched? }
114 report[:untouched] = report[:total] - report[:touched]
115 report[:coverage] = "%5.2f" % ((report[:touched].to_f / report[:total].to_f) * 100)
116 report[:resources] = Hash[*@collection.map do |name, wrapper|
117 [name, wrapper.to_hash]
118 end.flatten]
119 report[:excluded] = @excluded
120 report
121 end
122 end
123 end
124
95 end 125 end
96end 126end
diff --git a/lib/noop/task/report.rb b/lib/noop/task/report.rb
index 2693479..e5a0648 100644
--- a/lib/noop/task/report.rb
+++ b/lib/noop/task/report.rb
@@ -70,6 +70,21 @@ Facts hierarchy:
70 Noop::Config.dir_path_reports + file_name_report_json 70 Noop::Config.dir_path_reports + file_name_report_json
71 end 71 end
72 72
73 # @return [Pathname]
74 def dir_name_coverage
75 Pathname.new 'coverage'
76 end
77
78 # @return [Pathname]
79 def dir_path_coverage
80 Noop::Config.dir_path_reports + dir_name_coverage
81 end
82
83 # @return [Pathname]
84 def file_path_coverage_report
85 dir_path_coverage + Noop::Utils.convert_to_path("#{file_name_base_task_report}.yaml")
86 end
87
73 # @return [Hash] 88 # @return [Hash]
74 def file_data_report_json 89 def file_data_report_json
75 return unless file_present_report_json? 90 return unless file_present_report_json?
diff --git a/reports/coverage/.gitignore b/reports/coverage/.gitignore
new file mode 100644
index 0000000..646982d
--- /dev/null
+++ b/reports/coverage/.gitignore
@@ -0,0 +1,3 @@
1*.yaml
2*.lock
3*.json
diff --git a/spec/shared-examples.rb b/spec/shared-examples.rb
index 0eea5d0..c587a47 100644
--- a/spec/shared-examples.rb
+++ b/spec/shared-examples.rb
@@ -116,6 +116,26 @@ def run_test(manifest_file, *args)
116 true 116 true
117 end 117 end
118 118
119 at_exit do
120 Noop.dir_path_coverage.mktree unless Noop.dir_path_coverage.directory?
121 report = RSpec::Puppet::Coverage.report!
122 Noop::Utils.output "Coverage:#{report[:coverage]}% (#{report[:touched]}/#{report[:total]})"
123 if report[:untouched] > 0
124 resources_report = "Untouched resources:\n"
125 resources = report[:resources]
126 if resources.is_a? Hash
127 resources.each do |resource, status|
128 resources_report += "* #{resource}\n" unless status['touched']
129 end
130 end
131 Noop::Utils.output resources_report
132 end
133 Noop::Utils.debug "Saving coverage report to: '#{Noop.file_path_coverage_report}'"
134 File.open(Noop.file_path_coverage_report, 'w') do |file|
135 file.puts YAML.dump report
136 end
137 end if ENV['SPEC_COVERAGE']
138
119 yield self if block_given? 139 yield self if block_given?
120 140
121end 141end