rspec-puppet-utils 3.1.0 → 3.2.0
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 +4 -4
- data/README.md +38 -13
- data/lib/rspec_puppet_utils/rake/project_tasks.rb +49 -37
- data/rspec-puppet-utils.gemspec +2 -2
- data/spec/classes/rake/project_tasks_spec.rb +50 -28
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6408456fd57f31f7a1dac8a2e5d2f77abce8ec74
|
4
|
+
data.tar.gz: 4c315ea6bd272943af43901067793efd9e5b842c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfcc051e951a036c1a9037555f74e7be1a5de6b0a2310005013d97ff9f1c32a4ed03aeb8f10516952cbf3b541395940c8d98bd81db62f4efc2847ac047389a4a
|
7
|
+
data.tar.gz: 0aceea0bb7188ceff7ee84338de98310beded94f938f9e1ae5a6aec01f369dddd1b8444f0b739b0294cdd4dd9a80234cae8cc1911261027cf1fac4ea0910e83c
|
data/README.md
CHANGED
@@ -247,12 +247,11 @@ For more about usage see the [wiki page](../../wiki/Hiera-Data-Validator)
|
|
247
247
|
|
248
248
|
The `Rake::Puppet` class provides tasks that handle testing and building a Puppet project.
|
249
249
|
|
250
|
-
##### Usage
|
250
|
+
##### Usage
|
251
251
|
|
252
252
|
An example `Rakefile` might look like this:
|
253
253
|
|
254
254
|
```ruby
|
255
|
-
require 'rake'
|
256
255
|
require 'rspec_puppet_utils/rake/project_tasks'
|
257
256
|
|
258
257
|
puppet = Rake::Puppet.new
|
@@ -260,15 +259,15 @@ puppet.package_version = '1.0.0'
|
|
260
259
|
puppet.load_tasks
|
261
260
|
```
|
262
261
|
|
263
|
-
Running `rake -T`
|
262
|
+
Running `rake -T` should now show a list of spec and build tasks:
|
264
263
|
|
265
264
|
```bash
|
266
265
|
$ rake -T
|
267
266
|
rake build # Build puppet.zip v1.0.0
|
268
267
|
rake quick_build # Build puppet.zip v1.0.0 without tests
|
269
268
|
rake spec # Run specs in all modules
|
270
|
-
rake
|
271
|
-
rake
|
269
|
+
rake <mod a>:spec # Run <mod a> module specs
|
270
|
+
rake <mod b>:spec # Run <mod b> module specs
|
272
271
|
...
|
273
272
|
```
|
274
273
|
|
@@ -281,10 +280,40 @@ In the example above `package_version` is set as it's a required field. The othe
|
|
281
280
|
- module_path - The directory containing all the modules to test (default: 'modules')
|
282
281
|
- excluded_modules - Modules to exclude from rspec testing (default: [])
|
283
282
|
- package_dir - Where the puppet zip package will be created (default: 'pkg')
|
284
|
-
- package_files - Files and directories to include in the package (default: ['modules', 'modules-lib', '
|
283
|
+
- package_files - Files and directories to include in the package (default: ['modules', 'modules-lib', 'environment.conf'])
|
285
284
|
- package_versioning - Is the version included in the package name? (default: true)
|
286
285
|
|
287
|
-
#####
|
286
|
+
##### Setup
|
287
|
+
|
288
|
+
The `spec` task for each module actually just executes the `spec` task defined in the module's Rakefile,
|
289
|
+
and the `Rake::Puppet` class will filter out modules that dont have a Rakefile,
|
290
|
+
|
291
|
+
Therefore each module needs the following two files:
|
292
|
+
|
293
|
+
```ruby
|
294
|
+
# <mod>/Rakefile
|
295
|
+
require 'puppetlabs_spec_helper/rake_tasks'
|
296
|
+
```
|
297
|
+
|
298
|
+
```ruby
|
299
|
+
# <mod>/spec/spec_helper.rb
|
300
|
+
require 'rspec-puppet-utils'
|
301
|
+
require 'puppetlabs_spec_helper/module_spec_helper'
|
302
|
+
```
|
303
|
+
|
304
|
+
Extra content/tasks/options/etc can be added to these files, but this is the suggested minimum
|
305
|
+
|
306
|
+
In order for the `modules-lib` modules to be available to the Puppet server, each environment will need an `environment.conf` file to set the module path,
|
307
|
+
therefore an `environment.conf` file should be present in the project root:
|
308
|
+
|
309
|
+
```
|
310
|
+
# environment.conf
|
311
|
+
modulepath = ./modules:./modules-lib:$basemodulepath
|
312
|
+
```
|
313
|
+
|
314
|
+
Again, other settings can be changed, this is just the minimum to get the modules-lib pattern working
|
315
|
+
|
316
|
+
##### NB
|
288
317
|
|
289
318
|
The `package_files` list is setup for the modules-lib pattern by default. In this pattern external (e.g. Puppet Forge) modules are installed in a separate 'modules-lib', leaving the 'modules' dir for project modules such as 'components', 'profiles', 'role', etc.
|
290
319
|
If you're not using this pattern then just provide a new array for `package_files`.
|
@@ -293,12 +322,8 @@ Running the `build` or `quick_build` tasks will delete any existing builds in th
|
|
293
322
|
This is so the same build task can be run over and over on a build server (e.g. Jenkins) without filling up the disk.
|
294
323
|
It also guarantees that the binary at the end of a build was just built, and wasn't left over from a previous build.
|
295
324
|
|
296
|
-
##### ToDo
|
325
|
+
##### ToDo
|
297
326
|
|
298
|
-
Currently the `spec` task runs all the `
|
327
|
+
Currently the `spec` task runs all the `<module>:spec` tasks. If one of these fails then none of the subsequent tasks will run. This isn't ideal!
|
299
328
|
|
300
329
|
The zip commands need to be replaced by ruby zip library to avoid shelling out, this helps with support for Windows environments
|
301
|
-
|
302
|
-
### Module Tasks
|
303
|
-
|
304
|
-
WIP
|
@@ -27,88 +27,100 @@ module Rake
|
|
27
27
|
@excluded_dirs = ['.', '..']
|
28
28
|
@excluded_modules = []
|
29
29
|
@package_dir = 'pkg'
|
30
|
-
@package_files = ['modules', 'modules-lib', '
|
30
|
+
@package_files = ['modules', 'modules-lib', 'environment.conf']
|
31
31
|
@package_name = 'puppet'
|
32
32
|
@package_version = nil
|
33
33
|
@package_versioning = true
|
34
34
|
end
|
35
35
|
|
36
36
|
def load_tasks
|
37
|
-
|
37
|
+
load_module_tasks
|
38
38
|
load_build_tasks
|
39
39
|
end
|
40
40
|
|
41
41
|
def testable_modules
|
42
42
|
raise ArgumentError, 'Excluded modules must be an array' unless @excluded_modules.is_a? Array
|
43
43
|
module_dirs = Dir.entries(@module_path) - @excluded_dirs - @excluded_modules
|
44
|
-
module_dirs
|
44
|
+
filter_modules module_dirs
|
45
|
+
end
|
46
|
+
|
47
|
+
def filter_modules(module_dirs)
|
48
|
+
module_dirs.select! { |m| module_has_specs?(m) and module_has_rakefile?(m) }
|
45
49
|
module_dirs
|
46
50
|
end
|
47
51
|
|
48
|
-
def
|
52
|
+
def module_has_specs?(module_dir)
|
53
|
+
File.directory?("#{@module_path}/#{module_dir}/spec")
|
54
|
+
end
|
49
55
|
|
50
|
-
|
51
|
-
|
56
|
+
def module_has_rakefile?(module_dir)
|
57
|
+
rakefiles = ['rakefile', 'rakefile.rb']
|
58
|
+
entries = Dir.entries("#{@module_path}/#{module_dir}")
|
59
|
+
entries.collect! { |f| f.downcase }
|
60
|
+
rakefiles.each { |rf| return true if entries.include? rf }
|
61
|
+
false
|
62
|
+
end
|
52
63
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
64
|
+
def load_module_tasks
|
65
|
+
|
66
|
+
modules = testable_modules
|
67
|
+
spec_tasks = modules.collect { |m| "#{m}:#{:spec}" }
|
68
|
+
# lint_tasks = modules.collect { |m| "#{m}:#{:lint}" }
|
69
|
+
|
70
|
+
modules.each { |puppet_module|
|
71
|
+
namespace puppet_module do
|
57
72
|
|
58
73
|
desc "Run #{puppet_module} module specs"
|
59
|
-
|
60
|
-
|
61
|
-
|
74
|
+
task :spec do
|
75
|
+
Dir.chdir "#{@module_path}/#{puppet_module}" do
|
76
|
+
success = system('rake spec') # This isn't perfect but ...
|
77
|
+
exit success ? 0 : 1
|
78
|
+
end
|
62
79
|
end
|
63
|
-
|
64
|
-
|
80
|
+
|
81
|
+
end
|
82
|
+
}
|
83
|
+
|
84
|
+
# desc 'Run lint checks for all modules'
|
85
|
+
# task :lint => lint_tasks
|
65
86
|
|
66
87
|
desc 'Run specs in all modules'
|
67
|
-
task :spec =>
|
88
|
+
task :spec => spec_tasks
|
68
89
|
task :default => :spec
|
90
|
+
|
69
91
|
end
|
70
92
|
|
71
93
|
def load_build_tasks
|
72
94
|
|
73
95
|
raise(ArgumentError, 'Please provide a package_version (e.g. "1.0.0")') if @package_version.nil?
|
74
96
|
|
75
|
-
# The build_dir (i.e. 'puppet') is the root dir of the files when the zip is extracted
|
76
|
-
build_dir = "#{@package_dir}/puppet"
|
77
97
|
full_package_name = @package_versioning ? "puppet-#{@package_version}.zip" : 'puppet.zip'
|
78
98
|
package_desc = @package_versioning ? full_package_name : "#{full_package_name} v#{@package_version}"
|
99
|
+
package_path = "#{@package_dir}/#{full_package_name}"
|
79
100
|
|
80
101
|
namespace :build do
|
81
102
|
|
82
103
|
# Preps build directory
|
83
104
|
task :prep do
|
84
105
|
puts 'Preparing build'
|
85
|
-
FileUtils.
|
86
|
-
FileUtils.
|
87
|
-
@package_files.each {|f|
|
88
|
-
if File.exist? f
|
89
|
-
puts "Copying #{f} to #{build_dir}"
|
90
|
-
FileUtils.cp_r f, build_dir
|
91
|
-
else
|
92
|
-
fail "Could not find #{f} file or directory: Ensure that the package_files list is correct"
|
93
|
-
end
|
94
|
-
}
|
106
|
+
FileUtils.mkdir_p @package_dir
|
107
|
+
FileUtils.rm package_path if File.exist?(package_path)
|
95
108
|
end
|
96
109
|
|
97
110
|
task :package => [:prep] do
|
98
|
-
# Exclude
|
99
|
-
exclude_patterns = '
|
100
|
-
|
101
|
-
|
111
|
+
# Exclude all the spec code as it's not needed once deployed
|
112
|
+
exclude_patterns = ['modules/\*/spec/\*', 'modules-lib/\*/spec/\*']
|
113
|
+
exclude_string = "-x #{exclude_patterns.join(' ')}"
|
114
|
+
include_string = @package_files.join(' ')
|
115
|
+
cmd = "zip -qr #{package_path} #{include_string} #{exclude_string}"
|
116
|
+
success = system(cmd)
|
117
|
+
exit 1 unless success
|
102
118
|
end
|
103
119
|
|
104
|
-
task :cleanup do
|
105
|
-
puts "Cleaning up #{build_dir}/"
|
106
|
-
FileUtils.rm_r build_dir if File.exist?(build_dir)
|
107
|
-
end
|
108
120
|
end
|
109
121
|
|
110
122
|
desc "Build #{package_desc} without tests"
|
111
|
-
task :quick_build =>
|
123
|
+
task :quick_build => 'build:package' do
|
112
124
|
puts "Built #{package_desc}"
|
113
125
|
end
|
114
126
|
|
data/rspec-puppet-utils.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |gem|
|
3
3
|
gem.name = 'rspec-puppet-utils'
|
4
|
-
gem.version = '3.
|
4
|
+
gem.version = '3.2.0'
|
5
5
|
gem.description = 'Helper classes for mock/stub functions, templates and hieradata'
|
6
6
|
gem.summary = ''
|
7
7
|
gem.author = 'Tom Poulton'
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
13
|
gem.require_paths = ['lib']
|
14
14
|
|
15
|
-
gem.add_dependency('puppet'
|
15
|
+
gem.add_dependency('puppet')
|
16
16
|
gem.add_dependency('rspec')
|
17
17
|
gem.add_dependency('rspec-puppet')
|
18
18
|
gem.add_dependency('puppetlabs_spec_helper')
|
@@ -6,6 +6,7 @@ describe Rake::Puppet do
|
|
6
6
|
module_path = 'modules'
|
7
7
|
testable_modules = [ 'core', 'base' ]
|
8
8
|
modules_dir_list = [ 'core', 'base', 'role', 'profiles' ]
|
9
|
+
rakefile_names = ['Rakefile', 'rakefile', 'Rakefile.rb', 'rakefile.rb']
|
9
10
|
|
10
11
|
let(:puppet) { Rake::Puppet.new }
|
11
12
|
|
@@ -16,7 +17,7 @@ describe Rake::Puppet do
|
|
16
17
|
expect(puppet.package_files.count).to eq initial_count + 1
|
17
18
|
end
|
18
19
|
|
19
|
-
describe '
|
20
|
+
describe 'load_module_tasks' do
|
20
21
|
|
21
22
|
before(:each) do
|
22
23
|
puppet.stubs(:testable_modules).returns(testable_modules) # not exactly best practice, but hey
|
@@ -24,18 +25,18 @@ describe Rake::Puppet do
|
|
24
25
|
|
25
26
|
it 'includes namespace and task methods from Rake::DSL' do
|
26
27
|
# It would throw error on load if task or namespace methods are missing
|
27
|
-
expect { puppet.
|
28
|
+
expect { puppet.load_module_tasks }.to_not raise_error
|
28
29
|
end
|
29
30
|
|
30
31
|
it 'creates a task for each module' do
|
31
|
-
puppet.
|
32
|
+
puppet.load_module_tasks
|
32
33
|
testable_modules.each { |mod|
|
33
|
-
expect(Rake::Task.task_defined?("
|
34
|
+
expect(Rake::Task.task_defined?("#{mod}:spec")).to eq true
|
34
35
|
}
|
35
36
|
end
|
36
37
|
|
37
38
|
it 'loads the main spec task' do
|
38
|
-
puppet.
|
39
|
+
puppet.load_module_tasks
|
39
40
|
expect(Rake::Task.task_defined?(:spec)).to eq true
|
40
41
|
end
|
41
42
|
|
@@ -94,37 +95,57 @@ describe Rake::Puppet do
|
|
94
95
|
|
95
96
|
end
|
96
97
|
|
97
|
-
describe '
|
98
|
+
describe 'filter_modules' do
|
98
99
|
|
99
|
-
|
100
|
-
Dir.stubs(:entries).
|
100
|
+
before(:each) do
|
101
|
+
Dir.stubs(:entries).returns []
|
102
|
+
end
|
101
103
|
|
102
|
-
|
104
|
+
it 'filters modules with a spec directory' do
|
105
|
+
Dir.stubs(:entries).returns rakefile_names # bypass Rakefile filter
|
106
|
+
|
107
|
+
File.stubs(:directory?).returns false
|
103
108
|
File.stubs(:directory?).with(regexp_matches( /(#{testable_modules.join '|'})\/spec$/ )).returns(true)
|
104
109
|
|
105
|
-
result = puppet.
|
110
|
+
result = puppet.filter_modules modules_dir_list
|
106
111
|
expect(result).to match_array testable_modules
|
107
112
|
end
|
108
113
|
|
109
|
-
|
110
|
-
|
114
|
+
rakefile_names.each { |filename|
|
115
|
+
it 'filters modules with a Rakefile' do
|
116
|
+
File.stubs(:directory?).returns true # bypass spec dir filter
|
111
117
|
|
112
|
-
|
113
|
-
testable_modules.each { |m|
|
114
|
-
File.expects(:directory?).with(regexp_matches( /#{alt_module_path}\/#{m}/ )).returns(true)
|
115
|
-
}
|
118
|
+
Dir.stubs(:entries).with(regexp_matches( /#{testable_modules.join '|'}/ )).returns([filename])
|
116
119
|
|
117
|
-
|
118
|
-
|
120
|
+
result = puppet.filter_modules modules_dir_list
|
121
|
+
expect(result).to match_array testable_modules
|
122
|
+
end
|
123
|
+
}
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
describe 'testable_modules' do
|
128
|
+
|
129
|
+
before(:each) do
|
130
|
+
# Bypass the filter logic. Again, not exactly best practice, but hey
|
131
|
+
def puppet.filter_modules(_modules)
|
132
|
+
_modules
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'ignores excluded directories' do
|
137
|
+
Dir.stubs(:entries).with(module_path).returns testable_modules + ['.', '..']
|
138
|
+
|
139
|
+
result = puppet.testable_modules
|
140
|
+
expect(result).to match_array testable_modules
|
119
141
|
end
|
120
142
|
|
121
143
|
it 'ignores excluded modules' do
|
122
|
-
Dir.stubs(:entries).with(module_path).returns testable_modules
|
123
|
-
File.stubs(:directory?).returns(true)
|
144
|
+
Dir.stubs(:entries).with(module_path).returns testable_modules + ['exclude_me']
|
124
145
|
|
125
|
-
puppet.excluded_modules = ['
|
146
|
+
puppet.excluded_modules = ['exclude_me']
|
126
147
|
result = puppet.testable_modules
|
127
|
-
expect(result).to match_array
|
148
|
+
expect(result).to match_array testable_modules
|
128
149
|
end
|
129
150
|
|
130
151
|
it 'throws error if excluded modules is not an array' do
|
@@ -132,14 +153,15 @@ describe Rake::Puppet do
|
|
132
153
|
expect { puppet.testable_modules }.to raise_error(ArgumentError, /must be an array/)
|
133
154
|
end
|
134
155
|
|
135
|
-
it '
|
136
|
-
|
137
|
-
File.stubs(:directory?).returns(true)
|
156
|
+
it 'finds modules within module_path' do
|
157
|
+
alt_module_path = 'modules-alt'
|
138
158
|
|
139
|
-
|
140
|
-
|
159
|
+
Dir.expects(:entries).with(alt_module_path).returns modules_dir_list
|
160
|
+
|
161
|
+
puppet.module_path = alt_module_path
|
162
|
+
puppet.testable_modules
|
141
163
|
end
|
142
164
|
|
143
165
|
end
|
144
166
|
|
145
|
-
end
|
167
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-puppet-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Poulton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|