puppet-retrospec 0.11.0 → 0.12.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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +17 -0
  3. data/CHANGELOG.md +11 -0
  4. data/DEVELOPMENT.md +3 -0
  5. data/Gemfile +10 -9
  6. data/Gemfile.lock +2 -0
  7. data/README.md +211 -273
  8. data/Rakefile +8 -8
  9. data/VERSION +1 -1
  10. data/lib/retrospec-puppet.rb +3 -3
  11. data/lib/retrospec/plugins/v1/plugin/conditional.rb +5 -6
  12. data/lib/retrospec/plugins/v1/plugin/exceptions.rb +17 -0
  13. data/lib/retrospec/plugins/v1/plugin/generators.rb +7 -0
  14. data/lib/retrospec/plugins/v1/plugin/generators/fact_generator.rb +18 -10
  15. data/lib/retrospec/plugins/v1/plugin/generators/function_generator.rb +187 -0
  16. data/lib/retrospec/plugins/v1/plugin/generators/module_generator.rb +25 -26
  17. data/lib/retrospec/plugins/v1/plugin/generators/{facter.rb → parsers/facter.rb} +28 -35
  18. data/lib/retrospec/plugins/v1/plugin/generators/parsers/function.rb +91 -0
  19. data/lib/retrospec/plugins/v1/plugin/generators/parsers/type.rb +79 -0
  20. data/lib/retrospec/plugins/v1/plugin/generators/provider_generator.rb +107 -0
  21. data/lib/retrospec/plugins/v1/plugin/generators/schema_generator.rb +221 -0
  22. data/lib/retrospec/plugins/v1/plugin/generators/type_generator.rb +118 -0
  23. data/lib/retrospec/plugins/v1/plugin/helpers.rb +3 -7
  24. data/lib/retrospec/plugins/v1/plugin/puppet.rb +141 -60
  25. data/lib/retrospec/plugins/v1/plugin/puppet_module.rb +29 -26
  26. data/lib/retrospec/plugins/v1/plugin/resource.rb +6 -7
  27. data/lib/retrospec/plugins/v1/plugin/spec_object.rb +5 -8
  28. data/lib/retrospec/plugins/v1/plugin/template_helpers.rb +9 -10
  29. data/lib/retrospec/plugins/v1/plugin/templates/clone-hook +15 -8
  30. data/lib/retrospec/plugins/v1/plugin/type_code.rb +4 -4
  31. data/lib/retrospec/plugins/v1/plugin/variable_store.rb +26 -30
  32. data/lib/retrospec/plugins/v1/plugin/version.rb +1 -1
  33. data/puppet-retrospec.gemspec +43 -4
  34. data/spec/fixtures/facts/oracle_controls.rb +38 -0
  35. data/spec/fixtures/fixture_modules/required_parameters/manifests/init.pp +8 -0
  36. data/spec/fixtures/fixture_modules/sample_module/lib/facter/fix_installed.rb +11 -0
  37. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/awesome_parser.rb +13 -0
  38. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb +31 -0
  39. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/bad_sha1.rb +6 -0
  40. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/defined.rb +94 -0
  41. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/sha1.rb +6 -0
  42. data/spec/fixtures/fixture_modules/sample_module/spec/unit/facter/fix_installed_spec.rb +21 -0
  43. data/spec/fixtures/modules/tomcat/files/.gitkeep +0 -0
  44. data/spec/fixtures/modules/tomcat/templates/.gitkeep +0 -0
  45. data/spec/fixtures/modules/tomcat/tests/.gitkeep +0 -0
  46. data/spec/fixtures/providers/bmc/ipmitool.rb +188 -0
  47. data/spec/fixtures/providers/bmcuser/ipmitool.rb +140 -0
  48. data/spec/fixtures/types/bmc.rb +102 -0
  49. data/spec/fixtures/types/bmcuser.rb +46 -0
  50. data/spec/fixtures/types/db_opatch.rb +93 -0
  51. data/spec/integration/retrospec_spec.rb +1 -3
  52. data/spec/spec_helper.rb +33 -6
  53. data/spec/unit/conditional_spec.rb +12 -15
  54. data/spec/unit/generators/fact_generater_spec.rb +49 -17
  55. data/spec/unit/generators/function_generator_spec.rb +301 -0
  56. data/spec/unit/generators/function_spec.rb +67 -0
  57. data/spec/unit/generators/parsers/fact_spec.rb +62 -0
  58. data/spec/unit/generators/parsers/provider_spec.rb +44 -0
  59. data/spec/unit/generators/parsers/type_spec.rb +93 -0
  60. data/spec/unit/generators/provider_generator_spec.rb +120 -0
  61. data/spec/unit/generators/schema_generator_spec.rb +122 -0
  62. data/spec/unit/generators/type_generator_spec.rb +173 -0
  63. data/spec/unit/module_spec.rb +7 -10
  64. data/spec/unit/plugin_spec.rb +213 -15
  65. data/spec/unit/puppet-retrospec_spec.rb +81 -100
  66. data/spec/unit/resource_spec.rb +16 -17
  67. data/spec/unit/spec_object_spec.rb +46 -0
  68. data/spec/unit/type_code_spec.rb +9 -11
  69. data/spec/unit/variable_store_spec.rb +41 -43
  70. metadata +54 -4
  71. data/spec/unit/generators/fact_spec.rb +0 -58
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "conditional" do
4
-
3
+ describe 'conditional' do
5
4
  after :all do
