Ask Your Question
2

rspec-puppet: how to test virtual resources (@file, @user)?

asked 2013-05-21 07:53:43 -0500

updated 2013-05-21 07:54:46 -0500

How to test class like this one?


class someclass::user {

  $user = "user123"

   @user { $user:
    ensure      => present,
    home        => "/home/${user}",    
    shell       => "/bin/bash",
    managehome  => true,    
  }

  @file { "/home/${user}":
    ensure  => directory,
    owner   => $user,
    group   => $user,
    mode    => 0700,
    require => User["${user}"]
  }

}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2013-10-22 19:26:44 -0500

nanliu gravatar image

updated 2013-10-22 19:29:11 -0500

Since you can test any resource in the catalog, all you need is to realize the resource during spec testing. You can do this by adding a pre_condition:

let :pre_condition do
  'User <| |>'
end

The rest is normal rspec-puppet.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-05-21 07:53:43 -0500

Seen: 1,279 times

Last updated: Oct 22 '13