puppet-check 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -8
- data/README.md +42 -11
- data/lib/puppet-check.rb +5 -5
- data/lib/puppet-check/cli.rb +9 -1
- data/lib/puppet-check/puppet_parser.rb +2 -2
- data/lib/puppet-check/rspec_puppet_support.rb +91 -0
- data/lib/puppet-check/ruby_parser.rb +1 -1
- data/lib/puppet-check/tasks.rb +3 -90
- data/spec/puppet-check/rspec_puppet_support_spec.rb +31 -0
- data/spec/puppet-check/tasks_spec.rb +0 -25
- data/spec/puppet-check_spec.rb +5 -7
- data/spec/system/system_spec.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b2722f210a74837313e3463c41abd5f07018fcf
|
4
|
+
data.tar.gz: 5f36ae7fb5b25c86f4da1c56391aeacb61e14363
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93a0d80d2958ff85aa42f28936b0988f8cbab2701f2a49e9b44eeb4e44fa9a2bd006b606e82de10939451d0656c27f38521c0d72fa1546fb3f5ea01e83c5d6fd
|
7
|
+
data.tar.gz: 44d9243626055c3e2578e6c6c5ef6bb1b5a89978a543caa7a12588e319f1b52620d948fc20d6989ba3c535d02ecb43c407992bece46ecaf419c0c4bdad305dc5
|
data/CHANGELOG.md
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
### 1.4.0 (Roadmap)
|
2
|
-
- minimum puppet version bump to 3.5 and future parser enabled by force for version < 4 (search code on 'future')
|
3
|
-
|
4
1
|
### 1.3.0 (Roadmap)
|
5
2
|
- minimum ruby version bump to 2.0.0 (switch vagrant to centos7, remove 1.9.3 from travis.yml, add 2.3.x to travis.yml, update readme, remove psych::syntaxerror from dataparser.yaml, and remove 1.9.3 test from rubyparser.template style spec)
|
3
|
+
- minimum puppet version bump to 3.4
|
6
4
|
- rakefile interface with puppet-lint, rubocop, reek
|
7
5
|
- json and yaml output formats support (error_files becomes hash with file keys and array of issues; refactor output_results)
|
8
6
|
- rudimentary catalog compilation testing?
|
7
|
+
- rspec puppet stubbing
|
8
|
+
- infrataster and analogous docker task like thing ripienaar did?
|
9
|
+
- add additional hiera checks
|
9
10
|
|
10
|
-
### 1.2.1
|
11
|
-
-
|
12
|
-
-
|
13
|
-
-
|
14
|
-
- add additional hiera checks,
|
11
|
+
### 1.2.1
|
12
|
+
- Code and output cleanup.
|
13
|
+
- Add arguments support to external module download methods.
|
14
|
+
- PuppetLint dependency version updated for 2.0 release.
|
15
15
|
|
16
16
|
### 1.2.0
|
17
17
|
- Support for external module dependencies with RSpecPuppet.
|
data/README.md
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
- [Usage](#usage)
|
6
6
|
- [CLI](#cli)
|
7
7
|
- [Rake](#rake)
|
8
|
+
- [Docker](#docker)
|
8
9
|
- [Exit Codes](#exit-codes)
|
9
10
|
- [Optional Dependencies](#optional-dependencies)
|
10
11
|
- [Contributing](#contributing)
|
@@ -112,10 +113,13 @@ The following files have unrecognized formats and therefore were not processed:
|
|
112
113
|
- Puppetlabs Spec Helper intrinsically only executes spec tests against one module at a time.
|
113
114
|
- Puppetlabs Spec Helper requires an additional config file for RSpec Puppet support.
|
114
115
|
|
115
|
-
It is worth nothing that there is no current development objective for Puppet Check to achieve the same advanced level of robustness for spec testing that Puppetlabs Spec Helper enables. If you are performing standard spec testing on your Puppet code and data, then Puppet Check's spec testing is a fantastic lightweight and faster alternative to Puppetlabs Spec Helper. If you require advanced and intricate capabilities in your spec testing (e.g. direct interfacing to the `Puppet::Parser::Scope` API), you will likely prefer Puppetlabs Spec Helper's spec testing in conjunction with Puppet Check's file validation.
|
116
|
+
It is worth nothing that there is no current development objective for Puppet Check to achieve the same advanced level of robustness for spec testing that Puppetlabs Spec Helper enables. If you are performing standard spec testing on your Puppet code and data, then Puppet Check's spec testing is a fantastic lightweight and faster alternative to Puppetlabs Spec Helper. If you require advanced and intricate capabilities in your spec testing (e.g. direct interfacing to the `Puppet::Parser::Scope` API), then you will likely prefer Puppetlabs Spec Helper's spec testing in conjunction with Puppet Check's file validation.
|
116
117
|
|
117
118
|
## Usage
|
118
|
-
Puppet Check requires `ruby >= 1.9.3`, `puppet >= 3.2`, and `puppet-lint >=
|
119
|
+
Puppet Check requires `ruby >= 1.9.3`, `puppet >= 3.2`, and `puppet-lint >= 2.0.0`. All other dependencies should be fine with various versions. Puppet Check can be used either with a CLI or Rake tasks. Please note both interfaces will ignore any directories named `fixtures` or specified paths with that directory during file checks and spec tests.
|
120
|
+
|
121
|
+
#### Important Note for Ruby 1.9.3
|
122
|
+
If you are using Ruby 1.9.3, there is currently an issue where Hiera has an unspecified version dependency on JSonPure. Since JSonPure 2.0.2 requires `ruby >= 2.0.0`, this breaks Hiera installs on Ruby 1.9.3, which breaks Puppet installs, which breaks PuppetCheck installs. Therefore, you will need to restrict your installed version of JSonPure to something lower than 2.0.2 if you are using Ruby 1.9.3. A ticket with Puppet has been filed by me for this issue, so hopefully a resolution is forthcoming.
|
119
123
|
|
120
124
|
### CLI
|
121
125
|
```
|
@@ -132,7 +136,7 @@ The command line interface enables the ability to select the Puppet future parse
|
|
132
136
|
|
133
137
|
Example:
|
134
138
|
```
|
135
|
-
puppet-check -s --puppet-lint no-hard_tabs-check,no-
|
139
|
+
puppet-check -s --puppet-lint no-hard_tabs-check,no-140chars-check --rubocop Metrics/LineLength,Style/Encoding path/to/code_and_data
|
136
140
|
```
|
137
141
|
|
138
142
|
### Rake
|
@@ -156,11 +160,11 @@ PuppetCheck.future_parser = true
|
|
156
160
|
The style checks from within `rake puppetcheck:file` are directly interfaced to `puppet-lint`, `rubocop`, and `reek`. This means that all arguments and options should be specified from within your `.puppet-lint.rc`, `.rubocop.yml`, and `*.reek`. The capability to pass style arguments and options from within the `Rakefile` task block will be considered for future versions.
|
157
161
|
|
158
162
|
#### puppetcheck:spec
|
159
|
-
The spec tests will be executed against everything that matches the pattern `**/{classes, defines, facter, functions, hosts, puppet, unit, types}/**/*_spec.rb`. This means everything in the current path that appears to be a Puppet module spec test will be regarded as such and executed during this rake task.
|
163
|
+
The spec tests will be executed against everything that matches the pattern `**/{classes, defines, facter, functions, hosts, puppet, unit, types}/**/*_spec.rb`. Any of these directories inside of a `fixtures` directory will be ignored. This means everything in the current path that appears to be a Puppet module spec test for your module (not dependencies) will be regarded as such and executed during this rake task.
|
160
164
|
|
161
165
|
Please note it is perfectly acceptable to only execute standard RSpec tests in your modules and not use the extended RSpec Puppet matchers. If no Puppet module directories are identified during directory parsing, then no RSpec Puppet related actions (including those described below) will be performed.
|
162
166
|
|
163
|
-
Prior to executing the spec tests, Puppet Check will parse everything in the current path and identify all `spec` directories not within `fixtures` directories. It will then execute RSpec Puppet setup actions inside all directories one level above that contain a `manifests` directory. This is assumed to be a Puppet module directory. These setup actions include creating all of the necessary directories inside of `spec/fixtures`, creating a blank `site.pp` if it is missing, symlinking everything from the module that is needed into fixtures (automatically replaces functionality of self module symlink in `.fixtures.yaml` from Puppetlabs Spec Helper), and creates the `spec_helper.rb` if it is missing.
|
167
|
+
Prior to executing the spec tests, Puppet Check will parse everything in the current path and identify all `spec` directories not within `fixtures` directories. It will then execute RSpec Puppet setup actions inside all directories one level above that contain a `manifests` directory. This is assumed to be a Puppet module directory. These setup actions include creating all of the necessary directories inside of `spec/fixtures`, creating a blank `site.pp` if it is missing, symlinking everything from the module that is needed into fixtures (automatically replaces functionality of self module symlink in `.fixtures.yaml` from Puppetlabs Spec Helper), and creates the `spec_helper.rb` if it is missing. Note these setup actions can replace `rspec-puppet-init` from RSpec Puppet and currently are both faster and more accurate.
|
164
168
|
|
165
169
|
Puppet Check will also automatically download specified external module dependencies for and during RSpec Puppet testing. Currently `git`, `puppet forge`, and `hg` commands are supported. They can be implemented in the following way in your modules' `metadata.json`:
|
166
170
|
|
@@ -168,15 +172,18 @@ Puppet Check will also automatically download specified external module dependen
|
|
168
172
|
"dependencies": [
|
169
173
|
{
|
170
174
|
"name": "module-name",
|
171
|
-
"forge": "forge-name"
|
175
|
+
"forge": "forge-name",
|
176
|
+
"args": "puppet module install optional-arguments"
|
172
177
|
},
|
173
178
|
{
|
174
179
|
"name": "module-name",
|
175
|
-
"git": "git-url"
|
180
|
+
"git": "git-url",
|
181
|
+
"args": "git clone optional-arguments"
|
176
182
|
},
|
177
183
|
{
|
178
184
|
"name": "module-name",
|
179
|
-
"hg": "hg-url"
|
185
|
+
"hg": "hg-url",
|
186
|
+
"args": "hg clone optional-arguments"
|
180
187
|
}
|
181
188
|
]
|
182
189
|
```
|
@@ -187,7 +194,8 @@ Example:
|
|
187
194
|
"dependencies": [
|
188
195
|
{
|
189
196
|
"name": "puppetlabs/stdlib",
|
190
|
-
"forge": "puppetlabs-stdlib"
|
197
|
+
"forge": "puppetlabs-stdlib",
|
198
|
+
"args": "--do-something-cool"
|
191
199
|
},
|
192
200
|
{
|
193
201
|
"name": "puppetlabs/lvm",
|
@@ -197,14 +205,37 @@ Example:
|
|
197
205
|
```
|
198
206
|
|
199
207
|
#### puppetcheck:beaker
|
200
|
-
The spec tests will be executed against everything that matches the pattern `**/acceptance`. This means everything in the current path that appears to be a Puppet module acceptance test will be regarded as such and executed during this rake task.
|
208
|
+
The spec tests will be executed against everything that matches the pattern `**/acceptance`. Any of these directories inside of a `fixtures` directory will be ignored. This means everything in the current path that appears to be a Puppet module acceptance test for your module (not dependencies) will be regarded as such and executed during this rake task.
|
201
209
|
|
202
210
|
Please note this is merely a frontend to Beaker and that Beaker itself has a self-contained scope compared to all the other tools Puppet Check interfaces with and utilizes. This means if you want to add Beaker-RSpec, Serverspec, etc., or perform advanced configurations, those would be all be performed within Beaker itself. This task merely provides an interface to integrate Beaker in with your other testing infrastructure.
|
203
211
|
|
212
|
+
### Docker
|
213
|
+
|
214
|
+
You can also use Puppet Check inside of Docker for quick, portable, and disposable testing. Below is an example Dockerfile for this purpose:
|
215
|
+
|
216
|
+
```dockerfile
|
217
|
+
# a reliable and small container at the moment
|
218
|
+
FROM ubuntu:16.04
|
219
|
+
# you need ruby and any other extra dependencies that come from packages; in this example we install git to use it for downloading external module dependencies
|
220
|
+
RUN apt-get update && apt-get install ruby git -y
|
221
|
+
# you need puppet-check and any other extra dependencies that come from gems; in this example we install reek because the ruby ABI is 2.3 and then rspec-puppet and rake for extra testing
|
222
|
+
RUN gem install --no-rdoc --no-ri puppet-check reek rspec-puppet rake
|
223
|
+
# this is needed for the ruby json parser to not flip out on fresh os installs for some reason (change encoding value as necessary)
|
224
|
+
ENV LANG en_US.UTF-8
|
225
|
+
# create the directory for your module and change directory into it
|
226
|
+
WORKDIR /module_name
|
227
|
+
# copy the module contents into the module directory inside the container
|
228
|
+
COPY / .
|
229
|
+
# execute your tests; in this example we are executing the full suite of tests for this module
|
230
|
+
RUN rake puppetcheck
|
231
|
+
```
|
232
|
+
|
233
|
+
You can also build your own general container for testing various Puppet situations by removing the last three lines. You can then test each module, directory environment, etc. on top of that container by merely adding and modifying the final three lines to a Dockerfile that uses the container you built from the first four lines. This is recommended usage due to being very efficient and stable.
|
234
|
+
|
204
235
|
### Exit Codes
|
205
236
|
- 0: PuppetCheck exited with no internal exceptions or errors in your Puppet code and data.
|
206
237
|
- 1: PuppetCheck exited with an internal exception (takes preference over other non-zero exit codes).
|
207
|
-
- 2: PuppetCheck exited with errors in your Puppet code and data.
|
238
|
+
- 2: PuppetCheck exited with one or more errors in your Puppet code and data.
|
208
239
|
|
209
240
|
### Optional dependencies
|
210
241
|
- **reek**: will automatically (with `bundler`, otherwise manually) be installed as a dependency and checks enabled during style checks if your Ruby version is `>= 2.1.0`.
|
data/lib/puppet-check.rb
CHANGED
@@ -26,7 +26,7 @@ class PuppetCheck
|
|
26
26
|
# main runner for PuppetCheck
|
27
27
|
def run(paths)
|
28
28
|
# grab all of the files to be processed
|
29
|
-
files = parse_paths(paths)
|
29
|
+
files = self.class.parse_paths(paths)
|
30
30
|
|
31
31
|
# parse the files
|
32
32
|
execute_parsers(files)
|
@@ -39,7 +39,7 @@ class PuppetCheck
|
|
39
39
|
end
|
40
40
|
|
41
41
|
# parse the paths and return the array of files
|
42
|
-
def parse_paths(paths)
|
42
|
+
def self.parse_paths(paths)
|
43
43
|
files = []
|
44
44
|
|
45
45
|
# traverse the unique paths and return all files
|
@@ -50,12 +50,12 @@ class PuppetCheck
|
|
50
50
|
files.push(path)
|
51
51
|
end
|
52
52
|
end
|
53
|
-
# do not process fixtures
|
54
|
-
files.reject! { |file| file =~ /fixtures/ }
|
55
53
|
|
56
|
-
# check that at least one file was found, remove double slashes
|
54
|
+
# do not process fixtures, check that at least one file was found, and remove double slashes
|
55
|
+
files.reject! { |file| file =~ /fixtures/ }
|
57
56
|
raise "puppet-check: no files found in supplied paths #{paths.join(', ')}." if files.empty?
|
58
57
|
files.map! { |file| file.gsub('//', '/') }
|
58
|
+
|
59
59
|
files.uniq
|
60
60
|
end
|
61
61
|
|
data/lib/puppet-check/cli.rb
CHANGED
@@ -5,6 +5,7 @@ require_relative '../puppet-check'
|
|
5
5
|
class PuppetCheck::CLI
|
6
6
|
# run method for the cli
|
7
7
|
def self.run(args)
|
8
|
+
# gather the user arguments
|
8
9
|
parse(args)
|
9
10
|
raise 'puppet-check: no paths specified' if args.empty?
|
10
11
|
|
@@ -18,14 +19,21 @@ class PuppetCheck::CLI
|
|
18
19
|
# usage
|
19
20
|
opts.banner = 'usage: puppet-check [options] paths'
|
20
21
|
|
22
|
+
# base options
|
23
|
+
opts.on('--version', 'Display the current version.') do
|
24
|
+
puts 'puppet-check 1.2.1'
|
25
|
+
exit 0
|
26
|
+
end
|
27
|
+
|
21
28
|
# bool options
|
22
29
|
opts.on('-f', '--future', 'Enable future parser') { PuppetCheck.future_parser = true }
|
23
30
|
opts.on('-s', '--style', 'Enable style checks') { PuppetCheck.style_check = true }
|
31
|
+
|
24
32
|
# arguments to style checkers
|
25
33
|
opts.on('--puppet-lint arg_one,arg_two', Array, 'Arguments for PuppetLint ignored checks') do |puppetlint_args|
|
26
34
|
PuppetCheck.puppetlint_args += puppetlint_args.map { |arg| "--#{arg}" }
|
27
35
|
end
|
28
|
-
opts.on('-c', '--config file', 'Load PuppetLint options from file.') do |file|
|
36
|
+
opts.on('-c', '--config file', String, 'Load PuppetLint options from file.') do |file|
|
29
37
|
PuppetCheck.puppetlint_args += File.read(file).split("\n")
|
30
38
|
end
|
31
39
|
opts.on('--rubocop arg_one,arg_two', String, 'Arguments for Rubocop disabled cops') { |arg| PuppetCheck.rubocop_args = ['--except', arg] }
|
@@ -24,7 +24,7 @@ class PuppetParser
|
|
24
24
|
next PuppetCheck.error_files.push("-- #{file}:\n#{errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '')}")
|
25
25
|
end
|
26
26
|
|
27
|
-
# initialize warnings with output from the parser if it exists since
|
27
|
+
# initialize warnings with output from the parser if it exists, since the output is warnings if Puppet::Face did not trigger a SystemExit
|
28
28
|
warnings = errors.empty? ? "-- #{file}:" : "-- #{file}:\n#{errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '')}"
|
29
29
|
Puppet::Util::Log.close_all
|
30
30
|
|
@@ -37,7 +37,7 @@ class PuppetParser
|
|
37
37
|
begin
|
38
38
|
PuppetLint::OptParser.build.parse!(PuppetCheck.puppetlint_args)
|
39
39
|
rescue OptionParser::InvalidOption
|
40
|
-
raise
|
40
|
+
raise "puppet-lint: invalid option supplied among #{PuppetCheck.puppetlint_args}"
|
41
41
|
end
|
42
42
|
|
43
43
|
# prepare the PuppetLint object for style checks
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# class to prepare spec directory for rspec puppet testing
|
2
|
+
class RSpecPuppetSupport
|
3
|
+
# code diagram:
|
4
|
+
# 'puppetcheck:spec' task invokes 'run'
|
5
|
+
# 'run' invokes 'file_setup' always and 'dependency_setup' if metadata.json exists
|
6
|
+
# 'dependency_setup' invokes 'git/forge/hg' if dependencies exist and git/forge/hg is download option
|
7
|
+
|
8
|
+
# prepare the spec fixtures directory for rspec-puppet testing
|
9
|
+
def self.run
|
10
|
+
# ensure this method does not do anything inside module dependencies
|
11
|
+
specdirs = Dir.glob('**/spec').reject { |dir| dir =~ /fixtures/ }
|
12
|
+
return if specdirs.class.to_s == 'NilClass'
|
13
|
+
|
14
|
+
# setup fixtures for rspec-puppet testing
|
15
|
+
specdirs.each do |specdir|
|
16
|
+
# skip to next specdir if it does not seem like a puppet module
|
17
|
+
next unless File.directory?(specdir + '/../manifests')
|
18
|
+
|
19
|
+
# move up to module directory
|
20
|
+
Dir.chdir(specdir + '/..')
|
21
|
+
|
22
|
+
# grab the module name from the directory name of the module to pass to file_setup
|
23
|
+
file_setup(File.basename(Dir.pwd))
|
24
|
+
|
25
|
+
# invoke dependency_setup for module dependencies if metadata.json present
|
26
|
+
dependency_setup if File.file?('metadata.json')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# setup the files, directories, and symlinks for rspec-puppet testing
|
31
|
+
def self.file_setup(module_name)
|
32
|
+
require 'fileutils'
|
33
|
+
|
34
|
+
# create all the necessary fixture dirs that are missing
|
35
|
+
['spec/fixtures', 'spec/fixtures/manifests', 'spec/fixtures/modules', "spec/fixtures/modules/#{module_name}"].each do |dir|
|
36
|
+
FileUtils.mkdir(dir) unless File.directory?(dir)
|
37
|
+
end
|
38
|
+
|
39
|
+
# create empty site.pp if missing
|
40
|
+
FileUtils.touch('spec/fixtures/manifests/site.pp') unless File.file?('spec/fixtures/manifests/site.pp')
|
41
|
+
|
42
|
+
# symlink over everything the module needs for compilation
|
43
|
+
%w(hiera.yaml data hieradata functions manifests lib files templates).each do |file|
|
44
|
+
FileUtils.ln_s("../../../../#{file}", "spec/fixtures/modules/#{module_name}/#{file}") if File.exist?(file) && !File.exist?("spec/fixtures/modules/#{module_name}/#{file}")
|
45
|
+
end
|
46
|
+
|
47
|
+
# create spec_helper if missing
|
48
|
+
unless File.file?('spec/spec_helper.rb')
|
49
|
+
File.open('spec/spec_helper.rb', 'w') { |file| file.puts "require 'rspec-puppet/spec_helper'\n" }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# setup the module dependencies for rspec-puppet testing
|
54
|
+
def self.dependency_setup
|
55
|
+
require 'json'
|
56
|
+
|
57
|
+
# parse the metadata.json (assumes DataParser.json has already given it a pass)
|
58
|
+
parsed = JSON.parse(File.read('metadata.json'))
|
59
|
+
|
60
|
+
# grab dependencies if they exist
|
61
|
+
unless parsed['dependencies'].empty?
|
62
|
+
parsed['dependencies'].each do |dependency_hash|
|
63
|
+
# determine how the user wants to download the module dependency
|
64
|
+
if dependency_hash.key?('git')
|
65
|
+
git(dependency_hash['git'], dependency_hash['args'])
|
66
|
+
elsif dependency_hash.key?('forge')
|
67
|
+
forge(dependency_hash['forge'], dependency_hash['args'])
|
68
|
+
elsif dependency_hash.key?('hg')
|
69
|
+
hg(dependency_hash['hg'], dependency_hash['args'])
|
70
|
+
else
|
71
|
+
warn "#{dependency_hash['name']} has an unspecified, or specified but unsupported, download method."
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# download external module dependency with git
|
78
|
+
def self.git(git_url, args = '')
|
79
|
+
system("git -C spec/fixtures/modules/ clone #{args} #{git_url}")
|
80
|
+
end
|
81
|
+
|
82
|
+
# download external module dependency with forge
|
83
|
+
def self.forge(forge_name, args = '')
|
84
|
+
system("puppet module install --modulepath spec/fixtures/modules/ --force #{args} #{forge_name}")
|
85
|
+
end
|
86
|
+
|
87
|
+
# download external module dependency with hg
|
88
|
+
def self.hg(hg_url, args = '')
|
89
|
+
system("hg --cwd spec/fixtures/modules/ clone #{args} #{hg_url}")
|
90
|
+
end
|
91
|
+
end
|
@@ -76,7 +76,7 @@ class RubyParser
|
|
76
76
|
|
77
77
|
# check Rubocop
|
78
78
|
rubocop_args = PuppetCheck.rubocop_args.clone
|
79
|
-
# RuboCop is
|
79
|
+
# RuboCop is grumpy about non-snake_case filenames so disable the Style/FileName check
|
80
80
|
rubocop_args.include?('--except') ? rubocop_args[rubocop_args.index('--except') + 1] = "#{rubocop_args[rubocop_args.index('--except') + 1]},Style/FileName" : rubocop_args.concat(['--except', 'Style/FileName'])
|
81
81
|
warnings = Utils.capture_stdout { RuboCop::CLI.new.run(rubocop_args + ['--format', 'emacs', file]) }
|
82
82
|
|
data/lib/puppet-check/tasks.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
require 'rspec/core/rake_task'
|
2
2
|
require 'rake/tasklib'
|
3
|
-
require 'rake/task'
|
4
3
|
require_relative '../puppet-check'
|
4
|
+
require_relative 'rspec_puppet_support'
|
5
5
|
|
6
6
|
# the rake interface for PuppetCheck
|
7
7
|
class PuppetCheck::Tasks < ::Rake::TaskLib
|
8
8
|
def initialize
|
9
9
|
desc 'Execute all Puppet-Check checks'
|
10
|
-
task :puppetcheck
|
11
|
-
%w(puppetcheck:file puppetcheck:spec puppetcheck:beaker).each { |task| Rake::Task[task.to_sym].invoke }
|
12
|
-
end
|
10
|
+
task puppetcheck: %w(puppetcheck:file puppetcheck:spec puppetcheck:beaker)
|
13
11
|
|
14
12
|
namespace :puppetcheck do
|
15
13
|
desc 'Execute Puppet-Check file checks'
|
@@ -21,7 +19,7 @@ class PuppetCheck::Tasks < ::Rake::TaskLib
|
|
21
19
|
|
22
20
|
desc 'Execute RSpec and RSpec-Puppet tests'
|
23
21
|
RSpec::Core::RakeTask.new(:spec) do |task|
|
24
|
-
|
22
|
+
RSpecPuppetSupport.run
|
25
23
|
# generate tasks for all recognized directories and ensure spec tests inside module dependencies are ignored
|
26
24
|
spec_dirs = Dir.glob('**/{classes,defines,facter,functions,hosts,puppet,unit,types}/**/*_spec.rb').reject { |dir| dir =~ /fixtures/ }
|
27
25
|
task.pattern = spec_dirs.empty? ? 'skip_rspec' : spec_dirs
|
@@ -35,91 +33,6 @@ class PuppetCheck::Tasks < ::Rake::TaskLib
|
|
35
33
|
end
|
36
34
|
end
|
37
35
|
end
|
38
|
-
|
39
|
-
# code diagram for rspec-puppet support:
|
40
|
-
# puppetcheck:spec task invokes rspec_puppet_setup
|
41
|
-
# rspec_puppet_setup invokes rspec_puppet_file_setup always and rspec_puppet_dependency_setup if metadata.json exists
|
42
|
-
# rspec_puppet_dependency_setup invokes rspec_puppet_git/forge/hg if git/forge/hg is download option and dependencies exist
|
43
|
-
|
44
|
-
# prepare the spec fixtures directory for rspec-puppet testing
|
45
|
-
def self.rspec_puppet_setup
|
46
|
-
# ensure this method does not do anything inside module dependencies
|
47
|
-
specdirs = Dir.glob('**/spec').reject { |dir| dir =~ /fixtures/ }
|
48
|
-
return if specdirs.class.to_s == 'NilClass'
|
49
|
-
|
50
|
-
# setup fixtures for rspec-puppet testing
|
51
|
-
specdirs.each do |specdir|
|
52
|
-
# skip to next specdir if it does not seem like a puppet module
|
53
|
-
next unless File.directory?(specdir + '/../manifests')
|
54
|
-
|
55
|
-
# move up to module directory
|
56
|
-
Dir.chdir(specdir + '/..')
|
57
|
-
|
58
|
-
# grab the module name from the directory name of the module to pass to rspec_puppet_file_setup
|
59
|
-
rspec_puppet_file_setup(File.basename(Dir.pwd))
|
60
|
-
|
61
|
-
# invoke rspec_puppet_dependency_setup for module dependencies if metadata.json present
|
62
|
-
rspec_puppet_dependency_setup if File.file?('metadata.json')
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# setup the files, directories, and symlinks for rspec-puppet testing
|
67
|
-
def self.rspec_puppet_file_setup(module_name)
|
68
|
-
# create all the necessary fixture dirs that are missing
|
69
|
-
['spec/fixtures', 'spec/fixtures/manifests', 'spec/fixtures/modules', "spec/fixtures/modules/#{module_name}"].each do |dir|
|
70
|
-
FileUtils.mkdir(dir) unless File.directory?(dir)
|
71
|
-
end
|
72
|
-
|
73
|
-
# create empty site.pp if missing
|
74
|
-
FileUtils.touch('spec/fixtures/manifests/site.pp') unless File.file?('spec/fixtures/manifests/site.pp')
|
75
|
-
|
76
|
-
# symlink over everything the module needs for compilation
|
77
|
-
%w(hiera.yaml data hieradata functions manifests lib files templates).each do |file|
|
78
|
-
FileUtils.ln_s("../../../../#{file}", "spec/fixtures/modules/#{module_name}/#{file}") if File.exist?(file) && !File.exist?("spec/fixtures/modules/#{module_name}/#{file}")
|
79
|
-
end
|
80
|
-
|
81
|
-
# create spec_helper if missing
|
82
|
-
unless File.file?('spec/spec_helper.rb')
|
83
|
-
File.open('spec/spec_helper.rb', 'w') { |file| file.puts "require 'rspec-puppet/spec_helper'\n" }
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# setup the module dependencies for rspec-puppet testing
|
88
|
-
def self.rspec_puppet_dependency_setup
|
89
|
-
# parse the metadata.json (assumes PuppetCheck file checks have already given it a pass)
|
90
|
-
parsed = JSON.parse(File.read('metadata.json'))
|
91
|
-
|
92
|
-
# grab dependencies if they exist
|
93
|
-
unless parsed['dependencies'].empty?
|
94
|
-
parsed['dependencies'].each do |dependency_hash|
|
95
|
-
# determine how the user wants to download the module dependency
|
96
|
-
if dependency_hash.key?('git')
|
97
|
-
rspec_puppet_git(dependency_hash['git'])
|
98
|
-
elsif dependency_hash.key?('forge')
|
99
|
-
rspec_puppet_forge(dependency_hash['forge'])
|
100
|
-
elsif dependency_hash.key?('hg')
|
101
|
-
rspec_puppet_hg(dependency_hash['hg'])
|
102
|
-
else
|
103
|
-
warn "#{dependency_hash['name']} has an unspecified, or specified but unsupported, download method."
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
# download external module dependency with git
|
110
|
-
def self.rspec_puppet_git(git_url)
|
111
|
-
system("git -C spec/fixtures/modules/ clone #{git_url}")
|
112
|
-
end
|
113
|
-
|
114
|
-
# download external module dependency with forge
|
115
|
-
def self.rspec_puppet_forge(forge_name)
|
116
|
-
system("puppet module install #{forge_name} --modulepath spec/fixtures/modules/ --force")
|
117
|
-
end
|
118
|
-
|
119
|
-
# download external module dependency with hg
|
120
|
-
def self.rspec_puppet_hg(hg_url)
|
121
|
-
system("hg --cwd spec/fixtures/modules/ clone #{hg_url}")
|
122
|
-
end
|
123
36
|
end
|
124
37
|
|
125
38
|
PuppetCheck::Tasks.new
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative '../spec_helper.rb'
|
2
|
+
require_relative '../../lib/puppet-check/rspec_puppet_support'
|
3
|
+
|
4
|
+
describe RSpecPuppetSupport do
|
5
|
+
context '.run' do
|
6
|
+
let(:rspec_puppet_setup) { RSpecPuppetSupport.run }
|
7
|
+
before(:each) { Dir.chdir(fixtures_dir) }
|
8
|
+
|
9
|
+
it 'creates missing directories, missing site.pp, missing symlinks, and a missing spec_helper' do
|
10
|
+
expect { rspec_puppet_setup }.to output("puppetlabs/gruntmaster has an unspecified, or specified but unsupported, download method.\n").to_stderr
|
11
|
+
|
12
|
+
# .file_setup
|
13
|
+
expect(File.directory?('spec/fixtures/manifests')).to be true
|
14
|
+
expect(File.directory?('spec/fixtures/modules/fixtures')).to be true
|
15
|
+
expect(File.file?('spec/fixtures/manifests/site.pp')).to be true
|
16
|
+
expect(File.symlink?('spec/fixtures/modules/fixtures/hieradata')).to be true
|
17
|
+
expect(File.symlink?('spec/fixtures/modules/fixtures/manifests')).to be true
|
18
|
+
expect(File.symlink?('spec/fixtures/modules/fixtures/lib')).to be true
|
19
|
+
expect(File.symlink?('spec/fixtures/modules/fixtures/templates')).to be true
|
20
|
+
expect(File.file?('spec/spec_helper.rb')).to be true
|
21
|
+
|
22
|
+
# .dependency_setup
|
23
|
+
expect(File.directory?('spec/fixtures/modules/puppetlabs-lvm')).to be true
|
24
|
+
expect(File.directory?('spec/fixtures/modules/stdlib')).to be true
|
25
|
+
|
26
|
+
# cleanup rspec_puppet_setup
|
27
|
+
%w(spec/spec_helper.rb).each { |file| File.delete(file) }
|
28
|
+
%w(manifests modules).each { |dir| FileUtils.rm_r('spec/fixtures/' + dir) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -31,29 +31,4 @@ describe PuppetCheck::Tasks do
|
|
31
31
|
expect { beaker_tasks }.not_to raise_exception
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
35
|
-
context '.rspec_puppet_setup' do
|
36
|
-
let(:rspec_puppet_setup) { PuppetCheck::Tasks.rspec_puppet_setup }
|
37
|
-
before(:each) { Dir.chdir(fixtures_dir) }
|
38
|
-
|
39
|
-
it 'creates missing directories, missing site.pp, missing symlinks, and a missing spec_helper' do
|
40
|
-
expect { rspec_puppet_setup }.to output("puppetlabs/gruntmaster has an unspecified, or specified but unsupported, download method.\n").to_stderr
|
41
|
-
|
42
|
-
expect(File.directory?('spec/fixtures/manifests')).to be true
|
43
|
-
expect(File.directory?('spec/fixtures/modules/fixtures')).to be true
|
44
|
-
expect(File.file?('spec/fixtures/manifests/site.pp')).to be true
|
45
|
-
expect(File.symlink?('spec/fixtures/modules/fixtures/hieradata')).to be true
|
46
|
-
expect(File.symlink?('spec/fixtures/modules/fixtures/manifests')).to be true
|
47
|
-
expect(File.symlink?('spec/fixtures/modules/fixtures/lib')).to be true
|
48
|
-
expect(File.symlink?('spec/fixtures/modules/fixtures/templates')).to be true
|
49
|
-
expect(File.file?('spec/spec_helper.rb')).to be true
|
50
|
-
|
51
|
-
expect(File.directory?('spec/fixtures/modules/puppetlabs-lvm')).to be true
|
52
|
-
expect(File.directory?('spec/fixtures/modules/stdlib')).to be true
|
53
|
-
|
54
|
-
# cleanup rspec_puppet_setup
|
55
|
-
%w(spec/spec_helper.rb).each { |file| File.delete(file) }
|
56
|
-
%w(manifests modules).each { |dir| FileUtils.rm_r('spec/fixtures/' + dir) }
|
57
|
-
end
|
58
|
-
end
|
59
34
|
end
|
data/spec/puppet-check_spec.rb
CHANGED
@@ -2,8 +2,6 @@ require_relative 'spec_helper'
|
|
2
2
|
require_relative '../lib/puppet-check'
|
3
3
|
|
4
4
|
describe PuppetCheck do
|
5
|
-
let(:puppetcheck) { PuppetCheck.new }
|
6
|
-
|
7
5
|
context 'self' do
|
8
6
|
it 'future parser can be altered' do
|
9
7
|
PuppetCheck.future_parser = true
|
@@ -26,11 +24,11 @@ describe PuppetCheck do
|
|
26
24
|
context '.parse_paths' do
|
27
25
|
before(:each) { Dir.chdir(fixtures_dir) }
|
28
26
|
|
29
|
-
let(:no_files) {
|
30
|
-
let(:file) {
|
31
|
-
let(:dir) {
|
32
|
-
let(:multi_dir) {
|
33
|
-
let(:repeats) {
|
27
|
+
let(:no_files) { PuppetCheck.parse_paths(%w(foo bar baz)) }
|
28
|
+
let(:file) { PuppetCheck.parse_paths(['lib/good.rb']) }
|
29
|
+
let(:dir) { PuppetCheck.parse_paths(['.']) }
|
30
|
+
let(:multi_dir) { PuppetCheck.parse_paths(%w(hieradata lib manifests)) }
|
31
|
+
let(:repeats) { PuppetCheck.parse_paths(['hieradata', 'hieradata', 'lib', 'hieradata/good.json', 'manifests/good.pp', 'manifests/good.pp']) }
|
34
32
|
|
35
33
|
it 'raises an error if no files were found' do
|
36
34
|
expect { no_files }.to raise_error(RuntimeError, 'puppet-check: no files found in supplied paths foo, bar, baz.')
|
data/spec/system/system_spec.rb
CHANGED
@@ -5,7 +5,7 @@ require_relative '../../lib/puppet-check/tasks'
|
|
5
5
|
|
6
6
|
describe 'PuppetCheck' do
|
7
7
|
context 'executed as a system from the CLI with arguments and various files to be processed' do
|
8
|
-
let(:cli) { PuppetCheck::CLI.run(%w(-s --puppet-lint no-hard_tabs-check,no-
|
8
|
+
let(:cli) { PuppetCheck::CLI.run(%w(-s --puppet-lint no-hard_tabs-check,no-140chars-check --rubocop Metrics/LineLength,Style/Encoding .)) }
|
9
9
|
|
10
10
|
it 'outputs diagnostic results correctly after processing all of the files' do
|
11
11
|
Dir.chdir(fixtures_dir)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Schuchard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet
|
@@ -50,14 +50,14 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '2.0'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
60
|
+
version: '2.0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: spdx-licenses
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- lib/puppet-check/cli.rb
|
124
124
|
- lib/puppet-check/data_parser.rb
|
125
125
|
- lib/puppet-check/puppet_parser.rb
|
126
|
+
- lib/puppet-check/rspec_puppet_support.rb
|
126
127
|
- lib/puppet-check/ruby_parser.rb
|
127
128
|
- lib/puppet-check/tasks.rb
|
128
129
|
- lib/puppet-check/utils.rb
|
@@ -158,6 +159,7 @@ files:
|
|
158
159
|
- spec/puppet-check/cli_spec.rb
|
159
160
|
- spec/puppet-check/data_parser_spec.rb
|
160
161
|
- spec/puppet-check/puppet_parser_spec.rb
|
162
|
+
- spec/puppet-check/rspec_puppet_support_spec.rb
|
161
163
|
- spec/puppet-check/ruby_parser_spec.rb
|
162
164
|
- spec/puppet-check/tasks_spec.rb
|
163
165
|
- spec/puppet-check/utils_spec.rb
|
@@ -222,6 +224,7 @@ test_files:
|
|
222
224
|
- spec/puppet-check/cli_spec.rb
|
223
225
|
- spec/puppet-check/data_parser_spec.rb
|
224
226
|
- spec/puppet-check/puppet_parser_spec.rb
|
227
|
+
- spec/puppet-check/rspec_puppet_support_spec.rb
|
225
228
|
- spec/puppet-check/ruby_parser_spec.rb
|
226
229
|
- spec/puppet-check/tasks_spec.rb
|
227
230
|
- spec/puppet-check/utils_spec.rb
|