puppet-retrospec 1.7.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27cdd72f261a6435b150e84efb8d4c275f331b29874744d7d2951a6aa3a09f29
4
- data.tar.gz: 1a129e2fb6b34b42af3fae5caae73e093b8992760f2213a3d78e1c23c7c09fd0
3
+ metadata.gz: c5281f0e925c582ae6b13d860d21a9121f2544b1817feb8de0bd7ca443f73208
4
+ data.tar.gz: 256827372f2b26f19ac30c9b9d679a1d419977207fa7ed5141da0d7ae5a05c6a
5
5
  SHA512:
6
- metadata.gz: f3181062fdb594c444dbe2928b4fbcb5c020566e8c42a415774e01f593bf4fcb6f6f3d5644726955f12452952d2230a3fcb93b295ef57bd594aeaeb8cbb7af9d
7
- data.tar.gz: 5d08f7a3dd567eba29f6de1d46313cb7711ce48bd53321ea3390e306d5fbbd93de1ceec13eccf56dad3e1cc4b66ef846f311d4ccbc91b474f7eef7953b74bd47
6
+ metadata.gz: 847d7ecdb5aa7b16b9855491e174b97e126cb23958698fd5f9c6a08a1855bbe8e47d56aba88ef0f12b45f72bed9228e8f6db7ab191f83d4f0c3ec3de654b509d
7
+ data.tar.gz: fbb3390ab4b005fcd13f40cc0b05d24974be2bac7db58b4c04b3c04c88da3b9b159b607589088a4388c474df3153c37fcfb42b58b47fde20aa7f6caed602d5af
@@ -0,0 +1 @@
1
+ 2.5.1
data/Gemfile CHANGED
@@ -12,6 +12,7 @@ group :development do
12
12
  end
13
13
 
14
14
  group :test do
15
+ gem 'rb-readline'
15
16
  gem 'bundler', '~> 2.0'
16
17
  gem 'fakefs', :require => 'fakefs/safe'
17
18
  gem 'json_pure', '= 2.0.1' # force this gem as 2.0.2 requires ruby > 2.0.0
@@ -8,7 +8,7 @@ GIT
8
8
  PATH
9
9
  remote: .
10
10
  specs:
11
- puppet-retrospec (1.7.0)
11
+ puppet-retrospec (1.8.0)
12
12
  awesome_print
13
13
  facets
14
14
  optimist (~> 3.0.0)
@@ -49,6 +49,7 @@ GEM
49
49
  method_source (~> 0.9.0)
50
50
  rainbow (3.0.0)
51
51
  rake (12.3.2)
52
+ rb-readline (0.5.5)
52
53
  rdoc (3.12.2)
53
54
  json (~> 1.4)
54
55
  rspec (3.8.0)
@@ -91,6 +92,7 @@ DEPENDENCIES
91
92
  puppet (= 4.10.8)!
92
93
  puppet-retrospec!
93
94
  rake
95
+ rb-readline
94
96
  rdoc (~> 3.12)
95
97
  retrospec!
96
98
  rspec (~> 3.2)
@@ -46,6 +46,42 @@ module Retrospec
46
46
  raise NotImplementedError
47
47
  end
48
48
 
49
+ # generates a file path for spec tests based on the resource name. An added option
50
+ # is to generate directory names for each parent resource as a default option
51
+ def item_spec_path
52
+ file_name = generate_file_name(item_name.downcase)
53
+ path = generate_path("#{file_name}_spec.rb", item_name)
54
+ File.join(spec_path, path )
55
+ end
56
+
57
+ # returns the base filename of the type
58
+ def generate_file_name(iname)
59
+ tokens = iname.split('::')
60
+ file_name = tokens.pop
61
+ end
62
+
63
+ # @return [String] - a generated path
64
+ # @param file_name - the base name of the file to create
65
+ # @param iname - the type name or name of item
66
+ def generate_path(file_name, iname = item_name)
67
+ tokens = iname.split('::')
68
+ # if there are only two tokens ie. tomcat::params we dont need to create a subdirectory
69
+ if tokens.count > 2
70
+ # this is a deep level resource ie. tomcat::config::server::connector
71
+ # however we don't need the tomcat directory so we can just remove it
72
+ # this should leave us with config/server/connector_spec.rb
73
+ tokens.delete_at(0)
74
+ # remove the last token since its the class name
75
+ tokens.pop
76
+ # so lets make a directory structure out of it
77
+ dir_name = File.join(tokens) # config/server
78
+ dir_name = File.join(dir_name, file_name) # spec/classes/tomcat/config/server
79
+ else
80
+ dir_name = File.join(file_name)
81
+ end
82
+ dir_name.downcase
83
+ end
84
+
49
85
  # run is the main method that gets called automatically
