puppet-retrospec 1.6.0 → 1.6.1

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
  SHA1:
3
- metadata.gz: 4224baa0aa258511ae8bc9bae2bc0c2cd4acbe51
4
- data.tar.gz: fafff7c4eb4efb843198521e3b6370745844b4ee
3
+ metadata.gz: 62765af0524e72cd3924e3c4406b7f418896e4f5
4
+ data.tar.gz: 50210328a846af0f1bbdec63765e9d4ee53caa38
5
5
  SHA512:
6
- metadata.gz: 4a72c6e609e917b2aac4689a7e4351e1b187d5bf82df550667bc97c174d2fe7823dd8cfea32cdfc0e201155324f0ea33655d0141ea6709916c088a27a0f6f58d
7
- data.tar.gz: c8fb49ce6e89aaebfbf850ea33be40e684833759217bfc4b1322c0bb2f6906657c2005c625b7cea225b0f8f72bb5c6c351c1ad49523f00990cd774e4390a099a
6
+ metadata.gz: 7a7b1e4da9e4a6234d01cd6f0c53b0b28f1305d83678e0e2d510ea61dda03f8e43ea691bd284fb9ed6983d8a9257441b5c6f60663cb0d13c91e620a570a70792
7
+ data.tar.gz: 4551ab67fa1fea42ce1dd427984dc04f1a8765c542f2ff69aec5341305471b09699c67757a2fc060b0db645774fc37910bd7d7addeb08d626419851b8b5dd653
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 1.6.1
6
+
7
+ ### Bug Fixes
8
+ * Require the base generator for module data
9
+ * Fixes #85 - native functions do not contain module name
10
+ * Fixes #92 - that requires throws errors
11
+ * Fixes #93 - native functions spec tests contain full namespaced name
12
+ * Fixes #87 - evaluation fails when parameters have logic
5
13
  ## 1.6.0
6
14
  * Fixes #77 - class requirements is not coded correctly
7
15
  * Fixes #75 - pdk cannot include retrospec due to character limit
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- puppet-retrospec (1.6.0)
4
+ puppet-retrospec (1.6.1)
5
5
  awesome_print
6
6
  facets
7
7
  retrospec (>= 0.6.2)
@@ -33,6 +33,11 @@ module Retrospec
33
33
  end
34
34
  end
35
35
 
36
+ # @return [String] - returns the main class name by reading the init.pp file
37
+ def main_class_name
38
+ File.read(File.join(module_path, 'manifests', 'init.pp')).scan(/\s*class\s(\w+)/).flatten.first || ''
39
+ end
40
+
36
41
  # returns v3,v4, native to specify the function type
37
42
  def function_type
38
43
  context.function_type
@@ -176,6 +181,11 @@ Generates a new function with the given name.
176
181
  File.extname(function_file) == '.pp'
177
182
  end
178
183
 
184
+ # @return [String] - returns the namespaced function name ie. stdlib::round
185
+ def namespaced_name
186
+ [main_class_name, function_name].join('::')
187
+ end
188
+
179
189
  # @return [Boolean] true if the function file is a v4 function
180
190
  def v4_function?(function_file)
181
191
  # mod_name/lib/puppet/functions
@@ -220,7 +230,10 @@ Generates a new function with the given name.
220
230
  puts "Function syntax is bad for #{file}, skipping".warning
221
231
  next # lets skip functions that have bad syntax
222
232
  end
223
- spec_path = File.join(spec_file_dir, "#{file_data.name}_spec.rb")
233
+ # separate out namespace for v4 and native functions
234
+ # TODO should we create sub directories for triple namespace functions one::two::three?
235
+ file_name = file_data.name.to_s.split('::').last
236
+ spec_path = File.join(spec_file_dir, "#{file_name}_spec.rb")
224
237
  spec_files << spec_path
225
238
  safe_create_template_file(spec_path, File.join(template_dir, template_file), file_data)
226
239
  end
@@ -1,5 +1,6 @@
1
1
  require 'retrospec/plugins/v1/module_helpers'
2
2
  require 'retrospec/plugins/v1'
3
+ require 'retrospec/plugins/v1/plugin/generators/base_generator'
3
4
 
4
5
  module Retrospec
5
6
  module Puppet
@@ -222,6 +222,7 @@ module Retrospec
222
222
  name_prefix = o.captures_rest ? '*' : ''
223
223
  name_part = "#{name_prefix}#{o.name}"
224
224
  data_type = dump_transform(dump_transform(o.value)).first || dump_transform(o.type_expr)
225
+
225
226
  # records what is most likely a variable of some time and its value
226
227
  variable_value = dump_transform(o.value)
227
228
  # need a case for Puppet::Pops::Model::LambdaExpression
@@ -273,6 +274,10 @@ module Retrospec
273
274
  result
274
275
  end
275
276
 
277
+
278
+ # @note this is the starting point where a test is created. A resource can include a class or define
279
+ # each resource contains parameters which can have variables or functions as values.
280
+ # @param o [Puppet::Pops::Model::ResourceBody]
276
281
  def dump_ResourceBody o
