puppet-retrospec 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +52 -0
  3. data/.gitlab-ci.yml +1 -0
  4. data/.overcommit.yml +33 -0
  5. data/.rubocop.yml +17 -3
  6. data/.rubocop_todo.yml +744 -0
  7. data/CHANGELOG.md +3 -1
  8. data/Gemfile +1 -4
  9. data/Gemfile.lock +34 -62
  10. data/README.md +2 -2
  11. data/Rakefile +3 -21
  12. data/lib/retrospec/plugins/v1/plugin/generators/fact_generator.rb +5 -5
  13. data/lib/retrospec/plugins/v1/plugin/generators/function_generator.rb +62 -18
  14. data/lib/retrospec/plugins/v1/plugin/generators/parsers/native_function.rb +58 -0
  15. data/lib/retrospec/plugins/v1/plugin/puppet.rb +1 -1
  16. data/lib/retrospec/plugins/v1/plugin/version.rb +1 -1
  17. data/puppet-retrospec.gemspec +5 -1648
  18. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/awesome_parser.rb +14 -0
  19. data/spec/fixtures/functions/abs.pp +4 -0
  20. data/spec/unit/generators/acceptance_generator_spec.rb +10 -14
  21. data/spec/unit/generators/definition_generator_spec.rb +4 -8
  22. data/spec/unit/generators/fact_generater_spec.rb +6 -7
  23. data/spec/unit/generators/function_generator_spec.rb +83 -17
  24. data/spec/unit/generators/function_spec.rb +1 -3
  25. data/spec/unit/generators/hostclass_generator_spec.rb +7 -10
  26. data/spec/unit/generators/node_generator_spec.rb +4 -7
  27. data/spec/unit/generators/parsers/fact_spec.rb +7 -10
  28. data/spec/unit/generators/parsers/provider_spec.rb +5 -5
  29. data/spec/unit/generators/parsers/type_spec.rb +8 -9
  30. data/spec/unit/generators/provider_generator_spec.rb +1 -2
  31. data/spec/unit/generators/report_generator_spec.rb +5 -7
  32. data/spec/unit/generators/resource_base_generator_spec.rb +3 -5
  33. data/spec/unit/generators/schema_generator_spec.rb +28 -32
  34. data/spec/unit/generators/serializers/rspec_dumper_spec.rb +35 -38
  35. data/spec/unit/generators/type_generator_spec.rb +116 -116
  36. data/spec/unit/plugin_spec.rb +15 -22
  37. data/spec/unit/puppet-retrospec_spec.rb +3 -5
  38. data/spec/unit/spec_object_spec.rb +17 -20
  39. metadata +9 -4
@@ -39,140 +39,140 @@ describe 'type generator' do
39
39
  end
40
40
 
41
41
  let(:context) do
42
- { :module_path => module_path, :template_dir => retrospec_templates_path}
42
+ { :module_path => module_path, :template_dir => retrospec_templates_path }
43
43
  end
44
44
 
45
45
  let(:args) do
46
- ['-p', 'param_one', 'param_two','-a', 'config1',
47
- 'config2', '-n', type_name]
46
+ ['-p', 'param_one', 'param_two', '-a', 'config1',
47
+ 'config2', '-n', type_name]
48
+ end
49
+
50
+ let(:cli_opts) do
51
+ Retrospec::Puppet::Generators::TypeGenerator.run_cli(context, args)
52
+ end
53
+
54
+ let(:generator) do
55
+ Retrospec::Puppet::Generators::TypeGenerator.new(module_path, cli_opts)
56
+ end
57
+
58
+ it 'returns type dir' do
59
+ expect(generator.type_dir).to eq(type_dir)
60
+ end
61
+
62
+ it 'returns module path' do
63
+ expect(generator.type_spec_dir).to eq(type_spec_dir)
64
+ end
65
+
66
+ it 'can return type name' do
67
+ expect(generator.type_name).to eq('vhost')
68
+ end
69
+
70
+ it 'can generate a type file' do
71
+ file_path = File.join(fixtures_path, 'modules', 'tomcat', 'lib', 'puppet', 'type', 'vhost.rb')
72
+ expect(generator.generate_type_files).to eq(file_path)
73
+ expect(File.exist?(File.join(generator.type_dir, "#{generator.type_name}.rb")))
74
+ end
75
+
76
+ it 'can generate a spec file' do
77
+ allow(generator).to receive(:type_dir).and_return(fixtures_type_path)
78
+ allow(generator).to receive(:type_name_path).and_return(File.join(type_dir, "#{generator.type_name}.rb"))
79
+ files = [File.join(type_spec_dir, 'bmc_spec.rb'),
80
+ File.join(type_spec_dir, 'bmcuser_spec.rb'),
81
+ File.join(type_spec_dir, 'db_opatch_spec.rb')]
82
+ expect(generator.generate_type_spec_files).to eq(files)
83
+ end
84
+
85
+ describe 'cli' do
86
+ let(:context) do
87
+ { :module_path => module_path, :template_dir => File.expand_path(File.join(ENV['HOME'], '.retrospec', 'repos', 'retrospec-puppet-templates')) }
88
+ end
89
+
90
+ let(:type_name) do
91
+ 'vhost'
92
+ end
93
+
94
+ let(:args) do
95
+ ['-p', 'param_one', 'param_two', '-a', 'prop_one',
96
+ 'prop_two', '-n', type_name]
48
97
  end