50
86
  def run
51
87
  generate_lib_files
@@ -59,10 +95,6 @@ module Retrospec
59
95
  File.join(lib_path, "#{item_name}.rb")
60
96
  end
61
97
 
62
- def item_spec_path
63
- File.join(spec_path, "#{item_name}_spec.rb")
64
- end
65
-
66
98
  def spec_path
67
99
  File.join(module_path, 'spec', 'unit', 'puppet', plural_name)
68
100
  end
@@ -0,0 +1,59 @@
1
+ # require 'retrospec/plugins/v1/module_helpers'
2
+ # require 'retrospec/plugins/v1'
3
+ require_relative 'resource_base_generator'
4
+
5
+ module Retrospec
6
+ module Puppet
7
+ module Generators
8
+ class DataTypeGenerator < Retrospec::Puppet::Generators::ResourceBaseGenerator
9
+
10
+ def initialize(module_path, spec_object = {})
11
+ super
12
+ @singular_name = 'type_alias'
13
+ @plural_name = 'type_aliases'
14
+ end
15
+
16
+ def self.manifest_files(module_path)
17
+ Dir.glob(File.join(module_path, 'types', '**', '*.pp'))
18
+ end
19
+
20
+ def spec_template_file
21
+ 'datatype_spec.rb.retrospec.erb'
22
+ end
23
+
24
+ def load_context_data
25
+ context.content = generate_content
26
+ context.parameters = parameters
27
+ context.type_name = type_name
28
+ context.resource_type = resource_type
29
+ context.resource_type_name = resource_type_name
30
+ context
31
+ end
32
+
33
+ def self.generate_spec_files(module_path, config_data)
34
+ manifest_files(module_path).map do |file|
35
+ datatype = new(module_path, config_data.merge({:manifest_file => file}))
36
+ next unless datatype.resource_type == ::Puppet::Pops::Model::TypeAlias
37
+ datatype.generate_spec_file
38
+ end.flatten
39
+ end
40
+
41
+ # returns the path to the templates
42
+ # first looks inside the external templates directory for specific file
43
+ # then looks inside the gem path templates directory, which is really only useful
44
+ # when developing new templates.
45
+ def template_dir
46
+ if config_data[:template_dir]
47
+ external_templates = Dir.glob(File.expand_path(File.join(config_data[:template_dir], 'type_aliases', '*.erb')))
48
+ end
49
+ if external_templates and external_templates.count > 0
50
+ File.join(config_data[:template_dir], 'type_aliases')
51
+ else
52
+ File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), 'templates', 'type_aliases'))
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+
@@ -12,9 +12,16 @@ module Retrospec
12
12
  # retrospec will initilalize this class so its up to you
13
13
  # to set any additional variables you need to get the job done.
14
14
  def initialize(module_path, spec_object = {})
15
+ spec_object.merge!({:manifest_file => spec_object[:manifest_file],
16
+ :content => nil, name: spec_object[:name]})
15
17
  super
16
- raise "NoManifestFileError" unless spec_object[:manifest_file]
17
- @context = OpenStruct.new(:manifest_file => spec_object[:manifest_file], :content => nil)
18
+ end
19
+
20
+ def item_spec_path
21
+ iname = type_name || item_name
22
+ file_name = generate_file_name(iname.downcase)
23
+ path = generate_path("#{file_name}_spec.rb", iname)
24
+ File.join(spec_path, path )
18
25
  end
19
26
 
20
27
  def singular_name
@@ -61,6 +68,7 @@ module Retrospec
61
68
  def self.generate_spec_files(module_path, config_data)
62
69
  manifests = manifest_files(module_path)
63
70
  files = Retrospec::Puppet::Generators::HostClassGenerator.generate_spec_files(module_path, config_data)
71
+ files << Retrospec::Puppet::Generators::DataTypeGenerator.generate_spec_files(module_path, config_data)
64
72
  files << Retrospec::Puppet::Generators::DefinitionGenerator.generate_spec_files(module_path, config_data)
65
73
  files.flatten
66
74
  end
@@ -158,40 +166,7 @@ module Retrospec
158
166
  # for files that have multiple types, we just don't care since it doesn't
159
167
  # follow the style guide
160
168
  def type_name
