puppet-retrospec icon indicating copy to clipboard operation
puppet-retrospec copied to clipboard

empty param value in defined type test case

Open azalio opened this issue 6 years ago • 5 comments

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?

azalio avatar Apr 29 '18 23:04 azalio

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

logicminds avatar Apr 30 '18 07:04 logicminds

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?

azalio avatar Apr 30 '18 19:04 azalio

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 avatar May 01 '18 22:05 logicminds

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

logicminds avatar May 11 '18 00:05 logicminds

Thank you very much for your work!

azalio avatar May 11 '18 08:05 azalio