Re: [Puppet Users] rspec-puppet: mocking included params class in defines

2014-01-16 Thread Gavin Williams
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 

On Friday, 27 December 2013 10:16:49 UTC, Vamsee Kanakala wrote:

 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. 


-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/b0d4f0e8-67c3-4e87-923f-da7f9d44df68%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [Puppet Users] rspec-puppet: mocking included params class in defines

2014-01-16 Thread Vamsee Kanakala
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.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/20140116144637.GA17935%40inara.serenity.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [Puppet Users] rspec-puppet: mocking included params class in defines

2013-12-27 Thread Vamsee Kanakala
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.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/20131227101649.GA27908%40inara.serenity.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [Puppet Users] rspec-puppet: mocking included params class in defines

2013-12-26 Thread Johan De Wit

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

On 12/24/2013 02:50 PM, vkanak...@gmail.com wrote:

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.


--
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+unsubscr...@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 (PCP006)
_
 
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

--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/52BBFD5C.7040705%40open-future.be.
For more options, visit https://groups.google.com/groups/opt_out.


[Puppet Users] rspec-puppet: mocking included params class in defines

2013-12-24 Thread vkanakala
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.


-- 
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+unsubscr...@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.