puppet_fixtures 1.0.0 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2da2aad2b8bb2ff1f802d3cb47675a3163d8e5d6007e7c820380e4c6d728d0f7
4
- data.tar.gz: 9d5c18705abde2484db94bfb3f6cb28c161f0027b1ffda25766129ede6c6da3d
3
+ metadata.gz: 1e780bf760c791a11e97ce20aeb04526e513f33d87c2649f7fe78b1c1aa470cf
4
+ data.tar.gz: cf4b77f4291d6b2a9aec9243d08a8732b6e7e4b7f27bba86b468f771da387ce9
5
5
  SHA512:
6
- metadata.gz: 4adfefd73703e4911e1f26276523da32a9eceb11535e66206f4b79458902d013beeb106760d8c93c07bbd30ab4da9bad9d03e132f83175232a768beefc9a9321
7
- data.tar.gz: 56369dba5f9e398fa625fb51a2261858cf08b26eca0f249f870be63bc2488ed67c0849d8fa1a50acf883c1a0b9de32a009bc748eeeffaa3371abf95c22943d75
6
+ metadata.gz: 331ee8832ad15fb77a1f174c8d76c7243c56017716b282cd5f28ee541b843d2d1fc172812eabc249c3c662cd3fba98bfd8a17041261a1a17bf1ec6a0b7e5ec00
7
+ data.tar.gz: 87dd05abaed4fada6bcb5fa0523d850ed901855ffd269751d08d5b9d5f1b81fab5676d033a71cdf2b303522e2204e667b55a94369cd1c46e25eaf7e7b176fa1a
data/bin/puppet-fixtures CHANGED
@@ -1,15 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ # frozen_string_literal: true
4
+
3
5
  require 'pathname'
4
6
  require 'optparse'
7
+ require 'English'
5
8
 
6
9
  require 'puppet_fixtures'
7
10
 
8
- COMMANDS = ['clean', 'install', 'show']
11
+ COMMANDS = %w[clean install show].freeze
9
12
 
10
13
  command = ARGV[0]
11
14
  unless COMMANDS.include?(command)
12
- $stderr.puts "Usage: #{$0} #{COMMANDS.join('|')}"
15
+ warn "Usage: #{$PROGRAM_NAME} #{COMMANDS.join('|')}"
13
16
  exit 1
14
17
  end
15
18
 
@@ -21,20 +24,20 @@ when 'clean'
21
24
  when 'install'
22
25
  fixtures.download
23
26
  when 'show'
24
- if (path = fixtures.fixture_path)
27
+ if fixtures.fixture_path
25
28
  puts "Parsing #{fixtures.fixture_path}"
26
29
 
27
30
  if fixtures.symlinks.any?
28
31
  puts
29
- puts "Symlinks"
30
- fixtures.symlinks.each do |_target, symlink|
32
+ puts 'Symlinks'
33
+ fixtures.symlinks.each_value do |symlink|
31
34
  puts " #{symlink}"
32
35
  end
33
36
  end
34
37
 
35
38
  if fixtures.forge_modules.any?
36
39
  puts
37
- puts "Forge modules"
40
+ puts 'Forge modules'
38
41
  fixtures.forge_modules.each do |mod, opts|
39
42
  dir = Pathname.new(opts[:target]).relative_path_from(fixtures.module_target_dir)
40
43
  description = mod
@@ -45,7 +48,7 @@ when 'show'
45
48
 
46
49
  if fixtures.repositories.any?
47
50
  puts
48
- puts "Repositories"
51
+ puts 'Repositories'
49
52
  fixtures.repositories.each do |repository, opts|
50
53
  dir = Pathname.new(opts[:target]).relative_path_from(fixtures.module_target_dir)
51
54
  description = ["#{opts[:scm]}+#{repository}", opts[:ref]]
@@ -54,6 +57,6 @@ when 'show'
54
57
  end
55
58
  end
56
59
  else
57
- $stderr.puts "No fixture file found"
60
+ warn 'No fixture file found'
58
61
  end
59
62
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../puppet_fixtures'
2
4
 
3
5
  require 'rake'
@@ -65,67 +65,65 @@ module PuppetFixtures
65
65
 
66
66
  def fixtures
67
67
  @fixtures ||= begin