49
98
 
50
99
  let(:cli_opts) do
51
- Retrospec::Puppet::Generators::TypeGenerator.run_cli(context, args)
100
+ cli_opts = Retrospec::Puppet::Generators::TypeGenerator.run_cli(context, args)
52
101
  end
53
102
 
54
103
  let(:generator) do
55
- Retrospec::Puppet::Generators::TypeGenerator.new(module_path, cli_opts)
104
+ Retrospec::Puppet::Generators::TypeGenerator.new(cli_opts[:module_path], cli_opts)
105
+ end
106
+
107
+ after :each do
108
+ FileUtils.rm_rf(File.dirname(File.dirname(generator.type_name_path))) # ensure the file does not exist
109
+ FileUtils.rm_rf(File.dirname(generator.type_spec_dir))
56
110
  end
57
111
 
58
- it 'returns type dir' do
59
- expect(generator.type_dir).to eq(type_dir)
112
+ it 'can run the cli options' do
113
+ # specify the parameters
114
+ expect(cli_opts).to be_an_instance_of Hash
115
+ expect(cli_opts[:properties]).to eq(%w(prop_one prop_two))
116
+ expect(cli_opts[:parameters]).to eq(%w(param_one param_two))
117
+ expect(cli_opts[:name]).to eq('vhost')
60
118
  end
61
119
 
62
- it 'returns module path' do
63
- expect(generator.type_spec_dir).to eq(type_spec_dir)
120
+ it 'generate type file with correct number of properties' do
121
+ file = generator.generate_type_files
122
+ require file
123
+ t = Puppet::Type.type(:vhost)
124
+ expect(t.properties.count). to eq(3)
64
125
  end
65
126
 
66
- it 'can return type name' do
67
- expect(generator.type_name).to eq('vhost')
127
+ context 'parameters' do
128
+ let(:args) do
129
+ ['-p', 'param_one', 'param_two', '-a', 'prop_one',
130
+ 'prop_two', '-n', 'vhost']
131
+ end
132
+ it 'generate type file with correct number of parameters' do
133
+ file = generator.generate_type_files
134
+ require file
135
+ t = Puppet::Type.type(:vhost)
136
+ expect(t.parameters.count). to eq(2)
137
+ end
68
138
  end
69
139
 
70
- it 'can generate a type file' do
71
- file_path = File.join(fixtures_path, 'modules', 'tomcat', 'lib', 'puppet', 'type', 'vhost.rb')
72
- expect(generator.generate_type_files).to eq(file_path)
73
- expect(File.exist?(File.join(generator.type_dir, "#{generator.type_name}.rb")))
140
+ context 'providers' do
141
+ let(:args) do
142
+ ['-p', 'param_one', 'param_two', '-a', 'prop_one',
143
+ 'prop_two', '-n', type_name, '--providers', 'default1', 'default2']
144
+ end
145
+
146
+ it 'generate type' do
147
+ file = generator.generate_type_files
148
+ require file
149
+ t = Puppet::Type.type(:vhost)
150
+ expect(File.exist?(file)).to eq(true)
151
+ end
152
+
153
+ it 'generate providers' do
154
+ file = generator.generate_type_files
155
+ p_vhost = File.join(provider_dir, 'vhost')
156
+ expect(File.exist?(File.join(p_vhost, 'default1.rb'))).to eq(true)
157
+ expect(File.exist?(File.join(p_vhost, 'default2.rb'))).to eq(true)
158
+ expect(generator.context.providers).to eq(%w(default1 default2))
159
+ end
74
160
  end
75
161
 
76
- it 'can generate a spec file' do
77
- allow(generator).to receive(:type_dir).and_return(fixtures_type_path)
78
- allow(generator).to receive(:type_name_path).and_return(File.join(type_dir, "#{generator.type_name}.rb"))
79
- files = [File.join(type_spec_dir, 'bmc_spec.rb'),
80
- File.join(type_spec_dir, 'bmcuser_spec.rb'),
81
- File.join(type_spec_dir, 'db_opatch_spec.rb')]
82
- expect(generator.generate_type_spec_files).to eq(files)
162
+ describe 'existing type' do
163
+ let(:type_name) do
164
+ 'package'
83
165
  end
84
166
 
85
- describe 'cli' do
86
- let(:context) do
87
- { :module_path => module_path, :template_dir => File.expand_path(File.join(ENV['HOME'], '.retrospec', 'repos', 'retrospec-puppet-templates')) }
88
- end
89
-
90
- let(:type_name) do
91
- 'vhost'
92
- end
93
-
94
- let(:args) do
95
- ['-p', 'param_one', 'param_two','-a', 'prop_one',
96
- 'prop_two', '-n', type_name]
97
- end
98
-
99
- let(:cli_opts) do
100
- cli_opts = Retrospec::Puppet::Generators::TypeGenerator.run_cli(context, args)
101
- end
102
-
103
- let(:generator) do
104
- Retrospec::Puppet::Generators::TypeGenerator.new(cli_opts[:module_path], cli_opts)
105
- end
106
-
107
- after :each do
108
- FileUtils.rm_rf(File.dirname(File.dirname(generator.type_name_path))) # ensure the file does not exist
109
- FileUtils.rm_rf(File.dirname(generator.type_spec_dir))
110
- end
111
-
112
- it 'can run the cli options' do
113
- # specify the parameters
114
- expect(cli_opts).to be_an_instance_of Hash
115
- expect(cli_opts[:properties]).to eq(%w(prop_one prop_two))
116
- expect(cli_opts[:parameters]).to eq(%w(param_one param_two))
117
- expect(cli_opts[:name]).to eq('vhost')
118
- end
119
-
120
- it 'generate type file with correct number of properties' do
121
- file = generator.generate_type_files
122
- require file
123
- t = Puppet::Type.type(:vhost)
124
- expect(t.properties.count). to eq(3)
125
- end
126
-
127
- context 'parameters' do
128
- let(:args) do
129
- ['-p', 'param_one', 'param_two','-a', 'prop_one',
130
- 'prop_two', '-n', 'vhost']
131
- end
132
- it 'generate type file with correct number of parameters' do
133
- file = generator.generate_type_files
134
- require file
135
- t = Puppet::Type.type(:vhost)
136
- expect(t.parameters.count). to eq(2)
137
- end
138
- end
139
-
140
- context 'providers' do
141
- let(:args) do
142
- ['-p', 'param_one', 'param_two','-a', 'prop_one',
143
- 'prop_two', '-n', type_name, '--providers', 'default1', 'default2']
144
- end
145
-
146
- it 'generate type' do
147
- file = generator.generate_type_files
148
- require file
149
- t = Puppet::Type.type(:vhost)
150
- expect(File.exist?(file)).to eq(true)
151
- end
152
-
153
- it 'generate providers' do
154
- file = generator.generate_type_files
155
- p_vhost = File.join(provider_dir, 'vhost')
156
- expect(File.exist?(File.join(p_vhost, 'default1.rb'))).to eq(true)
157
- expect(File.exist?(File.join(p_vhost, 'default2.rb'))).to eq(true)
158
- expect(generator.context.providers).to eq(%w(default1 default2))
159
- end
160
- end
161
-
162
- describe 'existing type' do
163
- let(:type_name) do
164
- 'package'
165
- end
166
-
167
- before :each do
168
- FileUtils.rm_rf(type_spec_dir)
169
- FileUtils.rm_rf(type_dir)
170
- end
171
-
172
- # it 'raise error' do
173
- # expect{Retrospec::Puppet::Generators::TypeGenerator.new(module_path,
174
- # cli_opts)}.to raise_exception Retrospec::Puppet::Generators::CoreTypeException
175
- # end
176
- end
177
- end
178
- end
167
+ before :each do
168
+ FileUtils.rm_rf(type_spec_dir)
169
+ FileUtils.rm_rf(type_dir)
170
+ end
171
+
172
+ # it 'raise error' do
173
+ # expect{Retrospec::Puppet::Generators::TypeGenerator.new(module_path,
174
+ # cli_opts)}.to raise_exception Retrospec::Puppet::Generators::CoreTypeException
175
+ # end
176
+ end
177
+ end
178
+ end
@@ -2,7 +2,6 @@ require 'spec_helper'
2
2
  require 'retrospec'