161
- if ast.eContents.first.respond_to?(:name)
162
- ast.eContents.first.name
163
- else
164
- #ast.eContents.first.host_matches.first
165
- end
166
- end
167
-
168
- # returns the filename of the type
169
- def generate_file_name(type_name)
170
- tokens = type_name.split('::')
171
- file_name = tokens.pop
172
- "#{file_name}_spec.rb"
173
- end
174
-
175
- # generates a file path for spec tests based on the resource name. An added option
176
- # is to generate directory names for each parent resource as a default option
177
- def item_spec_path
178
- file_name = generate_file_name(type_name)
179
- tokens = type_name.split('::')
180
- # if there are only two tokens ie. tomcat::params we dont need to create a subdirectory
181
- if tokens.count > 2
182
- # this is a deep level resource ie. tomcat::config::server::connector
183
- # however we don't need the tomcat directory so we can just remove it
184
- # this should leave us with config/server/connector_spec.rb
185
- tokens.delete_at(0)
186
- # remove the last token since its the class name
187
- tokens.pop
188
- # so lets make a directory structure out of it
189
- dir_name = File.join(tokens) # config/server
190
- dir_name = File.join(spec_path, dir_name, file_name) # spec/classes/tomcat/config/server
191
- else
192
- dir_name = File.join(spec_path, file_name)
193
- end
194
- dir_name
169
+ ast.eContents.first.name if ast.eContents.first.respond_to?(:name)
195
170
  end
196
171
 
197
172
  def ast
@@ -58,10 +58,6 @@ module Retrospec
58
58
  File.join(module_path, 'tasks', "#{item_name}.json")
59
59
  end
60
60
 
61
- def item_spec_path
62
- File.join(spec_path, plural_name, "#{item_name}_spec.rb")
63
- end
64
-
65
61
  def enable_beaker_tasks?
66
62
  false
67
63
  end
@@ -29,7 +29,7 @@ module Retrospec
29
29
  if CORE_TYPES.include?(spec_object[:name])
30
30
  raise Retrospec::Puppet::Generators::CoreTypeException
31
31
  end
32
- @context = OpenStruct.new(:type_name => spec_object[:name], :parameters => spec_object[:parameters],
32
+ @context = OpenStruct.new(:type_name => spec_object[:name], name: spec_object[:name], :parameters => spec_object[:parameters],
33
33
  :properties => spec_object[:properties], :providers => spec_object[:providers])
34
34
  end
35
35
 
@@ -1,5 +1,5 @@
1
1
  module Retrospec
2
2
  module Puppet
3
- VERSION = '1.7.0'
3
+ VERSION = '1.8.0'
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ type Sample_module::Ext::Sudoers_entry = Variant[String, Array[String]]
@@ -0,0 +1 @@
1
+ type Sample_module::Sudoers_entry = Variant[String, Array[String]]
@@ -0,0 +1 @@
1
+ type Sample_module::Ext::Sudoers_entry = Variant[String, Array[String]]
@@ -0,0 +1 @@
1
+ type Sample_module::Sudoers_entry = Variant[String, Array[String]]
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'datatype_generator' do
4
+ before(:each) do
5
+ FileUtils.rm_rf(spec_files_path) if File.exist?(spec_files_path)
6
+ end
7
+
8
+ let(:generator_opts) do
9
+ { :name => 'sudoers_entry', :puppet_context => puppet_context, :template_dir => retrospec_templates_path
10
+ }
11
+ end
12
+
13
+ let(:generator_opts) do
14
+ { :manifest_file => sample_file, :template_dir => retrospec_templates_path }
15
+ end
16
+
17
+ let(:sample_file) do
18
+ File.join(fixtures_path, 'manifests', 'sql.pp')
19
+ end
20
+
21
+ let(:module_path) do
22
+ sample_module_path
23
+ end
24
+
25
+ let(:spec_files_path) do
26
+ File.join(module_path, 'spec', 'type_aliases')
27
+ end
28
+
29
+ let(:datatypes_path) do
30
+ File.join(module_path, 'types')
31
+ end
32
+
33
+ let(:puppet_context) do
34
+ path = File.join(fixture_modules_path, 'tomcat')
35
+ opts = { :module_path => path, :enable_beaker_tests => false, :name => 'name-test123',
36
+ :enable_user_templates => false, :template_dir => retrospec_templates_path }
37
+ mod = Retrospec::Plugins::V1::Puppet.new(opts[:module_path], opts)
38
+ mod.post_init
39
+ mod.context
40
+ end
41
+
42
+ let(:generator) do
43
+ Retrospec::Puppet::Generators::DataTypeGenerator.new(module_path, generator_opts)
44
+ end
45
+
46
+ it 'should create datatype spec file' do
47
+ Retrospec::Puppet::Generators::DataTypeGenerator.generate_spec_files(module_path, generator_opts)
48
+ expect(File.exist?(File.join(spec_files_path, 'sudoers_entry_spec.rb'))).to eq(true)
49
+ end
50
+
51
+ it 'should create datatype ext spec file' do
52
+ Retrospec::Puppet::Generators::DataTypeGenerator.generate_spec_files(module_path, generator_opts)
53
+ expect(File.exist?(File.join(spec_files_path, 'ext','sudoers_entry_spec.rb'))).to eq(true)
54
+ end
55
+
56
+ it '#self.manifest_files' do
57
+ files = Retrospec::Puppet::Generators::DataTypeGenerator.manifest_files(module_path)
58
+ expect(files.count).to be > 0
59
+ end
60
+
61
+ end
@@ -37,8 +37,6 @@ describe 'HostClassGenerator' do
37
37
  File.read(generator.generate_spec_file)
38
38
  end
39
39
 
40
-
41
-
42
40
  it 'should create spec file' do
43
41
  expect(generator.run).to eq(spec_file)
44
42
  expect(File.exist?(spec_file)).to eq(true)
@@ -34,7 +34,12 @@ describe Retrospec::Puppet::Generators::ResourceBaseGenerator do
34
34
  File.join(spec_files_path, 'classes', 'sub', 'settings_spec.rb'),
35
35
  File.join(spec_files_path, 'defines', 'sub', 'settings_define_spec.rb'),
36
36
  File.join(spec_files_path, 'classes', 'parameter_logic_spec.rb'),
37
- File.join(spec_files_path, 'defines', 'one_define_spec.rb')]
37
+ File.join(spec_files_path, 'defines', 'one_define_spec.rb'),
38
+ File.join(spec_files_path, 'type_aliases', 'ext', 'sudoers_entry_spec.rb'),
39
+ File.join(spec_files_path, 'type_aliases','sudoers_entry_spec.rb')
40
+
41
+
42
+ ]
38
43
  end
39
44
 
40
45
  it 'should generate a bunch of files' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-retrospec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Osman
@@ -112,6 +112,7 @@ files:
112
112
  - ".rspec"
113
113
  - ".rubocop.yml"
114
114
  - ".rubocop_todo.yml"
115
+ - ".ruby-version"
115
116
  - CHANGELOG.md
116
117
  - DEVELOPMENT.md
117
118
  - Dockerfile
@@ -125,6 +126,7 @@ files:
125
126
  - lib/retrospec/plugins/v1/plugin/generators.rb
126
127
  - lib/retrospec/plugins/v1/plugin/generators/acceptance_generator.rb
127
128
  - lib/retrospec/plugins/v1/plugin/generators/base_generator.rb
129
+ - lib/retrospec/plugins/v1/plugin/generators/data_type_generator.rb
128
130
  - lib/retrospec/plugins/v1/plugin/generators/definition_generator.rb
129
131
  - lib/retrospec/plugins/v1/plugin/generators/fact_generator.rb
130
132
  - lib/retrospec/plugins/v1/plugin/generators/function_generator.rb
@@ -168,6 +170,8 @@ files:
168
170
  - spec/fixtures/fixture_modules/one_resource_module/manifests/params.pp
169
171
  - spec/fixtures/fixture_modules/one_resource_module/manifests/sub/settings.pp
170
172
  - spec/fixtures/fixture_modules/one_resource_module/manifests/sub/settings_define.pp
173
+ - spec/fixtures/fixture_modules/one_resource_module/types/ext/sudoers_entry.pp
174
+ - spec/fixtures/fixture_modules/one_resource_module/types/sudoers_entry.pp
171
175
  - spec/fixtures/fixture_modules/required_parameters/manifests/init.pp
172
176
  - spec/fixtures/fixture_modules/sample_module/lib/facter/fix_installed.rb
173
177
  - spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/awesome_parser.rb
@@ -178,6 +182,8 @@ files:
178
182
  - spec/fixtures/fixture_modules/sample_module/lib/puppet/reports/test
179
183
  - spec/fixtures/fixture_modules/sample_module/manifests/init.pp
180
184
  - spec/fixtures/fixture_modules/sample_module/spec/unit/facter/fix_installed_spec.rb
185
+ - spec/fixtures/fixture_modules/sample_module/types/ext/sudoers_entry.pp
186
+ - spec/fixtures/fixture_modules/sample_module/types/sudoers_entry.pp
181
187
  - spec/fixtures/fixture_modules/zero_resource_module/manifests/empty_class.pp
182
188
  - spec/fixtures/fixture_modules/zero_resource_module/manifests/not_a_resource_defination.pp
183
189
  - spec/fixtures/fixture_modules/zero_resource_module/metadata.json
@@ -415,6 +421,7 @@ files:
415
421
  - spec/integration/retrospec_spec.rb
416
422
  - spec/spec_helper.rb
417
423
  - spec/unit/generators/acceptance_generator_spec.rb
424
+ - spec/unit/generators/data_type_generator_spec.rb
418
425
  - spec/unit/generators/definition_generator_spec.rb
419
426
  - spec/unit/generators/fact_generater_spec.rb
420
427
  - spec/unit/generators/function_generator_spec.rb