简体   繁体   中英

Using external variable in rspec-puppet test

Have some stuck with using variable in rspec. Here is my params.pp

case $::osfamily{
  Debian: {
    $ssh_daemon = "ssh"
  }
  Redhat: {
    $ssh_daemon = "sshd"
  }

In an rspec test I need to use the variable $ssh_daemon like this:

it { should contain_service("${ssh_daemon}").with(
  :ensure => 'running',
  :enable => 'true',
)}

Here is my ssh.pp file

service { "${ssh_daemon}":
  ensure => running,
  enable => true,
}

How can I write this variable ($ssh_daemon) to get this test to work?

You can do this by mocking Facter output.

Something like:

context 'service on debian' do
  let(:facts) { { :osfamily => 'Debian' } }
  it { should contain_service("ssh") }
end

context 'service on redhat' do
  let(:facts) { { :osfamily => 'RedHat' } }
  it { should contain_service("sshd") }
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM