Ask Your Question

puppet-rspec fails when testing against none standard type

asked 2014-11-23 13:58:02 -0600

kemra102 gravatar image

I am working on adding testing to a module I write ( ).

I am currently writing the tests for the 'zabbix::repo' class and I am getting the following error:

  1) zabbix on ubuntu systems 
     Failure/Error: it { should contain_apt__source('ubuntu-zabbix') }
       Ubuntu  is not supported by this module. at /home/kemra102/projects/puppet-zabbix/spec/fixtures/modules/zabbix/manifests/params.pp:143 on node iacon.cybertron.local
     # ./spec/classes/zabbix_repo_spec.rb:16:in `block (3 levels) in <top (required)>'

Here is the test:

require 'spec_helper'

describe 'zabbix', :type => :class do
  it { should contain_class('zabbix::repo') }

  context 'on redhat family systems' do
    let (:facts) { { :osfamily => 'RedHat' } }

    it { should contain_yumrepo('zabbix') }
    it { should contain_yumrepo('zabbix-non-supported') }

  context 'on ubuntu systems' do
    let (:facts) { { :osfamily => 'Debian', :operatingsystem => 'Ubuntu' } }

    it { should contain_apt__source('ubuntu-zabbix') }


I find it strange that the apt::source test for Ubuntu is failing given that the yumrepo ones pass absolutely without error. I can give the missing '::operatingsystemmajrelease' it is looking for but then it just asks for other variables in a seemingly never ending list.

Any ideas why only the apt repo is failing?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2014-11-24 15:51:50 -0600

jonn gravatar image

Is it because you're only setting the $operatingsystem fact for the ubuntu context, and not for the redhat context?

  context 'on redhat family systems' do
    let (:facts) { { :osfamily => 'RedHat' } }

If there's no $operatingsystem fact, then your enclosing case statement at the bottom of params.pp doesn't get used at all (there's no default case on this one):

  case $::operatingsystem {
    'CentOS','RedHat','Scientific','OracleLinux': {
      case $::operatingsystemmajrelease {
        '5': { $version = '2.2' }
        '6': { $version = '2.4' }
        default: {
          fail("${::operatingsystem} ${::operatingsystemmajrelease}

and so the subsequent fail() never gets called.

If you do something like:

let (:facts) { { :osfamily => 'RedHat', :operatingsystem => 'Centos' } }

then I think the catalog should start to fail, as it does for the Ubuntu test.

You can probably catch this in future by adding a default to the case statement in params.pp that will fail the catalog if $operatingsystem is not set :)

edit flag offensive delete link more


This does seem to be the case, thanks!

kemra102 gravatar imagekemra102 ( 2014-11-24 16:34:32 -0600 )edit

answered 2014-11-24 03:33:57 -0600

nrvale0 gravatar image

Pretty sure you are falling through to the default case and executing the fail() because you did not specify the mock value for the fact ::operatingsystemrelease via let().

edit flag offensive delete link more


Assuming you mean ::operatingsystemmajrelease, though I beleive these are the same on Debian based distros. I agree that's what seems to be happening on the Ubuntu test, but if that’s the case why does the RedHat test not fail in a similar fashion?

kemra102 gravatar imagekemra102 ( 2014-11-24 11:05:22 -0600 )edit

Sorry, I didn't see the blurb at the end of your original post. I'll pull the module down and give it an rspec run later today and let you know what I find. Will send a PR if I get a chance.

nrvale0 gravatar imagenrvale0 ( 2014-11-24 11:22:28 -0600 )edit

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


Asked: 2014-11-23 13:58:02 -0600

Seen: 575 times

Last updated: Nov 24 '14