knowshan / puppetmod-uabopennebula

Puppet module for OpenNebula
2 stars 0 forks source link

rspec-puppet tests fail with Puppet error 'No matching value for selector param 'undef'' #10

Closed knowshan closed 12 years ago

knowshan commented 12 years ago

I am trying to write rspec tests for this Puppet module. I started with rspec-puppet setup guide and wrote a simple test to check a file resource - sha: 625b268f1f0057217c6a101a323ec489b8ad872a.

require 'spec_helper'

describe 'uabopennebula::conf::onedconf', :type => :class do
  let(:facts) {{:operatingsystem => 'CentOS'}}
  let(:facts) {{:rubyversion => '1.8.7'}}
  it do
    should contain_file($one_oned_conf_path).with({
      'mode' => '0640',
      'content' => 'template(\'uabopennebula/oned_conf.erb\')',
    })
  end
end

The test is failing with following error:

$ rake spec
/home/pavgi/.rvm/rubies/ruby-1.8.7-p357/bin/ruby -S rspec spec/classes/testme_spec.rb spec/classes/onedconf_spec.rb
.F

Failures:

  1) uabopennebula::conf::onedconf 
     Failure/Error: })
     Puppet::Error:
       No matching value for selector param 'undef' at /home/pavgi/PuppetModules/uabopennebula/spec/fixtures/modules/uabopennebula/manifests/params.pp:67 on node cheaha.uabgrid.uab.edu
     # ./spec/classes/onedconf_spec.rb:11

Finished in 0.3474 seconds
2 examples, 1 failure

Failed examples:

rspec ./spec/classes/onedconf_spec.rb:7 # uabopennebula::conf::onedconf 
rake aborted!
/home/pavgi/.rvm/rubies/ruby-1.8.7-p357/bin/ruby -S rspec spec/classes/testme_spec.rb spec/classes/onedconf_spec.rb failed

Tasks: TOP => spec
(See full trace by running task with --trace)

The params class which is inherited by the onedconf class uses facter values to set couple of variables. The error seems to be because of an undefined facter parameter/value. Not sure of all the details though.

knowshan commented 12 years ago

Multiple 'facts' should be specified as a hash in one block as follows:

let (:facts) {{:operatingsystem => 'CentOS', :rubyversion => '1.8.7'}}

This fixes the aforementioned error where :facts were getting overwritten.