6
5
  # enabling the removal slows down tests, but from time to time we may need to
7
6
  FileUtils.rm_rf(fixture_modules_path) if ENV['RETROSPEC_CLEAN_UP_TEST_MODULES'] =~ /true/
@@ -12,17 +11,15 @@ describe "conditional" do
12
11
  FileUtils.rm_rf(fixture_modules_path) if ENV['RETROSPEC_CLEAN_UP_TEST_MODULES'] =~ /true/
13
12
  end
14
13
 
15
-
16
14
  describe 'one resource module' do
17
-
18
- let(:instance) {Utilities::PuppetModule.send :new}
15
+ let(:instance) { Utilities::PuppetModule.send :new }
19
16
 
20
17
  it 'should initialize ' do
21
18
  my_path = File.expand_path(File.join('spec', 'fixtures', 'fixture_modules', 'one_resource_module'))
22
19
  m = instance
23
- m.module_path =my_path
20
+ m.module_path = my_path
24
21
  m.create_tmp_module_path(my_path)
25
- test_type = m.types.find {|x| x.name == 'one_resource::another_resource'}
22
+ test_type = m.types.find { |x| x.name == 'one_resource::another_resource' }
26
23
  Resource.all(test_type)
27
24
  conds = Conditional.find_conditionals(test_type)
28
25
  con = Conditional.new(conds.first, test_type.arguments)
@@ -32,27 +29,27 @@ describe "conditional" do
32
29
  it 'should generate conditional resources' do
33
30
  my_path = File.expand_path(File.join('spec', 'fixtures', 'fixture_modules', 'one_resource_module'))
34
31
  m = instance
35
- m.module_path =my_path
32
+ m.module_path = my_path
36
33
  m.create_tmp_module_path(my_path)
37
- test_type = m.types.find {|x| x.name == 'one_resource::another_resource'}
34
+ test_type = m.types.find { |x| x.name == 'one_resource::another_resource' }
38
35
  VariableStore.populate(test_type)
39
36
  r = Conditional.all(test_type)
40
37
  expect(r.length).to eq(1)
41
- expect(r[0].parameters).to eq({"ensure"=>"present"})
42
- expect(r[0].title).to eq("/tmp/test3/3")
43
- expect(r[0].type).to eq("file")
38
+ expect(r[0].parameters).to eq('ensure' => 'present')
39
+ expect(r[0].title).to eq('/tmp/test3/3')
40
+ expect(r[0].type).to eq('file')
44
41
  end
45
42
  end
46
43
 
47
44
  describe 'zero module' do
48
- let(:instance) {Utilities::PuppetModule.send :new}
45
+ let(:instance) { Utilities::PuppetModule.send :new }
49
46
  it 'should respond correctly when class is empty' do
50
47
  my_path = File.expand_path(File.join('spec', 'fixtures', 'fixture_modules', 'zero_resource_module'))
