Ask Your Question
0

hiera in rspec-puppet

asked 2015-06-22 09:59:13 -0500

Chutki gravatar image

Hi,

I have below manifests

class env {

  $line = hiera('ENV_LINE')

  file { '/tmp/puppet/etc' :
    ensure => directory
  }

  file { '/tmp/puppet/etc/ENV' :
    ensure  => file,
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
    content => "${line}\n",
    require => File['/tmp/puppet/etc'],
  }
}

include env

Below is my env_spec.rb

require 'spec_helper'

describe 'env', :type => 'class' do

  let(:hiera_config) { 'spec/fixtures/hieradata/hiera.yaml' }
  hiera = Hiera.new({ :config => 'spec/fixtures/hieradata/hiera.yaml' })

  ENV_LINE = hiera::lookup('ENV_LINE',nil,nil)

  let(:params) {{
    :ENV_LINE => ENV_LINE
  }}

  it{ should contain_file('/tmp/puppet/etc/ENV').with(
        'ensure'  => 'file',
        'owner'   => 'root',
        'group'   => 'root',
        'mode'    => '0644',
        'content' => 'ENV_LINE',
        'require' => 'File[/tmp/puppet/etc]')}

  #it{ should contain_class('env').with_ENV_LINE('ENV_LINE')}

end

And Below is my hera file /spec/fixtures/hieradata/env.yaml

---

ENV_LINE: 'Non-Prod'

when I run getting bewlow error

1) env
     Failure/Error: 'require' => 'File[/tmp/puppet/etc]')}
     Puppet::Error:
       Could not parse for environment production: Syntax error at 'ENV_LINE'; expected '}' at line 4 on node      # ./spec/classes/env_spec.rb:20
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-06-24 12:13:34 -0500

WhatsARanjit gravatar image

In order to "spoof" hieradata, look into mocking the hiera function itself:

https://github.com/Accuity/rspec-pupp...

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

Stats

Asked: 2015-06-22 09:59:13 -0500

Seen: 641 times

Last updated: Jun 24 '15