nwops / puppet-retrospec

The only tool you need to generate puppet code, tests, modules, facts, types, providers, data and everything else.
https://www.retrospec-puppet.com/
GNU Affero General Public License v3.0
137 stars 27 forks source link

handle differences between classes and user defined resources in generated beaker tests #45

Closed camara-tech closed 8 years ago

camara-tech commented 8 years ago

When generating the beaker tests for a module, all of the user defined resources are called using

class {'user-resource': }

rather than

user-resource {'replace-me': }

This causes Puppet to return an AST error for those tests.

logicminds commented 8 years ago

Thanks for reporting. The beaker tests are the least tested portion. And this is a bug in the templates.

https://github.com/nwops/retrospec-templates/blob/master/acceptance_spec_test.retrospec.erb#L7

You can easily fix this by updating the templates if you have forked them. And then change the location where retrospec gets its templates from.

See https://github.com/nwops/retrospec-templates#configuration for more information.

However, I need more documentation around creating the templates but I assume the fix would look like this.

<%- if @type.type == :definition -%>
  <%= @type.name %>{'some_value':
      <%- @parameters.each do |k,v| -%>
        <%- if v.nil? -%>
        <%= "#{k}  => 'place_value_here'," %>
        <%- else -%>
        <%= "##{k} => #{variable_value(v)}," %>
        <%- end -%>
      <%- end -%>
      }
  <%- else -%>
  class { '<%= @type.name %>':
      <%- @parameters.each do |k,v| -%>
        <%- if v.nil? -%>
        <%= "#{k}  => 'place_value_here'," %>
        <%- else -%>
        <%= "##{k} => #{variable_value(v)}," %>
        <%- end -%>
      <%- end -%>
      }
  <%- end -%> 

If you want to try this and and make a MR against the retrospec-templates repository that would be great.