51
48
  m = instance
52
49
  m.module_path = my_path
53
50
  m.create_tmp_module_path(my_path)
54
- test_type = m.types.find {|x| x.name == 'empty_class'}
55
- expect{Conditional.all(test_type)}.to_not raise_error
51
+ test_type = m.types.find { |x| x.name == 'empty_class' }
52
+ expect { Conditional.all(test_type) }.to_not raise_error
56
53
  end
57
54
  end
58
55
  end
@@ -4,8 +4,6 @@ describe "fact generator" do
4
4
 
5
5
  before :each do
6
6
  FileUtils.rm_rf(facter_spec_dir)
7
- allow(generator).to receive(:facter_dir).and_return(fixtures_facts_path)
8
- allow(generator).to receive(:fact_name_path).and_return(File.join(module_path, 'lib', 'facter', "#{generator.fact_name}.rb"))
9
7
  end
10
8
 
11
9
  after :each do
@@ -21,33 +19,67 @@ describe "fact generator" do
21
19
  end
22
20
 
23
21
  let(:context) do
24
- {:name => 'datacenter', :template_dir => File.expand_path(File.join(ENV['HOME'], '.retrospec', 'repos', 'retrospec-puppet-templates'))}
22
+ {:name => 'datacenter', :template_dir => retrospec_templates_path }
25
23
  end
26
24
 
27
25
  let(:generator) do
28
26
  Retrospec::Puppet::Generators::FactGenerator.new(module_path, context )
29
27
  end
30
28
 
31
- it 'returns facter dir' do
32
- expect(generator.facter_dir).to eq(fixtures_facts_path)
33
- end
29
+ describe :datacenter do
30
+ before(:each) do
31
+ allow(generator).to receive(:facter_dir).and_return(fixtures_facts_path)
32
+ allow(generator).to receive(:fact_name_path).and_return(File.join(module_path, 'lib', 'facter', "#{generator.fact_name}.rb"))
33
+ end
34
34
 
35
- it 'returns module path' do
36
- expect(generator.facter_spec_dir).to eq(facter_spec_dir)
37
- end
35
+ let(:context) do
36
+ {:name => 'datacenter', :template_dir => retrospec_templates_path}
37
+ end
38
+ it 'returns facter dir' do
39
+ expect(generator.facter_dir).to eq(fixtures_facts_path)
40
+ end
38
41
 
39
- it 'can return fact name' do
40
- expect(generator.fact_name).to eq('datacenter')
41
- end
42
+ it 'returns module path' do
43
+ expect(generator.facter_spec_dir).to eq(facter_spec_dir)
44
+ end
45
+
46
+ it 'can return fact name' do
47
+ expect(generator.fact_name).to eq('datacenter')
48
+ end
42
49
 
43
- it 'can generate a fact file' do
44
- expect(generator.generate_fact_file.count).to eq(3)
45
- expect(File.exists?(File.join(generator.facter_dir, "#{generator.fact_name}.rb")))
50
+ it 'can generate a fact file' do
51
+ expect(generator.generate_fact_file.count).to eq(6)
52
+ expect(File.exists?(File.join(generator.facter_dir, "#{generator.fact_name}.rb")))
53
+ end
54
+
55
+ it 'can generate a spec file' do
56
+ expect(generator.generate_fact_spec_files.count).to eq(6)
57
+ end
46
58
  end
47
59
 
48
- it 'can generate a spec file' do
60
+ describe :oracle_controls do
61
+ before(:each) do
62
+ allow(generator).to receive(:facter_dir).and_return(fixtures_facts_path)
63
+ allow(generator).to receive(:fact_name_path).and_return(File.join(module_path, 'lib', 'facter', "#{generator.fact_name}.rb"))
64
+ end
65
+
66
+ let(:context) do
67
+ {:name => 'oracle_controls',:template_dir => retrospec_templates_path}
68
+ end
49
69
 
50
- expect(generator.generate_fact_spec_files.count).to eq(3)
70
+ it 'can generate a spec file' do
71
+ allow(generator).to receive(:fact_files).and_return([File.join(fixtures_facts_path, 'oracle_controls.rb')])
72
+ expect(generator.generate_fact_spec_files.count).to eq(2)
73
+ end
51
74
  end
