puppetlabs_spec_helper 2.5.1 → 2.6.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -1
- data/lib/puppetlabs_spec_helper/rake_tasks.rb +210 -192
- data/lib/puppetlabs_spec_helper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3adeff1476e7d1c79bd8f1c565c1545bc03674f
|
4
|
+
data.tar.gz: 2d9d4b9869daa78653e68e05db09881cf1aa565a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95fc8c316731dd994d018c58b092ef7ae2408fe68f2eb0c7eb5b6dc5c0c552206267e49ca88e2718732b12c34385b65867abeffc36ee462ee4c4d68e8db86873
|
7
|
+
data.tar.gz: e3d978f0af9c5fccc97aff5638c2a9cf2d6dd39a9ba8d530e25ecb25385b71f4ac5cc20645506fdf0a2eee3d6780537b3593351b9399daaafff4f1632dc0fb83
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,17 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
+
## [2.6.1]
|
6
|
+
### Summary
|
7
|
+
Includes changes for 2.6.0 plus tests and bugfix of said feature.
|
8
|
+
|
9
|
+
## 2.6.0 - Yanked
|
10
|
+
### Summary
|
11
|
+
Adds a `defaults` section to `.fixtures.yml` to specify properties such as `flags` that apply to all fixtures in a category. One example use case is to specify an alternate forge URI for the `forge_modules` fixtures.
|
12
|
+
|
13
|
+
### Added
|
14
|
+
- Add `defaults` section to fixtures.
|
15
|
+
|
5
16
|
## [2.5.1]
|
6
17
|
### Summary
|
7
18
|
Adds a fix to the parallel_spec rake task.
|
@@ -415,7 +426,8 @@ compatible yet.
|
|
415
426
|
### Added
|
416
427
|
* Initial release
|
417
428
|
|
418
|
-
[unreleased]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.
|
429
|
+
[unreleased]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.6.1...master
|
430
|
+
[2.6.1]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.5.1...v2.6.1
|
419
431
|
[2.5.1]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.5.0...v2.5.1
|
420
432
|
[2.5.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.4.0...v2.5.0
|
421
433
|
[2.4.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.3.2...v2.4.0
|
@@ -4,6 +4,7 @@ require 'rspec/core/rake_task'
|
|
4
4
|
require 'tmpdir'
|
5
5
|
require 'yaml'
|
6
6
|
require 'pathname'
|
7
|
+
require 'puppetlabs_spec_helper/version'
|
7
8
|
|
8
9
|
# optional gems
|
9
10
|
begin
|
@@ -75,208 +76,246 @@ RSpec::Core::RakeTask.new(:beaker) do |t|
|
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
module PuppetlabsSpecHelper::RakeTasks
|
80
|
+
# This is a helper for the self-symlink entry of fixtures.yml
|
81
|
+
def source_dir
|
82
|
+
Dir.pwd
|
83
|
+
end
|
82
84
|
|
83
|
-
# cache the repositories and
|
84
|
-
def repositories
|
85
|
-
|
86
|
-
|
87
|
-
@repositories.each do |remote, opts|
|
88
|
-
if opts.instance_of?(String)
|
89
|
-
@repositories[remote] = {"target" => opts} # inject a hash
|
90
|
-
end
|
85
|
+
# cache the repositories and return a hash object
|
86
|
+
def repositories
|
87
|
+
unless @repositories
|
88
|
+
@repositories = fixtures('repositories')
|
91
89
|
end
|
90
|
+
@repositories
|
92
91
|
end
|
93
|
-
@repositories
|
94
|
-
end
|
95
92
|
|
96
|
-
# get the array of Beaker set names
|
97
|
-
# @return [Array<String>]
|
98
|
-
def beaker_node_sets
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
93
|
+
# get the array of Beaker set names
|
94
|
+
# @return [Array<String>]
|
95
|
+
def beaker_node_sets
|
96
|
+
return @beaker_nodes if @beaker_nodes
|
97
|
+
@beaker_nodes = Dir['spec/acceptance/nodesets/*.yml'].sort.map do |node_set|
|
98
|
+
node_set.slice!('.yml')
|
99
|
+
File.basename(node_set)
|
100
|
+
end
|
103
101
|
end
|
104
|
-
end
|
105
102
|
|
106
|
-
# Use "vagrant ssh" to login to the given node in the node set
|
107
|
-
# @param set [String] The name of the node set (yml file)
|
108
|
-
# @param node [String] The name of the node in the set. For multi-node sets.
|
109
|
-
def vagrant_ssh(set, node = nil)
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
103
|
+
# Use "vagrant ssh" to login to the given node in the node set
|
104
|
+
# @param set [String] The name of the node set (yml file)
|
105
|
+
# @param node [String] The name of the node in the set. For multi-node sets.
|
106
|
+
def vagrant_ssh(set, node = nil)
|
107
|
+
vagrant_yml_dir = File.join '.vagrant', 'beaker_vagrant_files', "#{set}.yml"
|
108
|
+
vagrant_file = File.join vagrant_yml_dir, 'Vagrantfile'
|
109
|
+
unless File.file? vagrant_file
|
110
|
+
puts "There is no Vagrantfile at: '#{vagrant_file}'. Perhaps, the node is not created or is destroyed."
|
111
|
+
exit 1
|
112
|
+
end
|
113
|
+
Dir.chdir(vagrant_yml_dir) do
|
114
|
+
command = 'vagrant ssh'
|
115
|
+
command += " #{node}" if node
|
116
|
+
# Vagrant is not distributed as a normal gem
|
117
|
+
# and we should protect it from the current Ruby environment
|
118
|
+
env = {
|
119
|
+
'RUBYLIB' => nil,
|
120
|
+
'GEM_PATH' => nil,
|
121
|
+
'BUNDLE_BIN_PATH' => nil,
|
122
|
+
}
|
123
|
+
system env, command
|
124
|
+
end
|
127
125
|
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def auto_symlink
|
131
|
-
{ File.basename(Dir.pwd).split('-').last => '#{source_dir}' }
|
132
|
-
end
|
133
126
|
|
134
|
-
def
|
135
|
-
|
136
|
-
fixtures_yaml = '.fixtures.yml'
|
137
|
-
elsif File.exists?('.fixtures.yaml')
|
138
|
-
fixtures_yaml = '.fixtures.yaml'
|
139
|
-
else
|
140
|
-
fixtures_yaml = ''
|
127
|
+
def auto_symlink
|
128
|
+
{ File.basename(Dir.pwd).split('-').last => '#{source_dir}' }
|
141
129
|
end
|
142
130
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
fixtures
|
147
|
-
|
148
|
-
|
149
|
-
|
131
|
+
def fixtures(category)
|
132
|
+
if ENV['FIXTURES_YML']
|
133
|
+
fixtures_yaml = ENV['FIXTURES_YML']
|
134
|
+
elsif File.exists?('.fixtures.yml')
|
135
|
+
fixtures_yaml = '.fixtures.yml'
|
136
|
+
elsif File.exists?('.fixtures.yaml')
|
137
|
+
fixtures_yaml = '.fixtures.yaml'
|
138
|
+
else
|
139
|
+
fixtures_yaml = false
|
140
|
+
end
|
150
141
|
|
151
|
-
|
152
|
-
|
153
|
-
|
142
|
+
begin
|
143
|
+
if fixtures_yaml
|
144
|
+
fixtures = YAML.load_file(fixtures_yaml) || { 'fixtures' => {} }
|
145
|
+
else
|
146
|
+
fixtures = { 'fixtures' => {} }
|
147
|
+
end
|
148
|
+
rescue Errno::ENOENT
|
149
|
+
fail("Fixtures file not found: '#{fixtures_yaml}'")
|
150
|
+
rescue Psych::SyntaxError => e
|
151
|
+
fail("Found malformed YAML in '#{fixtures_yaml}' on line #{e.line} column #{e.column}: #{e.problem}")
|
152
|
+
end
|
154
153
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
source = opts
|
160
|
-
target = "spec/fixtures/modules/#{fixture}"
|
161
|
-
real_source = eval('"'+source+'"')
|
162
|
-
result[real_source] = target
|
163
|
-
elsif opts.instance_of?(Hash)
|
154
|
+
unless fixtures.include?('fixtures')
|
155
|
+
# File is non-empty, but does not specify fixtures
|
156
|
+
fail("No 'fixtures' entries found in '#{fixtures_yaml}'; required")
|
157
|
+
end
|
164
158
|
|
165
|
-
|
166
|
-
|
167
|
-
|
159
|
+
if fixtures.include? 'defaults'
|
160
|
+
fixture_defaults = fixtures['defaults']
|
161
|
+
else
|
162
|
+
fixture_defaults = {}
|
163
|
+
end
|
164
|
+
|
165
|
+
fixtures = fixtures['fixtures']
|
166
|
+
|
167
|
+
if fixtures['symlinks'].nil?
|
168
|
+
fixtures['symlinks'] = auto_symlink
|
169
|
+
end
|
170
|
+
|
171
|
+
result = {}
|
172
|
+
if fixtures.include? category and fixtures[category] != nil
|
173
|
+
|
174
|
+
defaults = { "target" => "spec/fixtures/modules" }
|
168
175
|
|
169
|
-
|
170
|
-
|
176
|
+
# load defaults from the `.fixtures.yml` `defaults` section
|
177
|
+
# for the requested category and merge them into my defaults
|
178
|
+
if fixture_defaults.include? category
|
179
|
+
defaults = defaults.merge(fixture_defaults[category])
|
180
|
+
end
|
181
|
+
|
182
|
+
fixtures[category].each do |fixture, opts|
|
183
|
+
# convert a simple string fixture to a hash, by
|
184
|
+
# using the string fixture as the `repo` option of the hash.
|
185
|
+
if opts.instance_of?(String)
|
186
|
+
opts = { "repo" => opts }
|
171
187
|
end
|
188
|
+
# there should be a warning or something if it's not a hash...
|
189
|
+
if opts.instance_of?(Hash)
|
190
|
+
# merge our options into the defaults to get the
|
191
|
+
# final option list
|
192
|
+
opts = defaults.merge(opts)
|
172
193
|
|
173
|
-
|
194
|
+
real_target = eval('"'+opts["target"]+'"')
|
195
|
+
real_source = eval('"'+opts["repo"]+'"')
|
174
196
|
|
175
|
-
|
197
|
+
result[real_source] = { "target" => File.join(real_target,fixture), "ref" => opts["ref"], "branch" => opts["branch"], "scm" => opts["scm"], "flags" => opts["flags"], "subdir" => opts["subdir"]}
|
198
|
+
end
|
176
199
|
end
|
177
200
|
end
|
201
|
+
return result
|
202
|
+
end
|
203
|
+
|
204
|
+
def clone_repo(scm, remote, target, subdir=nil, ref=nil, branch=nil, flags = nil)
|
205
|
+
args = []
|
206
|
+
case scm
|
207
|
+
when 'hg'
|
208
|
+
args.push('clone')
|
209
|
+
args.push('-b', branch) if branch
|
210
|
+
args.push(flags) if flags
|
211
|
+
args.push(remote, target)
|
212
|
+
when 'git'
|
213
|
+
args.push('clone')
|
214
|
+
args.push('--depth 1') unless ref
|
215
|
+
args.push('-b', branch) if branch
|
216
|
+
args.push(flags) if flags
|
217
|
+
args.push(remote, target)
|
218
|
+
else
|
219
|
+
fail "Unfortunately #{scm} is not supported yet"
|
220
|
+
end
|
221
|
+
result = system("#{scm} #{args.flatten.join ' '}")
|
222
|
+
unless File::exists?(target)
|
223
|
+
fail "Failed to clone #{scm} repository #{remote} into #{target}"
|
224
|
+
end
|
225
|
+
result
|
178
226
|
end
|
179
|
-
return result
|
180
|
-
end
|
181
227
|
|
182
|
-
def
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
args.
|
193
|
-
args.push('-b', branch) if branch
|
194
|
-
args.push(flags) if flags
|
195
|
-
args.push(remote, target)
|
196
|
-
else
|
197
|
-
fail "Unfortunately #{scm} is not supported yet"
|
228
|
+
def revision(scm, target, ref)
|
229
|
+
args = []
|
230
|
+
case scm
|
231
|
+
when 'hg'
|
232
|
+
args.push('update', '--clean', '-r', ref)
|
233
|
+
when 'git'
|
234
|
+
args.push('reset', '--hard', ref)
|
235
|
+
else
|
236
|
+
fail "Unfortunately #{scm} is not supported yet"
|
237
|
+
end
|
238
|
+
system("cd #{target} && #{scm} #{args.flatten.join ' '}")
|
198
239
|
end
|
199
|
-
|
200
|
-
|
201
|
-
|
240
|
+
|
241
|
+
def remove_subdirectory(target, subdir)
|
242
|
+
unless subdir.nil?
|
243
|
+
Dir.mktmpdir {|tmpdir|
|
244
|
+
FileUtils.mv(Dir.glob("#{target}/#{subdir}/{.[^\.]*,*}"), tmpdir)
|
245
|
+
FileUtils.rm_rf("#{target}/#{subdir}")
|
246
|
+
FileUtils.mv(Dir.glob("#{tmpdir}/{.[^\.]*,*}"), "#{target}")
|
247
|
+
}
|
248
|
+
end
|
202
249
|
end
|
203
|
-
result
|
204
|
-
end
|
205
250
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
251
|
+
# creates a logger so we can log events with certain levels
|
252
|
+
def logger
|
253
|
+
unless @logger
|
254
|
+
require 'logger'
|
255
|
+
if ENV['ENABLE_LOGGER']
|
256
|
+
level = Logger::DEBUG
|
257
|
+
else
|
258
|
+
level = Logger::INFO
|
259
|
+
end
|
260
|
+
@logger = Logger.new(STDERR)
|
261
|
+
@logger.level = level
|
262
|
+
end
|
263
|
+
@logger
|
215
264
|
end
|
216
|
-
system("cd #{target} && #{scm} #{args.flatten.join ' '}")
|
217
|
-
end
|
218
265
|
|
219
|
-
def
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
FileUtils.mv(Dir.glob("#{tmpdir}/{.[^\.]*,*}"), "#{target}")
|
225
|
-
}
|
266
|
+
def module_working_directory
|
267
|
+
# The problem with the relative path is that PMT doesn't expand the path properly and so passing in a relative path here
|
268
|
+
# becomes something like C:\somewhere\backslashes/spec/fixtures/work-dir on Windows, and then PMT barfs itself.
|
269
|
+
# This has been reported as https://tickets.puppetlabs.com/browse/PUP-4884
|
270
|
+
File.expand_path(ENV['MODULE_WORKING_DIR'] ? ENV['MODULE_WORKING_DIR'] : 'spec/fixtures/work-dir')
|
226
271
|
end
|
227
|
-
end
|
228
272
|
|
229
|
-
#
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
273
|
+
# returns the current thread count that is currently active
|
274
|
+
# a status of false or nil means the thread completed
|
275
|
+
# so when anything else we count that as a active thread
|
276
|
+
def current_thread_count(items)
|
277
|
+
active_threads = items.find_all do |item, opts|
|
278
|
+
if opts[:thread]
|
279
|
+
opts[:thread].status
|
280
|
+
else
|
281
|
+
false
|
282
|
+
end
|
237
283
|
end
|
238
|
-
|
239
|
-
|
284
|
+
logger.debug "Current thread count #{active_threads.count}"
|
285
|
+
active_threads.count
|
286
|
+
end
|
287
|
+
|
288
|
+
# returns the max_thread_count
|
289
|
+
# because we may want to limit ssh or https connections
|
290
|
+
def max_thread_limit
|
291
|
+
unless @max_thread_limit
|
292
|
+
# the default thread count is 10 but can be
|
293
|
+
# raised by using environment variable MAX_FIXTURE_THREAD_COUNT
|
294
|
+
if ENV['MAX_FIXTURE_THREAD_COUNT'].to_i > 0
|
295
|
+
@max_thread_limit = ENV['MAX_FIXTURE_THREAD_COUNT'].to_i
|
296
|
+
else
|
297
|
+
@max_thread_limit = 10 # the default
|
298
|
+
end
|
299
|
+
end
|
300
|
+
@max_thread_limit
|
240
301
|
end
|
241
|
-
@logger
|
242
|
-
end
|
243
302
|
|
244
|
-
def
|
245
|
-
|
246
|
-
|
247
|
-
# This has been reported as https://tickets.puppetlabs.com/browse/PUP-4884
|
248
|
-
File.expand_path(ENV['MODULE_WORKING_DIR'] ? ENV['MODULE_WORKING_DIR'] : 'spec/fixtures/work-dir')
|
249
|
-
end
|
303
|
+
def check_directory_for_symlinks(dir='.')
|
304
|
+
dir = Pathname.new(dir) unless dir.is_a?(Pathname)
|
305
|
+
results = []
|
250
306
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
opts[:thread].status
|
258
|
-
else
|
259
|
-
false
|
307
|
+
dir.each_child(true) do |child|
|
308
|
+
if child.symlink?
|
309
|
+
results << child
|
310
|
+
elsif child.directory? && child.basename.to_s != '.git'
|
311
|
+
results.concat(check_directory_for_symlinks(child))
|
312
|
+
end
|
260
313
|
end
|
261
|
-
end
|
262
|
-
logger.debug "Current thread count #{active_threads.count}"
|
263
|
-
active_threads.count
|
264
|
-
end
|
265
314
|
|
266
|
-
|
267
|
-
# because we may want to limit ssh or https connections
|
268
|
-
def max_thread_limit
|
269
|
-
unless @max_thread_limit
|
270
|
-
# the default thread count is 10 but can be
|
271
|
-
# raised by using environment variable MAX_FIXTURE_THREAD_COUNT
|
272
|
-
if ENV['MAX_FIXTURE_THREAD_COUNT'].to_i > 0
|
273
|
-
@max_thread_limit = ENV['MAX_FIXTURE_THREAD_COUNT'].to_i
|
274
|
-
else
|
275
|
-
@max_thread_limit = 10 # the default
|
276
|
-
end
|
315
|
+
results
|
277
316
|
end
|
278
|
-
@max_thread_limit
|
279
317
|
end
|
318
|
+
include PuppetlabsSpecHelper::RakeTasks
|
280
319
|
|
281
320
|
desc "Create the fixtures directory"
|
282
321
|
task :spec_prep do
|
@@ -326,6 +365,7 @@ task :spec_prep do
|
|
326
365
|
repositories.each {|remote, opts| opts[:thread].join }
|
327
366
|
|
328
367
|
fixtures("symlinks").each do |target, link|
|
368
|
+
link = link['target']
|
329
369
|
unless File.symlink?(link)
|
330
370
|
logger.info("Creating symlink from #{link} to #{target}")
|
331
371
|
if is_windows
|
@@ -374,26 +414,19 @@ end
|
|
374
414
|
desc "Clean up the fixtures directory"
|
375
415
|
task :spec_clean do
|
376
416
|
fixtures("repositories").each do |remote, opts|
|
377
|
-
|
378
|
-
target = opts
|
379
|
-
elsif opts.instance_of?(Hash)
|
380
|
-
target = opts["target"]
|
381
|
-
end
|
417
|
+
target = opts["target"]
|
382
418
|
FileUtils::rm_rf(target)
|
383
419
|
end
|
384
420
|
|
385
421
|
fixtures("forge_modules").each do |remote, opts|
|
386
|
-
|
387
|
-
target = opts
|
388
|
-
elsif opts.instance_of?(Hash)
|
389
|
-
target = opts["target"]
|
390
|
-
end
|
422
|
+
target = opts["target"]
|
391
423
|
FileUtils::rm_rf(target)
|
392
424
|
end
|
393
425
|
|
394
426
|
FileUtils::rm_rf(module_working_directory)
|
395
427
|
|
396
|
-
fixtures("symlinks").each do |source,
|
428
|
+
fixtures("symlinks").each do |source, opts|
|
429
|
+
target = opts["target"]
|
397
430
|
FileUtils::rm_f(target)
|
398
431
|
end
|
399
432
|
|
@@ -591,21 +624,6 @@ task :release_checks do
|
|
591
624
|
Rake::Task["check:git_ignore"].invoke
|
592
625
|
end
|
593
626
|
|
594
|
-
def check_directory_for_symlinks(dir='.')
|
595
|
-
dir = Pathname.new(dir) unless dir.is_a?(Pathname)
|
596
|
-
results = []
|
597
|
-
|
598
|
-
dir.each_child(true) do |child|
|
599
|
-
if child.symlink?
|
600
|
-
results << child
|
601
|
-
elsif child.directory? && child.basename.to_s != '.git'
|
602
|
-
results.concat(check_directory_for_symlinks(child))
|
603
|
-
end
|
604
|
-
end
|
605
|
-
|
606
|
-
results
|
607
|
-
end
|
608
|
-
|
609
627
|
namespace :check do
|
610
628
|
desc "Fails if symlinks are present in directory"
|
611
629
|
task :symlinks do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppetlabs_spec_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet, Inc.
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-12-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mocha
|