puppet-retrospec 1.3.2 → 1.4.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/.rubocop_todo.yml +3 -1
- data/CHANGELOG.md +3 -0
- data/Gemfile +2 -1
- data/Gemfile.lock +13 -3
- data/README.md +10 -0
- data/lib/retrospec/plugins/v1/plugin/generators/base_generator.rb +4 -0
- data/lib/retrospec/plugins/v1/plugin/generators/function_generator.rb +6 -5
- data/lib/retrospec/plugins/v1/plugin/generators/module_data_generator.rb +115 -0
- data/lib/retrospec/plugins/v1/plugin/puppet.rb +7 -1
- data/lib/retrospec/plugins/v1/plugin/version.rb +1 -1
- data/puppet-retrospec.gemspec +2 -2
- data/spec/unit/generators/module_data_spec.rb +148 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6e329b9bf28b9a369953d9fca8ff19d1cc32e82
|
4
|
+
data.tar.gz: f5198887c6b93f1b6b44383d2dd3f9183cb001eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3601799c03379311d561889c8f9ecf7bafab7c817cf40d68ada86ed4ddbf572e01fd1dee95f685dcd6652c09c4efda9166dba6c30af767fd104d870c608f226
|
7
|
+
data.tar.gz: c21306e18c27ffac761fa3384c93f923b68063fe69e944b62bf828771b40634b62d9f3700eb0ebb0cda9aed1f0e3466a9cc0f7ad7fd54b1ec8932dc2cfb1437a
|
data/.rubocop_todo.yml
CHANGED
@@ -5,7 +5,8 @@
|
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
|
-
|
8
|
+
Bundler/OrderedGems:
|
9
|
+
Enabled: false
|
9
10
|
Style/MultilineIfModifier:
|
10
11
|
Exclude:
|
11
12
|
- 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb'
|
@@ -159,6 +160,7 @@ Style/AccessorMethodName:
|
|
159
160
|
- 'lib/retrospec/plugins/v1/plugin/generators/parsers/function.rb'
|
160
161
|
- 'lib/retrospec/plugins/v1/plugin/generators/parsers/type.rb'
|
161
162
|
- 'lib/retrospec/plugins/v1/plugin/helpers.rb'
|
163
|
+
- 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb'
|
162
164
|
|
163
165
|
# Offense count: 14
|
164
166
|
# Cop supports --auto-correct.
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -2,7 +2,7 @@ source 'http://rubygems.org'
|
|
2
2
|
|
3
3
|
gem 'awesome_print'
|
4
4
|
gem 'facets'
|
5
|
-
gem 'retrospec', '
|
5
|
+
gem 'retrospec', '>= 0.6.1'
|
6
6
|
gem 'trollop'
|
7
7
|
|
8
8
|
group :development do
|
@@ -20,4 +20,5 @@ group :test do
|
|
20
20
|
gem 'rspec', '~> 3.2'
|
21
21
|
gem 'rubocop'
|
22
22
|
gem 'yard', '~> 0.7'
|
23
|
+
gem 'puppet-retrospec', :path => './'
|
23
24
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
puppet-retrospec (1.4.0)
|
5
|
+
awesome_print
|
6
|
+
facets
|
7
|
+
retrospec (>= 0.6.2)
|
8
|
+
trollop
|
9
|
+
|
1
10
|
PATH
|
2
11
|
remote: vendor/gems/puppet-4.5.2
|
3
12
|
specs:
|
@@ -40,7 +49,7 @@ GEM
|
|
40
49
|
rake (11.3.0)
|
41
50
|
rdoc (3.12.2)
|
42
51
|
json (~> 1.4)
|
43
|
-
retrospec (0.6.
|
52
|
+
retrospec (0.6.2)
|
44
53
|
trollop
|
45
54
|
rspec (3.5.0)
|
46
55
|
rspec-core (~> 3.5.0)
|
@@ -79,13 +88,14 @@ DEPENDENCIES
|
|
79
88
|
overcommit
|
80
89
|
pry
|
81
90
|
puppet (= 4.5.2)!
|
91
|
+
puppet-retrospec!
|
82
92
|
rake
|
83
93
|
rdoc (~> 3.12)
|
84
|
-
retrospec (
|
94
|
+
retrospec (>= 0.6.1)
|
85
95
|
rspec (~> 3.2)
|
86
96
|
rubocop
|
87
97
|
trollop
|
88
98
|
yard (~> 0.7)
|
89
99
|
|
90
100
|
BUNDLED WITH
|
91
|
-
1.
|
101
|
+
1.14.6
|
data/README.md
CHANGED
@@ -50,6 +50,16 @@ TOC Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)
|
|
50
50
|
[](http://badge.fury.io/rb/puppet-retrospec)
|
51
51
|
|
52
52
|
## News
|
53
|
+
### 4/20/17
|
54
|
+
With all the changes in hiera recently and the ability to provide data in puppet modules. I thought it would be a good
|
55
|
+
time to create a generator for retrospec to create hiera backends and data in module scaffolding. With the 1.6.0 release
|
56
|
+
you are now a simple step away to retrofitting data into your module.
|
57
|
+
|
58
|
+
Just run `retrospec puppet module_data` to auto create the scaffolding.
|
59
|
+
|
60
|
+
Note: You must be using puppet 4.7+ (PE 2016.4.x) to actually use data in a module, but there is nothing stopping
|
61
|
+
you from creating the scaffolding.
|
62
|
+
|
53
63
|
### 3/7/17
|
54
64
|
You can now sync files. Any template file that contains a `.sync` in the file name will automatically
|
55
65
|
be syncronized. This is especially helpful for Gemfiles, Rakefiles and other static files that need to be updated.
|
@@ -12,9 +12,9 @@ module Retrospec
|
|
12
12
|
# below is the Spec Object which serves as a context for template rendering
|
13
13
|
# you will need to initialize this object, so the erb templates can get the binding
|
14
14
|
# the SpecObject can be customized to your liking as its different for every plugin gem.
|
15
|
-
@context = OpenStruct.new(:name => spec_object[:name], :return_type => spec_object[:return_type],
|
15
|
+
@context = OpenStruct.new({ :name => spec_object[:name], :return_type => spec_object[:return_type],
|
16
16
|
:function_type => spec_object[:type],
|
17
|
-
:test_type => spec_object[:test_type])
|
17
|
+
:test_type => spec_object[:test_type] }.merge(spec_object))
|
18
18
|
end
|
19
19
|
|
20
20
|
# Puppet currently has two versions of functions (v3, v4). At the time of writing v4 is still new
|
@@ -111,7 +111,7 @@ Generates a new function with the given name.
|
|
111
111
|
|
112
112
|
# returns the name of the function
|
113
113
|
def function_name
|
114
|
-
context.name
|
114
|
+
context.name.gsub('::', '_')
|
115
115
|
end
|
116
116
|
|
117
117
|
def function_file_path
|
@@ -119,8 +119,9 @@ Generates a new function with the given name.
|
|
119
119
|
end
|
120
120
|
|
121
121
|
# generates the function file based on the template and context
|
122
|
-
def generate_function_file
|
123
|
-
|
122
|
+
def generate_function_file(template = nil)
|
123
|
+
template ||= function_file_path
|
124
|
+
safe_create_template_file(function_path, template, context)
|
124
125
|
function_path
|
125
126
|
end
|
126
127
|
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'retrospec/plugins/v1/module_helpers'
|
2
|
+
require 'retrospec/plugins/v1'
|
3
|
+
|
4
|
+
module Retrospec
|
5
|
+
module Puppet
|
6
|
+
module Generators
|
7
|
+
class ModuleDataGenerator < Retrospec::Puppet::Generators::BaseGenerator
|
8
|
+
attr_reader :module_name, :spec_object
|
9
|
+
def initialize(module_path, spec_object = {})
|
10
|
+
super
|
11
|
+
@plural_name = 'module_data'
|
12
|
+
@spec_object = spec_object
|
13
|
+
@singular_name = @plural_name
|
14
|
+
end
|
15
|
+
|
16
|
+
def module_name
|
17
|
+
@module_name ||= Utilities::PuppetModule.instance.module_name.split(%r{-|\/}).last
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [String] backend type
|
21
|
+
def backend_type
|
22
|
+
context.backend_type
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [String] backend name
|
26
|
+
def backend_name
|
27
|
+
context.backend_name
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [String] function type
|
31
|
+
def backend_function_type
|
32
|
+
context.function_type
|
33
|
+
end
|
34
|
+
|
35
|
+
def generate_module_data_for_hiera
|
36
|
+
safe_create_directory_files(template_dir, module_path, context, /functions/)
|
37
|
+
end
|
38
|
+
|
39
|
+
def generate_hiera_file
|
40
|
+
path = File.join(module_path, 'hiera.yaml')
|
41
|
+
template = File.join(template_dir, 'hiera.yaml.retrospec.erb')
|
42
|
+
safe_create_template_file(path, template, self)
|
43
|
+
end
|
44
|
+
|
45
|
+
def generate_module_data_for_function(_type)
|
46
|
+
data = { :name => backend_name,
|
47
|
+
:type => backend_function_type,
|
48
|
+
:test_type => 'rspec',
|
49
|
+
:module_name => module_name }.merge(spec_object)
|
50
|
+
f = FunctionGenerator.new(module_path, data)
|
51
|
+
ext = backend_function_type == 'native' ? 'pp' : 'rb'
|
52
|
+
template_path = File.join(template_dir, 'functions', backend_function_type, "function_#{backend_type}.#{ext}.retrospec.erb")
|
53
|
+
f.generate_function_file(template_path)
|
54
|
+
generate_hiera_file
|
55
|
+
end
|
56
|
+
|
57
|
+
def template_dir
|
58
|
+
external_templates = File.expand_path(File.join(config_data[:template_dir], @plural_name))
|
59
|
+
if File.exist?(external_templates)
|
60
|
+
File.join(config_data[:template_dir], 'module_data')
|
61
|
+
else
|
62
|
+
File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), 'templates', @plural_name))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def run
|
67
|
+
if backend_type == 'hiera'
|
68
|
+
generate_module_data_for_hiera
|
69
|
+
else
|
70
|
+
generate_module_data_for_function(backend_type)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# used to display subcommand options to the cli
|
75
|
+
# the global options are passed in for your usage
|
76
|
+
# http://trollop.rubyforge.org
|
77
|
+
# all options here are available in the config passed into config object
|
78
|
+
# returns the parameters
|
79
|
+
def self.run_cli(global_opts, args = ARGV)
|
80
|
+
backend_types = %w(hiera data_hash lookup_key data_dig)
|
81
|
+
sub_command_opts = Trollop.options(args) do
|
82
|
+
banner <<-EOS
|
83
|
+
Generate the scaffolding required to use data in a module from hiera or a custom hiera backend.
|
84
|
+
* Data in module is only available in puppet 4.7+
|
85
|
+
* Hiera 5 backends are only available in puppet 4.9+
|
86
|
+
* https://docs.puppet.com/puppet/4.10/hiera_custom_backends.html
|
87
|
+
|
88
|
+
Examples:
|
89
|
+
retrospec puppet module_data -b data_hash -n my_custom_hash -t native
|
90
|
+
retrospec puppet module_data (uses defaults which is the hiera backend type, most people will want this )
|
91
|
+
|
92
|
+
Options:
|
93
|
+
|
94
|
+
EOS
|
95
|
+
opt :backend_type, "Which hiera backend type to use (#{backend_types.join(', ')})",
|
96
|
+
:type => :string, :required => false, default: 'hiera', :short => '-b'
|
97
|
+
opt :backend_name, 'The name of the custom backend',
|
98
|
+
:type => :string, :required => false, default: 'custom', :short => '-n'
|
99
|
+
opt :function_type, 'What type of function to create the backend type with (native or v4)',
|
100
|
+
:type => :string, :required => false, default: 'native', :short => '-t'
|
101
|
+
end
|
102
|
+
unless backend_types.include?(sub_command_opts[:backend_type])
|
103
|
+
Trollop.die :backend_type, "must be one of #{backend_types.join(', ')}"
|
104
|
+
end
|
105
|
+
unless %w(native v4).include?(sub_command_opts[:function_type])
|
106
|
+
Trollop.die :function_type, "must be one of #{%w(native v4).join(', ')}"
|
107
|
+
end
|
108
|
+
|
109
|
+
plugin_data = global_opts.merge(sub_command_opts)
|
110
|
+
plugin_data
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -92,7 +92,7 @@ module Retrospec
|
|
92
92
|
scm_branch = ENV['RETROSPEC_PUPPET_SCM_BRANCH'] || plugin_config['plugins::puppet::templates::ref'] || 'master'
|
93
93
|
beaker_tests = plugin_config['plugins::puppet::enable_beaker_tests'] || false
|
94
94
|
# a list of subcommands for this plugin
|
95
|
-
sub_commands = %w(new_module new_fact new_type new_provider new_function new_report)
|
95
|
+
sub_commands = %w(new_module new_fact new_type new_provider new_function new_report module_data)
|
96
96
|
if sub_commands.count > 0
|
97
97
|
sub_command_help = "Subcommands:\n #{sub_commands.join("\n ")}\n"
|
98
98
|
else
|
@@ -165,6 +165,12 @@ Generates puppet rspec test code and puppet module components.
|
|
165
165
|
plugin_data
|
166
166
|
end
|
167
167
|
|
168
|
+
def module_data(module_path, config, args=[])
|
169
|
+
plugin_data = Retrospec::Puppet::Generators::ModuleDataGenerator.run_cli(config, args)
|
170
|
+
p = Retrospec::Puppet::Generators::ModuleDataGenerator.new(module_path, plugin_data)
|
171
|
+
p.run
|
172
|
+
end
|
173
|
+
|
168
174
|
def new_report(module_path, config, args=[])
|
169
175
|
plugin_data = Retrospec::Puppet::Generators::ReportGenerator.run_cli(config, args)
|
170
176
|
p = Retrospec::Puppet::Generators::ReportGenerator.new(module_path, plugin_data)
|
data/puppet-retrospec.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.require_paths = ["lib"]
|
12
12
|
s.authors = ["Corey Osman"]
|
13
|
-
s.date = "2017-
|
13
|
+
s.date = "2017-04-20"
|
14
14
|
s.description = "Retrofits and generates valid puppet rspec test code to existing modules"
|
15
15
|
s.email = "corey@nwops.io"
|
16
16
|
s.extra_rdoc_files = [
|
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.rubygems_version = "2.4.5.1"
|
25
25
|
s.summary = "Generates puppet rspec test code based on the classes and defines inside the manifests directory. Aims to reduce some of the boilerplate coding with default test patterns."
|
26
26
|
s.add_runtime_dependency(%q<trollop>, [">= 0"])
|
27
|
-
s.add_runtime_dependency(%q<retrospec>, ["
|
27
|
+
s.add_runtime_dependency(%q<retrospec>, [">= 0.6.2"])
|
28
28
|
s.add_runtime_dependency(%q<awesome_print>, [">= 0"])
|
29
29
|
s.add_runtime_dependency(%q<facets>, [">= 0"])
|
30
30
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'ModuleDataGenerator' do
|
4
|
+
let(:cli_opts) do
|
5
|
+
cli_opts = Retrospec::Puppet::Generators::ModuleDataGenerator.run_cli(context, opts)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:context) do
|
9
|
+
{ :module_path => module_path,
|
10
|
+
:template_dir => retrospec_templates_path }
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:module_path) do
|
14
|
+
File.join(fixture_modules_path, 'tomcat')
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:generator) do
|
18
|
+
Retrospec::Puppet::Generators::ModuleDataGenerator.new(module_path, cli_opts)
|
19
|
+
end
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
FileUtils.rm_rf(File.join(module_path, 'data')) # ensure the file does not exist
|
23
|
+
FileUtils.rm_f(File.join(module_path, 'hiera.yaml')) # ensure the file does not exist
|
24
|
+
FileUtils.rm_rf(File.join(module_path, 'functions')) # ensure the file does not exist
|
25
|
+
FileUtils.rm_rf(File.join(module_path, 'lib', 'puppet', 'functions')) # ensure the file does not exist
|
26
|
+
|
27
|
+
Utilities::PuppetModule.instance.module_dir_name = File.basename(module_path)
|
28
|
+
Utilities::PuppetModule.instance.module_name = File.basename(module_path)
|
29
|
+
Utilities::PuppetModule.instance.module_path = module_path
|
30
|
+
Utilities::PuppetModule.create_tmp_module_path # this is required to finish initialization
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'hiera' do
|
34
|
+
let(:opts) do
|
35
|
+
['-b', 'hiera']
|
36
|
+
end
|
37
|
+
it 'works with hiera' do
|
38
|
+
generator.run
|
39
|
+
expect(File.exist?(File.join(module_path, 'data'))).to eq(true)
|
40
|
+
expect(File.exist?(File.join(module_path, 'functions'))).to eq(false)
|
41
|
+
expect(File.exist?(File.join(module_path, 'data', 'os'))).to eq(true)
|
42
|
+
expect(File.exist?(File.join(module_path, 'data', 'common.yaml'))).to eq(true)
|
43
|
+
expect(File.exist?(File.join(module_path, 'hiera.yaml'))).to eq(true)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'data_hash native' do
|
48
|
+
let(:opts) do
|
49
|
+
['-b', 'data_hash', '-n', 'my_custom', '-t', 'native']
|
50
|
+
end
|
51
|
+
it 'works with function' do
|
52
|
+
generator.run
|
53
|
+
expect(File.exist?(File.join(module_path, 'functions', 'my_custom.pp'))).to eq(true)
|
54
|
+
expect(File.exist?(File.join(module_path, 'data'))).to eq(false)
|
55
|
+
expect(File.exist?(File.join(module_path, 'data', 'os'))).to eq(false)
|
56
|
+
expect(File.exist?(File.join(module_path, 'data', 'common.yaml'))).to eq(false)
|
57
|
+
expect(File.exist?(File.join(module_path, 'hiera.yaml'))).to eq(true)
|
58
|
+
file_data = File.readlines(File.join(module_path, 'functions', 'my_custom.pp'))
|
59
|
+
expect(file_data.grep(/tomcat::my_custom/)).to eq(["function tomcat::my_custom(\n"])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'data_dig native' do
|
64
|
+
let(:opts) do
|
65
|
+
['-b', 'data_dig', '-n', 'my_custom', '-t', 'native']
|
66
|
+
end
|
67
|
+
it 'works with function' do
|
68
|
+
generator.run
|
69
|
+
expect(File.exist?(File.join(module_path, 'functions', 'my_custom.pp'))).to eq(true)
|
70
|
+
expect(File.exist?(File.join(module_path, 'data'))).to eq(false)
|
71
|
+
expect(File.exist?(File.join(module_path, 'data', 'os'))).to eq(false)
|
72
|
+
expect(File.exist?(File.join(module_path, 'data', 'common.yaml'))).to eq(false)
|
73
|
+
expect(File.exist?(File.join(module_path, 'hiera.yaml'))).to eq(true)
|
74
|
+
file_data = File.readlines(File.join(module_path, 'functions', 'my_custom.pp'))
|
75
|
+
expect(file_data.grep(/tomcat::my_custom/)).to eq(["function tomcat::my_custom(\n"])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe 'lookup_key native' do
|
80
|
+
let(:opts) do
|
81
|
+
['-b', 'lookup_key', '-n', 'my_custom', '-t', 'native']
|
82
|
+
end
|
83
|
+
it 'works with function' do
|
84
|
+
generator.run
|
85
|
+
expect(File.exist?(File.join(module_path, 'functions', 'my_custom.pp'))).to eq(true)
|
86
|
+
expect(File.exist?(File.join(module_path, 'data'))).to eq(false)
|
87
|
+
expect(File.exist?(File.join(module_path, 'data', 'os'))).to eq(false)
|
88
|
+
expect(File.exist?(File.join(module_path, 'data', 'common.yaml'))).to eq(false)
|
89
|
+
expect(File.exist?(File.join(module_path, 'hiera.yaml'))).to eq(true)
|
90
|
+
file_data = File.readlines(File.join(module_path, 'functions', 'my_custom.pp'))
|
91
|
+
expect(file_data.grep(/tomcat::my_custom/)).to eq(["function tomcat::my_custom(\n"])
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'data_hash ruby' do
|
96
|
+
let(:opts) do
|
97
|
+
['-b', 'data_hash', '-n', 'my_custom', '-t', 'v4']
|
98
|
+
end
|
99
|
+
it 'works with function' do
|
100
|
+
generator.run
|
101
|
+
expect(File.exist?(File.join(module_path, 'lib', 'puppet', 'functions', 'my_custom.rb'))).to eq(true)
|
102
|
+
expect(File.exist?(File.join(module_path, 'data'))).to eq(false)
|
103
|
+
expect(File.exist?(File.join(module_path, 'data', 'os'))).to eq(false)
|
104
|
+
expect(File.exist?(File.join(module_path, 'data', 'common.yaml'))).to eq(false)
|
105
|
+
expect(File.exist?(File.join(module_path, 'hiera.yaml'))).to eq(true)
|
106
|
+
file_data = File.readlines(File.join(module_path, 'lib', 'puppet', 'functions', 'my_custom.rb'))
|
107
|
+
expect(file_data.grep(/tomcat::my_custom/)).to eq(["Puppet::Functions.create_function(:\"tomcat::my_custom\") do\n"])
|
108
|
+
expect(file_data.grep(/dispatch :my_custom/)).to eq([" dispatch :my_custom do\n"])
|
109
|
+
expect(file_data.grep(/def my_custom/)).to eq([" def my_custom(options, context)\n"])
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe 'data_dig ruby' do
|
114
|
+
let(:opts) do
|
115
|
+
['-b', 'data_dig', '-n', 'my_custom', '-t', 'v4']
|
116
|
+
end
|
117
|
+
it 'works with function' do
|
118
|
+
generator.run
|
119
|
+
expect(File.exist?(File.join(module_path, 'lib', 'puppet', 'functions', 'my_custom.rb'))).to eq(true)
|
120
|
+
expect(File.exist?(File.join(module_path, 'data'))).to eq(false)
|
121
|
+
expect(File.exist?(File.join(module_path, 'data', 'os'))).to eq(false)
|
122
|
+
expect(File.exist?(File.join(module_path, 'data', 'common.yaml'))).to eq(false)
|
123
|
+
expect(File.exist?(File.join(module_path, 'hiera.yaml'))).to eq(true)
|
124
|
+
file_data = File.readlines(File.join(module_path, 'lib', 'puppet', 'functions', 'my_custom.rb'))
|
125
|
+
expect(file_data.grep(/tomcat::my_custom/)).to eq(["Puppet::Functions.create_function(:\"tomcat::my_custom\") do\n"])
|
126
|
+
expect(file_data.grep(/dispatch :my_custom/)).to eq([" dispatch :my_custom do\n"])
|
127
|
+
expect(file_data.grep(/def my_custom/)).to eq([" def my_custom(segments, options, context)\n"])
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe 'lookup_key ruby' do
|
132
|
+
let(:opts) do
|
133
|
+
['-b', 'lookup_key', '-n', 'my_custom', '-t', 'v4']
|
134
|
+
end
|
135
|
+
it 'works with function' do
|
136
|
+
generator.run
|
137
|
+
expect(File.exist?(File.join(module_path, 'lib', 'puppet', 'functions', 'my_custom.rb'))).to eq(true)
|
138
|
+
expect(File.exist?(File.join(module_path, 'data'))).to eq(false)
|
139
|
+
expect(File.exist?(File.join(module_path, 'data', 'os'))).to eq(false)
|
140
|
+
expect(File.exist?(File.join(module_path, 'data', 'common.yaml'))).to eq(false)
|
141
|
+
expect(File.exist?(File.join(module_path, 'hiera.yaml'))).to eq(true)
|
142
|
+
file_data = File.readlines(File.join(module_path, 'lib', 'puppet', 'functions', 'my_custom.rb'))
|
143
|
+
expect(file_data.grep(/tomcat::my_custom/)).to eq(["Puppet::Functions.create_function(:\"tomcat::my_custom\") do\n"])
|
144
|
+
expect(file_data.grep(/dispatch :my_custom/)).to eq([" dispatch :my_custom do\n"])
|
145
|
+
expect(file_data.grep(/def my_custom/)).to eq([" def my_custom(key, options, context)\n"])
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-retrospec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corey Osman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trollop
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: retrospec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.6.2
|
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: 0.6.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: awesome_print
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- lib/retrospec/plugins/v1/plugin/generators/fact_generator.rb
|
130
130
|
- lib/retrospec/plugins/v1/plugin/generators/function_generator.rb
|
131
131
|
- lib/retrospec/plugins/v1/plugin/generators/hostclass_generator.rb
|
132
|
+
- lib/retrospec/plugins/v1/plugin/generators/module_data_generator.rb
|
132
133
|
- lib/retrospec/plugins/v1/plugin/generators/module_generator.rb
|
133
134
|
- lib/retrospec/plugins/v1/plugin/generators/node_generator.rb
|
134
135
|
- lib/retrospec/plugins/v1/plugin/generators/parsers/facter.rb
|
@@ -415,6 +416,7 @@ files:
|
|
415
416
|
- spec/unit/generators/function_generator_spec.rb
|
416
417
|
- spec/unit/generators/function_spec.rb
|
417
418
|
- spec/unit/generators/hostclass_generator_spec.rb
|
419
|
+
- spec/unit/generators/module_data_spec.rb
|
418
420
|
- spec/unit/generators/node_generator_spec.rb
|
419
421
|
- spec/unit/generators/parsers/fact_spec.rb
|
420
422
|
- spec/unit/generators/parsers/provider_spec.rb
|