68
- categories = read_fixtures_file['fixtures']
69
-
70
- categories['symlinks'] ||= begin
71
- metadata = PuppetFixtures::Metadata.new(File.join(source_dir, 'metadata.json'))
72
- { metadata.name.split('-').last => source_dir }
73
- rescue ArgumentError
74
- {}
75
- end
76
- categories['forge_modules'] ||= {}
77
- categories['repositories'] ||= {}
78
-
79
- defaults = { 'target' => module_target_dir }
80
-
81
- ['symlinks', 'forge_modules', 'repositories'].to_h do |category|
82
- # load defaults from the `.fixtures.yml` `defaults` section
83
- # for the requested category and merge them into my defaults
84
- if (category_defaults = categories.dig('defaults', category))
85
- category_defaults = defaults.merge(category_defaults)
86
- else
87
- category_defaults = defaults
88
- end
89
-
90
- entries = categories[category].to_h do |fixture, opts|
91
- # convert a simple string fixture to a hash, by
92
- # using the string fixture as the `repo` option of the hash.
93
- if opts.instance_of?(String)
94
- opts = { 'repo' => opts }
95
- end
96
- # there should be a warning or something if it's not a hash...
97
- next unless opts.instance_of?(Hash)
98
-
99
- # merge our options into the defaults to get the
100
- # final option list
101
- opts = category_defaults.merge(opts)
102
-
103
- next unless include_repo?(opts['puppet_version'])
104
-
105
- entry = validate_fixture_hash!(
106
- target: File.join(opts['target'], fixture),
107
- ref: opts['ref'] || opts['tag'],
108
- branch: opts['branch'],
109
- scm: opts.fetch('scm', 'git'),
110
- flags: opts['flags'],
111
- subdir: opts['subdir'],
112
- )
113
-
114
- case category
115
- when 'forge_modules'
116
- entry.delete(:scm)
117
- entry.delete(:branch)
118
- entry.delete(:subdir)
119
- when 'symlinks'
120
- entry = PuppetFixtures::Symlink.new(link: entry[:target], target: opts['repo'])
121
- end
122
-
123
- [opts['repo'], entry]
124
- end
125
-
126
- [category, entries]
127
- end
128
- end
68
+ categories = read_fixtures_file['fixtures']
69
+
70
+ categories['symlinks'] ||= begin
71
+ metadata = PuppetFixtures::Metadata.new(File.join(source_dir, 'metadata.json'))
72
+ { metadata.name.split('-').last => source_dir }
73
+ rescue ArgumentError
74
+ {}
75
+ end
76
+ categories['forge_modules'] ||= {}
77
+ categories['repositories'] ||= {}
78
+
79
+ defaults = { 'target' => module_target_dir }
80
+
81
+ %w[symlinks forge_modules repositories].to_h do |category|
82
+ # load defaults from the `.fixtures.yml` `defaults` section
83
+ # for the requested category and merge them into my defaults
84
+ category_defaults = if (category_defaults = categories.dig('defaults', category))
85
+ defaults.merge(category_defaults)
86
+ else
87
+ defaults
88
+ end
89
+
90
+ entries = categories[category].to_h do |fixture, opts|
91
+ # convert a simple string fixture to a hash, by
92
+ # using the string fixture as the `repo` option of the hash.
93
+ opts = { 'repo' => opts } if opts.instance_of?(String)
94
+ # there should be a warning or something if it's not a hash...
95
+ next unless opts.instance_of?(Hash)
96
+
97
+ # merge our options into the defaults to get the
98
+ # final option list
99
+ opts = category_defaults.merge(opts)
100
+
101
+ next unless include_repo?(opts['puppet_version'])
102
+
103
+ entry = validate_fixture_hash!(
104
+ target: File.join(opts['target'], fixture),
105
+ ref: opts['ref'] || opts['tag'],
106
+ branch: opts['branch'],
107
+ scm: opts.fetch('scm', 'git'),
108
+ flags: opts['flags'],
109
+ subdir: opts['subdir'],
110
+ )
111
+
112
+ case category
113
+ when 'forge_modules'
114
+ entry.delete(:scm)
115
+ entry.delete(:branch)
116
+ entry.delete(:subdir)
117
+ when 'symlinks'
118
+ entry = PuppetFixtures::Symlink.new(link: entry[:target], target: opts['repo'])
119
+ end
120
+
121
+ [opts['repo'], entry]
122
+ end
123
+
124
+ [category, entries]
125
+ end
126
+ end
129
127
  end