52
75
 
76
+ describe 'real module' do
77
+ let(:module_path) do
78
+ sample_module_path
79
+ end
80
+
81
+ it 'can generate a spec file' do
82
+ expect(generator.generate_fact_spec_files).to eq([File.join(facter_spec_dir, 'fix_installed_spec.rb')])
83
+ end
84
+ end
53
85
  end
@@ -0,0 +1,301 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'function_generator' do
4
+ before :each do
5
+ FileUtils.rm_rf(generator.v3_spec_dir)
6
+ FileUtils.rm_rf(generator.v4_spec_dir)
7
+ FileUtils.rm_rf(function_path)
8
+ end
9
+
10
+ let(:function_path) do
11
+ File.join(module_path, 'lib', 'puppet', 'parser', 'functions', "#{function_name}.rb")
12
+ end
13
+
14
+ let(:module_path) do
15
+ sample_module_path
16
+ end
17
+
18
+ let(:context) do
19
+ { :module_path => module_path,
20
+ :template_dir => template_dir }
21
+ end
22
+
23
+ let(:template_dir) do
24
+ retrospec_templates_path
25
+ end
26
+
27
+ let(:function_name) do
28
+ 'awesome_parser'
29
+ end
30
+
31
+ let(:type_name) do
32
+ 'v4'
33
+ end
34
+
35
+ let(:return_type) do
36
+ 'rvalue'
37
+ end
38
+
39
+ let(:cli_opts) do
40
+ Retrospec::Puppet::Generators::FunctionGenerator.run_cli(context, opts)
41
+ end
42
+
43
+ let(:generator) do
44
+ Retrospec::Puppet::Generators::FunctionGenerator.new(module_path, cli_opts)
45
+ end
46
+
47
+ describe 'ruby unit tests' do
48
+ let(:opts) do
49
+ ['-n', function_name, '-r', return_type, '-t', type_name, '-u', 'ruby']
50
+ end
51
+
52
+ it 'contain template dir' do
53
+ expect(generator.template_dir).to match /templates\/functions/
54
+ end
55
+
56
+ it 'returns function name' do
57
+ expect(generator.function_name).to eq(function_name)
58
+ end
59
+
60
+ it 'generate spec files' do
61
+ files = [File.join(generator.v3_spec_dir, 'defined_spec.rb'),
62
+ File.join(generator.v3_spec_dir, 'sha1_spec.rb'),
63
+ File.join(generator.v4_spec_dir, 'reduce_spec.rb'),
64
+ File.join(generator.v4_spec_dir, 'awesome_parser_spec.rb')
65
+
66
+ ]
67
+ expect(generator.generate_spec_files).to match_array(files)
68
+ end
69
+
70
+ it 'returns found function files' do
71
+ files = [
72
+ File.join(module_path, 'lib', 'puppet', 'functions', 'awesome_parser.rb'),
73
+ File.join(module_path, 'lib', 'puppet', 'functions', 'reduce.rb'),
74
+ File.join(module_path, 'lib', 'puppet', 'parser', 'functions', 'bad_sha1.rb'),
75
+ File.join(module_path, 'lib', 'puppet', 'parser', 'functions', 'defined.rb'),
76
+ File.join(module_path, 'lib', 'puppet', 'parser', 'functions', 'sha1.rb'),
77
+ ]
78
+ expect(generator.discovered_functions).to match_array(files)
79
+ end
80
+
81
+ describe 'v3' do
82
+ let(:type_name) do
83
+ 'v3'
84
+ end
85
+
86
+ let(:function_path) do
87
+ File.join(module_path, 'lib', 'puppet', 'parser', 'functions', "#{function_name}.rb")
88
+ end
89
+
90
+ it 'returns function directory' do
91
+ path = File.join(module_path, 'lib', 'puppet', 'parser', 'functions')
92
+ expect(generator.function_dir).to eq(path)
93
+ end
94
+
95
+ it 'returns function path' do
96
+ path = File.join(module_path, 'lib', 'puppet', 'parser', 'functions', "#{function_name}.rb")
97
+ expect(generator.function_path).to eq(path)
98
+ end
99
+
100
+ it 'generate function file' do
101
+ expect(generator.generate_function_file).to eq(function_path)
102
+ end
103
+
104
+ it 'returns spec file directory' do
105
+ path = File.join(module_path, 'spec', 'unit', 'puppet', 'parser', 'functions')
106
+ expect(generator.spec_file_dir).to eq(path)
107
+ end
108
+
109
+ it 'return v3 template path' do
110
+ allow(generator).to receive(:function_type).and_return('v3')
111
+ path = File.join(gem_template_path, 'functions', 'v3')
112
+ expect(generator.template_dir).to match(/functions\/v3/)
113
+ end
114
+
115
+ it 'return true when v3 function' do
116
+ path = File.join(module_path, 'lib', 'puppet', 'parser', 'functions', 'bad_sha1.rb')
117
+ expect(generator.is_v3_function?(path)).to eq (true)
118
+ end
119
+
120
+ it 'return v3 template path when context is changed' do
121
+ generator.template_dir # uses v4
122
+ generator.context.function_type = 'v3'
123
+ expect(generator.template_dir).to match(/functions\/v3/)
124
+
125
+ end
126
+ end
127
+
128
+ describe 'v4' do
129
+ let(:type_name) do
130
+ 'v4'
131
+ end
132
+
133
+ let(:function_path) do
134
+ File.join(module_path, 'lib', 'puppet', 'functions', "#{function_name}.rb")
135
+ end
136
+
137
+ it 'return false when v4 function' do
138
+ path = File.join(module_path, 'lib', 'puppet', 'functions', 'reduce.rb')
139
+ expect(generator.is_v3_function?(path)).to eq (false)
140
+ end
141
+
142
+ it 'return v4 template path' do
143
+ allow(generator).to receive(:function_type).and_return('v4')
144
+ expect(generator.template_dir).to match(/functions\/v4/)
145
+ end
146
+
147
+ it 'return v4 template path when context is changed' do
148
+ generator.template_dir
149
+ generator.context.function_type = 'v4'
150
+ expect(generator.template_dir).to match(/functions\/v4/)
151
+ end
152
+
153
+ it 'returns function path' do
154
+ path = File.join(module_path, 'lib', 'puppet', 'functions', "#{function_name}.rb")
155
+ expect(generator.function_path).to eq(path)
156
+ end
157
+
158
+ it 'returns spec file directory' do
159
+ path = File.join(module_path, 'spec', 'unit', 'puppet', 'functions')
160
+ expect(generator.spec_file_dir).to eq(path)
161
+ end
162
+
163
+ it 'returns function directory' do
164
+ path = File.join(module_path, 'lib', 'puppet', 'functions')
165
+ expect(generator.function_dir).to eq(path)
166
+ end
167
+
168
+ it 'generate function file' do
169
+ expect(generator.generate_function_file).to eq(function_path)
170
+ end
171
+ end
172
+ end
173
+
174
+ describe 'rspec unit tests' do
175
+ let(:opts) do
176
+ ['-n', function_name, '-r', 'return_type', '-t', type_name, '-u', 'rspec']
177
+ end
178
+
179
+ it 'contain template dir' do
180
+ expect(generator.template_dir).to match /templates\/functions/
181
+ end
182
+
183
+ it 'returns function name' do
184
+ expect(generator.function_name).to eq(function_name)
185
+ end
186
+
187
+ it 'generate spec files' do
188
+ files = [File.join(generator.v3_spec_dir, 'defined_spec.rb'),
189
+ File.join(generator.v3_spec_dir, 'sha1_spec.rb'),
190
+ File.join(generator.v4_spec_dir, 'reduce_spec.rb'),
191
+ File.join(generator.v4_spec_dir, 'awesome_parser_spec.rb')
192
+
193
+ ]
194
+ expect(generator.generate_spec_files).to match_array(files)
195
+ end
196
+
197
+ it 'returns found function files' do
198
+ files = [
199
+ File.join(module_path, 'lib', 'puppet', 'functions', 'awesome_parser.rb'),
200
+ File.join(module_path, 'lib', 'puppet', 'functions', 'reduce.rb'),
201
+ File.join(module_path, 'lib', 'puppet', 'parser', 'functions', 'bad_sha1.rb'),
202
+ File.join(module_path, 'lib', 'puppet', 'parser', 'functions', 'defined.rb'),
203
+ File.join(module_path, 'lib', 'puppet', 'parser', 'functions', 'sha1.rb'),
204
+ ]
205
+ expect(generator.discovered_functions).to match_array(files)
206
+ end
207
+
208
+ describe 'v3' do
209
+ let(:type_name) do
210
+ 'v3'
211
+ end
212
+
213
+ let(:function_path) do
214
+ File.join(module_path, 'lib', 'puppet', 'parser', 'functions', "#{function_name}.rb")
215
+ end
216
+
217
+ it 'returns function directory' do
218
+ path = File.join(module_path, 'lib', 'puppet', 'parser', 'functions')
219
+ expect(generator.function_dir).to eq(path)
220
+ end
221
+
222
+ it 'returns function path' do
223
+ path = File.join(module_path, 'lib', 'puppet', 'parser', 'functions', "#{function_name}.rb")
224
+ expect(generator.function_path).to eq(path)
225
+ end
226
+
227
+ it 'generate function file' do
228
+ expect(generator.generate_function_file).to eq(function_path)
229
+ end
230
+
231
+ it 'returns spec file directory' do
232
+ path = File.join(module_path, 'spec', 'functions')
233
+ expect(generator.spec_file_dir).to eq(path)
234
+ end
235
+
236
+ it 'return v3 template path' do
237
+ allow(generator).to receive(:function_type).and_return('v3')
238
+ path = File.join(gem_template_path, 'functions', 'v3')
239
+ expect(generator.template_dir).to match(/functions\/v3/)
240
+ end
241
+
242
+ it 'return true when v3 function' do
243
+ path = File.join(module_path, 'lib', 'puppet', 'parser', 'functions', 'bad_sha1.rb')
244
+ expect(generator.is_v3_function?(path)).to eq (true)
245
+ end
246
+
247
+ it 'return v3 template path when context is changed' do
248
+ generator.template_dir # uses v4
249
+ generator.context.function_type = 'v3'
250
+ expect(generator.template_dir).to match(/functions\/v3/)
251
+ end
252
+ end
253
+
254
+ describe 'v4' do
255
+ let(:type_name) do
256
+ 'v4'
257
+ end
258
+
259
+ let(:function_path) do
260
+ File.join(module_path, 'lib', 'puppet', 'functions', "#{function_name}.rb")
261
+ end
262
+
263
+ it 'return false when v4 function' do
264
+ path = File.join(module_path, 'lib', 'puppet', 'functions', 'reduce.rb')
265
+ expect(generator.is_v3_function?(path)).to eq (false)
266
+ end
267
+
268
+ it 'return v4 template path' do
269
+ allow(generator).to receive(:function_type).and_return('v4')
270
+ expect(generator.template_dir).to match(/functions\/v4/)
271
+ end
272
+
273
+ it 'return v4 template path when context is changed' do
274
+ generator.template_dir
275
+ generator.context.function_type = 'v4'
276
+ expect(generator.template_dir).to match(/functions\/v4/)
277
+ end
278
+
279
+ it 'returns function path' do
280
+ path = File.join(module_path, 'lib', 'puppet', 'functions', "#{function_name}.rb")
281
+ expect(generator.function_path).to eq(path)
282
+ end
283
+
284
+ it 'returns spec file directory' do
285
+ path = File.join(module_path, 'spec', 'functions')
286
+ expect(generator.spec_file_dir).to eq(path)
287
+ end
288
+
289
+ it 'returns function directory' do
290
+ path = File.join(module_path, 'lib', 'puppet', 'functions')
291
+ expect(generator.function_dir).to eq(path)
292
+ end
293
+
294
+ it 'generate function file' do
295
+ expect(generator.generate_function_file).to eq(function_path)
296
+ end
297
+ end
298
+ end
299
+
300
+
301
+ end