3
3
 
4
4
  describe 'puppet' do
5
-
6
5
  it 'can show the version' do
7
6
  expect(Retrospec::Puppet::VERSION).to be_instance_of(String)
8
7
  end
@@ -27,7 +26,6 @@ describe 'puppet' do
27
26
  end
28
27
 
29
28
  describe 'new_module' do
30
-
31
29
  let(:module_path) do
32
30
  '/tmp/testabc123'
33
31
  end
@@ -44,7 +42,6 @@ describe 'puppet' do
44
42
  }
45
43
  end
46
44
 
47
-
48
45
  describe 'without module path' do
49
46
  before(:each) do
50
47
  FileUtils.rm_rf('/tmp/testabc123')
@@ -55,7 +52,7 @@ describe 'puppet' do
55
52
  end
56
53
 
57
54
  let(:global_opts) do
58
- {:module_path => module_path }
55
+ { :module_path => module_path }
59
56
  end
60
57
 
61
58
  let(:args) do
@@ -66,8 +63,8 @@ describe 'puppet' do
66
63
  retrospec
67
64
  expect(File.exist?(File.join(module_path, 'testabc123', 'manifests', 'init.pp'))).to eq(true)
68
65
  expect(File.exist?(File.join(module_path, 'testabc123', 'metadata.json'))).to eq(true)
69
- # FIXME temporary disabling schema
70
- #expect(File.exist?(File.join(module_path, 'testabc123', 'testabc123_schema.yaml'))).to eq(true)
66
+ # FIXME: temporary disabling schema
67
+ # expect(File.exist?(File.join(module_path, 'testabc123', 'testabc123_schema.yaml'))).to eq(true)
71
68
  metadata = JSON.parse(File.read(File.join(module_path, 'testabc123', 'metadata.json')))
72
69
  expect(metadata['author']).to eq('test_name')
73
70
  expect(metadata['license']).to eq('Apache-3.0')
@@ -80,7 +77,7 @@ describe 'puppet' do
80
77
  end
81
78
 
82
79
  let(:global_opts) do
83
- {:module_path => module_path }
80
+ { :module_path => module_path }
84
81
  end
85
82
 
86
83
  before(:all) do
@@ -95,8 +92,8 @@ describe 'puppet' do
95
92
  retrospec
96
93
  expect(File.exist?(File.join(module_path, 'manifests', 'init.pp'))).to eq(true)
97
94
  expect(File.exist?(File.join(module_path, 'metadata.json'))).to eq(true)
98
- # FIXME temporary disabling schema
99
- #expect(File.exist?(File.join(module_path, 'testabc124_schema.yaml'))).to eq(true)
95
+ # FIXME: temporary disabling schema
96
+ # expect(File.exist?(File.join(module_path, 'testabc124_schema.yaml'))).to eq(true)
100
97
  metadata = JSON.parse(File.read(File.join(module_path, 'metadata.json')))
101
98
  expect(metadata['author']).to eq('test_name')
102
99
  expect(metadata['license']).to eq('Apache-3.0')
@@ -121,15 +118,15 @@ describe 'puppet' do
121
118
  end