130
128
 
131
129
  # @param [String] remote
@@ -171,13 +169,14 @@ module PuppetFixtures
171
169
  end
172
170
  end
173
171
 
174
- command = ['puppet', 'module', 'install']
172
+ command = %w[puppet module install]
175
173
  command << '--version' << ref if ref
176
174
  command += flags if flags
177
175
  command += ['--ignore-dependencies', '--force', '--target-dir', module_target_dir, remote]
178
176
 
179
- unless run_command(command)
180
- raise "Failed to install module #{remote} to #{module_target_dir}"
177
+ Dir.mktmpdir do |working_dir|
178
+ command += ['--module_working_dir', working_dir]
179
+ raise "Failed to install module #{remote} to #{module_target_dir}" unless run_command(command)
181
180
  end
182
181
 
183
182
  true
@@ -215,14 +214,20 @@ module PuppetFixtures
215
214
  thread_count = [@max_thread_limit, queue.size].min
216
215
  logger.debug("Download queue size: #{queue.size}; using #{thread_count} threads")
217
216
 
218
- threads = thread_count.times.map do |i|
217
+ threads = Array.new(thread_count) do |_i|
219
218
  Thread.new do
220
- type, remote, opts = queue.pop(true)
221
- case type
222
- when :repository
223
- instance.download_repository(remote, **opts)
224
- when :forge
225
- instance.download_module(remote, **opts)
219
+ loop do
220
+ begin
221
+ type, remote, opts = queue.pop(true)
222
+ rescue ThreadError
223
+ break # Queue is empty
224
+ end
225
+ case type
226
+ when :repository
227
+ instance.download_repository(remote, **opts)
228
+ when :forge
229
+ instance.download_module(remote, **opts)
230
+ end
226
231
  end
227
232
  end
228
233
  end
@@ -260,8 +265,6 @@ module PuppetFixtures
260
265
  '.fixtures.yml'
261
266
  elsif File.exist?('.fixtures.yaml')
262
267
  '.fixtures.yaml'
263
- else
264
- nil
265
268
  end
266
269
  end
267
270
 
@@ -294,9 +297,9 @@ module PuppetFixtures
294
297
  # creates a logger so we can log events with certain levels
295
298
  def logger
296
299
  @logger ||= begin
297
- require 'logger'
298
- Logger.new($stderr, level: ENV['ENABLE_LOGGER'] ? Logger::DEBUG : Logger::INFO)
299
- end
300
+ require 'logger'
301
+ Logger.new($stderr, level: ENV['ENABLE_LOGGER'] ? Logger::DEBUG : Logger::INFO)
302
+ end
300
303
  end
301
304
 
302
305
  def read_fixtures_file
@@ -366,7 +369,7 @@ module PuppetFixtures
366
369
  # @return [String[1]] The module name
367
370
  def name
368
371
  n = @metadata['name']
369
- raise ArgumentError "No module name found" if !n || n.empty?
372
+ raise ArgumentError 'No module name found' if !n || n.empty?
370
373
 
371
374
  n
372
375
  end
@@ -374,7 +377,7 @@ module PuppetFixtures
374
377
  # @return [String[1]] The module version
375
378
  def version
376
379
  v = @metadata['version']
377
- raise ArgumentError "No module name found" if !v || v.empty?
380
+ raise ArgumentError 'No module name found' if !v || v.empty?
378
381
 
379
382
  v
380
383
  end
@@ -399,6 +402,7 @@ module PuppetFixtures
399
402
  begin
400
403
  require 'win32/dir'
401
404
  rescue LoadError
405
+ # the require only works on windows
402
406
  end
403
407
  target = File.join(File.dirname(@link), @target) unless Pathname.new(@target).absolute?
404
408
  if Dir.respond_to?(:create_junction)
@@ -472,9 +476,9 @@ module PuppetFixtures
472
476
 
473
477
  def remove_subdirectory(subdir)
474
478
  Dir.mktmpdir do |tmpdir|
