puppetfile_fixtures_generator 0.1.2 → 0.2.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/CHANGELOG.md +11 -0
- data/Gemfile.lock +60 -66
- data/README.md +5 -4
- data/bin/puppetfile_fixtures_generator +23 -8
- data/lib/puppetfile_fixtures_generator/diff.rb +0 -0
- data/lib/puppetfile_fixtures_generator/fixtures.rb +14 -38
- data/lib/puppetfile_fixtures_generator/puppetfile.rb +79 -0
- data/lib/puppetfile_fixtures_generator/version.rb +1 -1
- data/lib/puppetfile_fixtures_generator.rb +37 -5
- data/puppetfile_fixtures_generator.gemspec +13 -13
- data/spec/puppetfile_fixtures_generator_spec.rb +14 -1
- metadata +23 -9
- data/puppetfile_fixtures_generator-0.1.0.gem +0 -0
- data/puppetfile_fixtures_generator-0.1.1.gem +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dd88b4a58b0cf9583fa87be9ee6478b967b8f1cf
|
|
4
|
+
data.tar.gz: 0c4ef819664118d5b52b0a82e94ad925f22226c5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3555f30125d2ac4f735a78b0bfb3e2ed3a53bba68aa8f7380f8b71eaf8c45a3d293c8056e5ba1d05c67b1f9d2b5585145632a52e876a1142b89a30b1ae7ac517
|
|
7
|
+
data.tar.gz: 2959d88ff6f18033355a5d77273008dcef12c91206daa07d6bdaa9d0f225d513c96bc0a3050afb88001d68721605b3ceff14d20d90332d7f10d77fe2c279f540
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
All notable changes to this project will be documented in this file.
|
|
3
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4
|
+
|
|
5
|
+
## [0.2.0] - 2016-09-22
|
|
6
|
+
### Added
|
|
7
|
+
- Puppetfile class to simplify fixtures class
|
|
8
|
+
- Ability to diff a puppetfile and fixtures file
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Bumped version of r10k dependency
|
data/Gemfile.lock
CHANGED
|
@@ -1,42 +1,43 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
puppetfile_fixtures_generator (0.
|
|
4
|
+
puppetfile_fixtures_generator (0.2.0)
|
|
5
5
|
highline (~> 1.7)
|
|
6
|
-
r10k (~> 2.
|
|
6
|
+
r10k (~> 2.3.0)
|
|
7
7
|
trollop (~> 2.1)
|
|
8
8
|
|
|
9
9
|
GEM
|
|
10
10
|
remote: https://rubygems.org/
|
|
11
11
|
specs:
|
|
12
|
-
ast (2.
|
|
13
|
-
coderay (1.1.
|
|
12
|
+
ast (2.3.0)
|
|
13
|
+
coderay (1.1.1)
|
|
14
14
|
colored (1.2)
|
|
15
|
-
coveralls (0.8.
|
|
16
|
-
json (
|
|
17
|
-
|
|
18
|
-
simplecov (~> 0.11.0)
|
|
15
|
+
coveralls (0.8.15)
|
|
16
|
+
json (>= 1.8, < 3)
|
|
17
|
+
simplecov (~> 0.12.0)
|
|
19
18
|
term-ansicolor (~> 1.3)
|
|
20
19
|
thor (~> 0.19.1)
|
|
21
|
-
tins (
|
|
20
|
+
tins (>= 1.6.0, < 2)
|
|
22
21
|
cri (2.6.1)
|
|
23
22
|
colored (~> 1.2)
|
|
24
23
|
diff-lcs (1.2.5)
|
|
25
24
|
docile (1.1.5)
|
|
26
|
-
domain_name (0.5.20160128)
|
|
27
|
-
unf (>= 0.0.5, < 1.0.0)
|
|
28
25
|
faraday (0.9.2)
|
|
29
26
|
multipart-post (>= 1.2, < 3)
|
|
30
|
-
faraday_middleware (0.
|
|
27
|
+
faraday_middleware (0.10.0)
|
|
31
28
|
faraday (>= 0.7.4, < 0.10)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
multi_json
|
|
35
|
-
ffi (1.9.10)
|
|
29
|
+
fast_gettext (1.1.0)
|
|
30
|
+
ffi (1.9.14)
|
|
36
31
|
formatador (0.2.5)
|
|
37
|
-
|
|
32
|
+
gettext (3.2.2)
|
|
33
|
+
locale (>= 2.0.5)
|
|
34
|
+
text (>= 1.3.0)
|
|
35
|
+
gettext-setup (0.7)
|
|
36
|
+
fast_gettext (~> 1.1.0)
|
|
37
|
+
gettext (>= 3.0.2)
|
|
38
|
+
guard (2.14.0)
|
|
38
39
|
formatador (>= 0.2.4)
|
|
39
|
-
listen (>= 2.7,
|
|
40
|
+
listen (>= 2.7, < 4.0)
|
|
40
41
|
lumberjack (~> 1.0)
|
|
41
42
|
nenv (~> 0.1)
|
|
42
43
|
notiffany (~> 0.0)
|
|
@@ -44,97 +45,89 @@ GEM
|
|
|
44
45
|
shellany (~> 0.0)
|
|
45
46
|
thor (>= 0.18.1)
|
|
46
47
|
guard-compat (1.2.1)
|
|
47
|
-
guard-rspec (4.
|
|
48
|
+
guard-rspec (4.7.3)
|
|
48
49
|
guard (~> 2.1)
|
|
49
50
|
guard-compat (~> 1.1)
|
|
50
51
|
rspec (>= 2.99.0, < 4.0)
|
|
51
52
|
highline (1.7.8)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
rb-inotify (>= 0.9)
|
|
53
|
+
json (2.0.2)
|
|
54
|
+
listen (3.0.8)
|
|
55
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
|
56
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
|
57
|
+
locale (2.1.2)
|
|
58
58
|
log4r (1.1.10)
|
|
59
59
|
lumberjack (1.0.10)
|
|
60
60
|
method_source (0.8.2)
|
|
61
|
-
mime-types (2.99)
|
|
62
61
|
minitar (0.5.4)
|
|
63
|
-
multi_json (1.
|
|
62
|
+
multi_json (1.12.1)
|
|
64
63
|
multipart-post (2.0.0)
|
|
65
|
-
nenv (0.
|
|
66
|
-
|
|
67
|
-
notiffany (0.0.8)
|
|
64
|
+
nenv (0.3.0)
|
|
65
|
+
notiffany (0.1.1)
|
|
68
66
|
nenv (~> 0.1)
|
|
69
67
|
shellany (~> 0.0)
|
|
70
|
-
parser (2.3.
|
|
68
|
+
parser (2.3.1.4)
|
|
71
69
|
ast (~> 2.2)
|
|
72
70
|
powerpack (0.1.1)
|
|
73
|
-
pry (0.10.
|
|
71
|
+
pry (0.10.4)
|
|
74
72
|
coderay (~> 1.1.0)
|
|
75
73
|
method_source (~> 0.8.1)
|
|
76
74
|
slop (~> 3.4)
|
|
77
|
-
puppet_forge (2.
|
|
75
|
+
puppet_forge (2.2.2)
|
|
78
76
|
faraday (~> 0.9.0)
|
|
79
77
|
faraday_middleware (>= 0.9.0, < 0.11.0)
|
|
78
|
+
gettext-setup (>= 0.3)
|
|
80
79
|
minitar
|
|
81
80
|
semantic_puppet (~> 0.1.0)
|
|
82
|
-
r10k (2.
|
|
81
|
+
r10k (2.3.0)
|
|
83
82
|
colored (= 1.2)
|
|
84
83
|
cri (~> 2.6.1)
|
|
85
|
-
faraday (~> 0.9.0)
|
|
86
|
-
faraday_middleware (~> 0.9.0)
|
|
87
|
-
faraday_middleware-multi_json (~> 0.0.6)
|
|
88
84
|
log4r (= 1.1.10)
|
|
89
85
|
minitar
|
|
90
86
|
multi_json (~> 1.10)
|
|
91
|
-
puppet_forge (~> 2.
|
|
87
|
+
puppet_forge (~> 2.2)
|
|
92
88
|
semantic_puppet (~> 0.1.0)
|
|
93
89
|
rainbow (2.1.0)
|
|
94
90
|
rake (10.5.0)
|
|
95
91
|
rb-fsevent (0.9.7)
|
|
96
|
-
rb-inotify (0.9.
|
|
92
|
+
rb-inotify (0.9.7)
|
|
97
93
|
ffi (>= 0.5.0)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
rspec (3.
|
|
103
|
-
rspec-
|
|
104
|
-
|
|
105
|
-
rspec-mocks (~> 3.4.0)
|
|
106
|
-
rspec-core (3.4.2)
|
|
107
|
-
rspec-support (~> 3.4.0)
|
|
108
|
-
rspec-expectations (3.4.0)
|
|
94
|
+
rspec (3.5.0)
|
|
95
|
+
rspec-core (~> 3.5.0)
|
|
96
|
+
rspec-expectations (~> 3.5.0)
|
|
97
|
+
rspec-mocks (~> 3.5.0)
|
|
98
|
+
rspec-core (3.5.3)
|
|
99
|
+
rspec-support (~> 3.5.0)
|
|
100
|
+
rspec-expectations (3.5.0)
|
|
109
101
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
110
|
-
rspec-support (~> 3.
|
|
111
|
-
rspec-mocks (3.
|
|
102
|
+
rspec-support (~> 3.5.0)
|
|
103
|
+
rspec-mocks (3.5.0)
|
|
112
104
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
113
|
-
rspec-support (~> 3.
|
|
114
|
-
rspec-support (3.
|
|
115
|
-
rubocop (0.
|
|
116
|
-
parser (>= 2.3.
|
|
105
|
+
rspec-support (~> 3.5.0)
|
|
106
|
+
rspec-support (3.5.0)
|
|
107
|
+
rubocop (0.43.0)
|
|
108
|
+
parser (>= 2.3.1.1, < 3.0)
|
|
117
109
|
powerpack (~> 0.1)
|
|
118
110
|
rainbow (>= 1.99.1, < 3.0)
|
|
119
111
|
ruby-progressbar (~> 1.7)
|
|
120
|
-
|
|
121
|
-
|
|
112
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
|
113
|
+
ruby-progressbar (1.8.1)
|
|
114
|
+
semantic_puppet (0.1.4)
|
|
115
|
+
gettext-setup (>= 0.3)
|
|
122
116
|
shellany (0.0.1)
|
|
123
|
-
simplecov (0.
|
|
117
|
+
simplecov (0.12.0)
|
|
124
118
|
docile (~> 1.1.0)
|
|
125
|
-
json (
|
|
119
|
+
json (>= 1.8, < 3)
|
|
126
120
|
simplecov-html (~> 0.10.0)
|
|
127
121
|
simplecov-html (0.10.0)
|
|
128
122
|
slop (3.6.0)
|
|
129
123
|
term-ansicolor (1.3.2)
|
|
130
124
|
tins (~> 1.0)
|
|
125
|
+
text (1.3.1)
|
|
131
126
|
thor (0.19.1)
|
|
132
|
-
tins (1.
|
|
127
|
+
tins (1.12.0)
|
|
133
128
|
trollop (2.1.2)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
unf_ext (0.0.7.1)
|
|
137
|
-
yard (0.8.7.6)
|
|
129
|
+
unicode-display_width (1.1.1)
|
|
130
|
+
yard (0.9.5)
|
|
138
131
|
|
|
139
132
|
PLATFORMS
|
|
140
133
|
ruby
|
|
@@ -143,6 +136,7 @@ DEPENDENCIES
|
|
|
143
136
|
bundler (~> 1.10)
|
|
144
137
|
coveralls (~> 0.8)
|
|
145
138
|
guard-rspec (~> 4.6)
|
|
139
|
+
listen (~> 3.0.0)
|
|
146
140
|
pry (~> 0.10)
|
|
147
141
|
puppetfile_fixtures_generator!
|
|
148
142
|
rake (~> 10.0)
|
|
@@ -151,4 +145,4 @@ DEPENDENCIES
|
|
|
151
145
|
yard (~> 0.8)
|
|
152
146
|
|
|
153
147
|
BUNDLED WITH
|
|
154
|
-
1.
|
|
148
|
+
1.13.1
|
data/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
[](https://travis-ci.org/Ensighten/puppetfile_fixtures_generator)
|
|
2
|
+
[](https://coveralls.io/github/Ensighten/puppetfile_fixtures_generator?branch=master)
|
|
3
3
|
[](https://badge.fury.io/rb/puppetfile_fixtures_generator)
|
|
4
|
+
[](http://inch-ci.org/github/Ensighten/puppetfile_fixtures_generator)
|
|
4
5
|
|
|
5
6
|
# PuppetfileFixturesGenerator
|
|
6
7
|
|
|
@@ -37,7 +38,7 @@ The gem can be consumed as either a CLI tool or as a library.
|
|
|
37
38
|
|
|
38
39
|
### Library
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
See documentation: http://www.rubydoc.info/gems/puppetfile_fixtures_generator/
|
|
41
42
|
|
|
42
43
|
## Development
|
|
43
44
|
|
|
@@ -47,7 +48,7 @@ dependencies. Then, run `bundle exec rake` to run the tests.
|
|
|
47
48
|
## Contributing
|
|
48
49
|
|
|
49
50
|
Bug reports and pull requests are welcome on GitHub at
|
|
50
|
-
https://github.com/
|
|
51
|
+
https://github.com/Ensighten/puppetfile_fixtures_generator. This
|
|
51
52
|
project is intended to be a safe, welcoming space for collaboration,
|
|
52
53
|
and contributors are expected to adhere to the
|
|
53
54
|
[Contributor Covenant](contributor-covenant.org) code of conduct.
|
|
@@ -27,13 +27,17 @@ EOS
|
|
|
27
27
|
'The name of the module to include as the source_dir symlink in the fixtures file.',
|
|
28
28
|
type: :string,
|
|
29
29
|
default: nil
|
|
30
|
+
opt :diff,
|
|
31
|
+
'Diff puppetfile and fixtures instead of writing',
|
|
32
|
+
type: :bool,
|
|
33
|
+
default: false
|
|
30
34
|
opt :quiet,
|
|
31
35
|
'Do not prompt.',
|
|
32
36
|
type: :bool,
|
|
33
37
|
default: false
|
|
34
38
|
end
|
|
35
39
|
|
|
36
|
-
unless opts[:quiet]
|
|
40
|
+
unless opts[:quiet] || opts[:diff]
|
|
37
41
|
confirm = ask("This will overwrite #{opts[:fixtures_yml]}. Proceed? [Y/n] ") do |yn|
|
|
38
42
|
yn.case = :downcase
|
|
39
43
|
yn.default = 'y'
|
|
@@ -43,10 +47,21 @@ unless opts[:quiet]
|
|
|
43
47
|
exit unless confirm == 'y'
|
|
44
48
|
end
|
|
45
49
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
PuppetfileFixturesGenerator.create_fixtures(opts[:puppetfile],
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
if !opts[:diff]
|
|
51
|
+
say("Creating #{opts[:fixtures_yml]}...")
|
|
52
|
+
PuppetfileFixturesGenerator.create_fixtures(opts[:puppetfile],
|
|
53
|
+
opts[:fixtures_yml],
|
|
54
|
+
opts[:symlink_name])
|
|
55
|
+
say('Complete.')
|
|
56
|
+
exit
|
|
57
|
+
else
|
|
58
|
+
say('Diffing Puppetfile and fixtures')
|
|
59
|
+
diff = PuppetfileFixturesGenerator.diff(opts[:puppetfile],
|
|
60
|
+
opts[:fixtures_yml])
|
|
61
|
+
if diff[0]
|
|
62
|
+
say('Modules match in both files.')
|
|
63
|
+
exit
|
|
64
|
+
else
|
|
65
|
+
abort "Modules do not match in both files\n#{diff[1]}"
|
|
66
|
+
end
|
|
67
|
+
end
|
|
File without changes
|
|
@@ -6,59 +6,35 @@ module PuppetfileFixturesGenerator
|
|
|
6
6
|
# changes in the future this class will be rewritten.
|
|
7
7
|
class Fixtures
|
|
8
8
|
#
|
|
9
|
-
def initialize(fixtures_file, modules, symlink_name = nil)
|
|
9
|
+
def initialize(fixtures_file, modules = nil, symlink_name = nil)
|
|
10
10
|
@fixtures = Pathname.new(fixtures_file)
|
|
11
11
|
@modules = modules
|
|
12
12
|
@module_hash = { 'fixtures' => {} }
|
|
13
|
-
|
|
13
|
+
@symlink_name = symlink_name
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def
|
|
16
|
+
def modules_hash
|
|
17
|
+
YAML.load(@fixtures.read)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
#
|
|
21
|
+
def write(fixtures_pn = @fixtures)
|
|
22
|
+
return 'Cannot write empty modules' if @modules.nil?
|
|
17
23
|
# create hash of modules
|
|
18
|
-
|
|
24
|
+
@module_hash['fixtures'] = @modules
|
|
25
|
+
symlink_builder(@symlink_name)
|
|
19
26
|
# convert hash to yaml
|
|
20
27
|
yaml = @module_hash.to_yaml
|
|
21
28
|
# write yaml
|
|
22
|
-
|
|
29
|
+
fixtures_pn.write(yaml)
|
|
23
30
|
end
|
|
24
31
|
|
|
25
32
|
private
|
|
26
33
|
|
|
27
34
|
#
|
|
28
35
|
def symlink_builder(name)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
#
|
|
35
|
-
def hash_the_modules
|
|
36
|
-
@modules.each { |mod| module_builder(mod) } unless @modules.nil?
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
#
|
|
40
|
-
def module_builder(mod) # rubocop:disable Metrics/MethodLength
|
|
41
|
-
case mod.properties[:type]
|
|
42
|
-
when :forge
|
|
43
|
-
ctgry = 'forge_modules'
|
|
44
|
-
repo = mod.title
|
|
45
|
-
version = mod.expected_version
|
|
46
|
-
when :git
|
|
47
|
-
ctgry = 'repositories'
|
|
48
|
-
repo = mod.instance_variable_get :@remote
|
|
49
|
-
version = mod.instance_variable_get :@ref
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
@module_hash['fixtures'][ctgry] = {} unless
|
|
53
|
-
@module_hash['fixtures'].key?(ctgry)
|
|
54
|
-
|
|
55
|
-
add_module(ctgry, mod.name, repo, version)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
#
|
|
59
|
-
def add_module(category, name, repo, version)
|
|
60
|
-
hash = { name => { 'repo' => repo, 'ref' => version } }
|
|
61
|
-
@module_hash['fixtures'][category].merge!(hash)
|
|
36
|
+
return if name.nil?
|
|
37
|
+
@module_hash['fixtures']['symlinks'] = { name => '#{source_dir}' }
|
|
62
38
|
end
|
|
63
39
|
end
|
|
64
40
|
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require 'r10k/puppetfile'
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
module PuppetfileFixturesGenerator
|
|
5
|
+
# Manipulate Puppetfiles so they can be converted to fixtures or
|
|
6
|
+
# diffed
|
|
7
|
+
class Puppetfile
|
|
8
|
+
# Constructor
|
|
9
|
+
# @param puppetfile_path Path to the Puppetfile
|
|
10
|
+
def initialize(puppetfile_path)
|
|
11
|
+
@pf_path = puppetfile_path
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# @return [Hash] Modules from the Puppetfile
|
|
15
|
+
def modules_hash
|
|
16
|
+
@modules_hash ||=
|
|
17
|
+
begin
|
|
18
|
+
hash = {}
|
|
19
|
+
puppetfile.modules.each { |mod| module_builder(mod, hash) }
|
|
20
|
+
hash
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
# @param puppetfile_path Path to the Puppetfile
|
|
27
|
+
# @return [R10K::Puppetfile]
|
|
28
|
+
def puppetfile(puppetfile_path = @pf_path)
|
|
29
|
+
@puppetfile ||=
|
|
30
|
+
begin
|
|
31
|
+
pf = R10K::Puppetfile.new(Pathname.new(puppetfile_path).dirname.to_s)
|
|
32
|
+
pf.load
|
|
33
|
+
pf
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Deconstruct a module to its parts. Add the deconstructed module
|
|
38
|
+
# to the appropiate key in a hash. If the appropiate key does not
|
|
39
|
+
# exist in the hash add the key to the hash.
|
|
40
|
+
#
|
|
41
|
+
# @param hash [Hash] Hash to add the module to
|
|
42
|
+
# @param mod [R10K::Module]
|
|
43
|
+
# @return [Hash] Passed in hash with the module added
|
|
44
|
+
def module_builder(mod, hash) # rubocop:disable Metrics/MethodLength
|
|
45
|
+
case mod.properties[:type]
|
|
46
|
+
when :forge
|
|
47
|
+
ctgry = 'forge_modules'
|
|
48
|
+
repo = mod.title
|
|
49
|
+
version = mod.expected_version
|
|
50
|
+
when :git
|
|
51
|
+
ctgry = 'repositories'
|
|
52
|
+
repo = mod.instance_variable_get :@remote
|
|
53
|
+
version = mod.instance_variable_get :@ref
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
add_category(ctgry, hash)
|
|
57
|
+
add_module(ctgry, mod.name, repo, version, hash)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# @param category [String] The hash key to add the module to
|
|
61
|
+
# @param name [String] The name of the module
|
|
62
|
+
# @param repo [String] The repo for the module
|
|
63
|
+
# @param version [String] The version of the module
|
|
64
|
+
# @param hsh [Hash] The hash to add the module to
|
|
65
|
+
# @return [Hash] Passed in hash with module added
|
|
66
|
+
def add_module(category, name, repo, version, hsh)
|
|
67
|
+
hash = { name => { 'repo' => repo, 'ref' => version } }
|
|
68
|
+
hsh[category].merge!(hash)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# @param key [String] The key to add to the hash
|
|
72
|
+
# @param hsh [Hash] The hash to add the key to
|
|
73
|
+
# @return [Hash] Hash with added key
|
|
74
|
+
def add_category(key, hash)
|
|
75
|
+
hash[key] = {} unless
|
|
76
|
+
hash.key?(key)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require 'puppetfile_fixtures_generator/version'
|
|
2
2
|
require 'puppetfile_fixtures_generator/fixtures'
|
|
3
|
+
require 'puppetfile_fixtures_generator/puppetfile'
|
|
3
4
|
require 'r10k/puppetfile'
|
|
4
5
|
|
|
5
6
|
# Namespace for classes and modules that handle reading and writing
|
|
@@ -27,11 +28,8 @@ module PuppetfileFixturesGenerator
|
|
|
27
28
|
modules = nil
|
|
28
29
|
|
|
29
30
|
unless puppetfile.nil?
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
# parse puppetfile
|
|
33
|
-
pf.load
|
|
34
|
-
modules = pf.modules
|
|
31
|
+
pf = PuppetfileFixturesGenerator::Puppetfile.new(puppetfile)
|
|
32
|
+
modules = pf.modules_hash
|
|
35
33
|
end
|
|
36
34
|
|
|
37
35
|
# write fixtures
|
|
@@ -39,5 +37,39 @@ module PuppetfileFixturesGenerator
|
|
|
39
37
|
fixtures.write
|
|
40
38
|
end
|
|
41
39
|
|
|
40
|
+
# Takes a puppetfile and a fixtures file, converts themk to hashes,
|
|
41
|
+
# diffs the hashes, and returns the results.
|
|
42
|
+
#
|
|
43
|
+
# @param [String] puppetfile The path, local or absolute, to the
|
|
44
|
+
# Puppetfile. This Puppetfile will be loaded and parsed to create
|
|
45
|
+
# the fixtures YAML file.
|
|
46
|
+
# @param [String] fixtures The path, local or absolute, to the
|
|
47
|
+
# fixtures file to be written. The path, not the file, must exist.
|
|
48
|
+
#
|
|
49
|
+
# @return [Array] The results of self.hash_differ
|
|
50
|
+
def self.diff(puppetfile, fixtures)
|
|
51
|
+
pf = PuppetfileFixturesGenerator::Puppetfile.new(puppetfile)
|
|
52
|
+
fx = PuppetfileFixturesGenerator::Fixtures.new(fixtures)
|
|
53
|
+
|
|
54
|
+
pf_modules = pf.modules_hash['repositories'].to_a
|
|
55
|
+
fx_modules = fx.modules_hash['fixtures']['repositories'].to_a
|
|
56
|
+
|
|
57
|
+
hash_differ(pf_modules, fx_modules)
|
|
58
|
+
end
|
|
59
|
+
|
|
42
60
|
# @todo Add support for creating a Puppetfile from a fixtures file
|
|
61
|
+
|
|
62
|
+
# Takes two hashes, diffs them, and returns results
|
|
63
|
+
#
|
|
64
|
+
# @param hash1 [Hash] First hash to diff
|
|
65
|
+
# @param hash2 [Hash] Second hash to diff
|
|
66
|
+
#
|
|
67
|
+
# @return [Array] First element in array is a boolean for whether
|
|
68
|
+
# the files had differences. Second element is a hash of
|
|
69
|
+
# differences.
|
|
70
|
+
def self.hash_differ(hash1, hash2)
|
|
71
|
+
result = hash1 == hash2
|
|
72
|
+
return [result, {}] if result
|
|
73
|
+
[result, Hash[*(hash2.size > hash1.size ? hash2 - hash1 : hash1 - hash2).flatten]]
|
|
74
|
+
end
|
|
43
75
|
end
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
|
-
require 'rake'
|
|
3
|
-
|
|
4
2
|
lib = File.expand_path('../lib', __FILE__)
|
|
5
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
6
4
|
require 'puppetfile_fixtures_generator/version'
|
|
7
5
|
|
|
8
6
|
Gem::Specification.new do |s|
|
|
9
|
-
s.authors
|
|
10
|
-
s.bindir
|
|
11
|
-
s.description
|
|
12
|
-
s.email
|
|
7
|
+
s.authors = ['Alejandro Figueroa']
|
|
8
|
+
s.bindir = 'bin'
|
|
9
|
+
s.description = 'Create a .fixtures.yml file from a Puppetfile.'
|
|
10
|
+
s.email = ['alejandro@ideasftw.com']
|
|
13
11
|
s.executables << 'puppetfile_fixtures_generator'
|
|
14
|
-
s.files
|
|
15
|
-
s.homepage
|
|
16
|
-
s.license
|
|
17
|
-
s.name
|
|
18
|
-
s.summary
|
|
19
|
-
s.version
|
|
12
|
+
s.files = Dir['lib/**/*.rb'] + Dir['bin/*'] + Dir['[A-Z]*'] + Dir['spec/**/*']
|
|
13
|
+
s.homepage = 'https://github.com/Ensighten/puppetfile_fixtures_generator'
|
|
14
|
+
s.license = 'MIT'
|
|
15
|
+
s.name = 'puppetfile_fixtures_generator'
|
|
16
|
+
s.summary = 'Create a .fixtures.yml file from a Puppetfile.'
|
|
17
|
+
s.version = PuppetfileFixturesGenerator::VERSION
|
|
18
|
+
s.required_ruby_version = '>= 2.1'
|
|
20
19
|
|
|
21
20
|
s.add_runtime_dependency 'highline', '~> 1.7'
|
|
22
|
-
s.add_runtime_dependency 'r10k', '~> 2.
|
|
21
|
+
s.add_runtime_dependency 'r10k', '~> 2.3.0'
|
|
23
22
|
s.add_runtime_dependency 'trollop', '~> 2.1'
|
|
24
23
|
|
|
25
24
|
s.add_development_dependency 'bundler', '~> 1.10'
|
|
26
25
|
s.add_development_dependency 'coveralls', '~> 0.8'
|
|
27
26
|
s.add_development_dependency 'guard-rspec', '~> 4.6'
|
|
27
|
+
s.add_development_dependency 'listen', '~> 3.0.0'
|
|
28
28
|
s.add_development_dependency 'pry', '~> 0.10'
|
|
29
29
|
s.add_development_dependency 'rake', '~> 10.0'
|
|
30
30
|
s.add_development_dependency 'rspec', '~> 3.4'
|
|
@@ -5,6 +5,19 @@ describe PuppetfileFixturesGenerator do
|
|
|
5
5
|
expect(PuppetfileFixturesGenerator::VERSION).not_to be nil
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
-
describe '#
|
|
8
|
+
describe '#diff and #hash_differ' do
|
|
9
|
+
let(:puppetfile) { './spec/fixtures/Puppetfile' }
|
|
10
|
+
let(:matching_diff) { './spec/fixtures/matching_diffs/.fixtures.yml' }
|
|
11
|
+
let(:nonmatching_diff) { './spec/fixtures/nonmatching_diffs/.fixtures.yml' }
|
|
12
|
+
context 'test diffs' do
|
|
13
|
+
it 'matching diff' do
|
|
14
|
+
results = PuppetfileFixturesGenerator.diff(puppetfile, matching_diff)
|
|
15
|
+
expect(results[0]).to eq(true)
|
|
16
|
+
end
|
|
17
|
+
it 'nonmatching diff' do
|
|
18
|
+
results = PuppetfileFixturesGenerator.diff(puppetfile, nonmatching_diff)
|
|
19
|
+
expect(results[0]).to eq(false)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
9
22
|
end
|
|
10
23
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: puppetfile_fixtures_generator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alejandro Figueroa
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-09-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: highline
|
|
@@ -30,14 +30,14 @@ dependencies:
|
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
33
|
+
version: 2.3.0
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
40
|
+
version: 2.3.0
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: trollop
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -94,6 +94,20 @@ dependencies:
|
|
|
94
94
|
- - "~>"
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
96
|
version: '4.6'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: listen
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: 3.0.0
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: 3.0.0
|
|
97
111
|
- !ruby/object:Gem::Dependency
|
|
98
112
|
name: pry
|
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -172,6 +186,7 @@ executables:
|
|
|
172
186
|
extensions: []
|
|
173
187
|
extra_rdoc_files: []
|
|
174
188
|
files:
|
|
189
|
+
- CHANGELOG.md
|
|
175
190
|
- CODE_OF_CONDUCT.md
|
|
176
191
|
- Gemfile
|
|
177
192
|
- Gemfile.lock
|
|
@@ -182,15 +197,15 @@ files:
|
|
|
182
197
|
- TODO.md
|
|
183
198
|
- bin/puppetfile_fixtures_generator
|
|
184
199
|
- lib/puppetfile_fixtures_generator.rb
|
|
200
|
+
- lib/puppetfile_fixtures_generator/diff.rb
|
|
185
201
|
- lib/puppetfile_fixtures_generator/fixtures.rb
|
|
202
|
+
- lib/puppetfile_fixtures_generator/puppetfile.rb
|
|
186
203
|
- lib/puppetfile_fixtures_generator/version.rb
|
|
187
|
-
- puppetfile_fixtures_generator-0.1.0.gem
|
|
188
|
-
- puppetfile_fixtures_generator-0.1.1.gem
|
|
189
204
|
- puppetfile_fixtures_generator.gemspec
|
|
190
205
|
- spec/fixtures/Puppetfile
|
|
191
206
|
- spec/puppetfile_fixtures_generator_spec.rb
|
|
192
207
|
- spec/spec_helper.rb
|
|
193
|
-
homepage: https://github.com/
|
|
208
|
+
homepage: https://github.com/Ensighten/puppetfile_fixtures_generator
|
|
194
209
|
licenses:
|
|
195
210
|
- MIT
|
|
196
211
|
metadata: {}
|
|
@@ -202,7 +217,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
202
217
|
requirements:
|
|
203
218
|
- - ">="
|
|
204
219
|
- !ruby/object:Gem::Version
|
|
205
|
-
version: '
|
|
220
|
+
version: '2.1'
|
|
206
221
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
222
|
requirements:
|
|
208
223
|
- - ">="
|
|
@@ -215,4 +230,3 @@ signing_key:
|
|
|
215
230
|
specification_version: 4
|
|
216
231
|
summary: Create a .fixtures.yml file from a Puppetfile.
|
|
217
232
|
test_files: []
|
|
218
|
-
has_rdoc:
|
|
Binary file
|
|
Binary file
|