122
119
 
123
120
  let(:global_opts) do
124
- {:module_path => module_path }
121
+ { :module_path => module_path }
125
122
  end
126
123
 
127
124
  before(:each) do
128
125
  FileUtils.rm_rf(module_path)
129
126
  # ensure the module exists
130
127
  Retrospec::Plugins::V1::Puppet.run_cli(global_opts,
131
- global_config, plugin_config,
132
- ['new_module', '-n', 'testabc123'])
128
+ global_config, plugin_config,
129
+ ['new_module', '-n', 'testabc123'])
133
130
  end
134
131
 
135
132
  describe 'new_report' do
@@ -138,7 +135,7 @@ describe 'puppet' do
138
135
  end
139
136
 
140
137
  it 'should create report rb file' do
141
- report_file = File.join(module_path,'lib', 'puppet', 'reports', 'test_report.rb')
138
+ report_file = File.join(module_path, 'lib', 'puppet', 'reports', 'test_report.rb')
142
139
  retrospec
143
140
  expect(File.read(report_file)).to match(/Puppet::Reports\.register_report\(:test_report\)/)
144
141
  expect(File.exist?(report_file)).to eq(true)
@@ -146,14 +143,13 @@ describe 'puppet' do
146
143
  end
147
144
 
148
145
  describe 'new_fact' do
149
-
150
146
  let(:args) do
151
147
  ['new_fact', '-n', 'test_fact']
152
148
  end
153
149
 
154
150
  it 'should create spec and rb file' do
155
151
  retrospec
156
- expect(File.exist?(File.join(module_path,'lib', 'facter', 'test_fact.rb'))).to eq(true)
152
+ expect(File.exist?(File.join(module_path, 'lib', 'facter', 'test_fact.rb'))).to eq(true)
157
153
  expect(File.exist?(File.join(module_path, 'spec', 'unit', 'facter', 'test_fact_spec.rb'))).to eq(true)
158
154
  end
159
155
  end
@@ -163,7 +159,7 @@ describe 'puppet' do
163
159
  'type_a'
164
160
  end
165
161
  let(:type_dir) do
166
- File.join(module_path,'lib', 'puppet', 'type')
162
+ File.join(module_path, 'lib', 'puppet', 'type')
167
163
  end
168
164
 
169
165
  let(:type_spec_dir) do
@@ -193,20 +189,18 @@ describe 'puppet' do
193
189
  end
194
190
  end
195
191
  describe 'new_provider' do
196
-
197
192
  let(:args) do
198
193
  ['new_provider', '-n', 'pname', '--type', 'type_a']
199
194
  end
200
195
 
201
196
  it 'should create spec and rb file' do
202
197
  retrospec
203
- expect(File.exist?(File.join(module_path,'lib', 'puppet', 'provider', 'type_a', 'pname.rb'))).to eq(true)
198
+ expect(File.exist?(File.join(module_path, 'lib', 'puppet', 'provider', 'type_a', 'pname.rb'))).to eq(true)
204
199
  expect(File.exist?(File.join(module_path, 'spec', 'unit', 'puppet', 'provider', 'type_a', 'pname_spec.rb'))).to eq(true)
205
200
  end
206
201
  end
207
202
 
208
203
  describe 'new_function' do
209
-
210
204
  describe 'v3' do
211
205
  let(:args) do
212
206
  ['new_function', '-n', 'test_func_v3', '--type', 'v3']
@@ -214,14 +208,13 @@ describe 'puppet' do
214
208
 
215
209
  it 'should create v3 function' do
216
210
  retrospec
217
- expect(File.exist?(File.join(module_path,'lib', 'puppet','parser', 'functions', 'test_func_v3.rb'))).to eq(true)
211
+ expect(File.exist?(File.join(module_path, 'lib', 'puppet', 'parser', 'functions', 'test_func_v3.rb'))).to eq(true)
218
212
  end
219
213
 
220
214
  it 'should create v3 function spec file' do
221
215
  retrospec
222
216
  expect(File.exist?(File.join(module_path, 'spec', 'functions', 'test_func_v3_spec.rb'))).to eq(true)
223
217
  end
224
-
225
218
  end
226
219
  describe 'v4' do
