pronto-inspec 0.0.6

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f42d3eec19b2e8e318c9f47eedf294be7fdeea8e
4
+ data.tar.gz: 8b95b3839a31c78b5ca690ccc4698a8dd0934684
5
+ SHA512:
6
+ metadata.gz: 5a8861fe04cbcab288388b5eaad61cdde161b2183cf169827449d37ae7d6a0f295fee6db8c03be2998090d7484f11f1c228fb202aa122461aedcb58382a277b4
7
+ data.tar.gz: f5675179b5bb2baeb8e298b73e07e4a4835d63fb5d29cb3d99a0549763cd0715f69669e2513530de585ca3e0464e007e813c5149fe96e0315efbd6c1159c78ea
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2017 stiller-leser
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ Pronto Inspec
2
+ =============
3
+ [Pronto](https://github.com/prontolabs/pronto) Runner for Inspec tests.
4
+
5
+ How-To:
6
+ -------
7
+
8
+ Create a .pronto-inspec.yml where your kitchen file is and specify which suites should be run if which file has been changed.
9
+
10
+
11
+ To trigger the suite only if specifc files have been changed use : `files: ['my/cookbook/specifc_file.rb']`
12
+
13
+ By using `files: ['my/cookbook/*']` the suite defined for this `files` will be used if any file has been changed.
14
+
15
+ You can also specify `files: ['**']` to run the suite in any case.
16
+
17
+ I would also advise to always trigger the suite if any test cases in that suite have changed, e.g. `files: [test/my_tests_for_suite/*a]`
18
+
19
+ Example:
20
+ --------
21
+
22
+ See [this example file](.pronto-inspec.sample.yml)
23
+
24
+ Usage:
25
+ ------
26
+
27
+ pronto run -r inspec
28
+
29
+ Requirements:
30
+ -------------
31
+
32
+ The format for the inspec-verifier has to be set to: `format: junit`.
33
+
34
+
35
+ `chef`, `test-kitchen` and `inspec` all need to be installed and configured-
@@ -0,0 +1,124 @@
1
+ require 'pronto'
2
+ require 'yaml'
3
+ require 'colorize'
4
+ require 'nokogiri'
5
+ require 'open3'
6
+
7
+ module Pronto
8
+ class Inspec < Runner
9
+ def initialize(_, _ = nil)
10
+ super
11
+ begin
12
+ @config = YAML.load_file('.pronto-inspec.yml')
13
+ rescue
14
+ abort('Could not find .pronto-inspec file. See .pronto-inspec.sample.yml'.red)
15
+ end
16
+
17
+ @kitchen_command = @config['kitchen_command']
18
+ abort('Please specify a base command for kitchen, i.e. kitchen test'.red) if @kitchen_command.nil?
19
+ @inspec_file = @config['inspec_file']
20
+ abort('Please specify the name of the inspec file'.red) if @inspec_file.nil?
21
+
22
+ @suites_to_check = []
23
+ @config['suites'].each do |suite|
24
+ if suite['files'].count > 0
25
+ @suites_to_check.push(suite)
26
+ else
27
+ puts "No files configured for suite #{suite.first[0]}\n".yellow
28
+ end
29
+ end
30
+ abort('All suites are empty, please specify files.'.red) if @suites_to_check.count.zero?
31
+ @suites_to_run ||= []
32
+ end
33
+
34
+ def copy_lines(str_in, str_out)
35
+ str_in.each_line {|line| str_out.puts line}
36
+ end
37
+
38
+ def run
39
+ return [] if !@patches || @patches.count.zero?
40
+
41
+ @patches
42
+ .select { |patch| patch.additions > 0 }
43
+ .map { |patch| inspect(patch) }
44
+
45
+ result = []
46
+
47
+ if @suites_to_run.count > 0
48
+ puts "\nCreated runlist: #{@suites_to_run}\n".green
49
+ result = []
50
+ @suites_to_run.each do |suite|
51
+ cmd = "#{@kitchen_command} #{suite}"
52
+ Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
53
+ stdin.close
54
+ err_thr = Thread.new { copy_lines(stderr, $stdout) }
55
+ copy_lines(stdout, $stdout)
56
+ err_thr.join
57
+ exit_status = wait_thr.value
58
+ unless exit_status.success?
59
+ abort "Test kitchen failed".red
60
+ end
61
+ end
62
+ doc = Nokogiri::XML(File.open(@inspec_file))
63
+ testsuites = doc.xpath('//testsuite')
64
+ testsuites.each_with_index do |testsuite, index|
65
+ failed = testsuites[index].attr('failed')
66
+ name = testsuites[index].attr('name')
67
+ if failed.to_i > 0
68
+ failures = ''
69
+ testsuite.xpath('//failure').each do |failure|
70
+ failures += "- #{failure.attr('message')} \n"
71
+ end
72
+ result.push(create_message(suite, "Testsuite '#{name}' in #{suite} expirienced #{failed} failures: \n#{failures}".red))
73
+ else
74
+ puts "\n No failures found for testsuite '#{name}' in kitchen suite '#{suite}'".green
75
+ end
76
+ end
77
+ end
78
+ else
79
+ puts 'Found no matching files in suites'.red
80
+ end
81
+
82
+ result
83
+ end
84
+
85
+ private
86
+
87
+ def create_message(suite, output)
88
+ Message.new(suite, @patches.first.added_lines.first, :error, output)
89
+ end
90
+
91
+ def git_repo_path
92
+ @git_repo_path ||= Rugged::Repository.discover(File.expand_path(Dir.pwd)).workdir
93
+ end
94
+
95
+ def inspect(patch)
96
+ changed_file = patch.new_file_full_path.to_s
97
+ @suites_to_check.each do |suite|
98
+ suite_name = suite.first[0]
99
+ puts "\nInspecting '#{suite_name}'...".yellow
100
+ puts "\tSearching for '#{changed_file}' in suite '#{suite_name}'...".blue
101
+ suite['files'].each do |file|
102
+ if @suites_to_run.include?(suite_name)
103
+ next
104
+ elsif file.include?('**')
105
+ puts 'Found wildcard, adding suite to runlist'.green
106
+ @suites_to_run.push(suite_name)
107
+ elsif file[-1,1] == '*'
108
+ puts "\t\tMatching changed '#{changed_file}' against #{suite_name}".blue
109
+ if changed_file.include?(file[0, file.size-2])
110
+ puts "\t\t\tFound '#{file}' in '#{suite_name}'! Adding '#{suite_name}' to run list".green
111
+ @suites_to_run.push(suite_name)
112
+ end
113
+ elsif changed_file.include?(file)
114
+ puts "\t\tMatching changed '#{changed_file}' against suite file '#{file}'...".blue
115
+ puts "\t\t\tFound '#{file}' in '#{suite_name}'! Adding '#{suite_name}' to run list".green
116
+ @suites_to_run.push(suite_name)
117
+ else
118
+ next
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,5 @@
1
+ module Pronto
2
+ module InspecVersion
3
+ VERSION = '0.0.6'.freeze
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pronto-inspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - stiller-leser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pronto
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rugged
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.24'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 0.23.0
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '0.24'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.23.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: colorize
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.8'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.8'
61
+ - !ruby/object:Gem::Dependency
62
+ name: nokogiri
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.8'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.8'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '12.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '12.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rspec
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3.4'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '3.4'
103
+ - !ruby/object:Gem::Dependency
104
+ name: byebug
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ description:
118
+ email: ''
119
+ executables: []
120
+ extensions: []
121
+ extra_rdoc_files:
122
+ - LICENSE
123
+ - README.md
124
+ files:
125
+ - LICENSE
126
+ - README.md
127
+ - lib/pronto/inspec.rb
128
+ - lib/pronto/inspec/version.rb
129
+ homepage: https://github.com/stiller-leser/pronto-inspec
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: 2.0.0
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.6.14
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Pronto runner for running test kitchen
153
+ test_files: []