puppetlabs_spec_helper 2.5.1 → 2.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0130f0a082660bbb7b06949f05de5b12fba0495a
4
- data.tar.gz: 221164acdd88485d5c1925a6c1ff5f4c819a27b7
3
+ metadata.gz: b3adeff1476e7d1c79bd8f1c565c1545bc03674f
4
+ data.tar.gz: 2d9d4b9869daa78653e68e05db09881cf1aa565a
5
5
  SHA512:
6
- metadata.gz: 32cef604ccbab6524d8c19c77809d792084c87afb15dfdfcf2b178a7768a2eaccad081820fd58221d52febbea46822dd61815836118c20a14fe9cfa7c6c534bc
7
- data.tar.gz: 5aacb1ac9e6c48033d1c4779f857dc9869a18b00e38c374e26fac01cae4587e7e27b9afd04ddc2dea94817429579df84f1cd3da20de9501e4c824eb6e1042bc7
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.5.1...master
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
- # This is a helper for the self-symlink entry of fixtures.yml
79
- def source_dir
80
- Dir.pwd
81
- end
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 retruns and hash object
84
- def repositories
85
- unless @repositories
86
- @repositories = fixtures('repositories')
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
- return @beaker_nodes if @beaker_nodes
100
- @beaker_nodes = Dir['spec/acceptance/nodesets/*.yml'].sort.map do |node_set|
101
- node_set.slice!('.yml')
102
- File.basename(node_set)
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
- vagrant_yml_dir = File.join '.vagrant', 'beaker_vagrant_files', "#{set}.yml"
111
- vagrant_file = File.join vagrant_yml_dir, 'Vagrantfile'
112
- unless File.file? vagrant_file
113
- puts "There is no Vagrantfile at: '#{vagrant_file}'. Perhaps, the node is not created or is destroyed."
114
- exit 1
115
- end
116
- Dir.chdir(vagrant_yml_dir) do
117
- command = 'vagrant ssh'
118
- command += " #{node}" if node
119
- # Vagrant is not distributed as a normal gem
120
- # and we should protect it from the current Ruby environment
121
- env = {
122
- 'RUBYLIB' => nil,
123
- 'GEM_PATH' => nil,
124
- 'BUNDLE_BIN_PATH' => nil,
125
- }
126
- system env, command
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 fixtures(category)
135
- if File.exists?('.fixtures.yml')
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
- begin
144
- fixtures = (YAML.load_file(ENV['FIXTURES_YML'] || fixtures_yaml) || { fixtures: {} })["fixtures"]
145
- rescue Errno::ENOENT
146
- fixtures = {}
147
- rescue Psych::SyntaxError => e
148
- abort("Found malformed YAML in #{fixtures_yaml} on line #{e.line} column #{e.column}: #{e.problem}")
149
- end
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
- if fixtures['symlinks'].nil?
152
- fixtures['symlinks'] = auto_symlink
153
- end
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
- result = {}
156
- if fixtures.include? category and fixtures[category] != nil
157
- fixtures[category].each do |fixture, opts|
158
- if opts.instance_of?(String)
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
- if opts["target"]
166
- real_target = eval('"'+opts["target"]+'"')
167
- end
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
- unless real_target
170
- real_target = "spec/fixtures/modules"
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
- real_source = eval('"'+opts["repo"]+'"')
194
+ real_target = eval('"'+opts["target"]+'"')
195
+ real_source = eval('"'+opts["repo"]+'"')
174
196
 
175
- result[real_source] = { "target" => File.join(real_target,fixture), "ref" => opts["ref"], "branch" => opts["branch"], "scm" => opts["scm"], "flags" => opts["flags"], "subdir" => opts["subdir"]}
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 clone_repo(scm, remote, target, subdir=nil, ref=nil, branch=nil, flags = nil)
183
- args = []
184
- case scm
185
- when 'hg'
186
- args.push('clone')
187
- args.push('-b', branch) if branch
188
- args.push(flags) if flags
189
- args.push(remote, target)
190
- when 'git'
191
- args.push('clone')
192
- args.push('--depth 1') unless ref
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
- result = system("#{scm} #{args.flatten.join ' '}")
200
- unless File::exists?(target)
201
- fail "Failed to clone #{scm} repository #{remote} into #{target}"
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
- def revision(scm, target, ref)
207
- args = []
208
- case scm
209
- when 'hg'
210
- args.push('update', '--clean', '-r', ref)
211
- when 'git'
212
- args.push('reset', '--hard', ref)
213
- else
214
- fail "Unfortunately #{scm} is not supported yet"
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 remove_subdirectory(target, subdir)
220
- unless subdir.nil?
221
- Dir.mktmpdir {|tmpdir|
222
- FileUtils.mv(Dir.glob("#{target}/#{subdir}/{.[^\.]*,*}"), tmpdir)
223
- FileUtils.rm_rf("#{target}/#{subdir}")
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
- # creates a logger so we can log events with certain levels
230
- def logger
231
- unless @logger
232
- require 'logger'
233
- if ENV['ENABLE_LOGGER']
234
- level = Logger::DEBUG
235
- else
236
- level = Logger::INFO
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
- @logger = Logger.new(STDERR)
239
- @logger.level = level
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 module_working_directory
245
- # The problem with the relative path is that PMT doesn't expand the path properly and so passing in a relative path here
246
- # becomes something like C:\somewhere\backslashes/spec/fixtures/work-dir on Windows, and then PMT barfs itself.
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
- # returns the current thread count that is currently active
252
- # a status of false or nil means the thread completed
253
- # so when anything else we count that as a active thread
254
- def current_thread_count(items)
255
- active_threads = items.find_all do |item, opts|
256
- if opts[:thread]
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
- # returns the max_thread_count
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
- if opts.instance_of?(String)
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
- if opts.instance_of?(String)
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, target|
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
@@ -1,5 +1,5 @@
1
1
  module PuppetlabsSpecHelper
2
- VERSION = "2.5.1"
2
+ VERSION = "2.6.1"
3
3
 
4
4
  # compat for pre-1.2.0 users; deprecated
5
5
  module Version
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.5.1
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-11-22 00:00:00.000000000 Z
12
+ date: 2017-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mocha