277
282
  type_name = dump_transform(o.eContainer.type_name).gsub('::', '__')
278
283
  title = dump_transform(o.title).inspect
@@ -282,19 +287,22 @@ module Retrospec
282
287
  if o.operations.count > 0
283
288
  result[-1] += '.with('
284
289
  result << [:break]
290
+ # each operation should be a resource parameter and value
285
291
  o.operations.each do |p|
292
+ next unless p
286
293
  # this is a bit of a hack but the correct fix is to patch puppet
287
294
  result << dump_transform(p) << :break
288
295
  end
289
296
  result.pop # remove last line break which is easier than using conditional in loop
297
+ result << [:dedent, :break, ')']
290
298
  unless [::Puppet::Pops::Model::CallNamedFunctionExpression, ::Puppet::Pops::Model::BlockExpression].include?(o.eContainer.eContainer.class)
291
299
  result << dump_Resource_Relationship(o)
292
300
  end
293
- result << [:dedent, :break, ')']
294
301
  result << [:end]
295
302
  result << [:dedent]
303
+ result << [:break]
296
304
  else
297
- result << [:dedent,:dedent, :break,'end',:dedent, ' ']
305
+ result << [:dedent,:dedent, :break,'end',:dedent, ' ', :break]
298
306
  end
299
307
  result
300
308
  end
@@ -304,6 +312,12 @@ module Retrospec
304
312
  []
305
313
  end
306
314
 
315
+ # @param o [Puppet::Pops::Model::NamedAccessExpression]
316
+ # ie. $::var1.split(';')
317
+ def dump_NamedAccessExpression o
318
+ [do_dump(o.left_expr), ".", do_dump(o.right_expr)]
319
+ end
320
+
307
321
  # Interpolated strings are shown as (cat seg0 seg1 ... segN)
308
322
  def dump_ConcatenatedString o
309
323
  o.segments.collect {|x| dump_transform(x)}.join
@@ -330,6 +344,7 @@ module Retrospec
330
344
  end
331
345
 
332
346
  # this doesn't return anything as we use it to store variables
347
+ # @param o [Puppet::Pops::Model::AssignmentExpression]
333
348
  def dump_AssignmentExpression o
334
349
  oper = o.operator.to_s
335
350
  result = []
@@ -354,6 +369,7 @@ module Retrospec
354
369
  end
355
370
  end
356
371
 
372
+ # @param o [Puppet::Pops::Model::BlockExpression]
357
373
  def dump_BlockExpression o
358
374
  result = [:break]
359
375
  o.statements.each {|x| result << dump_transform(x) }
@@ -361,6 +377,7 @@ module Retrospec
361
377
  end
362
378
 
363
379
  # this is the beginning of the resource not the body itself
380
+ # @param o [Puppet::Pops::Model::ResourceExpression]
364
381
  def dump_ResourceExpression o
365
382
  result = []
366
383
  o.bodies.each do |b|
@@ -371,11 +388,13 @@ module Retrospec
371
388
 
372
389
  # defines the resource expression and outputs -> when used
373
390
  # this would be the place to insert relationsip matchers
391
+ # @param o [Puppet::Pops::Model::RelationshipExpression]
374
392
  def dump_RelationshipExpression o
375
393
  [dump_transform(o.left_expr), dump_transform(o.right_expr)]
376
394
  end
377
395
 
378
396
  # Produces (name => expr) or (name +> expr)
397
+ # @param o [Puppet::Pops::Model::AttributeOperation]
379
398
  def dump_AttributeOperation o
380
399
  key = o.attribute_name
381
400
  value = dump_transform(o.value_expr) || nil
@@ -384,7 +403,7 @@ module Retrospec
384
403
 
385
404
  # x[y] prints as (slice x y)
386
405
  # @return [String] the value of the array expression
387
- # @param [Puppet::Pops::Model::AccessExpression]
406
+ # @param o [Puppet::Pops::Model::AccessExpression]
388
407
  def dump_AccessExpression o
389
408
  # o.keys.pop is the item to get in the array
390
409
  # o.left_expr is the array
@@ -401,6 +420,18 @@ module Retrospec
401
420
  end
402
421
  end
403
422
 
423
+
424
+ # @return [String] the value of the expression or example value
425
+ # @param o [Puppet::Pops::Model::CallMethodExpression]
426
+ def dump_CallMethodExpression o
427
+ # ie. ["call-method", [".", "$::facttest", "split"], "/"]
428
+ result = [o.rval_required ? "# some_value" : do_dump(o.functor_expr),'(' ]
429
+ o.arguments.collect {|a| result << do_dump(a) }
430
+ results << ')'
431
+ result << do_dump(o.lambda) if o.lambda
432
+ result
433
+ end
434
+
404
435
  def dump_LiteralFloat o
405
436
  o.value.to_s
406
437
  end
@@ -1,5 +1,5 @@
1
1
  module Retrospec
2
2
  module Puppet
3
- VERSION = '1.6.0'
3
+ VERSION = '1.6.1'
4
4
  end
5
5
  end
@@ -0,0 +1,5 @@
1
+ class one_resource::parameter_logic(
2
+ String $param1 = $::facttest.split('/')[0]
3
+ ){
4
+
5
+ }
@@ -0,0 +1,7 @@
1
+ #lbsdafsdfad
2
+ #fsadfadsfsdfsd
3
+ class sample_module(
4
+ $var1 = 'sdfasd'
5
+ ) {
6
+
7
+ }
@@ -0,0 +1,4 @@
1
+ function simple::absolute(Integer $x) {
2
+ if $x < 0 { $x * -1 }
3
+ else { $x }
4
+ }
@@ -66,7 +66,7 @@ describe Retrospec::Puppet::Generators::DefinitionGenerator do
66
66
  end
67
67
 
68
68
  it 'should have resources' do
69
- resources = ["\n it do\n is_expected.to contain_notify('hello')\n end "]
69
+ resources = ["\n it do\n is_expected.to contain_notify('hello')\n end \n"]
70
70
  expect(context.resources).to eq(resources)
71
71
  end
72
72
 
@@ -321,6 +321,16 @@ describe 'function_generator' do
321
321
  expect(generator.v4_function?(path)).to eq false
322
322
  end
323
323
 
324
+ it 'returns main class name' do
325
+ allow(generator).to receive(:function_type).and_return('native')
326
+ expect(generator.main_class_name).to eq('sample_module')
327
+ end
328
+
329
+ it 'creates namespaced function name' do
330
+ allow(generator).to receive(:function_type).and_return('native')
331
+ expect(generator.namespaced_name).to eq('sample_module::awesome_parser')
332
+ end
333
+
324
334
  it 'return native template path' do
325
335
  allow(generator).to receive(:function_type).and_return('native')
326
336
  expect(generator.template_dir).to match(/functions\/native/)
@@ -84,7 +84,9 @@ describe 'HostClassGenerator' do
84
84
  File.join(spec_files_path, 'one_resource_spec.rb'),
85
85
  File.join(spec_files_path, 'params_spec.rb'),
86
86
  File.join(spec_files_path, 'array_param_spec.rb'),
87
- File.join(spec_files_path, 'sub', 'settings_spec.rb')]
87
+ File.join(spec_files_path, 'sub', 'settings_spec.rb'),
88
+ File.join(spec_files_path, 'parameter_logic_spec.rb')]
89
+
88
90
  end
89
91
 
90
92
  after(:each) do
@@ -222,8 +222,8 @@ describe 'rspec_serializer' do
222
222
 
223
223
  it 'relationship_exp' do
224
224
  output = serializer.dump(relationship_exp)
225
- expect(output).to include(".that_comes_before('Sql::backup[MSSQLSERVER]')")
226
- expect(output).to include(".that_requires('Class[sql::install]')")
225
+ expect(output).to include(")\n .that_comes_before('Sql::backup[MSSQLSERVER]')")
226
+ expect(output).to include(")\n .that_requires('Class[sql::install]')")
227
227
  end
228
228
 
229
229
  it 'should contain correct variables' do
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.6.0
4
+ version: 1.6.1
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-30 00:00:00.000000000 Z
11
+ date: 2018-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop
@@ -164,6 +164,7 @@ files:
164
164
  - spec/fixtures/fixture_modules/one_resource_module/manifests/node_file.pp
165
165
  - spec/fixtures/fixture_modules/one_resource_module/manifests/one_define.pp
166
166
  - spec/fixtures/fixture_modules/one_resource_module/manifests/one_resource_class.pp
167
+ - spec/fixtures/fixture_modules/one_resource_module/manifests/parameter_logic.pp
167
168
  - spec/fixtures/fixture_modules/one_resource_module/manifests/params.pp
168
169
  - spec/fixtures/fixture_modules/one_resource_module/manifests/sub/settings.pp
169
170
  - spec/fixtures/fixture_modules/one_resource_module/manifests/sub/settings_define.pp
@@ -175,11 +176,13 @@ files:
175
176
  - spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/defined.rb
176
177
  - spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/sha1.rb
177
178
  - spec/fixtures/fixture_modules/sample_module/lib/puppet/reports/test
179
+ - spec/fixtures/fixture_modules/sample_module/manifests/init.pp
178
180
  - spec/fixtures/fixture_modules/sample_module/spec/unit/facter/fix_installed_spec.rb
179
181
  - spec/fixtures/fixture_modules/zero_resource_module/manifests/empty_class.pp
180
182
  - spec/fixtures/fixture_modules/zero_resource_module/manifests/not_a_resource_defination.pp
181
183
  - spec/fixtures/fixture_modules/zero_resource_module/metadata.json
182
184
  - spec/fixtures/functions/abs.pp
185
+ - spec/fixtures/functions/absolute.pp
183
186
  - spec/fixtures/host_class_test.txt
184
187
  - spec/fixtures/manifests/apache.pp
185
188
  - spec/fixtures/manifests/includes-class.pp