Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

empty param value in defined type test case #97

Open
azalio opened this issue Apr 29, 2018 · 5 comments
Open

empty param value in defined type test case #97

azalio opened this issue Apr 29, 2018 · 5 comments
Labels
Milestone

Comments

@azalio
Copy link

azalio commented Apr 29, 2018

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
Copy link
Contributor

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

@azalio
Copy link
Author

azalio commented Apr 30, 2018

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
Copy link
Contributor

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 logicminds changed the title Empty hash. empty param value in defined type test case May 1, 2018
logicminds added a commit that referenced this issue May 11, 2018
  * Previously the serializer did not serialize literal hashes properely
    because the KeyedEntry type was missing.
@logicminds
Copy link
Contributor

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
Copy link
Author

azalio commented May 11, 2018

Thank you very much for your work!

@logicminds logicminds added this to the 1.6.0 milestone Jun 20, 2018
@logicminds logicminds added the bug label Jun 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants