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

empty param value in defined type test case #97

Open azalio opened 6 years ago

azalio commented 6 years ago

Thank you for the great software!
I use it to create a node test. Just change node to class and create a pseudo-class. All works correct, but in case hash I got the empty hash.
For example:

    mysql::instance { '2' :
        desc => 'install_android',
        slab_alloc_arena => 100,
        snapshot_hours => "4+",
        memcached_enabled => true,
        spaces => [ { idx => 1, indexes => [
          { 'type' => 'HASH', unique => 1, keyfields => [ { fieldno => 0, 'type' => 'STR' } ] },
          { 'type' => 'TREE', unique => 0, keyfields => [ { fieldno => 3, 'type' => 'STR' } ] },
          { 'type' => 'TREE', unique => 0, keyfields => [ { fieldno => 4, 'type' => 'STR' } ] },
          { 'type' => 'TREE', unique => 0, keyfields => [ { fieldno => 6, 'type' => 'STR' } ] },
                       ]
         } ],
        init_lua_content => "dofile('/usr/local/etc/mysql/rbappgoals_install.lua')\n",
    }

Changed to:

  it do
    is_expected.to contain_mysql__instance('2').with(
      desc: 'install_android',
      slab_alloc_arena: '100',
      snapshot_hours: '4+',
      memcached_enabled: true,
      spaces: [{}],
      init_lua_content: "dofile('/usr/local/etc/mysql/rbappgoals_install.lua')\n",
    )
  end

And then a run the test rspec I got error because spaces variable is not empty. Can you give me a hint, how I can fix it?

logicminds commented 6 years ago

You need to put something in the empty hash. Whatever you expect it to be should be in there.

azalio commented 6 years ago

I have created example module and run

retrospec --module-path=modules/example puppet

And I got test As I can see in src_cluster_addrs I got the empty hash, but I want to got hash with values in class example.
How can I modify retrospec to do it for me?

logicminds commented 6 years ago

Ahh ok I see now. Thanks for the clarification. Yes it should have been populated automatically. For some reason it is not working though. The problem would most likely be in the serializer. This is a bit complicated to understand as it descends the tree recursively.

https://github.com/nwops/puppet-retrospec/blob/master/lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb

I'll look into this later and put out a patch if necessary. Thanks for reporting.

logicminds commented 6 years ago

I found and fixed the issue, but the output looks terrible at the moment, and needs to be include the line breaks.

it do
    is_expected.to contain_resharder__instance('1').with(
      src_cluster_addrs: [{'addr'=>'127.0.0.1:43013', 'snapshot-url'=>'http://127.0.0.1:2990/1/snaps/'}, {'addr'=>'127.0.0.1:43014', 'snapshot-url'=>'http://127.0.0.1:2990/2/snaps/'}, {'addr'=>'127.0.0.1:43015', 'snapshot-url'=>'http://127.0.0.1:2990/3/snaps/'}, {'addr'=>'127.0.0.1:43016', 'snapshot-url'=>'http://127.0.0.1:2990/4/snaps/'}],
    )
  end
azalio commented 6 years ago

Thank you very much for your work!