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 +4 -4
- data/bin/puppet-fixtures +11 -8
- data/lib/puppet_fixtures/tasks.rb +2 -0
- data/lib/puppet_fixtures.rb +82 -84
- 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,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
|
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
|
-
|
304
|
-
|
305
|
-
|
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
|
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
|
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,
|
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,
|
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
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
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 = [
|
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 = [
|
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 = [
|
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([
|
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:
|
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: []
|