rspec-puppet does not support file_line resource

1k Views Asked by At

I have below manifests with file_line resource

class login {

  if $::operatingsystemmajrelease < 7 {

    file {'/etc/loginfile':
      ensure => present,
    }

    file_line { 'testfile':
      path   => '/etc/loginfile',
      line   => 'abc 022',
      match  => '^abc.*$',
    }
  }
}

Below is rspec file

require 'spec_helper'

describe 'login' do

  it { should contain_class('login')}

  let(:facts) {{:operatingsystemmajrelease => 6}}

  if (6 < 7)
    it { should contain_file('/etc/loginfile').with_ensure('present')}

    it { should contain_file_line('testfile').with(
      :path   => '/etc/loginfile',
      :line   => 'abc 022',
      :match  => '^abc.*$'
    )}
  end
end

When I run rake-spec command getting below error

 login
     Failure/Error: it { should contain_class('login')}
     Puppet::Error:
       Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type file_line at /etc/puppetlabs/modulename/login/spec/fixtures/modules/login_defs/manifests/init.pp:17 on node 
     # ./spec/classes/login_spec.rb:5

rspec will not support file_line resporce?

Becase if I remove "file_line" resource and run rsepc file its working

1

There are 1 best solutions below

0
On

file_line is in puppetlabs-stdlib, so you need to include that into your test fixture.

Easiest way is in .fixtures.yml:

fixtures:
  repositories:
    stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib"