knife-testcoverage 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/chef/knife/knife-testcoverage.rb +97 -0
- metadata +45 -0
@@ -0,0 +1,97 @@
|
|
1
|
+
class Chef
|
2
|
+
class Knife
|
3
|
+
class Testcoverage < Knife
|
4
|
+
|
5
|
+
banner "knife testcoverage COOKBOOK"
|
6
|
+
|
7
|
+
option :show_missing,
|
8
|
+
:short => "-s",
|
9
|
+
:long => "--show-missing",
|
10
|
+
:description => "Show the missing tests",
|
11
|
+
:default => false
|
12
|
+
|
13
|
+
def run
|
14
|
+
if @name_args.length != 1
|
15
|
+
stdout.puts "You must provide the name of the cookbook to review."
|
16
|
+
stdout.puts opt_parser
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
|
20
|
+
self.config = Chef::Config.merge!(config)
|
21
|
+
|
22
|
+
unless config[:cookbook_path]
|
23
|
+
stdout.puts("No cookbook path set in Chef config, cannot install cookbook.")
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
cookbook = @name_args[0]
|
28
|
+
|
29
|
+
cbpath=''
|
30
|
+
|
31
|
+
config[:cookbook_path].each do |cookbookdir|
|
32
|
+
|
33
|
+
cbpathtest = cookbookdir + cookbook
|
34
|
+
|
35
|
+
if File.directory?(cbpathtest)
|
36
|
+
cbpath = cbpathtest
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
if not File.directory?(cbpath)
|
42
|
+
stdout.puts "#{cookbook} does not exist in any known location"
|
43
|
+
exit 1
|
44
|
+
end
|
45
|
+
|
46
|
+
recipes = cbpath + "/recipes"
|
47
|
+
tests = cbpath + "/files/default/tests/minitest/"
|
48
|
+
|
49
|
+
if not File.directory?(recipes)
|
50
|
+
stdout.puts "#{cookbook} exists but contains no recipes"
|
51
|
+
exit 1
|
52
|
+
end
|
53
|
+
|
54
|
+
recipecount = 0
|
55
|
+
testcount = 0
|
56
|
+
|
57
|
+
missingtests = []
|
58
|
+
|
59
|
+
Dir.foreach(recipes) do |recipe|
|
60
|
+
# Avoid processing . and .., which show up as files in the directory
|
61
|
+
|
62
|
+
if recipe[-3,3] == ".rb"
|
63
|
+
|
64
|
+
recipecount += 1
|
65
|
+
|
66
|
+
basename = File.basename(recipe, ".rb")
|
67
|
+
|
68
|
+
testfile = basename + "_test.rb"
|
69
|
+
if not File.exists?("#{tests}#{testfile}")
|
70
|
+
missingtests.push(testfile)
|
71
|
+
#print "Missing #{testfile}\n"
|
72
|
+
else
|
73
|
+
testcount += 1
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
coverage = (testcount.to_f / recipecount.to_f * 100).round
|
79
|
+
|
80
|
+
print "#{coverage}% coverage. (#{recipecount} recipes, #{testcount} tests)\n"
|
81
|
+
|
82
|
+
if config[:show_missing]
|
83
|
+
print "Missing tests:\n"
|
84
|
+
missingtests.each do |missingtest|
|
85
|
+
print "#{missingtest}\n"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
if testcount == recipecount
|
90
|
+
exit 0
|
91
|
+
else
|
92
|
+
exit 1
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-testcoverage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brian Anderson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-15 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A simple plugin to report on minitest-handler coverage in a cookbook
|
15
|
+
email: brian@stormtrooperguy.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/chef/knife/knife-testcoverage.rb
|
21
|
+
homepage:
|
22
|
+
licenses: []
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 1.8.24
|
42
|
+
signing_key:
|
43
|
+
specification_version: 3
|
44
|
+
summary: Knife-testcoverage
|
45
|
+
test_files: []
|