475
- FileUtils.mv(Dir.glob(File.join(@target, subdir, "{.[^\.]*,*}")), tmpdir)
479
+ FileUtils.mv(Dir.glob(File.join(@target, subdir, '{.[^.]*,*}')), tmpdir)
476
480
  FileUtils.rm_rf(File.join(@target, subdir))
477
- FileUtils.mv(Dir.glob(File.join(tmpdir, "{.[^\.]*,*}")), @target.to_s)
481
+ FileUtils.mv(Dir.glob(File.join(tmpdir, '{.[^.]*,*}')), @target.to_s)
478
482
  end
479
483
  end
480
484
 
@@ -498,16 +502,16 @@ module PuppetFixtures
498
502
  def logger
499
503
  # TODO: duplicated
500
504
  @logger ||= begin
501
- require 'logger'
502
- # TODO: progname?
503
- Logger.new($stderr, level: ENV['ENABLE_LOGGER'] ? Logger::DEBUG : Logger::INFO)
504
- end
505
+ require 'logger'
506
+ # TODO: progname?
507
+ Logger.new($stderr, level: ENV['ENABLE_LOGGER'] ? Logger::DEBUG : Logger::INFO)
508
+ end
505
509
  end
506
510
  end
507
511
 
508
512
  class Git < Base
509
513
  def clone(flags = nil)
510
- command = ['git', 'clone']
514
+ command = %w[git clone]
511
515
  command.push('--depth', '1') unless @ref
512
516
  command.push('-b', @branch) if @branch
513
517
  command.push(flags) if flags
@@ -518,7 +522,7 @@ module PuppetFixtures
518
522
 
519
523
  def update
520
524
  # TODO: should this pull?
521
- command = ['git', 'fetch']
525
+ command = %w[git fetch]
522
526
  command.push('--unshallow') if shallow_git_repo?
523
527
 
524
528
  run_command(command, chdir: @target)
@@ -529,7 +533,7 @@ module PuppetFixtures
529
533
 
530
534
  command = ['git', 'reset', '--hard', @ref]
531
535
  result = run_command(command, chdir: @target)
532
- raise "Invalid ref #{ref} for #{@target}" unless result
536
+ raise "Invalid ref #{@ref} for #{@target}" unless result
533
537
 
534
538
  result
535
539
  end
@@ -552,7 +556,7 @@ module PuppetFixtures
552
556
 
553
557
  class Mercurial < Base
554
558
  def clone(flags = nil)
555
- command = ['hg', 'clone']
559
+ command = %w[hg clone]
556
560
  command.push('-b', @branch) if @branch
557
561
  command.push(flags) if flags
558
562
  command.push(@remote, @target)
@@ -561,7 +565,7 @@ module PuppetFixtures
561
565
  end
562
566
 
563
567
  def update
564
- run_command(['hg', 'pull'])
568
+ run_command(%w[hg pull])
565
569
  end
566
570
 
567
571
  def revision
@@ -569,7 +573,7 @@ module PuppetFixtures
569
573
 
570
574
  command = ['hg', 'update', '--clean', '-r', @ref]
571
575
  result = run_command(command, chdir: @target)
572
- raise "Invalid ref #{ref} for #{@target}" unless result
576
+ raise "Invalid ref #{@ref} for #{@target}" unless result
573
577
 
574
578
  result
575
579
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet_fixtures
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ewoud Kohl van Wijngaarden
@@ -23,6 +23,20 @@ dependencies:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
25
  version: '13.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: voxpupuli-rubocop
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: 4.2.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 4.2.0
26
40
  description: |
27
41
  Originally part of puppetlabs_spec_helper, but with a significant
28
42
  refactoring to make it available standalone.
@@ -47,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
47
61
  requirements:
48
62
  - - ">="
49
63
  - !ruby/object:Gem::Version
50
- version: '2.7'
64
+ version: '3.2'
51
65
  - - "<"
52
66
  - !ruby/object:Gem::Version
53
67
  version: '4'
@@ -57,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
71
  - !ruby/object:Gem::Version
58
72
  version: '0'
59
73
  requirements: []
60
- rubygems_version: 3.6.7
74
+ rubygems_version: 3.6.9
61
75
  specification_version: 4
62
76
  summary: Set up fixtures for Puppet testing
63
77
  test_files: []