rspec-puppet: mocking included params class in defines

1.273 de afișări
Accesați primul mesaj necitit

vkan...@gmail.com

necitită,
24 dec. 2013, 08:50:4224.12.2013
– puppet...@googlegroups.com
Hi all,

I'm trying to test a defined type that looks like this:

define app_setup::app($app_name = $title) {
  include app_setup::params

  $app_host       = $app_setup::params::app_hosts[$app_name]['url']
  $app_port       = $app_setup::params::app_hosts[$app_name]['port']
  $deploy_user    = $app_setup::params::deploy_user

   ...
}

And I'm trying to write a spec like this:

describe 'app_setup::app', :type => :define do
  let(:title) { 'some_app_name' }

end

My question is, how can I assign the values of $app_setup::params::app_hosts in the spec? I tried several combinations of 'let' but didn't work.

Thanks,
Vamsee.


Johan De Wit

necitită,
26 dec. 2013, 04:56:4426.12.2013
– puppet...@googlegroups.com
I use this one to set parameters for a define in my rspec

let(:facts) { { :hostname => 'sambaserver' } }

context 'default setting' do
let(:params) { { :share_path => '/testpath/share' } }
...
end

this is an expert of my define

define samba::define_share (
share_path,
share_browsable = $samba::params::share_browsable,
share_readonly = $samba::params::share_readonly,
share_write_list = $samba::params::share_write_list,
share_valid_users = $samba::params::share_valid_users,
..... )

hope this helps

Grt
Johan
> --
> You received this message because you are subscribed to the Google
> Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/6b1ca94d-97b6-4e1b-8c62-5b5ed1478705%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.


--
Johan De Wit

Open Source Consultant

Red Hat Certified Engineer (805008667232363)
Puppet Certified Professional 2013 (PCP0000006)
_________________________________________________________

Open-Future Phone +32 (0)2/255 70 70
Zavelstraat 72 Fax +32 (0)2/255 70 71
3071 KORTENBERG Mobile +32 (0)474/42 40 73
BELGIUM http://www.open-future.be
_________________________________________________________


Next Events:
Puppet Advanced Training | http://www.open-future.be/puppet-advanced-training-7-till-9th-january
Puppet Fundamentals Training | http://www.open-future.be/puppet-fundamentals-training-4-till-6th-february
Subscribe to our newsletter | http://eepurl.com/BUG8H

Vamsee Kanakala

necitită,
27 dec. 2013, 05:16:4927.12.2013
– puppet...@googlegroups.com
On Dec 26 10:56, Johan De Wit wrote:
> I use this one to set parameters for a define in my rspec
>
> let(:facts) { { :hostname => 'sambaserver' } }
>
> context 'default setting' do
> let(:params) { { :share_path => '/testpath/share' } }
> ...
> end
>

Thanks a bunch Johan, that gave me some ideas. I was able to rewrite
my tests successfully based on your pattern.


Vamsee.

Gavin Williams

necitită,
16 ian. 2014, 07:58:3716.01.2014
– puppet...@googlegroups.com
Vamsee

Are you able to share how you went about mocking out the ::params class include?

As I've got the same pattern that I want to test using rspec-puppet...

Cheers
Gavin

Vamsee Kanakala

necitită,
16 ian. 2014, 09:46:3716.01.2014
– puppet...@googlegroups.com
On Jan 16 04:58, Gavin Williams wrote:
> Vamsee
>
> Are you able to share how you went about mocking out the ::params class
> include?
>
> As I've got the same pattern that I want to test using rspec-puppet...
>

Hi Gavin,

I ended up adding all the params to the define explicity, instead of
including the params class:

define app_setup::app(
$app_name = $title,
$app_host = $app_setup::params::app_hosts[$title]['url'],
$app_port = $app_setup::params::app_hosts[$title]['port'],
$deploy_user = $app_setup::params::deploy_user,
...
)

The params are accessible in the define without inheriting because I did this in the
init.pp file:

class app_setup($deploy_env = 'UNSET') {
include app_setup::params
...
}

And testing it the usual way:

let(:params) { {
:app_host => 'api.example.net',
:app_port => '3009',
:deploy_user => 'test_user',
...
}}

Hope this helps. I thought this was much cleaner in its contract rather than including
the params class. This might or might not appeal to you, though.


Vamsee.

Răspundeți tuturor
Răspundeți autorului
Redirecționați
0 mesaje noi