puppet_fixtures 1.0.1 → 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: b53a2e361e5e579596d952064d66dfe220c494eac254ef1182abe9980e9d29b8
4
- data.tar.gz: e643dc886e1b95db27661f61b65028e9a30b3b97f555964843d8d6db9791ca2d
3
+ metadata.gz: 1e780bf760c791a11e97ce20aeb04526e513f33d87c2649f7fe78b1c1aa470cf
4
+ data.tar.gz: cf4b77f4291d6b2a9aec9243d08a8732b6e7e4b7f27bba86b468f771da387ce9
5
5
  SHA512:
6
- metadata.gz: d694b20b2344e1b11146c1cb434c27edee67ee39b1efd9dba1101fd8723e2c18ec56e342ef9aecf7a5bb9b7dec1a3881638dca50cf92ca49a9ccf1b1e9622b20
7
- data.tar.gz: 89dcec5bea40b9f9bb11a7bd82a9ad2c10ac30acbebdf3a48c883680d3b004cfd334b94e919d208131b471c5b0766483b449fb041a57970d6d58c06651dfa6a3
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,7 +214,7 @@ 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
219
  loop do
221
220
  begin
@@ -266,8 +265,6 @@ module PuppetFixtures
266
265
  '.fixtures.yml'
267
266
  elsif File.exist?('.fixtures.yaml')
268
267
  '.fixtures.yaml'
269
- else
270
- nil
271
268
  end
272
269
  end
273
270
 
@@ -300,9 +297,9 @@ module PuppetFixtures
300
297
  # creates a logger so we can log events with certain levels
301
298
  def logger
302
299
  @logger ||= begin
303
- require 'logger'
304
- Logger.new($stderr, level: ENV['ENABLE_LOGGER'] ? Logger::DEBUG : Logger::INFO)
305
- end
300
+ require 'logger'
301
+ Logger.new($stderr, level: ENV['ENABLE_LOGGER'] ? Logger::DEBUG : Logger::INFO)
302
+ end
306
303
  end
307
304
 
308
305
  def read_fixtures_file
@@ -372,7 +369,7 @@ module PuppetFixtures
372
369
  # @return [String[1]] The module name
373
370
  def name
374
371
  n = @metadata['name']
375
- raise ArgumentError "No module name found" if !n || n.empty?
372
+ raise ArgumentError 'No module name found' if !n || n.empty?
376
373
 
377
374
  n
378
375
  end
@@ -380,7 +377,7 @@ module PuppetFixtures
380
377
  # @return [String[1]] The module version
381
378
  def version
382
379
  v = @metadata['version']
383
- raise ArgumentError "No module name found" if !v || v.empty?
380
+ raise ArgumentError 'No module name found' if !v || v.empty?
384
381
 
385
382
  v
386
383
  end
@@ -405,6 +402,7 @@ module PuppetFixtures
405
402
  begin
406
403
  require 'win32/dir'
407
404
  rescue LoadError
405
+ # the require only works on windows
408
406
  end
409
407
  target = File.join(File.dirname(@link), @target) unless Pathname.new(@target).absolute?
410
408
  if Dir.respond_to?(:create_junction)
@@ -478,9 +476,9 @@ module PuppetFixtures
478
476
 
479
477
  def remove_subdirectory(subdir)
480
478
  Dir.mktmpdir do |tmpdir|
481
- FileUtils.mv(Dir.glob(File.join(@target, subdir, "{.[^\.]*,*}")), tmpdir)
479
+ FileUtils.mv(Dir.glob(File.join(@target, subdir, '{.[^.]*,*}')), tmpdir)
482
480
  FileUtils.rm_rf(File.join(@target, subdir))
483
- FileUtils.mv(Dir.glob(File.join(tmpdir, "{.[^\.]*,*}")), @target.to_s)
481
+ FileUtils.mv(Dir.glob(File.join(tmpdir, '{.[^.]*,*}')), @target.to_s)
484
482
  end
485
483
  end
486
484
 
@@ -504,16 +502,16 @@ module PuppetFixtures
504
502
  def logger
505
503
  # TODO: duplicated
506
504
  @logger ||= begin
507
- require 'logger'
508
- # TODO: progname?
509
- Logger.new($stderr, level: ENV['ENABLE_LOGGER'] ? Logger::DEBUG : Logger::INFO)
510
- end
505
+ require 'logger'
506
+ # TODO: progname?
507
+ Logger.new($stderr, level: ENV['ENABLE_LOGGER'] ? Logger::DEBUG : Logger::INFO)
508
+ end
511
509
  end
512
510
  end
513
511
 
514
512
  class Git < Base
515
513
  def clone(flags = nil)
516
- command = ['git', 'clone']
514
+ command = %w[git clone]
517
515
  command.push('--depth', '1') unless @ref
518
516
  command.push('-b', @branch) if @branch
519
517
  command.push(flags) if flags
@@ -524,7 +522,7 @@ module PuppetFixtures
524
522
 
525
523
  def update
526
524
  # TODO: should this pull?
527
- command = ['git', 'fetch']
525
+ command = %w[git fetch]
528
526
  command.push('--unshallow') if shallow_git_repo?
529
527
 
530
528
  run_command(command, chdir: @target)
@@ -535,7 +533,7 @@ module PuppetFixtures
535
533
 
536
534
  command = ['git', 'reset', '--hard', @ref]
537
535
  result = run_command(command, chdir: @target)
538
- raise "Invalid ref #{ref} for #{@target}" unless result
536
+ raise "Invalid ref #{@ref} for #{@target}" unless result
539
537
 
540
538
  result
541
539
  end
@@ -558,7 +556,7 @@ module PuppetFixtures
558
556
 
559
557
  class Mercurial < Base
560
558
  def clone(flags = nil)
561
- command = ['hg', 'clone']
559
+ command = %w[hg clone]
562
560
  command.push('-b', @branch) if @branch
563
561
  command.push(flags) if flags
564
562
  command.push(@remote, @target)
@@ -567,7 +565,7 @@ module PuppetFixtures
567
565
  end
568
566
 
569
567
  def update
570
- run_command(['hg', 'pull'])
568
+ run_command(%w[hg pull])
571
569
  end
572
570
 
573
571
  def revision
@@ -575,7 +573,7 @@ module PuppetFixtures
575
573
 
576
574
  command = ['hg', 'update', '--clean', '-r', @ref]
577
575
  result = run_command(command, chdir: @target)
578
- raise "Invalid ref #{ref} for #{@target}" unless result
576
+ raise "Invalid ref #{@ref} for #{@target}" unless result
579
577
 
580
578
  result
581
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.1
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: []