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 +4 -4
- data/bin/puppet-fixtures +11 -8
- data/lib/puppet_fixtures/tasks.rb +2 -0
- data/lib/puppet_fixtures.rb +94 -90
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e780bf760c791a11e97ce20aeb04526e513f33d87c2649f7fe78b1c1aa470cf
|
4
|
+
data.tar.gz: cf4b77f4291d6b2a9aec9243d08a8732b6e7e4b7f27bba86b468f771da387ce9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 = [
|
11
|
+
COMMANDS = %w[clean install show].freeze
|
9
12
|
|
10
13
|
command = ARGV[0]
|
11
14
|
unless COMMANDS.include?(command)
|
12
|
-
|
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
|
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
|
30
|
-
fixtures.symlinks.
|
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
|
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
|
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
|
-
|
60
|
+
warn 'No fixture file found'
|
58
61
|
end
|
59
62
|
end
|
data/lib/puppet_fixtures.rb
CHANGED
@@ -65,67 +65,65 @@ module PuppetFixtures
|
|
65
65
|
|
66
66
|
def fixtures
|
67
67
|
@fixtures ||= begin
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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 = [
|
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
|
-
|
180
|
-
|
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
|
217
|
+
threads = Array.new(thread_count) do |_i|
|
219
218
|
Thread.new do
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
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
|
-
|
298
|
-
|
299
|
-
|
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
|
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
|
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,
|
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,
|
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
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
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 = [
|
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 = [
|
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 = [
|
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([
|
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:
|
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
|
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.
|
74
|
+
rubygems_version: 3.6.9
|
61
75
|
specification_version: 4
|
62
76
|
summary: Set up fixtures for Puppet testing
|
63
77
|
test_files: []
|