227
220
  let(:args) do
@@ -230,7 +223,7 @@ describe 'puppet' do
230
223
 
231
224
  it 'should create v4 function' do
232
225
  retrospec
233
- expect(File.exist?(File.join(module_path,'lib', 'puppet', 'functions', 'test_func_v4.rb'))).to eq(true)
226
+ expect(File.exist?(File.join(module_path, 'lib', 'puppet', 'functions', 'test_func_v4.rb'))).to eq(true)
234
227
  end
235
228
 
236
229
  it 'should create v4 function spec file' do
@@ -120,7 +120,7 @@ describe 'puppet-retrospec' do
120
120
  context 'should' do
121
121
  let(:plugin_config) do
122
122
  {
123
- :enable_beaker_tests => true
123
+ :enable_beaker_tests => true
124
124
  }
125
125
  end
126
126
  it 'create acceptance test files' do
@@ -148,7 +148,7 @@ describe 'puppet-retrospec' do
148
148
  context 'should not' do
149
149
  let(:plugin_config) do
150
150
  {
151
- :enable_beaker_tests => false
151
+ :enable_beaker_tests => false
152
152
  }
153
153
  end
154
154
  let(:rs) do
@@ -182,7 +182,6 @@ describe 'puppet-retrospec' do
182
182
  expect(File.exist?(filepath)).to eq(false)
183
183
  end
184
184
  end
185
-
186
185
  end
187
186
 
188
187
  it 'should create proper spec helper file' do
@@ -215,8 +214,7 @@ describe 'puppet-retrospec' do
215
214
  'tomcat::purge_connectors' => nil,
216
215
  'tomcat::purge_realms' => nil,
217
216
  'tomcat::manage_user' => nil,
218
- 'tomcat::manage_group' => nil
219
- )
217
+ 'tomcat::manage_group' => nil)
220
218
 
221
219
  expect(File.read(filepath)).to include('#"tomcat::catalina_home" => \'\',')
222
220
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'spec_object' do
4
-
5
4
  let(:path) do
6
5
  File.join(fixture_modules_path, 'tomcat')
7
6
  end
@@ -21,26 +20,24 @@ describe 'spec_object' do
21
20
  end
22
21
 
23
22
  it 'should get all hiera data' do
24
- expect(puppet_context.class_hiera_data('tomcat')).to eq({"tomcat::catalina_home" => nil,
25
- "tomcat::group" => nil,
26
- "tomcat::install_from_source" => nil,
27
- "tomcat::manage_group" => nil,
28
- "tomcat::manage_user" => nil,
29
- "tomcat::purge_connectors" => nil,
30
- "tomcat::purge_realms" => nil,
31
- "tomcat::user" => nil,
32
- })
23
+ expect(puppet_context.class_hiera_data('tomcat')).to eq('tomcat::catalina_home' => nil,
24
+ 'tomcat::group' => nil,
25
+ 'tomcat::install_from_source' => nil,
26
+ 'tomcat::manage_group' => nil,
27
+ 'tomcat::manage_user' => nil,
28
+ 'tomcat::purge_connectors' => nil,
29
+ 'tomcat::purge_realms' => nil,
30
+ 'tomcat::user' => nil)
33
31
  end
34
32
 
35
33
  it 'should get all hiera data' do
36
- expect(puppet_context.all_hiera_data).to eq({"tomcat::catalina_home" => nil,
37
- "tomcat::group" => nil,
38
- "tomcat::install_from_source" => nil,
39
- "tomcat::manage_group" => nil,
40
- "tomcat::manage_user" => nil,
41
- "tomcat::purge_connectors" => nil,
42
- "tomcat::purge_realms" => nil,
43
- "tomcat::user" => nil,
44
- })
34
+ expect(puppet_context.all_hiera_data).to eq('tomcat::catalina_home' => nil,
35
+ 'tomcat::group' => nil,
36
+ 'tomcat::install_from_source' => nil,
37
+ 'tomcat::manage_group' => nil,
38
+ 'tomcat::manage_user' => nil,
39
+ 'tomcat::purge_connectors' => nil,
40
+ 'tomcat::purge_realms' => nil,
41
+ 'tomcat::user' => nil)
45
42
  end
46
- end
43
+ end